Typst Typesetting
Typst is a modern typesetting system designed as a faster, more ergonomic alternative to LaTeX. It uses a markup syntax with scripting capabilities.
Related skills:
/typst-touying - Slide presentations with animations and themes
/typst-cetz - Diagrams, flowcharts, plots (TikZ-style drawing)
When to use this skill
- Writing new Typst documents (
.typ files)
- Creating or modifying document templates
- Typesetting math, tables, figures, or bibliographies
- Integrating Typst with Quarto (
.qmd → Typst output)
- Debugging Typst compilation errors
- Styling pages, headings, or custom environments
When NOT to use this skill
- Slide presentations with animations → use
/typst-touying
- Diagrams or flowcharts → use
/typst-cetz
- LaTeX documents (different system entirely)
- Quarto HTML/PDF output that does not use Typst backend
- Tables generated by R's tinytable package → use
/write-tinytable
Instructions
Step 1: Classify the request
| Category |
Reference file |
Trigger |
| Math |
math-typesetting.md |
Equations, symbols, alignment, display math, numbering |
| Tables & figures |
tables-figures.md |
#table, #figure, #image, grids, cross-references |
| Quarto |
quarto-integration.md |
.qmd files, YAML frontmatter, raw Typst blocks, Quarto metadata |
| Citations |
citations-bibliography.md |
@key, #cite, #bibliography, CSL styles, supplements |
| Layout & styling |
page-layout-styling.md |
#set, #show, page setup, headers/footers, colors, custom functions |
Step 2: Read the reference file(s)
Use the Read tool to load the relevant reference. For requests that span multiple categories (e.g., "create a document with math and a bibliography"), read multiple files.
Step 3: Verify with Context7
When unsure about Typst syntax or function signatures, use Context7 to check the latest docs:
- Typst docs: library ID
/websites/typst_app (1300+ snippets)
- Quarto Typst format: library ID
/websites/quarto
Step 4: Apply core principles
- Use
#set rules for global defaults - avoid inline styling
- Use
#show rules for transformations - customize heading/link/code appearance
- Use relative units (
1fr, %) over hard-coded sizes
- Use labels and cross-references (
<label> + @label) over manual numbering
- Keep templates modular - separate layout from content
Step 5: Write the code
Follow the quick reference and anti-patterns below. When in doubt, consult the reference files.
Quick reference
Core syntax
// Markup
*bold* _italic_ `code`
#link("https://example.com")[Link text]
= Heading 1
== Heading 2
- Bullet
+ Numbered
/ Term: Definition
Set and show rules
// Set rules: global defaults
#set text(font: "New Computer Modern", size: 11pt)
#set par(justify: true)
#set page(margin: 2.5cm)
// Show rules: transform content
#show heading.where(level: 1): it => {
pagebreak(weak: true)
text(size: 18pt, weight: "bold", it.body)
}
Custom functions
#let note(body) = {
block(fill: luma(230), inset: 8pt, radius: 4pt, body)
}
Variables and logic
#let draft = true
#if draft [#text(fill: red)[DRAFT]]
#for x in (1, 2, 3) [Item #x. ]
Anti-patterns
| Avoid |
Prefer |
Reason |
| Inline styles everywhere |
#set rules |
Consistent, maintainable |
| Hard-coded sizes |
Relative units (1fr, %) |
Responsive layout |
| Manual numbering |
#counter() and @label |
Automatic updates |
\n for line breaks |
Blank line or \ |
More readable |
@key for narrative citations |
#cite(<key>, form: "prose") |
Correct rendering |
| Repeating styles per element |
#show rules |
Single source of truth |
Complete workflow example
// Document setup
#set text(font: "New Computer Modern", size: 11pt)
#set par(justify: true, leading: 0.65em)
#set page(paper: "a4", margin: (x: 2.5cm, y: 3cm))
#set heading(numbering: "1.1")
// Custom environments
#let abstract(body) = {
align(center)[*Abstract*]
pad(x: 2em, body)
}
// Title
#align(center)[
#text(size: 18pt, weight: "bold")[Document Title]
#v(0.5em)
Author Name \
#text(size: 9pt, fill: luma(100))[March 2026]
]
#abstract[
This paper examines...
]
= Introduction
We study the effect of $X$ on $Y$ using a difference-in-differences design.
= Data
#figure(
table(
columns: (auto, 1fr, 1fr),
stroke: none,
inset: (x: 10pt, y: 5pt),
table.hline(stroke: 1.5pt),
table.header([*Variable*], [*Mean*], [*SD*]),
table.hline(stroke: 0.5pt),
[Age], [34.2], [12.1],
[Income], [52,100], [18,400],
table.hline(stroke: 1.5pt),
),
caption: [Summary statistics.],
kind: table,
) <tbl-summary>
As shown in @tbl-summary, the sample includes...
= Results
Our main specification yields $beta = 0.42$ (SE = 0.08), significant at the 1% level.
$ Y_(i t) = alpha + beta D_(i t) + gamma_i + delta_t + epsilon_(i t) $ <eq-main>
@eq-main includes unit and time fixed effects.
#cite(<atz2022>, form: "prose") finds similar results in a related context.
#bibliography("references.bib", style: "apa")
Debugging tips
- Compilation errors: Check for unmatched brackets
[], (), {}
- Layout issues: Use
#box(stroke: red, [...]) to visualize bounds
- Math errors: Display math needs spaces inside
$: $ x^2 $ not $x^2$
- Missing content: Ensure content blocks
[] are properly closed
- Type errors: Use
#type(value) to inspect types at compile time
Resources
1---2name: typst3description: Modern Typst typesetting patterns for documents, slides, and academic writing. Use this skill when writing Typst markup (.typ files), creating document templates, building slide decks with Quarto, or debugging Typst compilation issues. Covers content blocks, styling, math typesetting, tables, figures, custom functions, citations, and Quarto integration. Also use when the user mentions #set rules, #show rules, Typst page layout, Typst math mode, or wants to convert LaTeX to Typst. Trigger even for brief Typst questions like formatting a table or equation.4license: CC-BY-4.05---67# Typst Typesetting89Typst is a modern typesetting system designed as a faster, more ergonomic alternative to LaTeX. It uses a markup syntax with scripting capabilities.1011**Related skills:**12- `/typst-touying` - Slide presentations with animations and themes13- `/typst-cetz` - Diagrams, flowcharts, plots (TikZ-style drawing)1415## When to use this skill1617- Writing new Typst documents (`.typ` files)18- Creating or modifying document templates19- Typesetting math, tables, figures, or bibliographies20- Integrating Typst with Quarto (`.qmd` → Typst output)21- Debugging Typst compilation errors22- Styling pages, headings, or custom environments2324## When NOT to use this skill2526- Slide presentations with animations → use `/typst-touying`27- Diagrams or flowcharts → use `/typst-cetz`28- LaTeX documents (different system entirely)29- Quarto HTML/PDF output that does not use Typst backend30- Tables generated by R's tinytable package → use `/write-tinytable`3132## Instructions3334### Step 1: Classify the request3536| Category | Reference file | Trigger |37|----------|---------------|---------|38| **Math** | [math-typesetting.md](references/math-typesetting.md) | Equations, symbols, alignment, display math, numbering |39| **Tables & figures** | [tables-figures.md](references/tables-figures.md) | `#table`, `#figure`, `#image`, grids, cross-references |40| **Quarto** | [quarto-integration.md](references/quarto-integration.md) | `.qmd` files, YAML frontmatter, raw Typst blocks, Quarto metadata |41| **Citations** | [citations-bibliography.md](references/citations-bibliography.md) | `@key`, `#cite`, `#bibliography`, CSL styles, supplements |42| **Layout & styling** | [page-layout-styling.md](references/page-layout-styling.md) | `#set`, `#show`, page setup, headers/footers, colors, custom functions |4344### Step 2: Read the reference file(s)4546Use the Read tool to load the relevant reference. For requests that span multiple categories (e.g., "create a document with math and a bibliography"), read multiple files.4748### Step 3: Verify with Context74950When unsure about Typst syntax or function signatures, use Context7 to check the latest docs:5152- **Typst docs**: library ID `/websites/typst_app` (1300+ snippets)53- **Quarto Typst format**: library ID `/websites/quarto`5455### Step 4: Apply core principles56571. **Use `#set` rules for global defaults** - avoid inline styling582. **Use `#show` rules for transformations** - customize heading/link/code appearance593. **Use relative units** (`1fr`, `%`) over hard-coded sizes604. **Use labels and cross-references** (`<label>` + `@label`) over manual numbering615. **Keep templates modular** - separate layout from content6263### Step 5: Write the code6465Follow the quick reference and anti-patterns below. When in doubt, consult the reference files.6667## Quick reference6869### Core syntax7071```typst72// Markup73*bold* _italic_ `code`74#link("https://example.com")[Link text]7576= Heading 177== Heading 27879- Bullet80+ Numbered81/ Term: Definition82```8384### Set and show rules8586```typst87// Set rules: global defaults88#set text(font: "New Computer Modern", size: 11pt)89#set par(justify: true)90#set page(margin: 2.5cm)9192// Show rules: transform content93#show heading.where(level: 1): it => {94 pagebreak(weak: true)95 text(size: 18pt, weight: "bold", it.body)96}97```9899### Custom functions100101```typst102#let note(body) = {103 block(fill: luma(230), inset: 8pt, radius: 4pt, body)104}105```106107### Variables and logic108109```typst110#let draft = true111#if draft [#text(fill: red)[DRAFT]]112113#for x in (1, 2, 3) [Item #x. ]114```115116## Anti-patterns117118| Avoid | Prefer | Reason |119|-------|--------|--------|120| Inline styles everywhere | `#set` rules | Consistent, maintainable |121| Hard-coded sizes | Relative units (`1fr`, `%`) | Responsive layout |122| Manual numbering | `#counter()` and `@label` | Automatic updates |123| `\n` for line breaks | Blank line or `\` | More readable |124| `@key` for narrative citations | `#cite(<key>, form: "prose")` | Correct rendering |125| Repeating styles per element | `#show` rules | Single source of truth |126127## Complete workflow example128129```typst130// Document setup131#set text(font: "New Computer Modern", size: 11pt)132#set par(justify: true, leading: 0.65em)133#set page(paper: "a4", margin: (x: 2.5cm, y: 3cm))134#set heading(numbering: "1.1")135136// Custom environments137#let abstract(body) = {138 align(center)[*Abstract*]139 pad(x: 2em, body)140}141142// Title143#align(center)[144 #text(size: 18pt, weight: "bold")[Document Title]145 #v(0.5em)146 Author Name \147 #text(size: 9pt, fill: luma(100))[March 2026]148]149150#abstract[151 This paper examines...152]153154= Introduction155156We study the effect of $X$ on $Y$ using a difference-in-differences design.157158= Data159160#figure(161 table(162 columns: (auto, 1fr, 1fr),163 stroke: none,164 inset: (x: 10pt, y: 5pt),165 table.hline(stroke: 1.5pt),166 table.header([*Variable*], [*Mean*], [*SD*]),167 table.hline(stroke: 0.5pt),168 [Age], [34.2], [12.1],169 [Income], [52,100], [18,400],170 table.hline(stroke: 1.5pt),171 ),172 caption: [Summary statistics.],173 kind: table,174) <tbl-summary>175176As shown in @tbl-summary, the sample includes...177178= Results179180Our main specification yields $beta = 0.42$ (SE = 0.08), significant at the 1% level.181182$ Y_(i t) = alpha + beta D_(i t) + gamma_i + delta_t + epsilon_(i t) $ <eq-main>183184@eq-main includes unit and time fixed effects.185186#cite(<atz2022>, form: "prose") finds similar results in a related context.187188#bibliography("references.bib", style: "apa")189```190191## Debugging tips1921931. **Compilation errors**: Check for unmatched brackets `[]`, `()`, `{}`1942. **Layout issues**: Use `#box(stroke: red, [...])` to visualize bounds1953. **Math errors**: Display math needs spaces inside `$`: `$ x^2 $` not `$x^2$`1964. **Missing content**: Ensure content blocks `[]` are properly closed1975. **Type errors**: Use `#type(value)` to inspect types at compile time198199## Resources200201- [Typst Documentation](https://typst.app/docs)202- [Typst Packages](https://typst.app/universe)203- [Quarto Typst Format](https://quarto.org/docs/output-formats/typst.html)