Math Equation Formatting
Typstyle uses flavor detection for equations, which is decided on the direct space after the opening $$.
Example
Before
$ sin $$ cos$$tan $
$ sin $$ cos$$tan $
After
$ sin $$ cos $$ tan$
$ sin $$ cos $$ tan$
You can easily switch equations between inline and block by altering the direct space after the opening $$.
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) $$ #mysum _(i=0) $
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$
$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$
$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$
typstyle can format math equations containing comments while preserving their meaning and proper placement:
Example
Before
$frac(// numeratorx, /* denominator */ y)$$mat(1, /* row 1 */ 2; 3, // row 24)$$sum_(i=1 /* start */ )^(n // end) x_i$
$frac(// numeratorx, /* denominator */ y)$$mat(1, /* row 1 */ 2; 3, // row 24)$$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$
$frac( // numerator x, /* denominator */ y)$$mat( 1, /* row 1 */ 2; 3, // row 2 4,)$$sum_(i=1 /* start */ )^(n // end) x_i$