typwriter
A Rust library for compiling, formatting, and watching Typst documents, with PDF metadata and permission management.
Usage
= { = "0.14", = ["full"] }
or
cargo add typwriter --fatures full
Tested Environment
The crate may function in other environments, but it has only been tested in the following environment:
- rustc 1.92.0 (ded5c06cf 2025-12-08)
- macOS Sequoia 26.1 (25B78)
Supported Typst Version
Version 0.14.2 (December 3, 2025)
This crate is for my personal use and learning purposes; it is not affiliated with the Typst project.
Crate Features
full
Specify full to enable all the following features.
compile
You can compile a Typst document to a PDF or a PNG file; a limited subset of typst-cli.
See examples/compile.rs for usage.
$ cargo run --example compile --features embed_additional_fonts
format
You can format a Typst document with typstyle.
See examples/format.rs for usage.
$ cargo run --example format --features format
pdf_metadata
You can update PDF metadata. Following metadata is supported:
| Metadata | In Acrobat Reader | In Apple Preview |
|---|---|---|
| Title | Title | Title |
| Author | Author | Author |
| Application | Application and PDF Producer | PDF Producer and Content creator |
| Subject | Subject and Description | Subject |
| Copyright status | Copyright Status | (None) |
| Copyright notice | Copyright Notice | Yes |
| Keywords | Keywords | Keywords |
| Creation date | Created | Creation date |
| Modification date | Modified | Modification date |
| Custom properties | Custom Properties | (None) |
[!Note]
- All metadata will be overwritten, not merged.
- Both creation and modification date are set automatically to the current date without time information which means time is always 0:00 UTC, for some privacy reasons (or my preference.)
You can specify some of them with Typst. As of Typst v0.14.2, the following metadata is supported:
- Title
- Author
- Description
- Keywords
- Date
See Document Function – Typst Documentation for details.
See examples/update_metadata.rs for usage.
$ cargo run --example update_metadata --features pdf_metadata
pdf_permission
You can set the following PDF 1.7 permissions:
- user password, which is required to open the document. Set to
Noneto allow anyone to open. - owner password, which is required to change permissions. Set to
Noneto allow anyone to change. - content copying for accessibility.
- page extraction.
- document assembly.
- commenting and form filling.
- form field fill-in or signing.
- other modifications.
- printing (high, low, or disallow).
- encrypt metadata.
The only supported encryption algorithm is AES-256.
See examples/set_permission.rs for usage.
$ cargo run --example set_permission --features pdf_permission
watch
You'll be able to preview your Typst document live. Changes for typ file, along with files with extension cbor, csv, gif, htm, html, jpeg, jpg, json, png, svg, toml, txt, xml, yaml, and yml in the same directory, recursively, will be watched. This is inspired by ItsEthra/typst-live.
See examples/watch.rs for usage.
$ cargo run --example watch --features watch
This feature also enables compile feature.
Embedding Fonts
You can embed additional fonts in the binary for easier deployment. Each feature also enables compile feature.
embed_additional_fonts: embed all fonts listed below.embed_cmu_roman: Computer Modern Romanembed_ia_writer_duo: iA Writer Duoembed_noto_emoji: Noto Emojiembed_noto_sans_jp: Noto Sans JPembed_noto_serif_jp: Noto Serif JPembed_recursive: Recursive Sans & Monoembed_source_code_pro: Source Code Proembed_warpnine_mono: WarpNine Monoembed_warpnine_sans: WarpNine Sans
[!Note] typst-cli defaults are always embedded.
[!Note] The following font features require network access at build time to download fonts:
embed_noto_sans_jpembed_noto_serif_jpembed_recursiveembed_warpnine_monoembed_warpnine_sansDownloaded fonts are cached in
$XDG_CACHE_HOME/typwriter/fonts(or~/.cache/typwriter/fontson macOS/Linux).
[!Warning]
- The crate won't search system fonts to ensure the reproducibility. All fonts you need should be explicitly added via
CompileParams.font_paths.- Embedding fonts will produce a large binary.
Testing
Naive tests are available. You can run them with:
$ cargo test --all-features
Note that you have to install exiftool to run all tests.
License
- The crate itself is licensed under the Apache License version 2.0, as same as Typst. See LICENSE for details.
- Fonts under the
assets/fontsdirectory are licensed under its own license. See theassets/fonts/README.mdfor details.
Acknowledgements
- typst/typst
- Enter-tainer/typstyle
- ItsEthra/typst-live
- All the font authors and contributors