一键导入
typst-writing-conventions
当编辑/创建 .typ 文件时,必须使用本技能以确保符合 Typst 语法规范(如 subset→subset.eq, \sigma→sigma, integral→integral 等)、符号映射规则、文档层级结构和写作风格约定。尤其适用于新增数学公式较多的笔记时。
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
当编辑/创建 .typ 文件时,必须使用本技能以确保符合 Typst 语法规范(如 subset→subset.eq, \sigma→sigma, integral→integral 等)、符号映射规则、文档层级结构和写作风格约定。尤其适用于新增数学公式较多的笔记时。
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
根据用户说明生成物理/数学教学插图的 AI 绘图提示词。涵盖模型示意图、函数曲线图等,支持多面板组合布局。
跨文件代码审查,检查 Typst 代码的一致性、可维护性和内容职责原则遵循情况
扫描 Typst 文件中的标签(如 <def:limit-of-sequence-of-sets>),在 Appendix 的 Glossary 节中生成字母索引。
审查数学证明的逻辑完整性、符号一致性和推理严密性
本技能文件规定了 `TypstTemplate/math-notes.typ` 模板的使用方式和所有可用组件。
本技能文件规定了如何编译验证 Typst 文件,确保修改后的笔记可以正确生成 PDF。
基于 SOC 职业分类
| name | typst-writing-conventions |
| description | 当编辑/创建 .typ 文件时,必须使用本技能以确保符合 Typst 语法规范(如 subset→subset.eq, \sigma→sigma, integral→integral 等)、符号映射规则、文档层级结构和写作风格约定。尤其适用于新增数学公式较多的笔记时。 |
| user_invocable | false |
| 语法 | 层级 | 含义 |
|---|---|---|
#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 | oo |
\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 |
\int | integral |
\iint, \iiint | integral.double, integral.triple |
\oint | integral.cont(闭合环路线积分) |
\cdot | dot |
\sim | ~ 或 approx |
\text{...} | text("...")(必须用字符串引号) |
\left(, \right) | 无对应命令,Typst 自动缩放括号 |
\left[, \right] | 无对应命令,Typst 自动缩放方括号 |
$in.not$,不要写 $notin$$subset$$->$、$<=>$,不保留 LaTeX 宏名$!=$(注意空格:$!= $ 或 $a != b$)$compose$dif x、dif tdot(x)、dot.double(x)、dot.triple(x)integral,不是 int。二重/三重:integral.double、integral.tripletext() 必须用字符串参数:写 text("something"),不是 text(something)a dot b,不用 a cdot b(cdot 不存在)\left(/\right) 不存在:Typst 自动缩放括号,不需要 \left/\rightTypst 不支持 $_x$,下标 _ 前必须有主体。
// 错误
$_x$
// 正确:空主体下标
$""_x$
Typst 将连续字母识别为内置函数名(如 sin、exp),导致编译错误。
// 正体多字母变量:用引号包裹
$"ext"$, $"const"$, $"max"$
// 斜体多字母变量:用空格分开
$e x t$
// 示例
$bold(F)_i^("ext")$ // 外力
独立数学公式的句号等标点必须写在数学环境内部:
// 错误
$
G(a_n; x) = sum_(n=0)^oo a_n x^n
$.
// 正确
$
G(a_n; x) = sum_(n=0)^oo a_n x^n.
$
如果原内容是 display math,不要擅自改写成行内数学。
Typst 自动缩放普通括号,通常不需要 LaTeX 的 \left/\right。需要长竖线时使用 lr(...)。
int → integral 遗忘LaTeX 习惯用 \int,Typst 必须写 integral。int 是未知变量,会报错。
// 错误
$int_0^1 f(x) dif x$
// 正确
$integral_0^1 f(x) dif x$
// 二重积分
$integral.double_S f dif S$
// 闭合曲面积分(无 oint 符号)
$integral_(partial V) bold(E) dot dif bold(S)$
text() 字符串参数Typst 的 text() 函数必须传入字符串,未加引号的参数会被当作变量:
// 错误 — "self" 被当作变量名
$U_(text(self))$
// 正确
$U_(text("self"))$
sim/cdot 等 LaTeX 宏不存在Typst 数学模式不识别 \sim、\cdot 等 LaTeX 宏名。使用原生操作符:
| 意图 | 错误写法 | 正确写法 |
|---|---|---|
| 约等于/相似 | $a sim b$ | $a ~ b$ 或 $a approx b$ |
| 点乘 | $a cdot b$ | $a dot b$ |
| 趋向 | $x to oo$ | $x arrow oo$ 或 $x -> oo$ |
ll, gg 等比较符号不存在Typst 数学模式不识别 \ll、\gg 等 LaTeX 宏名。使用原生比较操作符:
| 意图 | 错误写法 | 正确写法 |
|---|---|---|
| 远小于 | $d \ll \sqrt(A)$ | $d << \sqrt(A)$ |
| 远大于 | $a \gg b$ | $a >> b$ |
laplacian, oint 等非标准符号不存在Typst 数学模式不识别 \laplacian、\oint 等 LaTeX 宏名。使用等价表达:
| 意图 | 错误写法 | 正确写法 |
|---|---|---|
| 拉普拉斯算子 | $\laplacian V = 0$ | $nabla^2 V = 0$ |
| 闭合环路线积分 | $\oint_sigma bold(f) dot d bold(l)$ | $integral.cont_sigma bold(f) dot d bold(l)$ |
| 闭合曲面积分 | $\oint_sigma dif a$ | $integral_(partial sigma) dif a$ 或 $integral_sigma dif a$ |
const 等多字母标识符未加引号在数学模式中使用 text() 包裹的文本参数必须加引号,否则被当作未定义变量:
| 意图 | 错误写法 | 正确写法 |
|---|---|---|
| 常数符号 | $sigma approx frac(const, R_c)$ | $sigma approx frac("const", R_c)$ |
| 文本标签 | $V_(text(self))$ | $V_(text("self"))$ |
遇到不确定的数学符号时,查阅 Typst 官方符号文档: https://typst.app/docs/reference/symbols/sym/
常见需要查阅的情况:
\laplacian 等非标准 LaTeX 宏 — Typst 不支持,需用等价表达\ll、\gg、\lll 等罕见比较符号 — 可用 <<、>>、<<< 替代\hbar、\ell 等物理/数学特殊符号 — 查阅官网确认可用名称infty → oo无限大符号是 oo(两个字母 o),不是 infty 也不是 infinity:
// 错误
$n -> infinity$
// 正确
$n -> oo$
| 类型 | 前缀 | 示例 |
|---|---|---|
| 图片 | 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->oo) integral_X f_n dif mu$
每个笔记文件/章节只负责自己领域的内容,不重复其他笔记已有的定义和定理:
#note 提示读者参阅#link 或正文说明指向已有内容,避免信息冗余示例:在实分析笔记的"与 Riemann 积分的关系"一节中:
// 注释中:== Section Title // 中文标题name 参数使用英文*Step N*: 标记关键步骤#proof 组件自动添加 ■ 符号,不需要手动写 QED典型的定理/定律展开模式(按需选用):
#theorem / #law(name: "...")[...]
#proof[...]
#corollary[...] // 直接推论
#example[...] // 说明性例子或反例
#note[...] // 对比、适用条件说明
#law,数学定理用 #theorem#proof 可用于两者之后组件不能滥用。参考项目现有内容的分工:
| 组件 | 用途 | 何时使用 | 何时不用 |
|---|---|---|---|
#definition | 定义核心概念 | 引入新术语/新量时(电场强度、电流密度、通量) | 仅仅是列举属性或计算步骤时不用 |
#law | 物理定律(实验或简单推理得出) | 库仑定律、欧姆定律、焦耳定律、基尔霍夫定律、安培定律 | 纯数学定理不用 |
#theorem | 数学定理或推论(经严格证明的命题) | 唯一性定理、叠加原理、矢势的泊松方程 | 物理定律不用 |
#property | 一组相关性质的枚举 | 只有确实在列举一组属性时用(如"电力线的性质") | 单一公式、单一解释、计算过程不用 |
#example | 带计算的工作示例 | 演示定律的应用、对称性计算 | 纯文字说明不用 |
#note | 补充说明、对比、洞察 | 概念对比、适用条件、与其他定理的关系 | 核心内容不应放进 note |
#proof | 定理或定律的推导证明 | 紧跟在 #theorem / #law 之后 | 没有明确陈述时不用单独使用 |
#caution | 易错点或警告 | 需要强调不能忽略的条件 | 日常说明不用 |
两个常见误区:
#property 当作"包装任何非定理内容"的万能工具 — 很多内容直接写成普通段落即可参考写法对比:
// ✓ 正确:核心定义用 #definition
#definition(name: "Current Density")[
The *current density* $bold(J)$ is defined as $bold(J) = n q bold(v)$.
]
// ✓ 正确:过渡段直接写纯文本
The SI unit of the electric field is newtons per coulomb ($"N/C"$).
// ✓ 正确:分类列举直接写列表(不用 #property)
- *Volume current density* $bold(J)$
- *Surface current density* $bold(K)$
- *Line current* $I$
// ✓ 正确:property 只用于确实在列举属性时
#property(name: "Properties of Electric Field Lines")[
- They originate from positive charges and terminate on negative charges.
- They never cross each other.
]
// ✗ 错误:将 #property 当作通用包装器
#property(name: "Joule Heating")[ // ← 不应使用 property
The power density is $p = bold(J) dot bold(E)$.
]
// 应改为:
#law(name: "Joule Heating")[ // ← 物理定律用 law
The power density is $p = bold(J) dot bold(E)$.
]
// 或者直接写纯文本段落:
The power dissipated per unit volume is $p = bold(J) dot bold(E)$.
#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 验证)// 注释和 == Title // 中文标题 格式)