跳到主要内容

Typst

安装

  • Linux: View Typst on Repology
  • macOS: brew install typst
  • Windows: winget install --id Typst.Typst

编辑器

语法

三种语法模式:Markup、math 和 code

New modeSyntaxExample
CodePrefix the code with #Number: #(1 + 2)
MathSurround equation with $..$$-x$ is the opposite of $x$
MarkupSurround markup with [..]let name = [*Typst!*]

https://typst.app/docs/guides/guide-for-latex-users/

Markup

NameExampleSee
Paragraph breakBlank lineparbreak
Strong emphasis*strong*strong
Emphasis_emphasis_emph
Raw text`print(1)`raw
Linkhttps://typst.app/link
Label<intro>label
Reference@introref
Heading= Headingheading
Bullet list- itemlist
Numbered list+ itemenum
Term list/ Term: descriptionterms
Math$x^2$Math
Line break\linebreak
Smart quote'single' or "double"smartquote
Symbol shorthand~, ---Symbols
Code expression#rect(width: 1cm)Scripting
Character escapeTweet at us \#adBelow
Comment/* block */, // lineBelow

Math mode

NameExampleSee
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

NameExampleSee
Nonenonenone
Autoautoauto
Booleanfalse, truebool
Integer10, 0xffint
Floating-point number3.14, 1e5float
Length2pt, 3mm, 1em, ..length
Angle90deg, 1radangle
Fraction2frfraction
Ratio50%ratio
String"hello"str
Label<intro>label
Math$x^2$Math
Raw text`print(1)`raw
Variable accessxScripting
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-xScripting
Binary operatorx + yScripting
Assignmentx = 1Scripting
Field accessx.yScripting
Method callx.flatten()Scripting
Function callmin(x, y)Function
Argument spreadingmin(..nums)Arguments
Unnamed function(x, y) => x + yFunction
Let bindinglet x = 1Scripting
Named functionlet f(x) = 2 * xFunction
Set ruleset text(14pt)Styling
Set-if ruleset text(..) if ..Styling
Show-set ruleshow par: set block(..)Styling
Show rule with functionshow raw: it => {..}Styling
Show-everything ruleshow: columns.with(2)Styling
Context expressioncontext text.langContext
Conditionalif x == 1 {..} else {..}Scripting
For loopfor x in (1, 2, 3) {..}Scripting
While loopwhile x < 10 {..}Scripting
Loop control flowbreak, continueScripting
Return from functionreturn xFunction
Include moduleinclude "bar.typ"Scripting
Import moduleimport "bar.typ"Scripting
Import items from moduleimport "bar.typ": a, b, cScripting
Comment/* block */, // lineBelow

样式

  • 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