with one click
typst-writing-conventions
本技能文件规定了在本项目中使用 Typst 编写笔记时必须遵守的语法规范和最佳实践。
Install with Codex or Claude Copy this prompt, paste it into Codex, Claude, or another assistant, and let it review the skill page and install it for you.
Menu
本技能文件规定了在本项目中使用 Typst 编写笔记时必须遵守的语法规范和最佳实践。
Install with Codex or Claude Copy this prompt, paste it into Codex, Claude, or another assistant, and let it review the skill page and install it for you.
Based on SOC occupation classification
审查笔记目录结构的合理性,包括边界问题、内容重复、章节均衡、学习曲线等维度。当用户要求审查目录、检查章节划分是否合理、或询问某个知识点应该放在哪里时调用。
在 main.typ 中规划章节大纲,包括设计 == 二级目录和 === 三级目录,并编写 // 内容注释
根据笔记主题(如 Python、Java、数据结构等)在 main.typ 中生成注释形式的三层目录结构(Part-Chapter-Section)
根据 main.typ 中的目录草稿,为每个 Part 创建对应的章节文件并引入
本技能文件规定了如何编译验证 Typst 文件,确保修改后的笔记可以正确生成 PDF。
| name | typst-writing-conventions |
| description | 本技能文件规定了在本项目中使用 Typst 编写笔记时必须遵守的语法规范和最佳实践。 |
| 语法 | 层级 | 含义 |
|---|---|---|
#part("...") | Part | 大知识模块分组 |
= ... | Chapter(一级标题) | 完整知识单元 |
== ... | Section(二级标题) | 章内主要知识点 |
=== ... | Subsection(三级标题) | 节内细分 |
= 后必须有空格:= Title(正确)vs =Title(错误)= 直接到 ===)| 效果 | 语法 |
|---|---|
| 加粗 | *text* |
| 斜体 | _text_ |
| 行内代码 | `code` |
| 脚注 | #footnote[...] |
| 垂直间距 | #v(1cm) |
| 行内高亮 | #highlight[text] |
- item1. item / 2. item$ ... $(与文本同行)$ ... $(单独成段,前后有空行或换行)| LaTeX | Typst |
|---|---|
\mathbb{R} | bb(R) |
\mathcal{F} | cal(F) |
\mathscr{M} | scr(M) |
\to, \rightarrow | -> |
\Rightarrow | => |
\Leftrightarrow | <=> |
\infty | infinity |
\subseteq | subset |
\cup | union |
\cap | inter |
\notin | in.not |
\neq | != |
\land | and |
\lor | or |
\lnot | not |
\circ(复合) | compose |
\preceq | prec.eq |
\oplus(对称差) | plus.o |
\forall | forall |
\exists | exists |
\partial | partial |
\mathrm{d}x | dif x |
\liminf | liminf |
\limsup | limsup |
\sup | sup |
\inf | inf |
\overline{X} | overline(X) |
\chi_A(特征函数) | chi_A |
\backslash | backslash |
新增映射(根据实际写作经验):
| LaTeX | Typst | 说明 |
|---|---|---|
\sim | tilde | 波浪号,如 $epsilon tilde "Normal"(0,1)$ |
\ll | lt.lt | 远小于 |
\gg | gt.gt | 远大于 |
\pm | plus.minus | 加减号,如 $plus.minus 1$ |
\leftarrow | arrow(l) | 左箭头,如 $w arrow(l) w + eta x$ |
\rightarrow | -> 或 arrow(r) | 右箭头 |
\uparrow | arrow(u) | 上箭头,如 $lambda arrow(u)$ |
\downarrow | arrow(d) | 下箭头 |
\prod | product | 乘积符号,如 $product_(i) P(y_i)$ |
\implies | => | 推出符号,如 $lambda => ...$ |
\Rightarrow | => | 右双箭头 |
\to | -> | 到符号 |
$in.not$,不要写 $notin$$subset$$->$、$<=>$,不保留 LaTeX 宏名$!=$(注意空格:$!= $ 或 $a != b$)$compose$dif x、dif tdot(x)、dot.double(x)、dot.triple(x)$gt.gt$、$lt.lt$,不要用 >> 或 \gg$plus.minus$,不要用 pm 或 \pmarrow(l)、arrow(r)、arrow(u)、arrow(d),不要用 larr、uparrowproduct,不要用 prodTypst 不支持 $_x$,下标 _ 前必须有主体。
// 错误
$_x$
// 正确:空主体下标
$""_x$
Typst 将连续字母识别为内置函数名(如 sin、exp),导致编译错误。
// 正体多字母变量:用引号包裹
$"ext"$, $"const"$, $"max"$
// 斜体多字母变量:用空格分开
$e x t$
// 示例
$bold(F)_i^("ext")$ // 外力
独立数学公式的句号等标点必须写在数学环境内部:
// 错误
$
G(a_n; x) = sum_(n=0)^infinity a_n x^n
$.
// 正确
$
G(a_n; x) = sum_(n=0)^infinity a_n x^n.
$
如果原内容是 display math,不要擅自改写成行内数学。
Typst 自动缩放普通括号,通常不需要 LaTeX 的 \left/\right。需要长竖线时使用 lr(...)。
| 类型 | 前缀 | 示例 |
|---|---|---|
| 图片 | fig: | <fig:example> |
| 定理 | thm: | <thm:mvt> |
| 定义 | def: | <def:continuous> |
| 章节 | sec: | <sec:intro> |
@fig:example#link(<label>)[显示文本]#definition(name: "Continuous Function")[
A function $f: X -> Y$ is continuous if...
] <def:continuous>
Later, we refer to *#link(<def:continuous>)[Continuous Function]*.
#figure(
image("img/example.png", width: 60%),
caption: [This is an example figure.],
placement: auto,
supplement: [Fig.]
) <fig:example>
img/ 目录下表格单元格中如果包含数学公式,必须使用中括号 [...] 包裹,不能使用引号 "..."。
// 正确:数学公式用中括号
#tex-table(
("Translational", "Rotational"),
([Position $x$], [Angle $theta$]),
([Velocity $v = dot(x)$], [Angular velocity $omega = dot(theta)$]),
)
// 错误:引号内数学公式不会渲染
#tex-table(
("Translational", "Rotational"),
("Position $x$", "Angle $theta$"),
)
纯文本单元格可以使用引号。
@citation_key#footnote[...]#bibliography("references.bib")默认公式不编号。需要编号时使用模板提供的 #eq() 包装器:
#eq[$
E = m c^2
$]
编号格式为 (章号.公式序号),如 (1.1)。
使用 @preview/xarrow:0.4.0 包实现带标注的收敛箭头:
#import "@preview/xarrow:0.4.0": xarrow
// 几乎处处收敛
$f_n xarrow("a.e.") f$
// 依测度收敛
$f_n xarrow(mu) f$
// 几乎一致收敛
$f_n xarrow("a.u.") f$
// L^p 范数收敛
$f_n xarrow(L^p) f$
// 基本积分
$integral_X f dif mu$
// 集合上的积分
$integral_A f dif mu$
$integral_(E_n) f dif mu$
// 集合描述作为积分下标(注意花括号)
$integral_({|f| > M}) |f| dif mu$
$integral_({x in X : f(x) >= epsilon}) f dif mu$
// 上确界/下确界带下标
$sup_(s <= f) integral_X s dif mu$
$liminf_(n->infinity) integral_X f_n dif mu$
每个笔记文件/章节只负责自己领域的内容,不重复其他笔记已有的定义和定理:
#note 提示读者参阅#link 或正文说明指向已有内容,避免信息冗余示例:在实分析笔记的"与 Riemann 积分的关系"一节中:
// 注释形式附在标题后:== Section Title // 中文标题name 参数使用英文*Step N*: 标记关键步骤#proof 组件自动添加 ■ 符号,不需要手动写 QED典型的定理展开模式(按需选用):
#theorem(name: "...")[...]
#proof[...]
#corollary[...] // 直接推论
#example[...] // 说明性例子或反例
#note[...] // 与其他定理的对比、适用场景说明
#note:概念对比、适用条件说明、与其他定理的关系#caution:容易出错的地方、条件不能省略的警告#example:反例(说明条件不可去掉)、典型应用${x in X : P(x)}$(使用冒号 : 而非竖线)$L^1 (X, mu)$(空格分隔参数)$chi_A$ 或 $chi_(A)$a.e.,公式中写 "a.e."$integral_X f dif mu$$integral_A f dif mu$、$integral_(E_n) f dif mu$$integral_({|f| > M}) |f| dif mu$(注意花括号内的集合描述)typst compile 验证)chapters/*.typ)开头需要 #import 模板(因为它们可能被独立引用)tilde(非 sim)、arrow(l)(非 larr)、gt.gt(非 >>)、plus.minus(非 pm)、product(非 prod)"RSS"、"Normal"、"en"\alpha 等宏名在 Typst 中直接写 alpha,无反斜杠=== 内 1-2 个 Callout,过多则冗余**粗体** 在普通文本与数学公式交界处:**调整 $R^2$** 会导致 warning,应改为 *调整 $R^2$*