Skip to main content

typwriter/
lib.rs

1//! A naive Rust Library that provides a way to work with [Typst](https://typst.app/) document and PDF file programmatically.
2//!
3//! # Overview
4//!
5//! You can use this library to:
6//!
7//! - [compile](compile()) a Typst file to a PDF or PNG file
8//! - [format](format()) a Typst file
9//! - [update metadata](update_metadata()) of a PDF file
10//! - [set permission](set_permission()) of a PDF file
11//! - [watch](watch()) for changes in the input Typst file along with its dependencies and recompile
12//!   it when a change is detected
13//!
14//! # Supported Typst Version
15//!
16//! Version [0.14.2](https://github.com/typst/typst/releases/tag/v0.14.2) (December 3, 2025)
17//!
18//! This crate is for my personal use and Typst/Rust learning purposes; it is not affiliated with the [Typst](https://typst.app/) project.
19//!
20//! # Feature flags
21//!
22//! Below is a list of available feature flags. The crate does not define a `default` feature, so if
23//! you're unsure what you need, specify `full`, which enables all capabilities and fonts.
24//! However, be aware that this will result in longer compilation times and a larger binary size.
25//!
26//! ## Capabilities
27//!
28//! - `compile`: Enables the [`compile()`], [`list_fonts()`] functions, and [`PdfStandard`] enum.
29//! - `format`: Enables the [`format()`] function.
30//! - `pdf_metadata`: Enables the [`update_metadata()`] function.
31//! - `pdf_permission`: Enables the [`set_permission()`] function.
32//! - `watch`: Enables the [`watch()`] function. This feature also enables the `compile` feature.
33//!
34//! ## Fonts Embedding
35//!
36//! - `embed_additional_fonts`: embed all fonts listed below.
37//! - `embed_cmu_roman`: [Computer Modern Roman](https://www.fontsquirrel.com/fonts/computer-modern)
38//! - `embed_ia_writer_duo`: [iA Writer Duo](https://github.com/iaolo/iA-Fonts/)
39//! - `embed_jet_brains_mono_nl`: [JetBrains Mono NL](https://github.com/JetBrains/JetBrainsMono)
40//! - `embed_noto_emoji`: [Noto Emoji](https://fonts.google.com/noto/specimen/Noto+Emoji)
41//! - `embed_noto_sans_jp`: [Noto Sans JP](https://fonts.google.com/noto/specimen/Noto+Sans+JP)
42//! - `embed_noto_serif_jp`: [Noto Serif JP](https://fonts.google.com/noto/specimen/Noto+Serif+JP)
43//! - `embed_recursive`: [Recursive Sans & Mono](https://github.com/arrowtype/recursive/)
44//! - `embed_source_code_pro`: [Source Code Pro](https://fonts.google.com/specimen/Source+Code+Pro)
45//! - `embed_warpnine_mono`: [Warpnine Mono](https://github.com/0x6b/warpnine-fonts)
46//! - `embed_warpnine_sans`: [Warpnine Sans Condensed](https://github.com/0x6b/warpnine-fonts)
47//!
48//! Note that:
49//!
50//! - typst-cli [defaults](https://github.com/typst/typst-assets/blob/5ca2a6996da97dcba893247576a4a70bbbae8a7a/src/lib.rs#L67-L80)
51//!   are always embedded.
52//! - The crate won’t search system fonts to ensure the reproducibility. All fonts you need should
53//!   be explicitly added via [`CompileParams::font_paths`].
54
55#[cfg(feature = "compile")]
56pub use compile::{CompileParams, PdfStandard, compile};
57#[cfg(feature = "compile")]
58pub use fonts::list_fonts;
59#[cfg(feature = "format")]
60pub use format::{FormatParams, format};
61#[cfg(feature = "pdf_permission")]
62pub use set_permission::{PermissionParams, PrintPermission, set_permission};
63#[cfg(feature = "pdf_metadata")]
64pub use update_metadata::{PdfMetadata, update_metadata};
65pub use version::{typst_version, version};
66#[cfg(feature = "watch")]
67pub use watch::FittingType;
68#[cfg(feature = "watch")]
69pub use watch::watch;
70
71#[cfg(feature = "compile")]
72mod compile;
73#[cfg(feature = "compile")]
74mod download;
75#[cfg(feature = "compile")]
76mod fonts;
77#[cfg(feature = "format")]
78mod format;
79#[cfg(feature = "compile")]
80mod package;
81#[cfg(feature = "pdf_permission")]
82mod set_permission;
83#[cfg(feature = "pdf_metadata")]
84mod update_metadata;
85mod version;
86#[cfg(feature = "watch")]
87mod watch;
88#[cfg(feature = "compile")]
89mod world;