Compile and watch
typst compile <file.typ>
Compile to a PDF next to the source
Add an output path as a second argument; the extension picks
the format.
typst watch <file.typ>
Recompile on every change
typst init @preview/<template>
New project from a template
Append :<version> to pin one; the directory defaults to
the template name.
typst compile <file.typ> <out>.png
Export to PNG or SVG
Several pages need a {p} or {0p} placeholder in the output
name.
typst compile <file.typ> --pages 2-4
Export only some pages
typst compile --input <key>=<value>
<file.typ>
Pass a value into the document
Read it in the document with sys.inputs.<key>.
typst compile --root <dir> <file.typ>
Set the root for absolute paths
typst compile --font-path <dir>
<file.typ>
Add a font directory
typst fonts
List fonts Typst can use
typst --version
Show the installed version
typst fonts --variants
List fonts with their style variants
typst compile - <out>.pdf
Read the source from stdin
typst compile --ppi <n> <file.typ>
<out>.png
PNG resolution (default 144)
typst compile --pdf-standard a-2b <file.typ>
Archival PDF/A output
typst compile --deps <file> --deps-format make
<file.typ>
Write a dependency list for make
typst eval '<expr>' --in
<file.typ>
Evaluate code in the document's context
Replaces the deprecated typst query; query(<label>)
returns labelled elements as JSON.
typst update
Update the typst binary itself
Let, set, show
#let <name> = <value>
Define a variable
#let <f>(<a>, <b>: 1) =
[<body>]
Define a function
#set text(font: "<name>", size: 11pt)
Font and size from here on
#set page(paper: "a4", margin: 2cm)
Paper size and margins
#set page(numbering: "1")
Number the pages
#set par(justify: true, leading: 0.65em)
Justify and line spacing
#set heading(numbering: "1.1")
Number headings
#set text(lang: "de")
Language for hyphenation
#show heading: set text(blue)
Restyle every heading
#show: <template>.with(<args>)
Apply a template to the document
#set document(title: "<t>", author:
"<a>")
PDF metadata
#show "<word>": it => <expr>
Rewrite every match of a text
#show regex("<re>"): set text(red)
Style text by regex
#show heading.where(level: 1): it => <expr>
Rule for a subset
#set text(fill: rgb("#<hex>"))
Colour from a hex value
#image("<path>", width: 50%)
Insert an image
PNG, JPG, GIF, SVG and PDF are supported.
#figure(<content>, caption: [<text>])
Numbered figure with caption
#table(columns: 3, [<a>], [<b>],
[<c>])
Table; cells fill row by row
<label>
Attach a label to the element before it
@<label>
Reference a label
#grid(columns: (1fr, 1fr), gutter: 1em, ..)
Grid layout
#columns(2)[<content>]
Split into columns
#outline()
Table of contents
#bibliography("<file.bib>")
Bibliography from BibTeX or Hayagriva
@<key>
Cite a bibliography entry
#block(fill: luma(240), inset: 8pt)[<c>]
Shaded box
#table.header([<a>], [<b>])
Header row repeated on each page
#table.cell(colspan: 2)[<c>]
Cell spanning columns
#context counter(page).display()
Current page number
Context-dependent values need #context.
#set page(footer: context [..])
Page footer
Code and packages
#import "@preview/<pkg>:<ver>":
<name>
Use a package from Typst Universe
Downloaded and cached on first compile.
#import "<file.typ>": <name>
Import from a local file
#include "<file.typ>"
Insert another file's content
#for <x> in (1, 2, 3) [<body>]
Loop
#if <cond> [<a>] else [<b>]
Conditional
#(<a> + <b>)
Evaluate an expression
#{ <stmt>; <stmt> }
Code block with several statements
#let (<a>, <b>) = (1, 2)
Destructuring
(<k>: <v>)
Dictionary literal
#read("<file>")
Read a file as a string
#json("<file>") /
#csv("<file>")
Load structured data
#sys.inputs.at("<key>", default: none)
Read a --input value safely
#datetime.today().display()
Today's date