embedded-typst 0.1.0

A typst::World for embedding the Typst compiler: lazily loaded fonts, a virtual filesystem over several roots, Typst packages and reproducible dates. Native and Wasm.
Documentation

embedded-typst

A typst::World for embedding the Typst compiler in an application, without the typst CLI.

  • Fonts: Typst's bundled fonts, in-memory fonts (include_bytes!), system fonts and font directories. Fonts on disk are only read when a document uses them. Build once and share between compilations with an Arc.
  • EmbeddedWorld: the main source, in-memory files, root directories searched in order, sys.inputs, a fixed creation timestamp for reproducible datetime.today() and, with the packages feature, @preview/… and @local/… imports from the typst CLI's package directories. dependencies() lists every file read from disk.
  • Wasm: builds for wasm32-unknown-unknown; there, only fonts and files given as data are available.
use std::sync::Arc;
use embedded_typst::{EmbeddedWorld, Fonts};
use typst::syntax::VirtualPath;

let fonts = Arc::new(Fonts::builder().typst_fonts().system_fonts().build());
let world = EmbeddedWorld::new(VirtualPath::new("main.typ")?, source, fonts)
    .with_roots(vec!["templates".into()])
    .with_creation_timestamp(1_700_000_000);
let document = typst::compile::<typst_layout::PagedDocument>(&world).output?;

Features

Feature Default Adds
typst-fonts yes FontsBuilder::typst_fonts: Libertinus, New Computer Modern, DejaVu Sans Mono
packages no Packages and EmbeddedWorld::with_packages (native only)
download no Packages::download: fetch missing @preview packages from Typst Universe

Used by typstgen and renderreport.

License

MIT