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_noto_emoji`: [Noto Emoji](https://fonts.google.com/noto/specimen/Noto+Emoji)
40//! - `embed_noto_sans_jp`: [Noto Sans JP](https://fonts.google.com/noto/specimen/Noto+Sans+JP)
41//! - `embed_noto_serif_jp`: [Noto Serif JP](https://fonts.google.com/noto/specimen/Noto+Serif+JP)
42//! - `embed_recursive`: [Recursive Sans & Mono](https://github.com/arrowtype/recursive/)
43//! - `embed_source_code_pro`: [Source Code Pro](https://fonts.google.com/specimen/Source+Code+Pro)
44//! - `embed_warpnine_mono`: [Warpnine Mono](https://github.com/0x6b/warpnine-fonts)
45//! - `embed_warpnine_sans`: [Warpnine Sans Condensed](https://github.com/0x6b/warpnine-fonts)
46//!
47//! Note that:
48//!
49//! - typst-cli [defaults](https://github.com/typst/typst-assets/blob/5ca2a6996da97dcba893247576a4a70bbbae8a7a/src/lib.rs#L67-L80)
50//! are always embedded.
51//! - The crate won’t search system fonts to ensure the reproducibility. All fonts you need should
52//! be explicitly added via [`CompileParams::font_paths`].
53
54#[cfg(feature = "compile")]
55pub use compile::{CompileParams, PdfStandard, compile};
56#[cfg(feature = "compile")]
57pub use fonts::list_fonts;
58#[cfg(feature = "format")]
59pub use format::{FormatParams, format};
60#[cfg(feature = "pdf_permission")]
61pub use set_permission::{PermissionParams, PrintPermission, set_permission};
62#[cfg(feature = "pdf_metadata")]
63pub use update_metadata::{PdfMetadata, update_metadata};
64pub use version::{typst_version, version};
65#[cfg(feature = "watch")]
66pub use watch::FittingType;
67#[cfg(feature = "watch")]
68pub use watch::watch;
69
70#[cfg(feature = "compile")]
71mod compile;
72#[cfg(feature = "compile")]
73mod download;
74#[cfg(feature = "compile")]
75mod fonts;
76#[cfg(feature = "format")]
77mod format;
78#[cfg(feature = "compile")]
79mod package;
80#[cfg(feature = "pdf_permission")]
81mod set_permission;
82#[cfg(feature = "pdf_metadata")]
83mod update_metadata;
84mod version;
85#[cfg(feature = "watch")]
86mod watch;
87#[cfg(feature = "compile")]
88mod world;