typstgen
Compile an existing .typ file to PDF. No external typst binary, no
subprocess — Typst runs embedded as a Rust library. Template resolution is
config-driven instead of hardcoded.
Website and documentation: casoon.github.io/typstgen
your-document.typ + typstgen.toml (template_paths) → your-document.pdf
Usable three ways from one crate:
- CLI (
clifeature, default):typstgen compile input.typ - Rust library (always available):
typstgen::compile(path, &config) - Wasm (
wasmfeature): source and imports supplied as a JSON virtual filesystem
Why
docgen already does
PDF generation from Typst, but grew into a client/project-management tool
along the way and only ever hardcoded its template lookup paths. typstgen is
the minimal version of the same idea: one job (.typ in, PDF out), with the
template directory resolved from config instead of baked in.
The architecture follows
renderreport: embedded Typst,
feature-gated CLI/Wasm, embedded fonts only on Wasm.
Quick start
Imports are looked up next to the document, then in the template directories
from typstgen.toml (optional; without a config, ./templates and
./.typstgen/templates are used if they exist):
# typstgen.toml — paths are relative to the working directory.
# Every existing directory is searched per import, in order.
= ["templates"]
use ;
let config = load?;
let pdf_bytes = compile?;
write?;
Wasm
Build with cargo build --target wasm32-unknown-unknown --no-default-features --features wasm.
Generate JS bindings with wasm-bindgen, then pass the source and importable
text files as JSON; the returned bytes are a PDF:
import init from './pkg/typstgen.js';
await ;
const pdf =
License
MIT