{"route":"/en-US-v0.14.1/reference/math/","title":"Math","description":"Documentation for functions related to Math in Typst.","part":null,"outline":[{"id":"summary","name":"Summary","children":[]},{"id":"variables","name":"Variables","children":[]},{"id":"symbols","name":"Symbols","children":[]},{"id":"line-breaks","name":"Line Breaks","children":[]},{"id":"function-calls","name":"Function calls","children":[]},{"id":"alignment","name":"Alignment","children":[]},{"id":"math-fonts","name":"Math fonts","children":[]},{"id":"math-module","name":"Math module","children":[]},{"id":"accessibility","name":"Accessibility","children":[]},{"id":"definitions","name":"Definitions","children":[]}],"body":{"kind":"category","content":{"name":"math","title":"Math","details":"<p>Typst has special <a href=\"/en-US-v0.14.1/reference/syntax/#math\">syntax</a> and library functions to typeset\nmathematical formulas. Math formulas can be displayed inline with text or as\nseparate blocks. They will be typeset into their own block if they start and end\nwith at least one space (e.g. <code><span class=\"typ-math-delim\">$</span> x<span class=\"typ-math-op\">^</span>2 <span class=\"typ-math-delim\">$</span></code>).</p>\n<h2 id=\"variables\">Variables</h2>\n<p>In math, single letters are always displayed as is. Multiple letters, however,\nare interpreted as variables and functions. To display multiple letters\nverbatim, you can place them into quotes and to access single letter variables,\nyou can use the <a href=\"/en-US-v0.14.1/reference/scripting/#expressions\">hash syntax</a>.</p>\n<div class=\"previewed-code\"><pre><code><span class=\"typ-math-delim\">$</span> A = <span class=\"typ-pol\">pi</span> r<span class=\"typ-math-op\">^</span>2 <span class=\"typ-math-delim\">$</span>\n<span class=\"typ-math-delim\">$</span> <span class=\"typ-str\">&quot;area&quot;</span> = <span class=\"typ-pol\">pi</span> <span class=\"typ-pol\">dot</span> <span class=\"typ-str\">&quot;radius&quot;</span><span class=\"typ-math-op\">^</span>2 <span class=\"typ-math-delim\">$</span>\n<span class=\"typ-math-delim\">$</span> <span class=\"typ-func\">cal</span><span class=\"typ-punct\">(</span>A<span class=\"typ-punct\">)</span> <span class=\"typ-escape\">:=</span>\n    { x <span class=\"typ-pol\">in</span> <span class=\"typ-pol\">RR</span> | x <span class=\"typ-str\">&quot;is natural&quot;</span> } <span class=\"typ-math-delim\">$</span>\n<span class=\"typ-key\">#</span><span class=\"typ-key\">let</span> x <span class=\"typ-op\">=</span> <span class=\"typ-num\">5</span>\n<span class=\"typ-math-delim\">$</span> <span class=\"typ-pol\">#</span><span class=\"typ-pol\">x</span> &lt; 17 <span class=\"typ-math-delim\">$</span>\n</code></pre><div class=\"preview\"><img src=\"/en-US-v0.14.1/assets/8524e76a7c6784dd9c30bb62d92a4897.png\" alt=\"Preview\"></div></div>\n<h2 id=\"symbols\">Symbols</h2>\n<p>Math mode makes a wide selection of <a href=\"/en-US-v0.14.1/reference/symbols/sym/\">symbols</a> like <code>pi</code>,\n<code>dot</code>, or <code>RR</code> available. Many mathematical symbols are available in different\nvariants. You can select between different variants by applying\n<a href=\"/en-US-v0.14.1/reference/foundations/symbol/\">modifiers</a> to the symbol. Typst further recognizes a number of\nshorthand sequences like <code>=&gt;</code> that approximate a symbol. When such a shorthand\nexists, the symbol's documentation lists it.</p>\n<div class=\"previewed-code\"><pre><code><span class=\"typ-math-delim\">$</span> x &lt; y <span class=\"typ-escape\">=&gt;</span> x <span class=\"typ-pol\">gt</span><span class=\"typ-punct\">.</span><span class=\"typ-pol\">eq</span><span class=\"typ-punct\">.</span><span class=\"typ-pol\">not</span> y <span class=\"typ-math-delim\">$</span>\n</code></pre><div class=\"preview\"><img src=\"/en-US-v0.14.1/assets/dd08c3941abc7b8b1c9310fbebf71b6e.png\" alt=\"Preview\"></div></div>\n<h2 id=\"line-breaks\">Line Breaks</h2>\n<p>Formulas can also contain line breaks. Each line can contain one or multiple\n<em>alignment points</em> (<code>&amp;</code>) which are then aligned.</p>\n<div class=\"previewed-code\"><pre><code><span class=\"typ-math-delim\">$</span> <span class=\"typ-pol\">sum</span><span class=\"typ-math-op\">_</span><span class=\"typ-punct\">(</span>k=0<span class=\"typ-punct\">)</span><span class=\"typ-math-op\">^</span>n k\n    <span class=\"typ-math-op\">&amp;</span>= 1 + <span class=\"typ-escape\">...</span> + n <span class=\"typ-escape\">\\</span>\n    <span class=\"typ-math-op\">&amp;</span>= <span class=\"typ-punct\">(</span>n(n+1)<span class=\"typ-punct\">)</span> <span class=\"typ-math-op\">/</span> 2 <span class=\"typ-math-delim\">$</span>\n</code></pre><div class=\"preview\"><img src=\"/en-US-v0.14.1/assets/e18e117e8b98666dc9823bbeed6dd264.png\" alt=\"Preview\"></div></div>\n<h2 id=\"function-calls\">Function calls</h2>\n<p>Math mode supports special function calls without the hash prefix. In these\n&quot;math calls&quot;, the argument list works a little differently than in code:</p>\n<ul>\n<li>Within them, Typst is still in &quot;math mode&quot;. Thus, you can write math directly\ninto them, but need to use hash syntax to pass code expressions (except for\nstrings, which are available in the math syntax).</li>\n<li>They support positional and named arguments, as well as argument spreading.</li>\n<li>They don't support trailing content blocks.</li>\n<li>They provide additional syntax for 2-dimensional argument lists. The semicolon\n(<code>;</code>) merges preceding arguments separated by commas into an array argument.</li>\n</ul>\n<div class=\"previewed-code\"><pre><code><span class=\"typ-math-delim\">$</span> <span class=\"typ-func\">frac</span><span class=\"typ-punct\">(</span>a<span class=\"typ-math-op\">^</span>2<span class=\"typ-punct\">,</span> 2<span class=\"typ-punct\">)</span> <span class=\"typ-math-delim\">$</span>\n<span class=\"typ-math-delim\">$</span> <span class=\"typ-func\">vec</span><span class=\"typ-punct\">(</span>1<span class=\"typ-punct\">,</span> 2<span class=\"typ-punct\">,</span> delim<span class=\"typ-punct\">:</span> <span class=\"typ-str\">&quot;[&quot;</span><span class=\"typ-punct\">)</span> <span class=\"typ-math-delim\">$</span>\n<span class=\"typ-math-delim\">$</span> <span class=\"typ-func\">mat</span><span class=\"typ-punct\">(</span>1<span class=\"typ-punct\">,</span> 2<span class=\"typ-punct\">;</span> 3<span class=\"typ-punct\">,</span> 4<span class=\"typ-punct\">)</span> <span class=\"typ-math-delim\">$</span>\n<span class=\"typ-math-delim\">$</span> <span class=\"typ-func\">mat</span><span class=\"typ-punct\">(</span><span class=\"typ-op\">..</span><span class=\"typ-func\">#</span><span class=\"typ-func\">range</span><span class=\"typ-punct\">(</span><span class=\"typ-num\">1</span><span class=\"typ-punct\">,</span> <span class=\"typ-num\">5</span><span class=\"typ-punct\">)</span><span class=\"typ-punct\">.</span><span class=\"typ-func\">chunks</span><span class=\"typ-punct\">(</span><span class=\"typ-num\">2</span><span class=\"typ-punct\">)</span><span class=\"typ-punct\">)</span> <span class=\"typ-math-delim\">$</span>\n<span class=\"typ-math-delim\">$</span> <span class=\"typ-pol\">lim</span><span class=\"typ-math-op\">_</span>x =\n    <span class=\"typ-func\">op</span><span class=\"typ-punct\">(</span><span class=\"typ-str\">&quot;lim&quot;</span><span class=\"typ-punct\">,</span> limits<span class=\"typ-punct\">:</span> <span class=\"typ-key\">#</span><span class=\"typ-key\">true</span><span class=\"typ-punct\">)</span><span class=\"typ-math-op\">_</span>x <span class=\"typ-math-delim\">$</span>\n</code></pre><div class=\"preview\"><img src=\"/en-US-v0.14.1/assets/a04e7f595e2b6bd62e8eb21bcf63a042.png\" alt=\"Preview\"></div></div>\n<p>To write a verbatim comma or semicolon in a math call, escape it with a\nbackslash. The colon on the other hand is only recognized in a special way if\ndirectly preceded by an identifier, so to display it verbatim in those cases,\nyou can just insert a space before it.</p>\n<p>Functions calls preceded by a hash are normal code function calls and not\naffected by these rules.</p>\n<h2 id=\"alignment\">Alignment</h2>\n<p>When equations include multiple <em>alignment points</em> (<code>&amp;</code>), this creates blocks of\nalternatingly right- and left-aligned columns. In the example below, the\nexpression <code>(3x + y) / 7</code> is right-aligned and <code>= 9</code> is left-aligned. The word\n&quot;given&quot; is also left-aligned because <code>&amp;&amp;</code> creates two alignment points in a row,\nalternating the alignment twice. <code>&amp; &amp;</code> and <code>&amp;&amp;</code> behave exactly the same way.\nMeanwhile, &quot;multiply by 7&quot; is right-aligned because just one <code>&amp;</code> precedes it.\nEach alignment point simply alternates between right-aligned/left-aligned.</p>\n<div class=\"previewed-code\"><pre><code><span class=\"typ-math-delim\">$</span> <span class=\"typ-punct\">(</span>3x + y<span class=\"typ-punct\">)</span> <span class=\"typ-math-op\">/</span> 7 <span class=\"typ-math-op\">&amp;</span>= 9 <span class=\"typ-math-op\">&amp;</span><span class=\"typ-math-op\">&amp;</span> <span class=\"typ-str\">&quot;given&quot;</span> <span class=\"typ-escape\">\\</span>\n  3x + y <span class=\"typ-math-op\">&amp;</span>= 63 <span class=\"typ-math-op\">&amp;</span> <span class=\"typ-str\">&quot;multiply by 7&quot;</span> <span class=\"typ-escape\">\\</span>\n  3x <span class=\"typ-math-op\">&amp;</span>= 63 <span class=\"typ-escape\">-</span> y <span class=\"typ-math-op\">&amp;</span><span class=\"typ-math-op\">&amp;</span> <span class=\"typ-str\">&quot;subtract y&quot;</span> <span class=\"typ-escape\">\\</span>\n  x <span class=\"typ-math-op\">&amp;</span>= 21 <span class=\"typ-escape\">-</span> y<span class=\"typ-math-op\">/</span>3 <span class=\"typ-math-op\">&amp;</span> <span class=\"typ-str\">&quot;divide by 3&quot;</span> <span class=\"typ-math-delim\">$</span>\n</code></pre><div class=\"preview\"><img src=\"/en-US-v0.14.1/assets/f1233da95c9167f12592cfc2f7cf3674.png\" alt=\"Preview\"></div></div>\n<h2 id=\"math-fonts\">Math fonts</h2>\n<p>You can set the math font by with a <a href=\"/en-US-v0.14.1/reference/styling/#show-rules\">show-set rule</a> as\ndemonstrated below. Note that only special OpenType math fonts are suitable for\ntypesetting maths.</p>\n<div class=\"previewed-code\"><pre><code><span class=\"typ-key\">#</span><span class=\"typ-key\">show</span> math<span class=\"typ-punct\">.</span><span class=\"typ-func\">equation</span><span class=\"typ-punct\">:</span> <span class=\"typ-key\">set</span> <span class=\"typ-func\">text</span><span class=\"typ-punct\">(</span>font<span class=\"typ-punct\">:</span> <span class=\"typ-str\">&quot;Fira Math&quot;</span><span class=\"typ-punct\">)</span>\n<span class=\"typ-math-delim\">$</span> <span class=\"typ-pol\">sum</span><span class=\"typ-math-op\">_</span><span class=\"typ-punct\">(</span>i <span class=\"typ-pol\">in</span> <span class=\"typ-pol\">NN</span><span class=\"typ-punct\">)</span> 1 + i <span class=\"typ-math-delim\">$</span>\n</code></pre><div class=\"preview\"><img src=\"/en-US-v0.14.1/assets/a86f5771fd97e49bb413be94448c5f66.png\" alt=\"Preview\"></div></div>\n<h2 id=\"math-module\">Math module</h2>\n<p>All math functions are part of the <code>math</code> <a href=\"/en-US-v0.14.1/reference/scripting/#modules\">module</a>, which\nis available by default in equations. Outside of equations, they can be accessed\nwith the <code>math.</code> prefix.</p>\n<h2 id=\"accessibility\">Accessibility</h2>\n<p>To make math accessible, you must provide alternative descriptions of equations\nin natural language using the <a href=\"/en-US-v0.14.1/reference/math/equation/#parameters-alt\"><code>alt</code> parameter of\n<code>math.equation</code></a>. For more information, see the <a href=\"/en-US-v0.14.1/guides/accessibility/#textual-representations\">Textual\nRepresentations section of the Accessibility\nGuide</a>.</p>\n<div class=\"previewed-code\"><pre><code><span class=\"typ-pol\">#</span><span class=\"typ-pol\">math</span><span class=\"typ-punct\">.</span><span class=\"typ-func\">equation</span><span class=\"typ-punct\">(</span>\n  alt<span class=\"typ-punct\">:</span> <span class=\"typ-str\">&quot;d S equals delta q divided by T&quot;</span><span class=\"typ-punct\">,</span>\n  block<span class=\"typ-punct\">:</span> <span class=\"typ-key\">true</span><span class=\"typ-punct\">,</span>\n  <span class=\"typ-math-delim\">$</span> <span class=\"typ-pol\">dif</span> S = <span class=\"typ-punct\">(</span><span class=\"typ-pol\">delta</span> q<span class=\"typ-punct\">)</span> <span class=\"typ-math-op\">/</span> T <span class=\"typ-math-delim\">$</span><span class=\"typ-punct\">,</span>\n<span class=\"typ-punct\">)</span>\n</code></pre><div class=\"preview\"><img src=\"/en-US-v0.14.1/assets/20d64e50eb0363ab3beb776d3cec11dc.png\" alt=\"Preview\"></div></div>\n<p>In the future, Typst will automatically make equations without alternative\ndescriptions accessible in HTML and PDF 2.0 export.</p>","items":[{"name":"accent","route":"/en-US-v0.14.1/reference/math/accent/","oneliner":"Attaches an accent to a base.","code":true},{"name":"attach","route":"/en-US-v0.14.1/reference/math/attach/","oneliner":"Subscript, superscripts, and limits.","code":false},{"name":"binom","route":"/en-US-v0.14.1/reference/math/binom/","oneliner":"A binomial expression.","code":true},{"name":"cancel","route":"/en-US-v0.14.1/reference/math/cancel/","oneliner":"Displays a diagonal line over a part of an equation.","code":true},{"name":"cases","route":"/en-US-v0.14.1/reference/math/cases/","oneliner":"A case distinction.","code":true},{"name":"class","route":"/en-US-v0.14.1/reference/math/class/","oneliner":"Forced use of a certain math class.","code":true},{"name":"equation","route":"/en-US-v0.14.1/reference/math/equation/","oneliner":"A mathematical equation.","code":true},{"name":"frac","route":"/en-US-v0.14.1/reference/math/frac/","oneliner":"A mathematical fraction.","code":true},{"name":"lr","route":"/en-US-v0.14.1/reference/math/lr/","oneliner":"Delimiter matching.","code":false},{"name":"mat","route":"/en-US-v0.14.1/reference/math/mat/","oneliner":"A matrix.","code":true},{"name":"op","route":"/en-US-v0.14.1/reference/math/op/","oneliner":"A text operator in an equation.","code":true},{"name":"primes","route":"/en-US-v0.14.1/reference/math/primes/","oneliner":"Grouped primes.","code":true},{"name":"roots","route":"/en-US-v0.14.1/reference/math/roots/","oneliner":"Square and non-square roots.","code":false},{"name":"sizes","route":"/en-US-v0.14.1/reference/math/sizes/","oneliner":"Forced size styles for expressions within formulas.","code":false},{"name":"stretch","route":"/en-US-v0.14.1/reference/math/stretch/","oneliner":"Stretches a glyph.","code":true},{"name":"styles","route":"/en-US-v0.14.1/reference/math/styles/","oneliner":"Alternate letterforms within formulas.","code":false},{"name":"underover","route":"/en-US-v0.14.1/reference/math/underover/","oneliner":"Delimiters above or below parts of an equation.","code":false},{"name":"variants","route":"/en-US-v0.14.1/reference/math/variants/","oneliner":"Alternate typefaces within formulas.","code":false},{"name":"vec","route":"/en-US-v0.14.1/reference/math/vec/","oneliner":"A column vector.","code":true}],"shorthands":null}}}