{"route":"/en-US-v0.14.1/reference/syntax/","title":"Syntax","description":"A compact reference for Typst's syntax. Learn more about the language within\nmarkup, math, and code mode.\n","part":"Language","outline":[{"id":"modes","name":"Modes","children":[]},{"id":"markup","name":"Markup","children":[]},{"id":"math","name":"Math","children":[]},{"id":"code","name":"Code","children":[]},{"id":"comments","name":"Comments","children":[]},{"id":"escapes","name":"Escapes","children":[]},{"id":"identifiers","name":"Identifiers","children":[]},{"id":"paths","name":"Paths","children":[{"id":"project-root","name":"Project root","children":[]},{"id":"paths-and-packages","name":"Paths and packages","children":[]}]}],"body":{"kind":"html","content":"<h1>Syntax</h1>\n<p>Typst is a markup language. This means that you can use simple syntax to\naccomplish common layout tasks. The lightweight markup syntax is complemented by\nset and show rules, which let you style your document easily and automatically.\nAll this is backed by a tightly integrated scripting language with built-in and\nuser-defined functions.</p>\n<h2 id=\"modes\">Modes</h2>\n<p>Typst has three syntactical modes: Markup, math, and code. Markup mode is the\ndefault in a Typst document, math mode lets you write mathematical formulas, and\ncode mode lets you use Typst's scripting features.</p>\n<p>You can switch to a specific mode at any point by referring to the following\ntable:</p>\n<table><thead><tr><th>New mode</th><th>Syntax</th><th>Example</th></tr></thead><tbody>\n<tr><td>Code</td><td>Prefix the code with <code>#</code></td><td><code>Number: <span class=\"typ-punct\">#</span><span class=\"typ-punct\">(</span><span class=\"typ-num\">1</span> <span class=\"typ-op\">+</span> <span class=\"typ-num\">2</span><span class=\"typ-punct\">)</span></code></td></tr>\n<tr><td>Math</td><td>Surround equation with <code><span class=\"typ-math-delim\">$</span>..<span class=\"typ-math-delim\">$</span></code></td><td><code><span class=\"typ-math-delim\">$</span><span class=\"typ-escape\">-</span>x<span class=\"typ-math-delim\">$</span> is the opposite of <span class=\"typ-math-delim\">$</span>x<span class=\"typ-math-delim\">$</span></code></td></tr>\n<tr><td>Markup</td><td>Surround markup with <code>[..]</code></td><td><code><span class=\"typ-key\">let</span> name <span class=\"typ-op\">=</span> <span class=\"typ-punct\">[</span><span class=\"typ-strong\">*Typst!*</span><span class=\"typ-punct\">]</span></code></td></tr>\n</tbody></table>\n<p>Once you have entered code mode with <code>#</code>, you don't need to use further hashes\nunless you switched back to markup or math mode in between.</p>\n<h2 id=\"markup\">Markup</h2>\n<p>Typst provides built-in markup for the most common document elements. Most of\nthe syntax elements are just shortcuts for a corresponding function. The table\nbelow lists all markup that is available and links to the  best place to learn\nmore about their syntax and usage.</p>\n<table><thead><tr><th>Name</th><th>Example</th><th>See</th></tr></thead><tbody>\n<tr><td>Paragraph break</td><td>Blank line</td><td><a href=\"/en-US-v0.14.1/reference/model/parbreak/\" title=\"`parbreak`\"><code>parbreak</code></a></td></tr>\n<tr><td>Strong emphasis</td><td><code><span class=\"typ-strong\">*strong*</span></code></td><td><a href=\"/en-US-v0.14.1/reference/model/strong/\" title=\"`strong`\"><code>strong</code></a></td></tr>\n<tr><td>Emphasis</td><td><code><span class=\"typ-emph\">_emphasis_</span></code></td><td><a href=\"/en-US-v0.14.1/reference/model/emph/\" title=\"`emph`\"><code>emph</code></a></td></tr>\n<tr><td>Raw text</td><td><code><span class=\"typ-raw\">`print(1)`</span></code></td><td><a href=\"/en-US-v0.14.1/reference/text/raw/\" title=\"`raw`\"><code>raw</code></a></td></tr>\n<tr><td>Link</td><td><code><span class=\"typ-link\">https://typst.app/</span></code></td><td><a href=\"/en-US-v0.14.1/reference/model/link/\" title=\"`link`\"><code>link</code></a></td></tr>\n<tr><td>Label</td><td><code><span class=\"typ-label\">&lt;intro&gt;</span></code></td><td><a href=\"/en-US-v0.14.1/reference/foundations/label/\" title=\"`label`\"><code>label</code></a></td></tr>\n<tr><td>Reference</td><td><code><span class=\"typ-ref\">@intro</span></code></td><td><a href=\"/en-US-v0.14.1/reference/model/ref/\" title=\"`ref`\"><code>ref</code></a></td></tr>\n<tr><td>Heading</td><td><code><span class=\"typ-heading\">= Heading</span></code></td><td><a href=\"/en-US-v0.14.1/reference/model/heading/\" title=\"`heading`\"><code>heading</code></a></td></tr>\n<tr><td>Bullet list</td><td><code><span class=\"typ-marker\">-</span> item</code></td><td><a href=\"/en-US-v0.14.1/reference/model/list/\" title=\"`list`\"><code>list</code></a></td></tr>\n<tr><td>Numbered list</td><td><code><span class=\"typ-marker\">+</span> item</code></td><td><a href=\"/en-US-v0.14.1/reference/model/enum/\" title=\"`enum`\"><code>enum</code></a></td></tr>\n<tr><td>Term list</td><td><code><span class=\"typ-marker\">/</span> <span class=\"typ-term\">Term</span><span class=\"typ-punct\">:</span> description</code></td><td><a href=\"/en-US-v0.14.1/reference/model/terms/\" title=\"`terms`\"><code>terms</code></a></td></tr>\n<tr><td>Math</td><td><code><span class=\"typ-math-delim\">$</span>x<span class=\"typ-math-op\">^</span>2<span class=\"typ-math-delim\">$</span></code></td><td><a href=\"/en-US-v0.14.1/reference/math/\">Math</a></td></tr>\n<tr><td>Line break</td><td><code><span class=\"typ-escape\">\\</span></code></td><td><a href=\"/en-US-v0.14.1/reference/text/linebreak/\" title=\"`linebreak`\"><code>linebreak</code></a></td></tr>\n<tr><td>Smart quote</td><td><code>&#39;single&#39; or &quot;double&quot;</code></td><td><a href=\"/en-US-v0.14.1/reference/text/smartquote/\" title=\"`smartquote`\"><code>smartquote</code></a></td></tr>\n<tr><td>Symbol shorthand</td><td><code><span class=\"typ-escape\">~</span></code>, <code><span class=\"typ-escape\">---</span></code></td><td><a href=\"/en-US-v0.14.1/reference/symbols/sym/\">Symbols</a></td></tr>\n<tr><td>Code expression</td><td><code><span class=\"typ-func\">#</span><span class=\"typ-func\">rect</span><span class=\"typ-punct\">(</span>width<span class=\"typ-punct\">:</span> <span class=\"typ-num\">1cm</span><span class=\"typ-punct\">)</span></code></td><td><a href=\"/en-US-v0.14.1/reference/scripting/#expressions\">Scripting</a></td></tr>\n<tr><td>Character escape</td><td><code>Tweet at us <span class=\"typ-escape\">\\#</span>ad</code></td><td><a href=\"#escapes\">Below</a></td></tr>\n<tr><td>Comment</td><td><code><span class=\"typ-comment\">/* block */</span></code>, <code><span class=\"typ-comment\">// line</span></code></td><td><a href=\"#comments\">Below</a></td></tr>\n</tbody></table>\n<h2 id=\"math\">Math mode</h2>\n<p>Math mode is a special markup mode that is used to typeset mathematical\nformulas. It is entered by wrapping an equation in <code>$</code> characters. This works\nboth in markup and code. The equation will be typeset into its own block if it\nstarts and ends with 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>). Inline math can be\nproduced by omitting the whitespace (e.g. <code><span class=\"typ-math-delim\">$</span>x<span class=\"typ-math-op\">^</span>2<span class=\"typ-math-delim\">$</span></code>). An overview over the\nsyntax specific to math mode follows:</p>\n<table><thead><tr><th>Name</th><th>Example</th><th>See</th></tr></thead><tbody>\n<tr><td>Inline math</td><td><code><span class=\"typ-math-delim\">$</span>x<span class=\"typ-math-op\">^</span>2<span class=\"typ-math-delim\">$</span></code></td><td><a href=\"/en-US-v0.14.1/reference/math/\">Math</a></td></tr>\n<tr><td>Block-level math</td><td><code><span class=\"typ-math-delim\">$</span> x<span class=\"typ-math-op\">^</span>2 <span class=\"typ-math-delim\">$</span></code></td><td><a href=\"/en-US-v0.14.1/reference/math/\">Math</a></td></tr>\n<tr><td>Bottom attachment</td><td><code><span class=\"typ-math-delim\">$</span>x<span class=\"typ-math-op\">_</span>1<span class=\"typ-math-delim\">$</span></code></td><td><a href=\"/en-US-v0.14.1/reference/math/attach/\"><code>attach</code></a></td></tr>\n<tr><td>Top attachment</td><td><code><span class=\"typ-math-delim\">$</span>x<span class=\"typ-math-op\">^</span>2<span class=\"typ-math-delim\">$</span></code></td><td><a href=\"/en-US-v0.14.1/reference/math/attach/\"><code>attach</code></a></td></tr>\n<tr><td>Fraction</td><td><code><span class=\"typ-math-delim\">$</span>1 + <span class=\"typ-punct\">(</span>a+b<span class=\"typ-punct\">)</span><span class=\"typ-math-op\">/</span>5<span class=\"typ-math-delim\">$</span></code></td><td><a href=\"/en-US-v0.14.1/reference/math/frac/\"><code>frac</code></a></td></tr>\n<tr><td>Line break</td><td><code><span class=\"typ-math-delim\">$</span>x <span class=\"typ-escape\">\\</span> y<span class=\"typ-math-delim\">$</span></code></td><td><a href=\"/en-US-v0.14.1/reference/text/linebreak/\" title=\"`linebreak`\"><code>linebreak</code></a></td></tr>\n<tr><td>Alignment point</td><td><code><span class=\"typ-math-delim\">$</span>x <span class=\"typ-math-op\">&amp;</span>= 2 <span class=\"typ-escape\">\\</span> <span class=\"typ-math-op\">&amp;</span>= 3<span class=\"typ-math-delim\">$</span></code></td><td><a href=\"/en-US-v0.14.1/reference/math/\">Math</a></td></tr>\n<tr><td>Variable access</td><td><code><span class=\"typ-math-delim\">$</span><span class=\"typ-pol\">#</span><span class=\"typ-pol\">x</span><span class=\"typ-math-delim\">$</span>, <span class=\"typ-math-delim\">$</span><span class=\"typ-pol\">pi</span><span class=\"typ-math-delim\">$</span></code></td><td><a href=\"/en-US-v0.14.1/reference/math/\">Math</a></td></tr>\n<tr><td>Field access</td><td><code><span class=\"typ-math-delim\">$</span><span class=\"typ-pol\">arrow</span><span class=\"typ-punct\">.</span><span class=\"typ-pol\">r</span><span class=\"typ-punct\">.</span><span class=\"typ-pol\">long</span><span class=\"typ-math-delim\">$</span></code></td><td><a href=\"/en-US-v0.14.1/reference/scripting/#fields\">Scripting</a></td></tr>\n<tr><td>Implied multiplication</td><td><code><span class=\"typ-math-delim\">$</span>x y<span class=\"typ-math-delim\">$</span></code></td><td><a href=\"/en-US-v0.14.1/reference/math/\">Math</a></td></tr>\n<tr><td>Symbol shorthand</td><td><code><span class=\"typ-math-delim\">$</span><span class=\"typ-escape\">-&gt;</span><span class=\"typ-math-delim\">$</span></code>, <code><span class=\"typ-math-delim\">$</span><span class=\"typ-escape\">!=</span><span class=\"typ-math-delim\">$</span></code></td><td><a href=\"/en-US-v0.14.1/reference/symbols/sym/\">Symbols</a></td></tr>\n<tr><td>Text/string in math</td><td><code><span class=\"typ-math-delim\">$</span>a <span class=\"typ-str\">&quot;is natural&quot;</span><span class=\"typ-math-delim\">$</span></code></td><td><a href=\"/en-US-v0.14.1/reference/math/\">Math</a></td></tr>\n<tr><td>Math function call</td><td><code><span class=\"typ-math-delim\">$</span><span class=\"typ-func\">floor</span><span class=\"typ-punct\">(</span>x<span class=\"typ-punct\">)</span><span class=\"typ-math-delim\">$</span></code></td><td><a href=\"/en-US-v0.14.1/reference/math/\">Math</a></td></tr>\n<tr><td>Code expression</td><td><code><span class=\"typ-math-delim\">$</span><span class=\"typ-func\">#</span><span class=\"typ-func\">rect</span><span class=\"typ-punct\">(</span>width<span class=\"typ-punct\">:</span> <span class=\"typ-num\">1cm</span><span class=\"typ-punct\">)</span><span class=\"typ-math-delim\">$</span></code></td><td><a href=\"/en-US-v0.14.1/reference/scripting/#expressions\">Scripting</a></td></tr>\n<tr><td>Character escape</td><td><code><span class=\"typ-math-delim\">$</span>x<span class=\"typ-escape\">\\^</span>2<span class=\"typ-math-delim\">$</span></code></td><td><a href=\"#escapes\">Below</a></td></tr>\n<tr><td>Comment</td><td><code><span class=\"typ-math-delim\">$</span><span class=\"typ-comment\">/* comment */</span><span class=\"typ-math-delim\">$</span></code></td><td><a href=\"#comments\">Below</a></td></tr>\n</tbody></table>\n<h2 id=\"code\">Code mode</h2>\n<p>Within code blocks and expressions, new expressions can start without a leading\n<code>#</code> character. Many syntactic elements are specific to expressions. Below is\na table listing all syntax that is available in code mode:</p>\n<table><thead><tr><th>Name</th><th>Example</th><th>See</th></tr></thead><tbody>\n<tr><td>None</td><td><code><span class=\"typ-key\">none</span></code></td><td><a href=\"/en-US-v0.14.1/reference/foundations/none/\" title=\"`none`\"><code>none</code></a></td></tr>\n<tr><td>Auto</td><td><code><span class=\"typ-key\">auto</span></code></td><td><a href=\"/en-US-v0.14.1/reference/foundations/auto/\" title=\"`auto`\"><code>auto</code></a></td></tr>\n<tr><td>Boolean</td><td><code><span class=\"typ-key\">false</span></code>, <code><span class=\"typ-key\">true</span></code></td><td><a href=\"/en-US-v0.14.1/reference/foundations/bool/\" title=\"`bool`\"><code>bool</code></a></td></tr>\n<tr><td>Integer</td><td><code><span class=\"typ-num\">10</span></code>, <code><span class=\"typ-num\">0xff</span></code></td><td><a href=\"/en-US-v0.14.1/reference/foundations/int/\" title=\"`int`\"><code>int</code></a></td></tr>\n<tr><td>Floating-point number</td><td><code><span class=\"typ-num\">3.14</span></code>, <code><span class=\"typ-num\">1e5</span></code></td><td><a href=\"/en-US-v0.14.1/reference/foundations/float/\" title=\"`float`\"><code>float</code></a></td></tr>\n<tr><td>Length</td><td><code><span class=\"typ-num\">2pt</span></code>, <code><span class=\"typ-num\">3mm</span></code>, <code><span class=\"typ-num\">1em</span></code>, ..</td><td><a href=\"/en-US-v0.14.1/reference/layout/length/\" title=\"`length`\"><code>length</code></a></td></tr>\n<tr><td>Angle</td><td><code><span class=\"typ-num\">90deg</span></code>, <code><span class=\"typ-num\">1rad</span></code></td><td><a href=\"/en-US-v0.14.1/reference/layout/angle/\" title=\"`angle`\"><code>angle</code></a></td></tr>\n<tr><td>Fraction</td><td><code><span class=\"typ-num\">2fr</span></code></td><td><a href=\"/en-US-v0.14.1/reference/layout/fraction/\" title=\"`fraction`\"><code>fraction</code></a></td></tr>\n<tr><td>Ratio</td><td><code><span class=\"typ-num\">50%</span></code></td><td><a href=\"/en-US-v0.14.1/reference/layout/ratio/\" title=\"`ratio`\"><code>ratio</code></a></td></tr>\n<tr><td>String</td><td><code><span class=\"typ-str\">&quot;hello&quot;</span></code></td><td><a href=\"/en-US-v0.14.1/reference/foundations/str/\" title=\"`str`\"><code>str</code></a></td></tr>\n<tr><td>Label</td><td><code><span class=\"typ-label\">&lt;intro&gt;</span></code></td><td><a href=\"/en-US-v0.14.1/reference/foundations/label/\" title=\"`label`\"><code>label</code></a></td></tr>\n<tr><td>Math</td><td><code><span class=\"typ-math-delim\">$</span>x<span class=\"typ-math-op\">^</span>2<span class=\"typ-math-delim\">$</span></code></td><td><a href=\"/en-US-v0.14.1/reference/math/\">Math</a></td></tr>\n<tr><td>Raw text</td><td><code><span class=\"typ-raw\">`print(1)`</span></code></td><td><a href=\"/en-US-v0.14.1/reference/text/raw/\" title=\"`raw`\"><code>raw</code></a></td></tr>\n<tr><td>Variable access</td><td><code>x</code></td><td><a href=\"/en-US-v0.14.1/reference/scripting/#blocks\">Scripting</a></td></tr>\n<tr><td>Code block</td><td><code><span class=\"typ-punct\">{</span> <span class=\"typ-key\">let</span> x <span class=\"typ-op\">=</span> <span class=\"typ-num\">1</span><span class=\"typ-punct\">;</span> x <span class=\"typ-op\">+</span> <span class=\"typ-num\">2</span> <span class=\"typ-punct\">}</span></code></td><td><a href=\"/en-US-v0.14.1/reference/scripting/#blocks\">Scripting</a></td></tr>\n<tr><td>Content block</td><td><code><span class=\"typ-punct\">[</span><span class=\"typ-strong\">*Hello*</span><span class=\"typ-punct\">]</span></code></td><td><a href=\"/en-US-v0.14.1/reference/scripting/#blocks\">Scripting</a></td></tr>\n<tr><td>Parenthesized expression</td><td><code><span class=\"typ-punct\">(</span><span class=\"typ-num\">1</span> <span class=\"typ-op\">+</span> <span class=\"typ-num\">2</span><span class=\"typ-punct\">)</span></code></td><td><a href=\"/en-US-v0.14.1/reference/scripting/#blocks\">Scripting</a></td></tr>\n<tr><td>Array</td><td><code><span class=\"typ-punct\">(</span><span class=\"typ-num\">1</span><span class=\"typ-punct\">,</span> <span class=\"typ-num\">2</span><span class=\"typ-punct\">,</span> <span class=\"typ-num\">3</span><span class=\"typ-punct\">)</span></code></td><td><a href=\"/en-US-v0.14.1/reference/foundations/array/\">Array</a></td></tr>\n<tr><td>Dictionary</td><td><code><span class=\"typ-punct\">(</span>a<span class=\"typ-punct\">:</span> <span class=\"typ-str\">&quot;hi&quot;</span><span class=\"typ-punct\">,</span> b<span class=\"typ-punct\">:</span> <span class=\"typ-num\">2</span><span class=\"typ-punct\">)</span></code></td><td><a href=\"/en-US-v0.14.1/reference/foundations/dictionary/\">Dictionary</a></td></tr>\n<tr><td>Unary operator</td><td><code><span class=\"typ-op\">-</span>x</code></td><td><a href=\"/en-US-v0.14.1/reference/scripting/#operators\">Scripting</a></td></tr>\n<tr><td>Binary operator</td><td><code>x <span class=\"typ-op\">+</span> y</code></td><td><a href=\"/en-US-v0.14.1/reference/scripting/#operators\">Scripting</a></td></tr>\n<tr><td>Assignment</td><td><code>x <span class=\"typ-op\">=</span> <span class=\"typ-num\">1</span></code></td><td><a href=\"/en-US-v0.14.1/reference/scripting/#operators\">Scripting</a></td></tr>\n<tr><td>Field access</td><td><code>x<span class=\"typ-punct\">.</span>y</code></td><td><a href=\"/en-US-v0.14.1/reference/scripting/#fields\">Scripting</a></td></tr>\n<tr><td>Method call</td><td><code>x<span class=\"typ-punct\">.</span><span class=\"typ-func\">flatten</span><span class=\"typ-punct\">(</span><span class=\"typ-punct\">)</span></code></td><td><a href=\"/en-US-v0.14.1/reference/scripting/#methods\">Scripting</a></td></tr>\n<tr><td>Function call</td><td><code><span class=\"typ-func\">min</span><span class=\"typ-punct\">(</span>x<span class=\"typ-punct\">,</span> y<span class=\"typ-punct\">)</span></code></td><td><a href=\"/en-US-v0.14.1/reference/foundations/function/\">Function</a></td></tr>\n<tr><td>Argument spreading</td><td><code><span class=\"typ-func\">min</span><span class=\"typ-punct\">(</span><span class=\"typ-op\">..</span>nums<span class=\"typ-punct\">)</span></code></td><td><a href=\"/en-US-v0.14.1/reference/foundations/arguments/\">Arguments</a></td></tr>\n<tr><td>Unnamed function</td><td><code><span class=\"typ-punct\">(</span>x<span class=\"typ-punct\">,</span> y<span class=\"typ-punct\">)</span> <span class=\"typ-op\">=&gt;</span> x <span class=\"typ-op\">+</span> y</code></td><td><a href=\"/en-US-v0.14.1/reference/foundations/function/\">Function</a></td></tr>\n<tr><td>Let binding</td><td><code><span class=\"typ-key\">let</span> x <span class=\"typ-op\">=</span> <span class=\"typ-num\">1</span></code></td><td><a href=\"/en-US-v0.14.1/reference/scripting/#bindings\">Scripting</a></td></tr>\n<tr><td>Named function</td><td><code><span class=\"typ-key\">let</span> <span class=\"typ-func\">f</span><span class=\"typ-punct\">(</span>x<span class=\"typ-punct\">)</span> <span class=\"typ-op\">=</span> <span class=\"typ-num\">2</span> <span class=\"typ-op\">*</span> x</code></td><td><a href=\"/en-US-v0.14.1/reference/foundations/function/\">Function</a></td></tr>\n<tr><td>Set rule</td><td><code><span class=\"typ-key\">set</span> <span class=\"typ-func\">text</span><span class=\"typ-punct\">(</span><span class=\"typ-num\">14pt</span><span class=\"typ-punct\">)</span></code></td><td><a href=\"/en-US-v0.14.1/reference/styling/#set-rules\">Styling</a></td></tr>\n<tr><td>Set-if rule</td><td><code><span class=\"typ-key\">set</span> <span class=\"typ-func\">text</span><span class=\"typ-punct\">(</span><span class=\"typ-op\">..</span><span class=\"typ-punct\">)</span> <span class=\"typ-key\">if</span> .. </code></td><td><a href=\"/en-US-v0.14.1/reference/styling/#set-rules\">Styling</a></td></tr>\n<tr><td>Show-set rule</td><td><code><span class=\"typ-key\">show</span> <span class=\"typ-func\">heading</span><span class=\"typ-punct\">:</span> <span class=\"typ-key\">set</span> <span class=\"typ-func\">block</span><span class=\"typ-punct\">(</span><span class=\"typ-op\">..</span><span class=\"typ-punct\">)</span></code></td><td><a href=\"/en-US-v0.14.1/reference/styling/#show-rules\">Styling</a></td></tr>\n<tr><td>Show rule with function</td><td><code><span class=\"typ-key\">show</span> <span class=\"typ-func\">raw</span><span class=\"typ-punct\">:</span> it <span class=\"typ-op\">=&gt;</span> <span class=\"typ-punct\">{</span>..<span class=\"typ-punct\">}</span></code></td><td><a href=\"/en-US-v0.14.1/reference/styling/#show-rules\">Styling</a></td></tr>\n<tr><td>Show-everything rule</td><td><code><span class=\"typ-key\">show</span><span class=\"typ-punct\">:</span> <span class=\"typ-func\">template</span></code></td><td><a href=\"/en-US-v0.14.1/reference/styling/#show-rules\">Styling</a></td></tr>\n<tr><td>Context expression</td><td><code><span class=\"typ-key\">context</span> text<span class=\"typ-punct\">.</span>lang</code></td><td><a href=\"/en-US-v0.14.1/reference/context/\">Context</a></td></tr>\n<tr><td>Conditional</td><td><code><span class=\"typ-key\">if</span> x <span class=\"typ-op\">==</span> <span class=\"typ-num\">1</span> <span class=\"typ-punct\">{</span>..<span class=\"typ-punct\">}</span> <span class=\"typ-key\">else</span> <span class=\"typ-punct\">{</span>..<span class=\"typ-punct\">}</span></code></td><td><a href=\"/en-US-v0.14.1/reference/scripting/#conditionals\">Scripting</a></td></tr>\n<tr><td>For loop</td><td><code><span class=\"typ-key\">for</span> x <span class=\"typ-key\">in</span> <span class=\"typ-punct\">(</span><span class=\"typ-num\">1</span><span class=\"typ-punct\">,</span> <span class=\"typ-num\">2</span><span class=\"typ-punct\">,</span> <span class=\"typ-num\">3</span><span class=\"typ-punct\">)</span> <span class=\"typ-punct\">{</span>..<span class=\"typ-punct\">}</span></code></td><td><a href=\"/en-US-v0.14.1/reference/scripting/#loops\">Scripting</a></td></tr>\n<tr><td>While loop</td><td><code><span class=\"typ-key\">while</span> x <span class=\"typ-op\">&lt;</span> <span class=\"typ-num\">10</span> <span class=\"typ-punct\">{</span>..<span class=\"typ-punct\">}</span></code></td><td><a href=\"/en-US-v0.14.1/reference/scripting/#loops\">Scripting</a></td></tr>\n<tr><td>Loop control flow</td><td><code><span class=\"typ-key\">break</span>, <span class=\"typ-key\">continue</span></code></td><td><a href=\"/en-US-v0.14.1/reference/scripting/#loops\">Scripting</a></td></tr>\n<tr><td>Return from function</td><td><code><span class=\"typ-key\">return</span> x</code></td><td><a href=\"/en-US-v0.14.1/reference/foundations/function/\">Function</a></td></tr>\n<tr><td>Include module</td><td><code><span class=\"typ-key\">include</span> <span class=\"typ-str\">&quot;bar.typ&quot;</span></code></td><td><a href=\"/en-US-v0.14.1/reference/scripting/#modules\">Scripting</a></td></tr>\n<tr><td>Import module</td><td><code><span class=\"typ-key\">import</span> <span class=\"typ-str\">&quot;bar.typ&quot;</span></code></td><td><a href=\"/en-US-v0.14.1/reference/scripting/#modules\">Scripting</a></td></tr>\n<tr><td>Import items from module</td><td><code><span class=\"typ-key\">import</span> <span class=\"typ-str\">&quot;bar.typ&quot;</span><span class=\"typ-punct\">:</span> a<span class=\"typ-punct\">,</span> b<span class=\"typ-punct\">,</span> c</code></td><td><a href=\"/en-US-v0.14.1/reference/scripting/#modules\">Scripting</a></td></tr>\n<tr><td>Comment</td><td><code><span class=\"typ-comment\">/* block */</span></code>, <code><span class=\"typ-comment\">// line</span></code></td><td><a href=\"#comments\">Below</a></td></tr>\n</tbody></table>\n<h2 id=\"comments\">Comments</h2>\n<p>Comments are ignored by Typst and will not be included in the output. This is\nuseful to exclude old versions or to add annotations. To comment out a single\nline, start it with <code>//</code>:</p>\n<div class=\"previewed-code\"><pre><code><span class=\"typ-comment\">// our data barely supports</span>\n<span class=\"typ-comment\">// this claim</span>\n\nWe show with <span class=\"typ-math-delim\">$</span>p &lt; 0.05<span class=\"typ-math-delim\">$</span>\nthat the difference is\nsignificant.\n</code></pre><div class=\"preview\"><img src=\"/en-US-v0.14.1/assets/aa63c9c9fd83801f26f5ba5d0dc73151.png\" alt=\"Preview\"></div></div>\n<p>Comments can also be wrapped between <code>/*</code> and <code>*/</code>. In this case, the comment\ncan span over multiple lines:</p>\n<div class=\"previewed-code\"><pre><code>Our study design is as follows:\n<span class=\"typ-comment\">/* Somebody write this up:\n   - 1000 participants.\n   - 2x2 data design. */</span>\n</code></pre><div class=\"preview\"><img src=\"/en-US-v0.14.1/assets/d1b7773edfcc1952006a027c9e9b8c30.png\" alt=\"Preview\"></div></div>\n<h2 id=\"escapes\">Escape sequences</h2>\n<p>Escape sequences are used to insert special characters that are hard to type or\notherwise have special meaning in Typst. To escape a character, precede it with\na backslash. To insert any Unicode codepoint, you can write a hexadecimal escape\nsequence: <code><span class=\"typ-escape\">\\u{1f600}</span></code>. The same kind of escape sequences also work in\n<a href=\"/en-US-v0.14.1/reference/foundations/str/\">strings</a>.</p>\n<div class=\"previewed-code\"><pre><code>I got an ice cream for\n<span class=\"typ-escape\">\\$</span>1.50! <span class=\"typ-escape\">\\u{1f600}</span>\n</code></pre><div class=\"preview\"><img src=\"/en-US-v0.14.1/assets/d87ab5c15ab42543dde046ab1ad05951.png\" alt=\"Preview\"></div></div>\n<h2 id=\"identifiers\">Identifiers</h2>\n<p>Names of variables, functions, and so on (<em>identifiers</em>) can contain letters,\nnumbers, hyphens (<code>-</code>), and underscores (<code>_</code>). They must start with a letter or\nan underscore.</p>\n<p>More specifically, the identifier syntax in Typst is based on the\n<a href=\"https://www.unicode.org/reports/tr31/\">Unicode Standard Annex #31</a>, with two\nextensions: Allowing <code>_</code> as a starting character, and allowing both <code>_</code> and <code>-</code>\nas continuing characters.</p>\n<p>For multi-word identifiers, the recommended case convention is\n<a href=\"https://en.wikipedia.org/wiki/Letter_case#Kebab_case\">Kebab case</a>. In Kebab\ncase, words are written in lowercase and separated by hyphens (as in\n<code>top-edge</code>). This is especially relevant when developing modules and packages\nfor others to use, as it keeps things predictable.</p>\n<div class=\"previewed-code\"><pre><code><span class=\"typ-key\">#</span><span class=\"typ-key\">let</span> kebab-case <span class=\"typ-op\">=</span> <span class=\"typ-punct\">[</span>Using hyphen<span class=\"typ-punct\">]</span>\n<span class=\"typ-key\">#</span><span class=\"typ-key\">let</span> _schön <span class=\"typ-op\">=</span> <span class=\"typ-str\">&quot;😊&quot;</span>\n<span class=\"typ-key\">#</span><span class=\"typ-key\">let</span> 始料不及 <span class=\"typ-op\">=</span> <span class=\"typ-str\">&quot;😱&quot;</span>\n<span class=\"typ-key\">#</span><span class=\"typ-key\">let</span> π <span class=\"typ-op\">=</span> calc<span class=\"typ-punct\">.</span>pi\n\n<span class=\"typ-pol\">#</span><span class=\"typ-pol\">kebab-case</span>\n<span class=\"typ-key\">#</span><span class=\"typ-key\">if</span> <span class=\"typ-op\">-</span>π <span class=\"typ-op\">&lt;</span> <span class=\"typ-num\">0</span> <span class=\"typ-punct\">{</span> _schön <span class=\"typ-punct\">}</span> <span class=\"typ-key\">else</span> <span class=\"typ-punct\">{</span> 始料不及 <span class=\"typ-punct\">}</span>\n<span class=\"typ-comment\">// -π means -1 * π,</span>\n<span class=\"typ-comment\">// so it&#39;s not a valid identifier</span>\n</code></pre><div class=\"preview\"><img src=\"/en-US-v0.14.1/assets/77fa42f9351fc5ea2759a99ce3d73e26.png\" alt=\"Preview\"></div></div>\n<h2 id=\"paths\">Paths</h2>\n<p>Typst has various features that require a file path to reference external\nresources such as images, Typst files, or data files. Paths are represented as\n<a href=\"/en-US-v0.14.1/reference/foundations/str/\">strings</a>. There are two kinds of paths: Relative and absolute.</p>\n<ul>\n<li>\n<p>A <strong>relative path</strong> searches from the location of the Typst file where the\nfeature is invoked. It is the default:</p>\n<pre><code><span class=\"typ-func\">#</span><span class=\"typ-func\">image</span><span class=\"typ-punct\">(</span><span class=\"typ-str\">&quot;images/logo.png&quot;</span><span class=\"typ-punct\">)</span>\n</code></pre></li>\n<li>\n<p>An <strong>absolute path</strong> searches from the <em>root</em> of the project. It starts with a\nleading <code>/</code>:</p>\n<pre><code><span class=\"typ-func\">#</span><span class=\"typ-func\">image</span><span class=\"typ-punct\">(</span><span class=\"typ-str\">&quot;/assets/logo.png&quot;</span><span class=\"typ-punct\">)</span>\n</code></pre></li>\n</ul>\n<h3 id=\"project-root\">Project root</h3>\n<p>By default, the project root is the parent directory of the main Typst file.\nFor security reasons, you cannot read any files outside of the root directory.</p>\n<p>If you want to set a specific folder as the root of your project, you can use\nthe CLI's <code>--root</code> flag. Make sure that the main file is contained in the\nfolder's subtree!</p>\n<pre style=\"background-color:#ffffff;\">\n<span style=\"color:#4b69c6;\">typst</span><span style=\"color:#000000;\"> compile --root .. file.typ\n</span></pre>\n<p>In the web app, the project itself is the root directory. You can always read\nall files within it, no matter which one is previewed (via the eye toggle next\nto each Typst file in the file panel).</p>\n<h3 id=\"paths-and-packages\">Paths and packages</h3>\n<p>A package can only load files from its own directory. Within it, absolute paths\npoint to the package root, rather than the project root. For this reason, it\ncannot directly load files from the project directory. If a package needs\nresources from the project (such as a logo image), you must pass the already\nloaded image, e.g. as a named parameter <code>logo: <span class=\"typ-func\">image</span><span class=\"typ-punct\">(</span><span class=\"typ-str\">&quot;mylogo.svg&quot;</span><span class=\"typ-punct\">)</span></code>. Note that\nyou can then still customize the image's appearance with a set rule within the\npackage.</p>\n<p>In the future, paths might become a\n<a href=\"https://github.com/typst/typst/issues/971\">distinct type from strings</a>, so that\nthey can retain knowledge of where they were constructed. This way, resources\ncould be loaded from a different root.</p>"}}