Typst
- Markup-based typesetting system
Modes
| Mode | How to enter |
|---|---|
| Markup | [ ... ] |
| Code | #... |
| Math | $ ... $ |
Markup
- Heading:
== h2 - Bold:
*text* - Italic:
_text_ - List:
- Ordered:
+ text - Unordered:
- text - Ident to nest
- Ordered:
- Label
- Declare:
<label-name> - Reference:
@label-name
- Declare:
- Line break:
\ - Space:
~ - Comment:
//,/* */
Math
- Inline:
$a$, block:$ a $ - Raw text:
"start time" + "duration" - Symbols:
nebula,arrow.squiggly - Function:
vec(1,2,3) - Fraction:
1/2 - Sub-expression:
e^(a+b), Parentheses are smartly resolved
Code
Data Types
- None:
none, Auto:auto - Boolean, Integer, Float, String
- Length:
32pt, Angle:90deg - Fraction:
2fr, Ratio:30% - Array:
(1, 2, 3), Dictionary:(a: 1, b: "hi") - Content, Selector, Label
- Function
- ...
Function
- Pure except some builtin ones.
- Params: positional or settable(keyword).
- Definition:
typst
#let alert(body, fill: red) = {
set align(center)
rect(
fill: fill,
[*Warning:\ #body*],
)
}- Anonymous function:
it => [#it #it] - Set default values:
#set fn(param=default_value) - Syntax sugar for content argument:
#fn(args)[content]=#fn(args, content)
Modules and Packages
- Include:
#include "bar.typ" - Import:
#import "bar.typ" as baz,#import "bar.typ": a as b - From value:
#import emoji: face - From package:
#import "@preview/example:0.1.0": add
Show Rules
typst
#show heading: it => [
#set align(center)
#block(smallcaps(it.body))
]
#show: wrapper
paragraph...Context
- Context-aware:
typst
#let value = context text.lang
#value // "en"
#set text(lang: "de")
#value // "de"- Context is fixed for each block:
typst
#let c = counter("mycounter")
#c.update(1)
#context [
#c.update(2)
#c.display() \ // 1
#context c.display() // 2
]- Compiler iterates to resolve contextual interactions. (Max 5 attempts).
meow
- The output document can be used like a console:
#type( ... ). - Love the 3 contexts design.