{"route":"/en-US-v0.14.1/reference/foundations/std/","title":"Standard Library","description":"Documentation for the std functions.","part":null,"outline":[{"id":"summary","name":"Summary","children":[]},{"id":"using-shadowed-definitions","name":"Using \"shadowed\" definitions","children":[]},{"id":"conditional-access","name":"Conditional access","children":[]},{"id":"functions","name":"Functions","children":[]}],"body":{"kind":"group","content":{"name":"std","title":"Standard Library","details":"<p>A module that contains all globally accessible items.</p>\n<h2 id=\"using-shadowed-definitions\">Using &quot;shadowed&quot; definitions</h2>\n<p>The <code>std</code> module is useful whenever you overrode a name from the global\nscope (this is called <em>shadowing</em>). For instance, you might have used the\nname <code>text</code> for a parameter. To still access the <code>text</code> element, write\n<code>std.text</code>.</p>\n<div class=\"previewed-code\"><pre><code><span class=\"typ-key\">#</span><span class=\"typ-key\">let</span> par <span class=\"typ-op\">=</span> <span class=\"typ-punct\">[</span>My special paragraph.<span class=\"typ-punct\">]</span>\n<span class=\"typ-key\">#</span><span class=\"typ-key\">let</span> <span class=\"typ-func\">special</span><span class=\"typ-punct\">(</span>text<span class=\"typ-punct\">)</span> <span class=\"typ-op\">=</span> <span class=\"typ-punct\">{</span>\n  <span class=\"typ-key\">set</span> std<span class=\"typ-punct\">.</span><span class=\"typ-func\">text</span><span class=\"typ-punct\">(</span>style<span class=\"typ-punct\">:</span> <span class=\"typ-str\">&quot;italic&quot;</span><span class=\"typ-punct\">)</span>\n  <span class=\"typ-key\">set</span> std<span class=\"typ-punct\">.</span>par<span class=\"typ-punct\">.</span><span class=\"typ-func\">line</span><span class=\"typ-punct\">(</span>numbering<span class=\"typ-punct\">:</span> <span class=\"typ-str\">&quot;1&quot;</span><span class=\"typ-punct\">)</span>\n  text\n<span class=\"typ-punct\">}</span>\n\n<span class=\"typ-func\">#</span><span class=\"typ-func\">special</span><span class=\"typ-punct\">(</span>par<span class=\"typ-punct\">)</span>\n\n<span class=\"typ-func\">#</span><span class=\"typ-func\">lorem</span><span class=\"typ-punct\">(</span><span class=\"typ-num\">10</span><span class=\"typ-punct\">)</span>\n</code></pre><div class=\"preview\"><img src=\"/en-US-v0.14.1/assets/2736820672bb7a52dce20390b13a1cb0.png\" alt=\"Preview\"></div></div>\n<h2 id=\"conditional-access\">Conditional access</h2>\n<p>You can also use this in combination with the <a href=\"/en-US-v0.14.1/reference/foundations/dictionary/\">dictionary\nconstructor</a> to conditionally access global definitions. This\ncan, for instance, be useful to use new or experimental functionality when\nit is available, while falling back to an alternative implementation if\nused on an older Typst version. In particular, this allows us to create\n<a href=\"https://en.wikipedia.org/wiki/Polyfill_(programming)\">polyfills</a>.</p>\n<p>This can be as simple as creating an alias to prevent warning messages, for\nexample, conditionally using <code>pattern</code> in Typst version 0.12, but using\n<a href=\"/en-US-v0.14.1/reference/visualize/tiling/\" title=\"`tiling`\"><code>tiling</code></a> in newer versions. Since the parameters accepted by the <code>tiling</code>\nfunction match those of the older <code>pattern</code> function, using the <code>tiling</code>\nfunction when available and falling back to <code>pattern</code> otherwise will unify\nthe usage across all versions. Note that, when creating a polyfill,\n<a href=\"/en-US-v0.14.1/reference/foundations/sys/\"><code>sys.version</code></a> can also be very useful.</p>\n<pre><code><span class=\"typ-key\">#</span><span class=\"typ-key\">let</span> tiling <span class=\"typ-op\">=</span> <span class=\"typ-key\">if</span> <span class=\"typ-str\">&quot;tiling&quot;</span> <span class=\"typ-key\">in</span> std <span class=\"typ-punct\">{</span> tiling <span class=\"typ-punct\">}</span> <span class=\"typ-key\">else</span> <span class=\"typ-punct\">{</span> pattern <span class=\"typ-punct\">}</span>\n\n<span class=\"typ-escape\">...</span>\n</code></pre>","functions":[],"global_attributes":[]}}}