Expand description
§typst-bake
Bake Typst templates, fonts, and packages into your Rust binary — use Typst as a self-contained, embedded library.
§Cargo Features
pdf(default) - Enable PDF generation viaDocument::to_pdfsvg- Enable SVG generation viaDocument::to_svgpng- Enable PNG rasterization viaDocument::to_pngfull- Enable all output formats
§Features
- Multiple Output Formats - Generate PDF, SVG, or PNG from the same template
- File Embedding - All files in
template-dirare embedded and accessible from.typfiles - Font Embedding - Fonts (TTF, OTF, TTC) in
fonts-dirare 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/IntoDictderive macros - Page Selection - Select specific pages for output via
Document::select_pages
§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§
Structs§
- Category
Stats - Statistics for a category of files (templates, fonts).
- Dedup
Stats - Statistics for content deduplication across all categories.
- Document
- A fully self-contained document ready for rendering.
- Embed
Stats - Compression statistics for all embedded content.
- Package
Info - Statistics for a single package.
- Package
Stats - Statistics for all packages.
- Pages
- A lightweight view into a
Documentwith a page selection filter.
Enums§
- Error
- Errors that can occur during document compilation and rendering.
Traits§
- HasCompression
Ratio - Trait for types that have original/compressed sizes and can compute a compression ratio.
Functions§
- rebuild_
if_ changed - Emits
cargo:rerun-if-changeddirectives for template and font directories.
Type Aliases§
- Result
- A specialized Result type for typst-bake operations.