= 一级标题 == 二级标题 这是普通文本,支持 *强调* 和 _斜体_。 行内代码:`let x = 1` #strong[加粗内容] #emph[强调内容]
let x = 1- 无序项 A - 无序项 B - 子项 + 有序项 1 + 有序项 2 - [ ] 待办 - [x] 已完成
#let name = "Typst" #let square(x) = x * x 你好,#name! 9 的平方是 #square(9)。 #for i in range(1, 4) [ 第 #i 行 ]
#let score = 92 #if score >= 90 [ 等级:A ] else if score >= 80 [ 等级:B ] else [ 等级:C ]
行内公式:$a^2 + b^2 = c^2$ 块公式: $ sum_(i=1)^n i = (n(n+1))/2 $ $ integral_0^1 x^2 dif x = 1/3 $
// 公式编号与样式
#set math.equation(numbering: "(1)")
#show math.equation: set text(size: 11pt)
// 多行对齐(& 对齐点,\ 换行)
$ x &= y + z \
&= t $
// 分段函数
$ f(x) = cases(
x^2, x >= 0;
-x, x < 0;
) $
// 矩阵
$ A = mat(
1, 2;
3, 4;
) $
// 重音与标注
$ hat(x), bar(y), vec(v) $
$ overbrace(a + b, "sum") $
// 编号与引用
$ e^(i pi) + 1 = 0 $ <eq:euler>
见式 @eq:euler。
#table( columns: (1fr, 1fr, 1fr), align: center, [Name], [Score], [Grade], [Alice], [95], [A], [Bob], [82], [B], )
| Name | Score | Grade |
|---|---|---|
| Alice | 95 | A |
| Bob | 82 | B |
#figure(
image("demo.png", width: 70%),
caption: [示例图片]
) <fig:demo>
如图 @fig:demo 所示。
#set page( paper: "a4", margin: 2cm, ) #set text( font: "Noto Serif CJK SC", size: 11pt, ) #set heading(numbering: "1.")
#let badge(text, color: blue) = [
#set text(fill: color, weight: "bold")
[#text]
]
#let callout(title, body) = [
#block(
inset: 8pt,
stroke: 1pt + gray,
radius: 4pt,
[*#title*]
#linebreak()
#body
)
]
#badge("NEW")
#badge("WARN", color: red)
#callout(
title: "提示",
body: [这是通过宏渲染的内容。]
)
// 文本与强调 #text(), #strong(), #emph(), #underline() #sub(), #super(), #smallcaps(), #link() // 页面与布局 #page(), #par(), #block(), #box(), #align() #pad(), #place(), #columns(), #stack() #grid(), #table() // 图像与图形 #figure(), #image(), #line(), #rect(), #circle() // 引用与文献 #label(), #ref(), #footnote() #bibliography(), #cite(), #outline() // 代码与计算 #range(), #len(), #type(), #assert() #calc.abs(), #calc.max(), #calc.sqrt() #rgb(), #cmyk(), #luma() // grid 示例 #grid( columns: (1fr, 1fr, 1fr), gutter: 6pt, [A], [B], [C], grid.cell(colspan: 2)[D], [E], )
| 函数 | 常见参数 | 参数含义 / 常见取值 |
|---|---|---|
text(...) |
fill, size, font, weight |
文字颜色、字号、字体、字重(如 "bold" 或数值)。 |
page(...) |
paper, margin, header, footer |
纸张尺寸(如 "a4")、页边距、页眉页脚内容。 |
block(...) |
inset, outset, stroke, fill, radius |
块内边距/外边距、边框、背景、圆角,常用于卡片/提示框。 |
align(...) |
left/center/right,以及 top/bottom |
内容对齐方式,可组合水平和垂直方向。 |
pad(...) |
x, y, left/right/top/bottom |
给内容增加留白,常用于微调布局间距。 |
grid(...) |
columns, rows, gutter, align |
网格布局核心参数:列宽/行高、间距、单元对齐。配合 grid.cell(colspan:, rowspan:) 做跨行跨列。 |
table(...) |
columns, align, stroke, inset, fill |
表格列定义、对齐、边框、单元内边距和底色。 |
image(path, ...) |
width, height, fit, alt |
图片尺寸与适配方式(如 contain/cover),alt 用于可访问性。 |
figure(body, ...) |
caption, kind, placement |
包裹图/表并带编号标题,可用于交叉引用。 |
ref(label) |
label |
引用目标标签(图、表、章节等),渲染为对应编号文本。 |
bibliography(file, ...) |
title, style |
加载文献库(如 .bib),并控制参考文献输出样式。 |
cite(key, ...) |
form, style, loc |
在正文插入引用,可调引用显示形式与附加定位。 |
range(start, end, step) |
start, end, step |
生成序列,常配合 for 循环渲染重复结构。 |
calc.*(...) |
abs/min/max/sqrt/pow/round |
数值计算函数集合;参数通常为数字或长度值。 |
rgb(...), cmyk(...), luma(...) |
颜色通道值(0~255 或 0~1) | 构造颜色对象,常传给 fill / stroke / text(fill: ...)。 |
#函数[内容] 或 #set/#show 组合扩展。