typst-author skill
Overview
This skill helps agents generate, edit, and reason about Typst documents. It provides quick‑start examples, detailed workflows, and links to the full Typst documentation (guides, tutorials, reference).
Minimal document example
#set document(title: "My Document", author: "Author Name")
#set page(numbering: "1")
#set text(lang: "en")
// Enable paragraph justification and character-level justification
#set par(
justify: true,
justification-limits: (
tracking: (min: -0.012em, max: 0.012em),
spacing: (min: 75%, max: 120%),
)
)
#title[My Document]
= Heading 1
This is a paragraph in Typst.
== Heading 2
#lorem(50)
Workflows
- Creating a new Typst project: Use the "Minimal document example" above as a starting point. Skim the tutorial for the basics (docs/tutorial/writing-in-typst.md), then create the
.typ file(s). After each .typ edit, follow the post-edit formatting checks below when typstyle is available.
- Editing existing content: Locate the target text and apply changes; confirm syntax against the reference when needed (docs/reference/). After each modified
.typ file, follow the post-edit formatting checks below.
- Formatting & Styling: Consult the styling guide (docs/reference/styling.md) for
set rule, show rule, and custom themes.
Documentation
- Syntax & foundations:
docs/reference/syntax.md
- Styling & show/set rules:
docs/reference/styling.md
- Scripting & runtime behavior:
docs/reference/scripting.md
- Page setup & tables:
docs/guides/page-setup.md and docs/guides/tables.md
- Task-oriented authoring help:
docs/tutorial/writing-in-typst.md, docs/guides/*.md, and docs/reference/**/*.md
Detailed instructions
- PRIORITY: Trust local documentation. Your internal training data regarding Typst may be outdated or hallucinated. Always verify function names, parameters, and syntax against the local
docs/ folder before generating code.
- Read the relevant documentation using local file search and open tools on the paths above.
- Use local docs for syntax and reference questions. Verify syntax, function names, parameters, and reference behavior from the bundled docs. Run a minimal Typst probe only when runtime or evaluation behavior remains unclear after checking the docs.
- Generate or modify the
.typ source according to the user's request.
- Run the post-edit formatting checks below for every
.typ file you created or edited in that pass.
- Validate with
typst compile after the formatting decision is complete when you created or edited .typ files, or when the user explicitly asks for verification (if tool access is allowed).
- Summarize touched files and outcomes. Provide full
.typ content only when the user requests it or when direct editing is not possible, and optionally include a rendered preview (PDF/HTML).
Probing uncertain behavior
- Use a probe when the bundled docs do not settle runtime or evaluation behavior.
- Model the case with Typst scripting as described in docs/reference/scripting.md.
- When a probe is necessary, prefer a fileless probe through stdin instead of creating scratch
.typ files. Expose the value with metadata(...) <probe> and read it with typst query - "<probe>" --field value --one. See docs/reference/introspection/query.md and docs/reference/introspection/metadata.md.
- Example:
printf '#metadata(1 + 2) <probe>\n' | typst query - "<probe>" --field value --one
Post-edit formatting checks
- Check whether
typstyle is available with command -v typstyle. If it is unavailable, skip the remaining formatting checks.
- After each
.typ file modification, run typstyle --check <file> for the file you just created or edited.
- If
typstyle --check fails, inspect the formatter changes with typstyle --diff <file> before deciding what to do.
- Apply formatting with
typstyle -i <file> only when the formatter changes are limited to a newly created file or to code you created or edited in the current task.
- Stop and ask the user when formatting would change untouched pre-existing code. If the diff reaches outside your own edits, or if you cannot confidently prove that every formatter change is limited to your edits, ask instead of formatting.
Quick syntax reference
Critical distinctions
- Arrays:
(item1, item2) (parentheses). See docs/reference/foundations/array.md.
- Dictionaries:
(key: value, key2: value2) (parentheses with colons). See docs/reference/foundations/dictionary.md.
- Content blocks:
[markup content] (square brackets). See docs/reference/foundations/content.md.
- NO tuples: Typst only has arrays.
Hash usage (markup vs code)
- Use
# to start a code expression inside markup or content blocks; it disambiguates code from text. This is required for content-producing function calls and field access in markup: #figure[...], #image("file.png"), text(...)[#numbering(...)].
- Do not use
# inside code contexts (argument lists, code blocks, show-rule bodies). Example: #figure(image("file.png")) (no # before image).
- Reference: docs/reference/scripting.md, docs/tutorial/writing-in-typst.md
// Incorrect (missing # inside content block)
text(...)[(numbering(...))]
// Correct
text(...)[(#numbering(...))]
Styling rules: set vs show
set: Set rule to configure optional parameters on element functions (style defaults scoped to the current block or file).
show: Show rule to target selected elements and apply a set rule or transform/replace the element output.
- Use
set for common styling; use show for selective or structural changes (e.g., heading.where(level: 1), labels, text, regex).
// Set rule: configure optional parameters for an element type
#set heading(numbering: "I.")
#set text(font: "New Computer Modern")
// Show-set rule: apply a set rule only to selected elements
#show heading: set text(navy)
// Show transform rule: replace/reshape element output
#show heading: it => block[#emph(it.body)]
Common mistakes to avoid
- Calling things "tuples" (Typst only has arrays).
- Using
[] for arrays (use () instead).
- Accessing array elements with
arr[0] (use arr.at(0)).
- Omitting
# in markup/content blocks (e.g., text(...)[numbering(...)] should be text(...)[#numbering(...)]).
- Using
# inside code contexts (e.g., figure(#image("x.png")) in an argument list).
- Mixing up content blocks
[] with code blocks {}.
- Forgetting to include the namespace when accessing imported variables/functions (e.g., use
color.hsl instead of just hsl).
- Using LaTeX syntax (do NOT use
\begin{...}, \section, or other LaTeX commands).
- Hallucinating environments (e.g.,
tabular does not exist; use table).
Advanced features
- Custom themes: See docs/reference/styling.md for theme creation.
- Scripting: Use Typst's scripting capabilities (docs/reference/scripting.md) for automatic generation.
- Math and visualisation: Reference docs/reference/math/ and docs/reference/visualize/ for formulas and diagrams.
For large projects
When working on large projects, consider organizing the project across multiple files.
- Use
#include "file.typ" to split into multiple files
- Relevant documentation: docs/reference/foundations/module.md
Troubleshooting
Missing font warnings
If you see "unknown font family" warnings, remove the font specification to use system defaults. Note: Font warnings don't prevent compilation; the document will use fallback fonts.
Template/Package not found
If import fails with "package not found":
- Verify exact package name and version on Typst Universe.
- Check for typos in
@preview/package:version syntax.
Compilation errors
Common fixes:
- "expected content, found ...": You're using code where markup is expected - wrap in
#{ } or use proper syntax.
- "expected expression, found ...": Missing
# (or #(...)) in markup/content blocks.
- "unknown variable": Check spelling, ensure imports are correct.
- Array/dictionary errors: Review syntax - use
() for both, dictionaries need key: value, singleton arrays are (elem,).
1---2name: typst-author3description: Generate idiomatic Typst (.typ) code, edit and troubleshoot Typst documents and projects, and answer Typst syntax/reference questions. Use when working with .typ files or when the user explicitly asks for Typst document creation, editing, debugging, compilation, formatting, template work, or package usage.4---5
6# typst-author skill
7
8## Overview
9
10This skill helps agents generate, edit, and reason about Typst documents. It provides quick‑start examples, detailed workflows, and links to the full Typst documentation (guides, tutorials, reference).
11
12## Minimal document example
13
14```typst
15#set document(title: "My Document", author: "Author Name")
16#set page(numbering: "1")
17#set text(lang: "en")
18
19// Enable paragraph justification and character-level justification
20#set par(
21 justify: true,
22 justification-limits: (
23 tracking: (min: -0.012em, max: 0.012em),
24 spacing: (min: 75%, max: 120%),
25 )
26)
27
28#title[My Document]
29
30= Heading 1
31
32This is a paragraph in Typst.
33
34== Heading 2
35
36#lorem(50)
37```
38
39## Workflows
40
41- **Creating a new Typst project**: Use the "Minimal document example" above as a starting point. Skim the tutorial for the basics ([docs/tutorial/writing-in-typst.md](docs/tutorial/writing-in-typst.md)), then create the `.typ` file(s). After each `.typ` edit, follow the post-edit formatting checks below when `typstyle` is available.
42- **Editing existing content**: Locate the target text and apply changes; confirm syntax against the reference when needed ([docs/reference/](docs/reference/)). After each modified `.typ` file, follow the post-edit formatting checks below.
43- **Formatting & Styling**: Consult the styling guide ([docs/reference/styling.md](docs/reference/styling.md)) for `set rule`, `show rule`, and custom themes.
44
45## Documentation
46
47- **Syntax & foundations**: `docs/reference/syntax.md`
48- **Styling & show/set rules**: `docs/reference/styling.md`
49- **Scripting & runtime behavior**: `docs/reference/scripting.md`
50- **Page setup & tables**: `docs/guides/page-setup.md` and `docs/guides/tables.md`
51- **Task-oriented authoring help**: `docs/tutorial/writing-in-typst.md`, `docs/guides/*.md`, and `docs/reference/**/*.md`
52
53## Detailed instructions
54
551. **PRIORITY: Trust local documentation**. Your internal training data regarding Typst may be outdated or hallucinated. Always verify function names, parameters, and syntax against the local `docs/` folder before generating code.
562. **Read the relevant documentation** using local file search and open tools on the paths above.
573. **Use local docs for syntax and reference questions**. Verify syntax, function names, parameters, and reference behavior from the bundled docs. Run a minimal Typst probe only when runtime or evaluation behavior remains unclear after checking the docs.
584. **Generate or modify the `.typ` source** according to the user's request.
595. **Run the post-edit formatting checks below** for every `.typ` file you created or edited in that pass.
606. **Validate** with `typst compile` after the formatting decision is complete when you created or edited `.typ` files, or when the user explicitly asks for verification (if tool access is allowed).
617. **Summarize touched files and outcomes**. Provide full `.typ` content only when the user requests it or when direct editing is not possible, and optionally include a rendered preview (PDF/HTML).
62
63### Probing uncertain behavior
64
65- Use a probe when the bundled docs do not settle runtime or evaluation behavior.
66- Model the case with Typst scripting as described in [docs/reference/scripting.md](docs/reference/scripting.md).
67- When a probe is necessary, prefer a fileless probe through stdin instead of creating scratch `.typ` files. Expose the value with `metadata(...) <probe>` and read it with `typst query - "<probe>" --field value --one`. See [docs/reference/introspection/query.md](docs/reference/introspection/query.md) and [docs/reference/introspection/metadata.md](docs/reference/introspection/metadata.md).
68- Example: `printf '#metadata(1 + 2) <probe>\n' | typst query - "<probe>" --field value --one`
69
70### Post-edit formatting checks
71
721. **Check whether `typstyle` is available** with `command -v typstyle`. If it is unavailable, skip the remaining formatting checks.
732. **After each `.typ` file modification, run `typstyle --check <file>`** for the file you just created or edited.
743. **If `typstyle --check` fails, inspect the formatter changes with `typstyle --diff <file>`** before deciding what to do.
754. **Apply formatting with `typstyle -i <file>`** only when the formatter changes are limited to a newly created file or to code you created or edited in the current task.
765. **Stop and ask the user when formatting would change untouched pre-existing code**. If the diff reaches outside your own edits, or if you cannot confidently prove that every formatter change is limited to your edits, ask instead of formatting.
77
78## Quick syntax reference
79
80### Critical distinctions
81
82- **Arrays**: `(item1, item2)` (parentheses). See [docs/reference/foundations/array.md](docs/reference/foundations/array.md).
83- **Dictionaries**: `(key: value, key2: value2)` (parentheses with colons). See [docs/reference/foundations/dictionary.md](docs/reference/foundations/dictionary.md).
84- **Content blocks**: `[markup content]` (square brackets). See [docs/reference/foundations/content.md](docs/reference/foundations/content.md).
85- **NO tuples**: Typst only has arrays.
86
87### Hash usage (markup vs code)
88
89- Use `#` to start a code expression inside markup or content blocks; it disambiguates code from text. This is required for content-producing function calls and field access in markup: `#figure[...]`, `#image("file.png")`, `text(...)[#numbering(...)]`.
90- Do not use `#` inside code contexts (argument lists, code blocks, show-rule bodies). Example: `#figure(image("file.png"))` (no `#` before `image`).
91- Reference: [docs/reference/scripting.md](docs/reference/scripting.md), [docs/tutorial/writing-in-typst.md](docs/tutorial/writing-in-typst.md)
92
93```typst
94// Incorrect (missing # inside content block)
95text(...)[(numbering(...))]
96
97// Correct
98text(...)[(#numbering(...))]
99```
100
101### Styling rules: set vs show
102
103- `set`: Set rule to configure optional parameters on element functions (style defaults scoped to the current block or file).
104- `show`: Show rule to target selected elements and apply a set rule or transform/replace the element output.
105- Use `set` for common styling; use `show` for selective or structural changes (e.g., `heading.where(level: 1)`, labels, text, regex).
106
107```typst
108// Set rule: configure optional parameters for an element type
109#set heading(numbering: "I.")
110#set text(font: "New Computer Modern")
111
112// Show-set rule: apply a set rule only to selected elements
113#show heading: set text(navy)
114
115// Show transform rule: replace/reshape element output
116#show heading: it => block[#emph(it.body)]
117```
118
119## Common mistakes to avoid
120
121- Calling things "tuples" (Typst only has arrays).
122- Using `[]` for arrays (use `()` instead).
123- Accessing array elements with `arr[0]` (use `arr.at(0)`).
124- Omitting `#` in markup/content blocks (e.g., `text(...)[numbering(...)]` should be `text(...)[#numbering(...)]`).
125- Using `#` inside code contexts (e.g., `figure(#image("x.png"))` in an argument list).
126- Mixing up content blocks `[]` with code blocks `{}`.
127- Forgetting to include the namespace when accessing imported variables/functions (e.g., use `color.hsl` instead of just `hsl`).
128- Using LaTeX syntax (do **NOT** use `\begin{...}`, `\section`, or other LaTeX commands).
129- Hallucinating environments (e.g., `tabular` does not exist; use `table`).
130
131## Advanced features
132
133- **Custom themes**: See [docs/reference/styling.md](docs/reference/styling.md) for theme creation.
134- **Scripting**: Use Typst's scripting capabilities ([docs/reference/scripting.md](docs/reference/scripting.md)) for automatic generation.
135- **Math and visualisation**: Reference [docs/reference/math/](docs/reference/math/) and [docs/reference/visualize/](docs/reference/visualize/) for formulas and diagrams.
136
137### For large projects
138
139When working on large projects, consider organizing the project across multiple files.
140
141- Use `#include "file.typ"` to split into multiple files
142- Relevant documentation: [docs/reference/foundations/module.md](docs/reference/foundations/module.md)
143
144## Troubleshooting
145
146### Missing font warnings
147
148If you see "unknown font family" warnings, remove the font specification to use system defaults. Note: Font warnings don't prevent compilation; the document will use fallback fonts.
149
150### Template/Package not found
151
152If import fails with "package not found":
153
154- Verify exact package name and version on Typst Universe.
155- Check for typos in `@preview/package:version` syntax.
156
157### Compilation errors
158
159Common fixes:
160
161- **"expected content, found ..."**: You're using code where markup is expected - wrap in `#{ }` or use proper syntax.
162- **"expected expression, found ..."**: Missing `#` (or `#(...)`) in markup/content blocks.
163- **"unknown variable"**: Check spelling, ensure imports are correct.
164- **Array/dictionary errors**: Review syntax - use `()` for both, dictionaries need `key: value`, singleton arrays are `(elem,)`.