Math
Math is a special environment that has special features related to... math.
Syntax
To start math environment, $
. The spacing around $
will make it either
inline math (smaller, used in text) or display math (used on math equations on their own).
// This is inline math
Let $a$, $b$, and $c$ be the side
lengths of right-angled triangle.
Then, we know that:
// This is display math
$ a^2 + b^2 = c^2 $
Prove by induction:
// You can use new lines as spacing too!
$
sum_(k=1)^n k = (n(n+1)) / 2
$
Math.equation
The element that math is displayed in is called math.equation
. You can use it for set/show rules:
#show math.equation: set text(red)
$
integral_0^oo (f(t) + g(t))/2
$
Any symbol/command that is available in math, is also available in code mode using math.command
:
#math.integral, #math.underbrace([a + b], [c])
Letters and commands
Typst aims to have as simple and effective syntax for math as possible. That means no special symbols, just using commands.
To make it short, Typst uses several simple rules:
-
All single-letter words turn into variables. That includes any unicode symbols too!
-
All multi-letter words turn into commands. They may be built-in commands (available with math.something outside of math environment). Or they may be user-defined variables/functions. If the command isn't defined, there will be compilation error.
If you use kebab-case or snake_case for variables you want to use in math, you will have to refer to them as #snake-case-variable. -
To write simple text, use quotes:
$a "equals to" 2$
Spacing matters there!$a "is" 2$, $a"is"2$
-
You can turn it into multi-letter variables using
italic
:$(italic("mass") v^2)/2$
Commands see there (go to the links to see the commands).
All symbols see there.
Multiline equations
To create multiline display equation, use the same symbol as in markup mode: \
:
$
a = b\
a = c
$
Escaping
Any symbol that is used may be escaped with \
, like in markup mode. For example, you can disable fraction:
$
a / b \
a \/ b
$
The same way it works with any other syntax.
Wrapping inline math
Sometimes, when you write large math, it may be too close to text (especially for some long letter tails).
#lorem(17) $display(1)/display(1+x^n)$ #lorem(20)
You may easily increase the distance it by wrapping into box:
#lorem(17) #box($display(1)/display(1+x^n)$, inset: 0.2em) #lorem(20)