Crates.io | typstyle-core |
lib.rs | typstyle-core |
version | 0.13.17 |
created_at | 2024-12-16 15:40:47.922337+00 |
updated_at | 2025-08-03 13:30:54.934413+00 |
description | A pretty printer for typst. |
homepage | https://typstyle-rs.github.io/typstyle/ |
repository | https://github.com/typstyle-rs/typstyle |
max_upload_size | |
id | 1485175 |
size | 224,786 |
A beautiful and reliable code formatter for Typst.
Try typstyle instantly in your browser: 🎮 Playground
The playground runs the latest version of typstyle with live formatting. Perfect for testing formatting behavior before installing locally.
You can install typstyle
using any of the following methods:
Download the binary from the release page.
Install it from your package manager: https://repology.org/project/typstyle/versions.
Install using cargo-binstall
:
cargo binstall typstyle
Install it with cargo
:
cargo install typstyle --locked
Beautiful and reliable typst code formatter
Usage: typstyle [OPTIONS] [INPUT]...
Arguments:
[INPUT]... List of files or directories to format [default: stdin]
Options:
-i, --inplace Format the file in place
--check Run in 'check' mode. Exits with 0 if input is formatted correctly. Exits with a non-zero status code if formatting is required
--diff Run in 'diff' mode. Shows unified diff of what formatting changes would be made. Exits with 0 if input is formatted correctly. Exits with a non-zero status code if formatting is required
-h, --help Print help
-V, --version Print version
Format Configuration:
-l, --line-width <LINE_WIDTH> Maximum width of each line [default: 80] [aliases: column] [short aliases: c]
-t, --indent-width <INDENT_WIDTH> Number of spaces per indentation level [default: 2] [aliases: tab-width]
--no-reorder-import-items Disable alphabetical reordering of import items
--wrap-text Wrap text in markup to fit within the line width. Implies `--collapse-spaces`
Debug Options:
-a, --ast Print the AST of the input file
-p, --pretty-doc Print the pretty document
--timing Show elapsed time taken by the formatter
Log Levels:
-v, --verbose Enable verbose logging
-q, --quiet Print diagnostics, but nothing else
Format a file in place:
typstyle -i file.typ
Format a file and print the result to stdout:
typstyle file.typ
Format multiple files in place:
typstyle -i file1.typ file2.typ dir/
Format all files in a directory:
typstyle -i dir
Read from stdin and print the result to stdout:
cat file.typ | typstyle > file-formatted.typ
Typstyle has been integrated into tinymist. You can use it in your editor by installing the tinymist plugin and set tinymist.formatterMode
to typstyle
.
Checkout typstyle-tampermonkey, a userscript that integrates typstyle into the typst.app editor.
Try the playground at: https://typstyle-rs.github.io/typstyle/playground
The playground integrates the latest version of typstyle. If you encounter formatting issues, please verify them in the playground first before reporting bugs.
The typstyle-action maintained by @grayespinoza can install and run typstyle in a GitHub Action.
If you find typstyle is not working as expected, you can use // @typstyle off
or /* @typstyle off */
to disable the formatter on the next node of code.
Typstyle also gives up formatting part of the code if it is not able to format it correctly. Specifically, it will print that part as is if:
And please let us know the issue by creating an issue on the GitHub repository
We maintain a comprehensive suite of tests to ensure the correctness and reliability of typstyle.
snapshots
directory and are compared to the current result when running the tests.tablex
, cetz
, fletcher
... and format them to ensure: (a) the format result converges, and (b) the rendered output is the same.We provide benchmarks for node attribute computation and pretty printing. Typically, it can format a large document (given parsed source) within 5ms (e.g., tablex.typ
with ~3000 lines).
We also have continuous benchmarking for each commit on master
branch. See https://typstyle-rs.github.io/typstyle-bench-results/dev/bench/.
Why there is a need for another formatter? We already have typstfmt, typstfmt, prettypst. Why another one?
Typstyle started because I had a bunch of ideas on how to improve typst source code formatting but kept finding typstfmt wasn't a good codebase to explore them with. Namely:
So I decided to write something from scratch. I started it about half a year ago and kept working on it in my spare time. Currently it lacks some advanced features but it is already usable for most of the cases. I hope you like it!
See https://typstyle-rs.github.io/typstyle/.
See the tracking issue.
You tell us! Bad formatting? Incorrect output? Please create an issue on the GitHub repository!
We've set up comprehensive test suites to ensure the correctness of the formatter. If you find any issues, please let us know! And we can add more tests to prevent the issue from happening again.
See CONTRIBUTING.md for details.