typst

Use when user asks to create PDF, write documents, generate reports, typeset papers, create presentations, make resumes, invoices, letters, or any document generation task.

Typst Document Generation Skill

You are an expert Typst typesetter. Generate professional PDF, PNG, SVG, or HTML documents using Typst.

Quick Reference

TaskCode / Command
Compile to PDFtypst compile doc.typ
Compile to PNGtypst compile doc.typ --format png --ppi 300
Compile & opentypst compile doc.typ --open
Set page#set page(paper: "a4", margin: 2.5cm)
Set font#set text(font: "Linux Libertine", size: 11pt)
CJK font#set text(lang: "zh", font: ("Source Han Serif SC", "SimSun", "Microsoft YaHei"))
Heading= Title / == Subtitle / === Sub-subtitle
Math$ integral_0^infinity e^(-x^2) dif x = sqrt(pi) / 2 $
Import package#import "@preview/cetz:0.3.4": canvas, draw
Load data#let data = json("data.json") or csv("data.csv")
Evaluate expressiontypst eval "1 + 2"
Conditional format#if target() == "html" { ... } else { ... }
List fontstypst fonts

Workflow

1. Verify Typst is available

typst --version

If not installed, instruct the user:

  • Windows: winget install --id Typst.Typst
  • macOS: brew install typst
  • Any platform: cargo install typst-cli

2. Create the .typ source file

  • Choose a template from references/typst-templates.md
  • Consult references/typst-language-reference.md for syntax
  • For advanced layouts, see references/typst-design-patterns.md
  • Write the .typ file to the user's desired location

3. Compile to output

typst compile document.typ                          # PDF (default)
typst compile document.typ --format png --ppi 300   # High-res PNG
typst compile document.typ output.svg               # SVG

See references/typst-cli-reference.md for all options.

4. Iterate

Read compilation errors, fix the .typ file, and recompile.

Gotchas / Common Mistakes

MistakeFix
CJK glyphs missing or tofu (□)MUST set lang AND provide a CJK font fallback chain: #set text(lang: "zh", font: ("Source Han Serif SC", "SimSun"))
Windows path errors in #image() / #include()Use forward slashes: image("images/photo.jpg"), not backslashes
Font not foundRun typst fonts to list available fonts; bundle custom fonts with --font-path ./fonts
context errors in Typst v0.14+Accessing counter(), state(), or text.fill requires wrapping in a context block
show rules leaking to other sectionsWrap scoped show rules in a block { ... } to limit their effect
Multi-page PNG/SVG produces single fileUse {p} placeholder in output: typst compile doc.typ "page-{p}.png"
Package download failsFirst compile with a new @preview package requires internet; check --package-cache-path
Paragraph spacing looks wrongSet #set par(justify: true, leading: 0.8em) explicitly; defaults may vary
Math script styles not workingUse scr(), cal(), frak(), bb() — not LaTeX \mathscr, \mathcal

When NOT to use

  • Existing LaTeX projects — use LaTeX directly for .tex files
  • Simple plain-text documents — Markdown is simpler
  • Spreadsheet / tabular data output — use CSV or Excel tools
  • Interactive web pages — use HTML/CSS directly (Typst HTML export available via --features html but limited)

Reference Documentation

Read these files on demand (not all at once):

ReferencePathContent
CLI Referencereferences/typst-cli-reference.mdAll CLI commands, options, environment variables
Language Referencereferences/typst-language-reference.mdComplete syntax, functions, and features
Templatesreferences/typst-templates.mdReady-to-use templates (general, CJK, academic, resume, letter, report, slides, invoice)
Design Patternsreferences/typst-design-patterns.mdAdvanced patterns (themes, layouts, components, PDF capabilities)

Output Formats

FormatExtensionNotes
PDF.pdfDefault. Supports PDF/A standards and tagged PDF.
PNG.pngOne image per page. Use --ppi for resolution (default 144).
SVG.svgOne file per page. Vector graphics.
HTML.htmlExperimental. Use --features html.