embedded_typst/lib.rs
1//! A [`typst::World`] for embedding the Typst compiler in an application.
2//!
3//! - [`Fonts`]: Typst's bundled fonts, in-memory fonts, system fonts and font
4//! directories. Fonts on disk are read only when a document uses them.
5//! Build once, share between compilations.
6//! - [`EmbeddedWorld`]: the main source, in-memory files, root directories
7//! searched in order, `sys.inputs`, a fixed date for reproducible output
8//! and, with the `packages` feature, `@preview` and `@local` packages.
9//!
10//! On `wasm32` there is no filesystem: only fonts and files given as data
11//! are available, and `datetime.today()` needs a creation timestamp.
12//!
13//! ```
14//! # #[cfg(feature = "typst-fonts")] {
15//! use std::sync::Arc;
16//! use embedded_typst::{EmbeddedWorld, Fonts};
17//! use typst::syntax::VirtualPath;
18//!
19//! let fonts = Arc::new(Fonts::builder().typst_fonts().build());
20//! let main = VirtualPath::new("main.typ").unwrap();
21//! let world = EmbeddedWorld::new(main, "#import \"lib.typ\": greet\n#greet", fonts)
22//! .with_creation_timestamp(0);
23//! world.add_file(VirtualPath::new("lib.typ").unwrap(), b"#let greet = [Hello]".to_vec());
24//!
25//! let document = typst::compile::<typst_layout::PagedDocument>(&world)
26//! .output
27//! .expect("compiles");
28//! assert_eq!(document.pages().len(), 1);
29//! # }
30//! ```
31
32mod fonts;
33#[cfg(all(feature = "packages", not(target_arch = "wasm32")))]
34mod packages;
35mod world;
36
37pub use fonts::{Fonts, FontsBuilder};
38#[cfg(all(feature = "packages", not(target_arch = "wasm32")))]
39pub use packages::Packages;
40#[cfg(not(target_arch = "wasm32"))]
41pub use world::Dependency;
42pub use world::{project_file, EmbeddedWorld};