Math
Typst has special syntax and library functions
to typeset mathematical formulas. Math formulas can be displayed inline with
text or as separate blocks. They will be typeset into their own block if they
start and end with at least one space (e.g. $ x^2 $
).
In math, single letters are always displayed as is. Multiple letters, however, are interpreted as variables and functions. To display multiple letters verbatim, you can place them into quotes and to access single letter variables, you can use the hashtag syntax.
$ A = pi r^2 $
$ "area" = pi dot "radius"^2 $
$ cal(A) :=
{ x in RR | x "is natural" } $
#let x = 5
$ #x < 17 $

Math mode makes a wide selection of symbols like
pi
, dot
, or RR
available. Many mathematical symbols are available in
different variants. You can select between different variants by applying
modifiers to the symbol. Typst further recognizes a number of
shorthand sequences like =>
that approximate a symbol. When such a shorthand
exists, the symbol's documentation lists it.
$ x < y => x gt.eq.not y $

Formulas can also contain line breaks. Each line can contain one or multiple
alignment points (&
) which are then aligned.
$ sum_(k=0)^n k
&= 1 + ... + n \
&= (n(n+1)) / 2 $

Math mode supports special function calls without the hashtag prefix. In these "math calls", the argument list works a little differently than in code:
- Within them, Typst is still in "math mode". Thus, you can write math directly into them, but need to use hashtag syntax to pass code expressions (except for strings, which are available in the math syntax).
- They support positional and named arguments, but don't support trailing content blocks and argument spreading.
- They provide additional syntax for 2-dimensional argument lists. The
semicolon (
;
) merges preceding arguments separated by commas into an array argument.
$ frac(a^2, 2) $
$ vec(1, 2, delim: "[") $
$ mat(1, 2; 3, 4) $
$ lim_x =
op("lim", limits: #true)_x $

To write a verbatim comma or semicolon in a math call, escape it with a backslash. The colon on the other hand is only recognized in a special way if directly preceded by an identifier, so to display it verbatim in those cases, you can just insert a space before it.
Functions calls preceded by a hashtag are normal code function calls and not affected by these rules.
All math functions are part of the math
module, which
is available by default in equations. Outside of equations, they can be
accessed with the math.
prefix. For example, to set the font used for
equations, write:
#show math.equation: set text(font: "Fira Math")
$ sum_(i in NN) 1 + i $

Functions
accent
Attach an accent to a base.- attachSubscript, superscripts, and limits.
binom
A binomial expression.cancel
Displays a diagonal line over a part of an equation.cases
A case distinction.equation
A mathematical equation.frac
A mathematical fraction.- lrDelimiter matching.
mat
A matrix.op
A text operator in an equation.- rootsSquare and non-square roots.
round
Round an expression.- stylesAlternate letterforms within formulas.
- underoverDelimiters above or below parts of an equation.
- variantsAlternate typefaces within formulas.
vec
A column vector.