Skip to content

typst-letter-generator

Source: .opencode/skills/typst-letter-generator/SKILL.md — site rebuilt 2026-09-05.


--- name: typst-letter-generator description: Generate formal legal letters and correspondence in Typst on a fixed letterhead template with section headings and hanging paragraphs. Use when asked to draft or edit a legal letter or formal correspondence.


Typst Formal Legal Letter Skill

MANDATORY: run typst-planner first. No letter is drafted or compiled until a typst-planner plan for this document has been emitted and signed off.

This skill governs the drafting, layout, and formatting of formal legal correspondence, settlement proposals, and statutory notices using Typst.

1. Page Geometry & Letterhead Setup

  • Page 1 Background: Embeds the GREYSCALE letterhead Word Letterhead Template Greyscale.png (resources\, 300dpi PyMuPDF render of the colour master PDF) full-bleed (width: 100%, height: 100%) only on Page 1 via if counter(page).get().at(0) == 1. House style is grey scale: never embed the colour Word Letterhead Template.pdf directly.
  • Top Offset: Page 1 content begins after #v(3.8cm) to clear the letterhead banner.
  • Page 2+ Footer: Displays right-aligned page counter: Page X of Y in 9pt gray text.
  • Typography: Liberation Sans / Arial, 11pt, leading: 0.75em, justified text.

2. Structural Helper Functions

#sec(num, title) — Section Headings

Grid-aligned section headings with 3.5em fixed number width:

#sec("1.1.", "Instructions and Parties")

#item(num, body) — Perfect Hanging Paragraphs

Grid-aligned hanging numbered paragraphs:

#item("1.1.1.", [As you know, we act as principal solicitors for McAuley Architecture Ltd.])

3. Required Document Layout Sequence

  1. Top Spacing: #v(3.8cm)
  2. Confidentiality: *STRICTLY PRIVATE & CONFIDENTIAL*
  3. Recipient Block: #align(left)[ *Firm/Name* \ Address \ _(By Email: ...)_ ]
  4. Metadata: Date: [Date] \ Our Ref: [Ref]
  5. Salutation: Dear Sirs, / Dear [Name],
  6. Subject Re-Block: #block(width: 100%)[ #set text(size: 11pt, weight: "bold") ... ]
  7. Body Content: Structured using #sec(...) and #item(...).
  8. Sign-off Block:
    #v(20pt)
    #block(breakable: false)[
      Yours faithfully,\
      #v(8pt)
      #image("apw signature.png", width: 4.5cm)
      #v(8pt)
      *The Building Law Practice* \
      *Solicitors for the Pursuer*
    ]
    

4. Typst Manual & Reference

Before drafting or when unsure of any Typst function, parameter, or syntax, consult the local, searchable mirror of the official Typst documentation at:

..\_typst-manual\
  • Function/element/type reference (e.g. #image, #align, #block, #counter, #set, #text, grid, v, h, place): search the Rust doc comments under _typst-manual\typst-src\crates\typst-library\src\ — every library item's full documentation and examples live there directly above its definition.
  • Language / syntax / scripting (#let, #set, #show, markup, math, context): _typst-manual\typst-src\docs\content\reference\language\*.typ and tutorial\.
  • Tutorials & guides: _typst-manual\typst-src\docs\content\tutorial\ and guides\.

See _typst-manual\README.md for lookup guidance.

Self-Learning: Runtime Environment Probe (RUN FIRST)

Before generating ANY document, probe the actual environment so you never ship a font or package that does not exist (Typst silently falls back, causing font discrepancies between the preview and the intended design):

powershell -ExecutionPolicy Bypass -File "..\_typst-manual\probe-fonts.ps1"

Read the output and the persisted report _typst-manual\font-probe-report.json. Then:

  • Rewrite every font stack so its FIRST member is an installed font from the report (e.g. this machine lacks Liberation Sans/Linux Libertine, so prefer Arial / a real installed serif such as Libertinus Serif, Georgia, Cambria, or Times New Roman). Never leave a missing font as the leading choice.
  • Verify each @preview/... import is reported as cached; if missing, note that compilation needs network or the package must be cached first.
  • Only after resolving fonts/packages should you compile and generate the preview.

5. Compilation & Native Preview Workflow

Whenever generating or editing a letter with this skill, you MUST compile the document into high-resolution PNGs and generate an interactive Carousel Artifact so the user can preview it natively in a local previews\ folder:

Step 1: Compile to PNG in Artifact Directory

typst compile letter.typ "previews\letter-page-{0p}.png" --ppi 144

Step 2: Create a Markdown Artifact (document_preview.md) Set UserFacing: true and output a markdown preview referencing the PNGs by relative path.

# Native Document Preview

````carousel
![Page 1](previews/letter-page-01.png)
<!-- slide -->
![Page 2](previews/letter-page-02.png)
````