Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
T

typstyle

> 数据库
Open source

Beautiful and reliable typst code formatter

870 stars0 likes0 views
WebsiteGitHub

About

Beautiful and reliable typst code formatter

typstyle

A beautiful and reliable code formatter for Typst.

Try Online First

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.

Installation and Usage

Use as a CLI

Installation

You can install typstyle using any of the following methods:

  1. Download the binary from the release page.

  2. Install it from your package manager: .

    1. Notably, typstyle is available in Archlinux CN repo.
  3. Install using cargo-binstall:

    bash
    cargo binstall typstyle
  4. Install it with cargo:

    bash
    cargo install typstyle --locked

CLI Usage

…

Examples

  • Format a file in place:

    bash
    typstyle -i file.typ
  • Format a file and print the result to stdout:

    bash
    typstyle file.typ
  • Format multiple files in place:

    bash
    typstyle -i file1.typ file2.typ dir/
  • Format all files in a directory:

    bash
    typstyle -i dir
  • Read from stdin and print the result to stdout:

    bash
    cat file.typ | typstyle > file-formatted.typ

Use in your editor

Typstyle has been integrated into tinymist. You can use it in your editor by installing the tinymist plugin and set tinymist.formatterMode to typstyle.

Use in typst.app

Checkout typstyle-tampermonkey, a userscript that integrates typstyle into the typst.app editor.

Use as a web app

Try the playground at:

The playground integrates the latest version of typstyle. If you encounter formatting issues, please verify them in the playground first before reporting bugs.

Use as a Library

  • Rust:
  • WebAssembly:

Use as a GitHub Action

The typstyle-action maintained by @grayespinoza can install and run typstyle in a GitHub Action.

Use with pre-commit

Add this to your .pre-commit-config.yaml:

yaml
  - repo: https://github.com/typstyle-rs/pre-commit-typstyle
    rev: ''  # The revision or tag you want to use
    hooks:
      - id: typstyle

Features & Design

Design Goals

  1. Opinionated: We want to have a consistent style across all codebases.
  2. Code only: We want to format only the code. Contents should be left untouched as much as possible.
  3. Convergence: Running the formatter twice should not change the code.
  4. Correctness: The formatter should not change the looking of the rendered output.

Escape Hatch

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:

  • contains syntax error
  • contains syntaxes that are not supported by the formatter

And please let us know the issue by creating an issue on the GitHub repository

Testing

We maintain a comprehensive suite of tests to ensure the correctness and reliability of typstyle.

  1. Convergence tests: Format result must be the same when applied twice.
  2. Snapshot tests: Format result are stored in the snapshots directory and are compared to the current result when running the tests.
  3. Correctness test: We compare the rendered output of the code before and after formatting and ensure they are the same.
  4. E2E Correctness test: We collect a bunch of typst code repo including tablex, cetz, fletcher... and format them to ensure: (a) the format result converges, and (b) the rendered output is the same.
  5. CLI tests: We ensure that the CLI arguments can correctly control the behavior of the program, and the output is desirable.

Benchmark

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 .

Why Another Formatter?

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:

  • I wanted to use Wadler's pretty printer (implemented by pretty.rs) to get consistent and beautiful output for any width. (Note that it is the same technique used in the prettier formatter)
  • I didn't have much energy to maintain a bunch combination of configuration options. It turns out to be very hard to make everything correct. So I decided to make it opinionated.
  • I wanted to experiment with more testing techniques and make sure the formatter is correct.

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!

Documentation

See .

Roadmap

See the tracking issue.

Known Issues

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.

Contributing

See CONTRIBUTING.md for details.

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Rustformattertypsttypstfmt

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category数据库
PricingOpen source

> Related tools

P
PostgreSQL
功能强大的开源关系型数据库
R
Redis
内存数据结构存储,常用作缓存与队列
M
MySQL
广泛使用的开源关系型数据库