1. Introduction
  2. User Guide
  3. 1. Installation
  4. 2. Quick Start
  5. 3. Changelog
  6. Usage
  7. 4. Command Line Interface
  8. 5. Editor Integration
  9. Features
  10. 6. Formatting Features
    1. 6.1. Markup
    2. 6.2. Code
    3. 6.3. Math Equations
    4. 6.4. Tables
  11. 7. Escape Hatch
  12. 8. Limitations
  13. Advanced
  14. 9. How It Works
  15. 10. Developer Guide
    1. 10.1. Core
    2. 10.2. Documentation
    3. 10.3. Playground

typstyle

#

Formatting Features

Typstyle follows a consistent set of formatting rules to ensure your Typst code is readable, maintainable, and follows established conventions. This page documents the core formatting styles applied by typstyle.

ℹ Note

All examples are automatically rendered using the embedded typstyle formatter, ensuring they always reflect the latest features.

However, documentation updates may lag behind new features. If there are inconsistencies between descriptions and example output, the actual formatting behavior takes precedence.

#

Configuration

#

Line Width and Indentation

  • Default line width: 80 characters (configurable with --line-width)
  • Default indentation: 2 spaces per level (configurable with --indent-width)
  • File endings: typstyle ensures files end with a newline character

#

Comments

#

Inline Comments

Inline comments are preserved and positioned correctly:

Example
Before
#let conf(   title: none,//comments
authors: (),
  abstract: [],
    lang:     "zh",// language
  doctype: "book",//comments

doc,// my docs
) = { doc
}

#{
  let c = 0// my comment
}
After
#let conf(
  title: none, //comments
  authors: (),
  abstract: [],
  lang: "zh", // language
  doctype: "book", //comments
  doc, // my docs
) = { doc }

#{
  let c = 0 // my comment
}

#

Block Comments

Block comments are automatically aligned and formatted:

Example
Before
#{
  let x = 1   /* Attached block comment
      that spans
 multiple lines
  */

  /* Block comment
      that spans
 multiple lines
  */
}

Aligned: /* Block comment with leading stars
    *  that
        *  spans
 *  multiple
    *  lines
  */
After
#{
  let x = 1 /* Attached block comment
                 that spans
            multiple lines
             */

  /* Block comment
       that spans
  multiple lines
   */
}

Aligned: /* Block comment with leading stars
          *  that
          *  spans
          *  multiple
          *  lines
          */

#

Disabling Formatting

Use // @typstyle off to disable formatting for specific code regions:

Example
Before
// @typstyle off
#let intentionally_bad_format    =    "preserved";
#let properly_formatted="cleaned up"
After
// @typstyle off
#let intentionally_bad_format    =    "preserved";
#let properly_formatted = "cleaned up"
ℹ Note

The escape hatch only applies to the next syntax node, not the rest of the code.

There is no closing // @typstyle on directive.

For details, please see Escape Hatch.