typstgenv0.3.0

CASOON Open Source

Typst in, PDF out.

typstgen compiles an existing .typ file to PDF with the Typst engine built in: no typst binary, no subprocess. Template directories come from a config file instead of hardcoded paths.

cargo install typstgen
cargo install --git https://github.com/casoon/typstgen
cargo add typstgen --no-default-features
MITcrates.io 0.3.0Rust 1.92+Typst 0.15
typstgen compile --help
Compile a single .typ file to PDF

Usage: typstgen compile [OPTIONS] <INPUT>

Arguments:
  <INPUT>  Path to the .typ file

Options:
  -o, --output <OUTPUT>
          Output PDF path (defaults to input with .pdf extension)
  -c, --config <CONFIG>
          Path to typstgen.toml (defaults to ./typstgen.toml if present)
      --input <KEY=VALUE>
          Add a string key-value pair visible through `sys.inputs`
      --pdf-standard <STANDARD>
          PDF standards to enforce, comma-separated (e.g. a-2b, ua-1, 1.7)
      --creation-timestamp <UNIX_SECONDS>
          Creation date as a Unix timestamp; also used by datetime.today() [env: SOURCE_DATE_EPOCH=]
      --pages <PAGES>
          Pages to export, comma-separated (e.g. 1-3,5,8-); implies an untagged PDF
      --no-pdf-tags
          Write an untagged PDF (smaller, but without document structure)
  -h, --help
          Print help
external typst binaries or subprocesses
0
bundled font files, also in Wasm
17
entry points: CLI, Rust library, Wasm
3
keys in typstgen.toml
3

What it does

  1. Typst as a library

    typst and typst-pdf 0.15 are compiled into typstgen. The CLI writes the PDF; the library returns its bytes.

  2. Template paths from config

    typstgen.toml lists template directories. Each import is looked up next to the document first, then in every template directory in order. None of them is required.

  3. Fonts you can rely on

    Typst’s fallback fonts are always bundled. Turn system fonts off and add project fonts, and the same input gives the same PDF on every machine.

  4. Runs in Wasm

    The wasm feature takes the source and its imports as a JSON virtual filesystem and returns the PDF bytes. No filesystem needed.

Compiled by typstgen

All examples →

This browser does not show PDFs inline. Use the links below.

Open letter.pdf · Download letter.pdf (19.2 KiB)

examples/letter.typ imports a template from examples/templates/. typstgen compiled it to this PDF; examples/regenerate.sh rebuilds all fixtures with the current CLI.

examples/letter.pdf

Quickstart

Three steps from a .typ file to a PDF. The documentation covers template lookup, fonts and the config file.

  1. Install the CLI with cargo install typstgen.
  2. List your template directories in typstgen.toml.
  3. Run typstgen compile on your document.
terminalShell
# typstgen.toml
template_paths = ["templates"]

# letter.typ imports templates/letterhead.typ
typstgen compile letter.typ
# → letter.pdf