typwriter

Crates.iotypwriter
lib.rstypwriter
version0.14.26
created_at2026-01-10 16:14:38.913487+00
updated_at2026-01-18 06:37:51.704888+00
descriptionA Rust library for compiling, formatting, and watching Typst documents, with PDF metadata and permission management.
homepagehttps://github.com/0x6b/typwriter
repositoryhttps://github.com/0x6b/typwriter
max_upload_size
id2034395
size4,708,864
kaoru (0x6b)

documentation

https://docs.rs/typwriter

README

typwriter

A Rust library for compiling, formatting, and watching Typst documents, with PDF metadata and permission management.

Usage

typwriter = { version = "0.14", features = ["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 Tahoe 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 None to allow anyone to open.
  • owner password, which is required to change permissions. Set to None to 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.

[!Note] typst-cli defaults are always embedded.

[!Note] The following font features require network access at build time to download fonts:

  • embed_noto_sans_jp
  • embed_noto_serif_jp
  • embed_recursive
  • embed_warpnine_mono
  • embed_warpnine_sans

Downloaded fonts are cached in $XDG_CACHE_HOME/typwriter/fonts (or ~/.cache/typwriter/fonts on 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/fonts directory are licensed under its own license. See the assets/fonts/README.md for details.

Acknowledgements

Reference

Commit count: 542

cargo fmt