Crate typst_bake

Crate typst_bake 

Source
Expand description

§typst-bake

Bake Typst templates, fonts, and packages into your Rust binary — use Typst as a self-contained, embedded library.

§Cargo Features

§Features

  • Multiple Output Formats - Generate PDF, SVG, or PNG from the same template
  • File Embedding - All files in template-dir are embedded and accessible from templates
  • Font Embedding - Fonts (TTF, OTF, TTC) in fonts-dir are automatically bundled
  • Package Bundling - Scans for package imports and recursively resolves all dependencies
  • Optimized Binary Size - Resources are compressed with zstd and decompressed lazily at runtime
  • Runtime Inputs - Pass dynamic data from Rust structs to Typst via IntoValue / IntoDict derive macros

§Quick Start

Add to your Cargo.toml:

[package.metadata.typst-bake]
template-dir = "./templates"
fonts-dir = "./fonts"

[dependencies]
typst-bake = "0.1"

Then use the document! macro:

// Generate PDF
let pdf = typst_bake::document!("main.typ").to_pdf()?;

// Generate SVG (one per page)
let svgs = typst_bake::document!("main.typ").to_svg()?;

// Generate PNG at 144 DPI (Retina)
let pngs = typst_bake::document!("main.typ").to_png(144.0)?;

Macros§

document
Creates a Document with embedded templates, fonts, and packages.

Structs§

CategoryStats
Statistics for a category of files (templates, fonts)
Document
A fully self-contained document ready for rendering.
EmbedStats
Compression statistics for all embedded content.
PackageInfo
Statistics for a single package
PackageStats
Statistics for all packages

Enums§

Error
Errors that can occur during document compilation and rendering.

Functions§

rebuild_if_changed
Emits cargo:rerun-if-changed directives for template and font directories.

Type Aliases§

Result
A specialized Result type for typst-bake operations.

Derive Macros§

IntoDict
Derive macro for converting a struct to a Typst dictionary.
IntoValue
Derive macro for converting a struct to a Typst value.