Typst Cheatsheet

This is a comprehensive cheatsheet covering Typst syntax, models, text, and math, styled for the web.


1. Headings

Typst uses = for headings. The number of = determines the heading level (H1 to H6).

= H1
== H2
=== H3
==== H4
===== H5

2. H1

2.1. H2

2.1.1. H3

2.1.1.1. H4
2.1.1.1.1. H5

3. Text & Formatting

Typst provides granular control over text styling, including capitalization, decorations, and styling.

Emphasis: _Italics_ and *Bold*.

Combined: *Bold and _Italic_*.

Raw Text: `print("code")`.

Highlight: #highlight[Highlighted].

Underline: #underline[Underlined].

Overline: #overline[Overlined].

Strikethrough: #strike[Strikethrough].

Subscript/Superscript: H#sub[2]O, E = mc#super[2].

Small Capitals: #smallcaps[Small Caps].

Lowercase: #lower("LOWERCASE").

Uppercase: #upper("uppercase").

Smartquote: "Smart" and 'Quotes'.

Line Break: Text \ breaks here.

Lorem: #lorem(5)

Emphasis: Italics and Bold.

Combined: Bold and Italic.

Raw Text: print("code").

Highlight: Highlighted.

Underline: Underlined.

Overline: Overlined.

Strikethrough: Strikethrough.

Subscript/Superscript: H2O, E = mc2.

Small Capitals: Small Caps.

Lowercase: lowercase.

Uppercase: UPPERCASE.

Smartquote: “Smart” and ‘Quotes’.

Line Break: Text
breaks here.

Lorem: Lorem ipsum dolor sit amet.


4. Lists

Typst uses - for unordered lists and + for ordered lists. Definition lists use /. Lists can be nested by indenting.

- Unordered list
  - Nested item

+ Ordered list
  + Nested ordered

/ Term: Definition
  1. Ordered list

    1. Nested ordered
Term
Definition

5. Links

Use #link("url")[text] for inline links. Raw URLs are automatically linked.

#link("https://typst.app")[I'm an inline-style link]

Raw URL: https://typst.app

I’m an inline-style link

Raw URL: https://typst.app


6. Images

Use #figure wrapping our custom #h("img") element to display images with captions. (Note: standard #image() is reserved for PDF compilation).

#figure(
  h("img", src: "https://picsum.photos/480/300?random=1", alt: "A random image generated by Picsum"),
  caption: [A random image]
)

A random image generated by Picsum

Figure 1: A random image

7. Tables

The #table function creates tables.

#table(
  columns: (auto, auto, auto),
  [*Tables*], [*Are*], [*Cool*],
  [Col 1], [Col 2], [Col 3]
)
TablesAreCool
Col 1Col 2Col 3

8. Blockquotes

Use #quote(block: true) to create semantic blockquotes, optionally providing an attribution string.

#quote(block: true, attribution: "Typst Docs")[
  Typst is a new markup-based typesetting system.
]
Typst is a new markup-based typesetting system.

— Typst Docs


9. Divider

Use #divider() for horizontal lines.

#divider()

10. Math Operations

Typst has a powerful native math engine. Surround inline math with $, or use it block-level by giving it a dedicated line.

Inline Equation: $E = m c^2$

Fractions: $(a+b)/c$ or $x/y$

Roots: $sqrt(x)$ or $root(3, x)$

Primes: $f'(x)$ or $f''(x)$

Binomials: $binom(n, k)$

Vectors: $vec(1, 2, 3)$

Matrices: $mat(1, 2; 3, 4)$

Cases: $f(x) = cases(1 "if" x > 0, 0 "else")$

Block Equations:
$ sum_(k=1)^n k = (n(n+1)) / 2 $

Multi-line Block:
$ 
  f(x) = x^2 + 2x + 1 \
       = (x + 1)^2 
$

Inline Equation: 𝐸=𝑚𝑐2

Fractions: 𝑎+𝑏𝑐 or 𝑥𝑦

Roots: 𝑥 or 𝑥3

Primes: 𝑓(𝑥) or 𝑓(𝑥)

Binomials: (𝑛𝑘)

Vectors: (123)

Matrices: (1234)

Cases: 𝑓(𝑥)={1if𝑥>00else

Block Equations:

𝑘=1𝑛𝑘=𝑛(𝑛+1)2

Multi-line Block:

𝑓(𝑥)=𝑥2+2𝑥+1=(𝑥+1)2

11. Math Styling & Layout

Math supports advanced attachments, styling, alignment, and semantic grouping.

Accents: $hat(x), bar(y), diaer(u), vec(a)$

Under/Over: $underbrace(x + y, z)$ or $overbrace(a, b)$

Attach: $x_1^2$ or $scripts(sum)_1^2$

Left/Right Auto-scaling: $lr(( x / y ))$

Styles: $cal(A), frak(B), bb(C)$

Sizes: $display(x/y) != script(x/y)$

Text Operator: $op("argmax")_x f(x)$

Variants: $epsilon != epsilon.alt$

Stretch: $x stretch(=) y$

Accents: 𝑥̂,|𝑦|,𝑢̈,(𝑎)

Under/Over: 𝑥+𝑦𝑧 or 𝑎𝑏

Attach: 𝑥12 or 12

Left/Right Auto-scaling: (𝑥𝑦)

Styles: 𝒜︀,𝔅,

Sizes: 𝑥𝑦𝑥𝑦

Text Operator: argmax𝑥𝑓(𝑥)

Variants: 𝜀𝜖

Stretch: 𝑥=𝑦


12. Data Loading

Typst can natively read JSON, CSV, TOML, YAML, and XML files, allowing you to generate dynamic documents from structured data.

#let data = json("/src/assets/data.json")
*Title:* #data.title \
*First Item:* #data.items.at(0).name (#data.items.at(0).type)

Title: Typst Data Example
First Item: JSON Support (Structured)


13. Interactive Components

You can use the #h("script") hyperscript component to easily attach inline JavaScript for client-side interactivity.

#let inline-counter(id: "example-counter") = {
  h("button#" + id + ".counter", type: "button")[Count is 0]
  h("script", "
    (function() {
      let count = 0;
      const btn = document.getElementById('" + id + "');
      btn?.addEventListener('click', () => {
        btn.innerHTML = `Count is ${++count}`;
      });
    })();
  ")
}

#inline-counter()

Alternatively, you can load a Web Component using the component macro:

#let typx-counter = component("/src/components/counter.ts", "typx-counter")
#typx-counter(class: "btn counter")[Count is 0]
Count is 0

14. References & Footnotes

Citations use @. Footnotes use #footnote[]. Bibliographies are generated automatically from .bib files.

Typst is fast#footnote[Typst is written in Rust].
According to @typst, creating PDFs is easy.

#bibliography("/src/assets/works.bib")

Typst is fast1. According to [1], creating PDFs is easy.

Bibliography

  • [1] T. Team, The Typst Documentation. Typst, 2024.
  1. 1Typst is written in Rust