# embedded-typst
A [`typst::World`](https://docs.rs/typst/latest/typst/trait.World.html) 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.
```rust
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
| `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](https://github.com/casoon/typstgen) and
[renderreport](https://github.com/casoon/renderreport).
## License
MIT