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
PDF is enabled by default. To use only SVG: default-features = false, features = ["svg"].
§Features
- Simple API - Set
template-dirandfonts-dirinCargo.toml, then generate documents with justdocument!("main.typ").to_pdf() - Multi-Format Output - Generate PDF, SVG, or PNG with optional page selection
- Self-Contained Binary - Templates, fonts, and packages are all embedded into the binary at compile time. No external files or internet connection needed at runtime
- Automatic Package Resolution - Just use
#import "@preview/..."as in Typst. Packages are resolved automatically using Typst’s own cache and data directories - Runtime Inputs - Pass dynamic data from Rust structs to Typst via
IntoValue/IntoDictderive macros - Runtime Files - Inject files at runtime with
Document::add_filefor dynamically generated content or downloaded resources - Optimized Binary Size - Embedded resources are deduplicated and compressed automatically
§Quick Start
Add to your Cargo.toml:
[dependencies]
typst-bake = "0.1"
[package.metadata.typst-bake]
template-dir = "./templates"
fonts-dir = "./fonts"Then use the document! macro:
ⓘ
let doc = typst_bake::document!("main.typ");
let pdf = doc.to_pdf()?;
std::fs::write("output.pdf", &pdf)?;
let svgs = doc.to_svg()?;
std::fs::write("page1.svg", &svgs[0])?;
let pngs = doc.to_png(144.0)?; // 144 DPI
std::fs::write("page1.png", &pngs[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. - PdfConfig
pdf - PDF export configuration for
Document::with_pdf_config. - PdfTimestamp
pdf - A PDF creation timestamp.
Enums§
- Error
- Errors that can occur during document compilation and rendering.
- PdfStandard
pdf - A PDF conformance standard to enforce on export.
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.