Expand description
A typst::World for embedding the Typst compiler in an application.
Fonts: Typst’s bundled fonts, in-memory fonts, system fonts and font directories. Fonts on disk are read only when a document uses them. Build once, share between compilations.EmbeddedWorld: the main source, in-memory files, root directories searched in order,sys.inputs, a fixed date for reproducible output and, with thepackagesfeature,@previewand@localpackages.
On wasm32 there is no filesystem: only fonts and files given as data
are available, and datetime.today() needs a creation timestamp.
use std::sync::Arc;
use embedded_typst::{EmbeddedWorld, Fonts};
use typst::syntax::VirtualPath;
let fonts = Arc::new(Fonts::builder().typst_fonts().build());
let main = VirtualPath::new("main.typ").unwrap();
let world = EmbeddedWorld::new(main, "#import \"lib.typ\": greet\n#greet", fonts)
.with_creation_timestamp(0);
world.add_file(VirtualPath::new("lib.typ").unwrap(), b"#let greet = [Hello]".to_vec());
let document = typst::compile::<typst_layout::PagedDocument>(&world)
.output
.expect("compiles");
assert_eq!(document.pages().len(), 1);Structs§
- Dependency
- A file Typst read during a compilation, see
EmbeddedWorld::dependencies. - Embedded
World - A Typst world for one compilation: the main source, in-memory files and, on native targets, files looked up in a list of root directories and in Typst packages.
- Fonts
- Font metadata for Typst plus the fonts themselves. Fonts given as data are loaded up front; fonts found on disk are only read into memory when Typst actually uses them.
- Fonts
Builder - Collects fonts for
Fonts.
Functions§
- project_
file - The id of a file in the project (not in a package).