{"route":"/en-US-v0.13.1/reference/text/raw/","title":"Raw Text / Code","description":"Documentation for the `raw` function.","part":null,"outline":[{"id":"summary","name":"Summary","children":[]},{"id":"example","name":"Example","children":[]},{"id":"syntax","name":"Syntax","children":[]},{"id":"parameters","name":"Parameters","children":[{"id":"parameters-text","name":"text","children":[]},{"id":"parameters-block","name":"block","children":[]},{"id":"parameters-lang","name":"lang","children":[]},{"id":"parameters-align","name":"align","children":[]},{"id":"parameters-syntaxes","name":"syntaxes","children":[]},{"id":"parameters-theme","name":"theme","children":[]},{"id":"parameters-tab-size","name":"tab-size","children":[]}]},{"id":"definitions","name":"Definitions","children":[{"id":"definitions-line","name":"Raw Text / Code Line","children":[{"id":"definitions-line-number","name":"number","children":[]},{"id":"definitions-line-count","name":"count","children":[]},{"id":"definitions-line-text","name":"text","children":[]},{"id":"definitions-line-body","name":"body","children":[]}]}]}],"body":{"kind":"func","content":{"path":[],"name":"raw","title":"Raw Text / Code","keywords":[],"oneliner":"Raw text with optional syntax highlighting.","element":true,"contextual":false,"deprecation":null,"details":"<p>Raw text with optional syntax highlighting.</p>\n<p>Displays the text verbatim and in a monospace font. This is typically used\nto embed computer code into your document.</p>\n<h2 id=\"example\">Example</h2>\n<div class=\"previewed-code\"><pre><code>Adding <span class=\"typ-raw\">`rbx`</span> to <span class=\"typ-raw\">`rcx`</span> gives\nthe desired result.\n\nWhat is <span class=\"typ-raw\">```rust fn main()```</span> in Rust\nwould be <span class=\"typ-raw\">```c int main()```</span> in C.\n\n<span class=\"typ-raw\">```rust\nfn main() {\n    println!(&quot;Hello World!&quot;);\n}\n```</span>\n\nThis has <span class=\"typ-raw\">``` `backticks` ```</span> in it\n(but the spaces are trimmed). And\n<span class=\"typ-raw\">``` here```</span> the leading space is\nalso trimmed.\n</code></pre><div class=\"preview\"><img src=\"/en-US-v0.13.1/assets/1c6e6aa444c644eee774123542b7a4f6.png\" alt=\"Preview\"></div></div>\n<p>You can also construct a <a href=\"/en-US-v0.13.1/reference/text/raw/\" title=\"`raw`\"><code>raw</code></a> element programmatically from a string (and\nprovide the language tag via the optional <a href=\"/en-US-v0.13.1/reference/text/raw/#parameters-lang\"><code>lang</code></a> argument).</p>\n<div class=\"previewed-code\"><pre><code><span class=\"typ-func\">#</span><span class=\"typ-func\">raw</span><span class=\"typ-punct\">(</span><span class=\"typ-str\">&quot;fn &quot;</span> <span class=\"typ-op\">+</span> <span class=\"typ-str\">&quot;main() {}&quot;</span><span class=\"typ-punct\">,</span> lang<span class=\"typ-punct\">:</span> <span class=\"typ-str\">&quot;rust&quot;</span><span class=\"typ-punct\">)</span>\n</code></pre><div class=\"preview\"><img src=\"/en-US-v0.13.1/assets/30d00188c2b14f13cf697cc8c1fb8f3d.png\" alt=\"Preview\"></div></div>\n<h2 id=\"syntax\">Syntax</h2>\n<p>This function also has dedicated syntax. You can enclose text in 1 or 3+\nbackticks (<code>`</code>) to make it raw. Two backticks produce empty raw text.\nThis works both in markup and code.</p>\n<p>When you use three or more backticks, you can additionally specify a\nlanguage tag for syntax highlighting directly after the opening backticks.\nWithin raw blocks, everything (except for the language tag, if applicable)\nis rendered as is, in particular, there are no escape sequences.</p>\n<p>The language tag is an identifier that directly follows the opening\nbackticks only if there are three or more backticks. If your text starts\nwith something that looks like an identifier, but no syntax highlighting is\nneeded, start the text with a single space (which will be trimmed) or use\nthe single backtick syntax. If your text should start or end with a\nbacktick, put a space before or after it (it will be trimmed).</p>","example":null,"self":false,"params":[{"name":"text","details":"<p>The raw text.</p>\n<p>You can also use raw blocks creatively to create custom syntaxes for\nyour automations.</p>","example":"<div class=\"previewed-code\"><pre><code><span class=\"typ-comment\">// Parse numbers in raw blocks with the</span>\n<span class=\"typ-comment\">// `mydsl` tag and sum them up.</span>\n<span class=\"typ-key\">#</span><span class=\"typ-key\">show</span> raw<span class=\"typ-punct\">.</span><span class=\"typ-func\">where</span><span class=\"typ-punct\">(</span>lang<span class=\"typ-punct\">:</span> <span class=\"typ-str\">&quot;mydsl&quot;</span><span class=\"typ-punct\">)</span><span class=\"typ-punct\">:</span> it <span class=\"typ-op\">=&gt;</span> <span class=\"typ-punct\">{</span>\n  <span class=\"typ-key\">let</span> sum <span class=\"typ-op\">=</span> <span class=\"typ-num\">0</span>\n  <span class=\"typ-key\">for</span> part <span class=\"typ-key\">in</span> it<span class=\"typ-punct\">.</span>text<span class=\"typ-punct\">.</span><span class=\"typ-func\">split</span><span class=\"typ-punct\">(</span><span class=\"typ-str\">&quot;+&quot;</span><span class=\"typ-punct\">)</span> <span class=\"typ-punct\">{</span>\n    sum <span class=\"typ-op\">+=</span> <span class=\"typ-func\">int</span><span class=\"typ-punct\">(</span>part<span class=\"typ-punct\">.</span><span class=\"typ-func\">trim</span><span class=\"typ-punct\">(</span><span class=\"typ-punct\">)</span><span class=\"typ-punct\">)</span>\n  <span class=\"typ-punct\">}</span>\n  sum\n<span class=\"typ-punct\">}</span>\n\n<span class=\"typ-raw\">```mydsl\n1 + 2 + 3 + 4 + 5\n```</span>\n</code></pre><div class=\"preview\"><img src=\"/en-US-v0.13.1/assets/e95a5eae34283fc132d0b8949399b41d.png\" alt=\"Preview\"></div></div>","types":["str"],"strings":[],"default":null,"positional":true,"named":false,"required":true,"variadic":false,"settable":false},{"name":"block","details":"<p>Whether the raw text is displayed as a separate block.</p>\n<p>In markup mode, using one-backtick notation makes this <code><span class=\"typ-key\">false</span></code>.\nUsing three-backtick notation makes it <code><span class=\"typ-key\">true</span></code> if the enclosed content\ncontains at least one line break.</p>","example":"<div class=\"previewed-code\"><pre><code><span class=\"typ-comment\">// Display inline code in a small box</span>\n<span class=\"typ-comment\">// that retains the correct baseline.</span>\n<span class=\"typ-key\">#</span><span class=\"typ-key\">show</span> raw<span class=\"typ-punct\">.</span><span class=\"typ-func\">where</span><span class=\"typ-punct\">(</span>block<span class=\"typ-punct\">:</span> <span class=\"typ-key\">false</span><span class=\"typ-punct\">)</span><span class=\"typ-punct\">:</span> box<span class=\"typ-punct\">.</span><span class=\"typ-func\">with</span><span class=\"typ-punct\">(</span>\n  fill<span class=\"typ-punct\">:</span> <span class=\"typ-func\">luma</span><span class=\"typ-punct\">(</span><span class=\"typ-num\">240</span><span class=\"typ-punct\">)</span><span class=\"typ-punct\">,</span>\n  inset<span class=\"typ-punct\">:</span> <span class=\"typ-punct\">(</span>x<span class=\"typ-punct\">:</span> <span class=\"typ-num\">3pt</span><span class=\"typ-punct\">,</span> y<span class=\"typ-punct\">:</span> <span class=\"typ-num\">0pt</span><span class=\"typ-punct\">)</span><span class=\"typ-punct\">,</span>\n  outset<span class=\"typ-punct\">:</span> <span class=\"typ-punct\">(</span>y<span class=\"typ-punct\">:</span> <span class=\"typ-num\">3pt</span><span class=\"typ-punct\">)</span><span class=\"typ-punct\">,</span>\n  radius<span class=\"typ-punct\">:</span> <span class=\"typ-num\">2pt</span><span class=\"typ-punct\">,</span>\n<span class=\"typ-punct\">)</span>\n\n<span class=\"typ-comment\">// Display block code in a larger block</span>\n<span class=\"typ-comment\">// with more padding.</span>\n<span class=\"typ-key\">#</span><span class=\"typ-key\">show</span> raw<span class=\"typ-punct\">.</span><span class=\"typ-func\">where</span><span class=\"typ-punct\">(</span>block<span class=\"typ-punct\">:</span> <span class=\"typ-key\">true</span><span class=\"typ-punct\">)</span><span class=\"typ-punct\">:</span> block<span class=\"typ-punct\">.</span><span class=\"typ-func\">with</span><span class=\"typ-punct\">(</span>\n  fill<span class=\"typ-punct\">:</span> <span class=\"typ-func\">luma</span><span class=\"typ-punct\">(</span><span class=\"typ-num\">240</span><span class=\"typ-punct\">)</span><span class=\"typ-punct\">,</span>\n  inset<span class=\"typ-punct\">:</span> <span class=\"typ-num\">10pt</span><span class=\"typ-punct\">,</span>\n  radius<span class=\"typ-punct\">:</span> <span class=\"typ-num\">4pt</span><span class=\"typ-punct\">,</span>\n<span class=\"typ-punct\">)</span>\n\nWith <span class=\"typ-raw\">`rg`</span>, you can search through your files quickly.\nThis example searches the current directory recursively\nfor the text <span class=\"typ-raw\">`Hello World`</span>:\n\n<span class=\"typ-raw\">```bash\nrg &quot;Hello World&quot;\n```</span>\n</code></pre><div class=\"preview\"><img src=\"/en-US-v0.13.1/assets/3e05c29a6af60a7e77667a5640e9ccc3.png\" alt=\"Preview\"></div></div>","types":["bool"],"strings":[],"default":"<code><span class=\"typ-key\">false</span></code>","positional":false,"named":true,"required":false,"variadic":false,"settable":true},{"name":"lang","details":"<p>The language to syntax-highlight in.</p>\n<p>Apart from typical language tags known from Markdown, this supports the\n<code><span class=\"typ-str\">&quot;typ&quot;</span></code>, <code><span class=\"typ-str\">&quot;typc&quot;</span></code>, and <code><span class=\"typ-str\">&quot;typm&quot;</span></code> tags for\n<a href=\"/en-US-v0.13.1/reference/syntax/#markup\">Typst markup</a>,\n<a href=\"/en-US-v0.13.1/reference/syntax/#code\">Typst code</a>, and\n<a href=\"/en-US-v0.13.1/reference/syntax/#math\">Typst math</a>, respectively.</p>","example":"<div class=\"previewed-code\"><pre><code><span class=\"typ-raw\">```typ\nThis is *Typst!*\n```</span>\n\nThis is <span class=\"typ-raw\">```typ also *Typst*```</span>, but inline!\n</code></pre><div class=\"preview\"><img src=\"/en-US-v0.13.1/assets/6e35373cc945b3d9ac522ef64138479c.png\" alt=\"Preview\"></div></div>","types":["none","str"],"strings":[],"default":"<code><span class=\"typ-key\">none</span></code>","positional":false,"named":true,"required":false,"variadic":false,"settable":true},{"name":"align","details":"<p>The horizontal alignment that each line in a raw block should have.\nThis option is ignored if this is not a raw block (if specified\n<code>block: false</code> or single backticks were used in markup mode).</p>\n<p>By default, this is set to <code>start</code>, meaning that raw text is\naligned towards the start of the text direction inside the block\nby default, regardless of the current context's alignment (allowing\nyou to center the raw block itself without centering the text inside\nit, for example).</p>","example":"<div class=\"previewed-code\"><pre><code><span class=\"typ-key\">#</span><span class=\"typ-key\">set</span> <span class=\"typ-func\">raw</span><span class=\"typ-punct\">(</span>align<span class=\"typ-punct\">:</span> center<span class=\"typ-punct\">)</span>\n\n<span class=\"typ-raw\">```typc\nlet f(x) = x\ncode = &quot;centered&quot;\n```</span>\n</code></pre><div class=\"preview\"><img src=\"/en-US-v0.13.1/assets/42863ad475a373b308500053afc9afc3.png\" alt=\"Preview\"></div></div>","types":["alignment"],"strings":[],"default":"<code>start</code>","positional":false,"named":true,"required":false,"variadic":false,"settable":true},{"name":"syntaxes","details":"<p>Additional syntax definitions to load. The syntax definitions should be\nin the <a href=\"https://www.sublimetext.com/docs/syntax.html\"><code>sublime-syntax</code> file format</a>.</p>\n<p>You can pass any of the following values:</p>\n<ul>\n<li>A path string to load a syntax file from the given path. For more\ndetails about paths, see the <a href=\"/en-US-v0.13.1/reference/syntax/#paths\">Paths section</a>.</li>\n<li>Raw bytes from which the syntax should be decoded.</li>\n<li>An array where each item is one the above.</li>\n</ul>","example":"<div class=\"previewed-code\"><pre><code><span class=\"typ-key\">#</span><span class=\"typ-key\">set</span> <span class=\"typ-func\">raw</span><span class=\"typ-punct\">(</span>syntaxes<span class=\"typ-punct\">:</span> <span class=\"typ-str\">&quot;SExpressions.sublime-syntax&quot;</span><span class=\"typ-punct\">)</span>\n\n<span class=\"typ-raw\">```sexp\n(defun factorial (x)\n  (if (zerop x)\n    ; with a comment\n    1\n    (* x (factorial (- x 1)))))\n```</span>\n</code></pre><div class=\"preview\"><img src=\"/en-US-v0.13.1/assets/7f5c04b4a7636eec32f8b54d18867f8a.png\" alt=\"Preview\"></div></div>","types":["str","bytes","array"],"strings":[],"default":"<code><span class=\"typ-punct\">(</span><span class=\"typ-punct\">)</span></code>","positional":false,"named":true,"required":false,"variadic":false,"settable":true},{"name":"theme","details":"<p>The theme to use for syntax highlighting. Themes should be in the\n<a href=\"https://www.sublimetext.com/docs/color_schemes_tmtheme.html\"><code>tmTheme</code> file format</a>.</p>\n<p>You can pass any of the following values:</p>\n<ul>\n<li><code><span class=\"typ-key\">none</span></code>: Disables syntax highlighting.</li>\n<li><code><span class=\"typ-key\">auto</span></code>: Highlights with Typst's default theme.</li>\n<li>A path string to load a theme file from the given path. For more\ndetails about paths, see the <a href=\"/en-US-v0.13.1/reference/syntax/#paths\">Paths section</a>.</li>\n<li>Raw bytes from which the theme should be decoded.</li>\n</ul>\n<p>Applying a theme only affects the color of specifically highlighted\ntext. It does not consider the theme's foreground and background\nproperties, so that you retain control over the color of raw text. You\ncan apply the foreground color yourself with the <a href=\"/en-US-v0.13.1/reference/text/text/\" title=\"`text`\"><code>text</code></a> function and\nthe background with a <a href=\"/en-US-v0.13.1/reference/layout/block/#parameters-fill\">filled block</a>. You could also use\nthe <a href=\"/en-US-v0.13.1/reference/data-loading/xml/\" title=\"`xml`\"><code>xml</code></a> function to extract these properties from the theme.</p>","example":"<div class=\"previewed-code\"><pre><code><span class=\"typ-key\">#</span><span class=\"typ-key\">set</span> <span class=\"typ-func\">raw</span><span class=\"typ-punct\">(</span>theme<span class=\"typ-punct\">:</span> <span class=\"typ-str\">&quot;halcyon.tmTheme&quot;</span><span class=\"typ-punct\">)</span>\n<span class=\"typ-key\">#</span><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-func\">block</span><span class=\"typ-punct\">(</span>\n  fill<span class=\"typ-punct\">:</span> <span class=\"typ-func\">rgb</span><span class=\"typ-punct\">(</span><span class=\"typ-str\">&quot;#1d2433&quot;</span><span class=\"typ-punct\">)</span><span class=\"typ-punct\">,</span>\n  inset<span class=\"typ-punct\">:</span> <span class=\"typ-num\">8pt</span><span class=\"typ-punct\">,</span>\n  radius<span class=\"typ-punct\">:</span> <span class=\"typ-num\">5pt</span><span class=\"typ-punct\">,</span>\n  <span class=\"typ-func\">text</span><span class=\"typ-punct\">(</span>fill<span class=\"typ-punct\">:</span> <span class=\"typ-func\">rgb</span><span class=\"typ-punct\">(</span><span class=\"typ-str\">&quot;#a2aabc&quot;</span><span class=\"typ-punct\">)</span><span class=\"typ-punct\">,</span> it<span class=\"typ-punct\">)</span>\n<span class=\"typ-punct\">)</span>\n\n<span class=\"typ-raw\">```typ\n= Chapter 1\n#let hi = &quot;Hello World&quot;\n```</span>\n</code></pre><div class=\"preview\"><img src=\"/en-US-v0.13.1/assets/ff79dd534cb52ac3a90c032ff7df46c3.png\" alt=\"Preview\"></div></div>","types":["none","auto","str","bytes"],"strings":[],"default":"<code><span class=\"typ-key\">auto</span></code>","positional":false,"named":true,"required":false,"variadic":false,"settable":true},{"name":"tab-size","details":"<p>The size for a tab stop in spaces. A tab is replaced with enough spaces to\nalign with the next multiple of the size.</p>","example":"<div class=\"previewed-code\"><pre><code><span class=\"typ-key\">#</span><span class=\"typ-key\">set</span> <span class=\"typ-func\">raw</span><span class=\"typ-punct\">(</span>tab-size<span class=\"typ-punct\">:</span> <span class=\"typ-num\">8</span><span class=\"typ-punct\">)</span>\n<span class=\"typ-raw\">```tsv\nYear\tMonth\tDay\n2000\t2\t3\n2001\t2\t1\n2002\t3\t10\n```</span>\n</code></pre><div class=\"preview\"><img src=\"/en-US-v0.13.1/assets/38037df252d0e30521ad3ae36d5093cb.png\" alt=\"Preview\"></div></div>","types":["int"],"strings":[],"default":"<code><span class=\"typ-num\">2</span></code>","positional":false,"named":true,"required":false,"variadic":false,"settable":true}],"returns":["content"],"scope":[{"path":["raw"],"name":"line","title":"Raw Text / Code Line","keywords":[],"oneliner":"A highlighted line of raw text.","element":true,"contextual":false,"deprecation":null,"details":"<p>A highlighted line of raw text.</p>\n<p>This is a helper element that is synthesized by <a href=\"/en-US-v0.13.1/reference/text/raw/\" title=\"`raw`\"><code>raw</code></a> elements.</p>\n<p>It allows you to access various properties of the line, such as the line\nnumber, the raw non-highlighted text, the highlighted text, and whether it\nis the first or last line of the raw block.</p>","example":null,"self":false,"params":[{"name":"number","details":"<p>The line number of the raw line inside of the raw block, starts at 1.</p>","example":null,"types":["int"],"strings":[],"default":null,"positional":true,"named":false,"required":true,"variadic":false,"settable":false},{"name":"count","details":"<p>The total number of lines in the raw block.</p>","example":null,"types":["int"],"strings":[],"default":null,"positional":true,"named":false,"required":true,"variadic":false,"settable":false},{"name":"text","details":"<p>The line of raw text.</p>","example":null,"types":["str"],"strings":[],"default":null,"positional":true,"named":false,"required":true,"variadic":false,"settable":false},{"name":"body","details":"<p>The highlighted raw text.</p>","example":null,"types":["content"],"strings":[],"default":null,"positional":true,"named":false,"required":true,"variadic":false,"settable":false}],"returns":["content"],"scope":[]}]}}}