typstfmt is a formatter for Typst code.
It only formats inputs that are valid Typst code. It aims to make the code consistent.
cargo install --git https://github.com/jeffa5/typstfmtThe flake provides an overlay which you can use with nixpkgs.
Add this to your .pre-commit-config.yaml:
- repo: https://github.com/jeffa5/typstfmt
rev: '' # Use the sha / tag you want to point at
hooks:
- id: typstfmt# format stdin
typstfmt
# format typst files in current directory
typstfmt *.typnix run github:jeffa5/typstfmtYou can configure some aspects of the formatting with a typstfmt.toml file in the current directory, or specify its location with the --config-path flag.
The default configuration is:
indent = 2 # spaces
spacing = true # whether to manage spacingList some fuzz targets:
cargo fuzz listThen run one, e.g. for crash_proof:
cargo fuzz run crash_proofThe typst packages repo is a submodule (typst-packages).
We can run the formatter against it to check the formatting and for erroneous outputs with:
cargo run -- typst-packages --checkAnd try to format them all (useful for manual diffing):
cargo run -- typst-packagestypstfmt is a rewrite of typst-fmt which aims to retain all original text whilst also be able to be flexible in its configuration.
I tried writing some rules for that formatter before beginning the redesign present here.