Typst
安装
- Linux: View Typst on Repology
- macOS: brew install typst
- Windows: winget install --id Typst.Typst
编辑器
- VSCode: https://github.com/Myriad-Dreamin/tinymist
- Obsidian: https://github.com/fenjalien/obsidian-typst
语法
三种语法模式:Markup、math 和 code
| New mode | Syntax | Example |
|---|---|---|
| Code | Prefix the code with # | Number: #(1 + 2) |
| Math | Surround equation with $..$ | $-x$ is the opposite of $x$ |
| Markup | Surround markup with [..] | let name = [*Typst!*] |
https://typst.app/docs/guides/guide-for-latex-users/
Markup
| Name | Example | See |
|---|---|---|
| Paragraph break | Blank line | parbreak |
| Strong emphasis | *strong* | strong |
| Emphasis | _emphasis_ | emph |
| Raw text | `print(1)` | raw |
| Link | https://typst.app/ | link |
| Label | <intro> | label |
| Reference | @intro | ref |
| Heading | = Heading | heading |
| Bullet list | - item | list |
| Numbered list | + item | enum |
| Term list | / Term: description | terms |
| Math | $x^2$ | Math |
| Line break | \ | linebreak |
| Smart quote | 'single' or "double" | smartquote |
| Symbol shorthand | ~, --- | Symbols |
| Code expression | #rect(width: 1cm) | Scripting |
| Character escape | Tweet at us \#ad | Below |
| Comment | /* block */, // line | Below |
Math mode
| Name | Example | See |
|---|---|---|
| Inline math | $x^2$ | Math |
| Block-level math | $ x^2 $ | Math |
| Bottom attachment | $x_1$ | attach |
| Top attachment | $x^2$ | attach |
| Fraction | $1 + (a+b)/5$ | frac |
| Line break | $x \ y$ | linebreak |
| Alignment point | $x &= 2 \ &= 3$ | Math |
| Variable access | $#x$, $pi$ | Math |
| Field access | $arrow.r.long$ | Scripting |
| Implied multiplication | $x y$ | Math |
| Symbol shorthand | $->$, $!=$ | Symbols |
| Text/string in math | $a "is natural"$ | Math |
| Math function call | $floor(x)$ | Math |
| Code expression | $#rect(width: 1cm)$ | Scripting |
| Character escape | $x\^2$ | Below |
| Comment | $/* comment */$ | Below |
Code mode
| Name | Example | See |
|---|---|---|
| None | none | none |
| Auto | auto | auto |
| Boolean | false, true | bool |
| Integer | 10, 0xff | int |
| Floating-point number | 3.14, 1e5 | float |
| Length | 2pt, 3mm, 1em, .. | length |
| Angle | 90deg, 1rad | angle |
| Fraction | 2fr | fraction |
| Ratio | 50% | ratio |
| String | "hello" | str |
| Label | <intro> | label |
| Math | $x^2$ | Math |
| Raw text | `print(1)` | raw |
| Variable access | x | Scripting |
| Code block | { let x = 1; x + 2 } | Scripting |
| Content block | [*Hello*] | Scripting |
| Parenthesized expression | (1 + 2) | Scripting |
| Array | (1, 2, 3) | Array |
| Dictionary | (a: "hi", b: 2) | Dictionary |
| Unary operator | -x | Scripting |
| Binary operator | x + y | Scripting |
| Assignment | x = 1 | Scripting |
| Field access | x.y | Scripting |
| Method call | x.flatten() | Scripting |
| Function call | min(x, y) | Function |
| Argument spreading | min(..nums) | Arguments |
| Unnamed function | (x, y) => x + y | Function |
| Let binding | let x = 1 | Scripting |
| Named function | let f(x) = 2 * x | Function |
| Set rule | set text(14pt) | Styling |
| Set-if rule | set text(..) if .. | Styling |
| Show-set rule | show par: set block(..) | Styling |
| Show rule with function | show raw: it => {..} | Styling |
| Show-everything rule | show: columns.with(2) | Styling |
| Context expression | context text.lang | Context |
| Conditional | if x == 1 {..} else {..} | Scripting |
| For loop | for x in (1, 2, 3) {..} | Scripting |
| While loop | while x < 10 {..} | Scripting |
| Loop control flow | break, continue | Scripting |
| Return from function | return x | Function |
| Include module | include "bar.typ" | Scripting |
| Import module | import "bar.typ" | Scripting |
| Import items from module | import "bar.typ": a, b, c | Scripting |
| Comment | /* block */, // line | Below |
样式
- set
- text
- page
- par
- heading
- document
- show
https://typst.app/docs/guides/page-setup-guide/
脚本
- 表达式
- 块
- 代码块
- 内容块
模板
示例
#set text(
font: "Menlo",
size: 20pt
)
= heading 1
+ The climate
- Temperature
- Precipitation
+ The topography
+ The geology