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

#

Math Equation Formatting

#

Formatting Rules

typstyle applies specific formatting rules to math equations:

  • Spaces are preserved around fractions when they exist
  • No padding is added to the last cell in math alignments
  • Backslashes are preserved
  • Inline equations are never aligned or padded
  • Spaces between variables and underscores are preserved: $ #mysum _(i=0) $

#

Alignment

typstyle aligns & symbols in math equations, even with multiline cells. Non-block equations are never aligned:

Example
Before
$1/2x + y &= 3 \ y &= 3 - 1/2x$

$
F_n&=sum_(i=1)^n i^2&n > 0 \
a&<b+1&forall b < 1
$

$
a&=cases(
x + y, "if condition A",
z + w, "if condition B"
) \
b&=matrix(
1, 2;
3, 4
) \
c&=sum_(i=1)^n x_i
$
After
$1/2x + y &= 3 \ y &= 3 - 1/2x$

$
  F_n & =sum_(i=1)^n i^2 &        n > 0 \
    a & <b+1             & forall b < 1
$

$
  a & =cases(
        x + y, "if condition A",
        z + w, "if condition B"
      ) \
  b & =matrix(
        1, 2;
        3, 4
      ) \
  c & =sum_(i=1)^n x_i
$

#

Block vs Inline Equations

typstyle uses flavor detection for equations. Block equations with newlines are formatted with proper indentation:

Example
Before
$ F(x) = integral_0^x f(t) dif t
$

$
F(x) = integral_0^x f(t) dif t $
After
$
  F(x) = integral_0^x f(t) dif t
$

$
  F(x) = integral_0^x f(t) dif t
$

#

Comments in Math

typstyle can format math equations containing comments while preserving their meaning and proper placement:

Example
Before
$frac(// numerator
x, /* denominator */ y)$

$mat(1, /* row 1 */ 2; 3, // row 2
4)$

$sum_(i=1 /* start */ )^(n // end
) x_i$
After
$frac(
  // numerator
  x, /* denominator */ y
)$

$mat(
  1, /* row 1 */ 2; 3, // row 2
  4,
)$

$sum_(i=1 /* start */ )^(n // end
) x_i$