Typst Author

jihe520/mathmodelagent/skills/typst-author

作者 jihe52003f4eb388b38無授權條款6.1K 個星標收錄於 2026年10月8日更新於 2026年10月8日儲存庫5 天前更新

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.

僅含說明Documents & Office
AI 產生的概覽

運用內附的 Typst 文件來產生、編輯、格式化並排解 Typst(.typ)文件的問題。

功能
此技能引導代理撰寫與修改 Typst 標記原始檔,涵蓋語法、以 set 與 show 規則進行的樣式設定、腳本、數學公式、表格與頁面設定。它內附 Typst 參考、指南與教學,讓代理能在本機核對函式名稱與參數,而不依賴訓練資料。它也說明使用 typstyle 進行編輯後格式化、透過 typst compile 驗證,以及用 typst query 進行無檔案探測的流程。產出為 .typ 原始檔,可選擇編譯成 PDF 或 HTML 預覽。
適用情境
適用於建立或編輯 .typ 檔案、使用者要求進行 Typst 文件建立、格式化、範本或套件使用時,或排解 Typst 語法與編譯錯誤時。也適合回答需要對照內附文件核實的 Typst 參考問題。
執行需求
僅為說明性內容,不附帶指令碼。需要可讀取內附的 docs/ 目錄,可選需要 typst 命令列工具用於編譯與查詢探測,以及 typstyle 用於格式化檢查。解析 Typst Universe 套件時可能需要網路存取。

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

typst
#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 [blocked]), 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/ [blocked]). After each modified .typ file, follow the post-edit formatting checks below.
  • Formatting & Styling: Consult the styling guide (docs/reference/styling.md [blocked]) 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

  1. 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.
  2. Read the relevant documentation using local file search and open tools on the paths above.
  3. 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.
  4. Generate or modify the .typ source according to the user's request.
  5. Run the post-edit formatting checks below for every .typ file you created or edited in that pass.
  6. 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).
  7. 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 [blocked].
  • 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 [blocked] and docs/reference/introspection/metadata.md [blocked].
  • Example: printf '#metadata(1 + 2) <probe>\n' | typst query - "<probe>" --field value --one

Post-edit formatting checks

  1. Check whether typstyle is available with command -v typstyle. If it is unavailable, skip the remaining formatting checks.
  2. After each .typ file modification, run typstyle --check <file> for the file you just created or edited.
  3. If typstyle --check fails, inspect the formatter changes with typstyle --diff <file> before deciding what to do.
  4. 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.
  5. 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 [blocked].
  • Dictionaries: (key: value, key2: value2) (parentheses with colons). See docs/reference/foundations/dictionary.md [blocked].
  • Content blocks: [markup content] (square brackets). See docs/reference/foundations/content.md [blocked].
  • 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 [blocked], docs/tutorial/writing-in-typst.md [blocked]
typst
// Incorrect (missing # inside content block)text(...)[(numbering(...))]
// Correcttext(...)[(#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).
typst
// 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 [blocked] for theme creation.
  • Scripting: Use Typst's scripting capabilities (docs/reference/scripting.md [blocked]) for automatic generation.
  • Math and visualisation: Reference docs/reference/math/ [blocked] and docs/reference/visualize/ [blocked] 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 [blocked]

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,).

來源與署名

來源:jihe520/mathmodelagent位於skills/typst-author提交03f4eb3

授權條款: 無授權條款

內容歸原作者所有。SourceWeft 從公開儲存庫中收錄這些內容。

檢舉或申請下架