{"route":"/en-US-v0.14.1/reference/model/heading/","title":"Heading","description":"Documentation for the `heading` function.","part":null,"outline":[{"id":"summary","name":"Summary","children":[]},{"id":"example","name":"Example","children":[]},{"id":"syntax","name":"Syntax","children":[]},{"id":"accessibility","name":"Accessibility","children":[]},{"id":"html-export","name":"HTML export","children":[]},{"id":"parameters","name":"Parameters","children":[{"id":"parameters-level","name":"level","children":[]},{"id":"parameters-depth","name":"depth","children":[]},{"id":"parameters-offset","name":"offset","children":[]},{"id":"parameters-numbering","name":"numbering","children":[]},{"id":"parameters-supplement","name":"supplement","children":[]},{"id":"parameters-outlined","name":"outlined","children":[]},{"id":"parameters-bookmarked","name":"bookmarked","children":[]},{"id":"parameters-hanging-indent","name":"hanging-indent","children":[]},{"id":"parameters-body","name":"body","children":[]}]}],"body":{"kind":"func","content":{"path":[],"name":"heading","title":"Heading","keywords":[],"oneliner":"A section heading.","element":true,"contextual":false,"deprecationMessage":null,"deprecationUntil":null,"details":[{"kind":"html","content":"<p>A section heading.</p>\n<p>With headings, you can structure your document into sections. Each heading\nhas a <em>level,</em> which starts at one and is unbounded upwards. This level\nindicates the logical role of the following content (section, subsection,\netc.) A top-level heading indicates a top-level section of the document (not\nthe document's title). To insert a title, use the <a href=\"/en-US-v0.14.1/reference/model/title/\"><code>title</code></a> element\ninstead.</p>\n<p>Typst can automatically number your headings for you. To enable numbering,\nspecify how you want your headings to be numbered with a\n<a href=\"/en-US-v0.14.1/reference/model/numbering/\">numbering pattern or function</a>.</p>\n<p>Independently of the numbering, Typst can also automatically generate an\n<a href=\"/en-US-v0.14.1/reference/model/outline/\" title=\"outline\">outline</a> of all headings for you. To exclude one or more headings from this\noutline, you can set the <code>outlined</code> parameter to <code><span class=\"typ-key\">false</span></code>.</p>\n<p>When writing a <a href=\"/en-US-v0.14.1/reference/styling/#show-rules\">show rule</a> that accesses the\n<a href=\"/en-US-v0.14.1/reference/model/heading/#parameters-body\"><code>body</code> field</a> to create a completely custom look for\nheadings, make sure to wrap the content in a <a href=\"/en-US-v0.14.1/reference/layout/block/\"><code>block</code></a> (which is\nimplicitly <a href=\"/en-US-v0.14.1/reference/layout/block/#parameters-sticky\">sticky</a> for headings through a built-in show-set\nrule). This prevents headings from becoming &quot;orphans&quot;, i.e. remaining\nat the end of the page with the following content being on the next page.</p>\n<h2 id=\"example\">Example</h2>\n<div class=\"previewed-code\"><pre><code><span class=\"typ-key\">#</span><span class=\"typ-key\">set</span> <span class=\"typ-func\">heading</span><span class=\"typ-punct\">(</span>numbering<span class=\"typ-punct\">:</span> <span class=\"typ-str\">&quot;1.a)&quot;</span><span class=\"typ-punct\">)</span>\n\n<span class=\"typ-heading\">= Introduction</span>\nIn recent years, <span class=\"typ-escape\">...</span>\n\n<span class=\"typ-heading\">== Preliminaries</span>\nTo start, <span class=\"typ-escape\">...</span>\n</code></pre><div class=\"preview\"><img src=\"/en-US-v0.14.1/assets/3da8ed6c330c3767836190a4021f5927.png\" alt=\"Preview\"></div></div>\n<h2 id=\"syntax\">Syntax</h2>\n<p>Headings have dedicated syntax: They can be created by starting a line with\none or multiple equals signs, followed by a space. The number of equals\nsigns determines the heading's logical nesting depth. The <code>offset</code> field\ncan be set to configure the starting depth.</p>\n<h2 id=\"accessibility\">Accessibility</h2>\n<p>Headings are important for accessibility, as they help users of Assistive\nTechnologies (AT) like screen readers to navigate within your document.\nScreen reader users will be able to skip from heading to heading, or get an\noverview of all headings in the document.</p>\n<p>To make your headings accessible, you should not skip heading levels. This\nmeans that you should start with a first-level heading. Also, when the\nprevious heading was of level 3, the next heading should be of level 3\n(staying at the same depth), level 4 (going exactly one level deeper), or\nlevel 1 or 2 (new hierarchically higher headings).</p>\n<h2 id=\"html-export\">HTML export</h2>\n<p>As mentioned above, a top-level heading indicates a top-level section of\nthe document rather than its title. This is in contrast to the HTML <code>&lt;h1&gt;</code>\nelement of which there should be only one per document.</p>\n<p>For this reason, in HTML export, a <a href=\"/en-US-v0.14.1/reference/model/title/\" title=\"`title`\"><code>title</code></a> element will turn into an\n<code>&lt;h1&gt;</code> and headings turn into <code>&lt;h2&gt;</code> and lower (a level 1 heading thus turns\ninto <code>&lt;h2&gt;</code>, a level 2 heading into <code>&lt;h3&gt;</code>, etc).</p>"}],"self":false,"params":[{"name":"level","details":[{"kind":"html","content":"<p>The absolute nesting depth of the heading, starting from one. If set\nto <code><span class=\"typ-key\">auto</span></code>, it is computed from <code>offset <span class=\"typ-op\">+</span> depth</code>.</p>\n<p>This is primarily useful for usage in <a href=\"/en-US-v0.14.1/reference/styling/#show-rules\">show rules</a>\n(either with <a href=\"/en-US-v0.14.1/reference/foundations/function/#definitions-where\"><code>where</code></a> selectors or by accessing the\nlevel directly on a shown heading).</p>"},{"kind":"example","content":{"body":"<div class=\"previewed-code\"><pre><code><span class=\"typ-key\">#</span><span class=\"typ-key\">show</span> heading<span class=\"typ-punct\">.</span><span class=\"typ-func\">where</span><span class=\"typ-punct\">(</span>level<span class=\"typ-punct\">:</span> <span class=\"typ-num\">2</span><span class=\"typ-punct\">)</span><span class=\"typ-punct\">:</span> <span class=\"typ-key\">set</span> <span class=\"typ-func\">text</span><span class=\"typ-punct\">(</span>red<span class=\"typ-punct\">)</span>\n\n<span class=\"typ-heading\">= Level 1</span>\n<span class=\"typ-heading\">== Level 2</span>\n\n<span class=\"typ-key\">#</span><span class=\"typ-key\">set</span> <span class=\"typ-func\">heading</span><span class=\"typ-punct\">(</span>offset<span class=\"typ-punct\">:</span> <span class=\"typ-num\">1</span><span class=\"typ-punct\">)</span>\n<span class=\"typ-heading\">= Also level 2</span>\n<span class=\"typ-heading\">== Level 3</span>\n</code></pre><div class=\"preview\"><img src=\"/en-US-v0.14.1/assets/fe90e6f8fd396e0fe319b97dbaf1a394.png\" alt=\"Preview\"></div></div>","title":null}}],"types":["auto","int"],"strings":[],"default":"<code><span class=\"typ-key\">auto</span></code>","positional":false,"named":true,"required":false,"variadic":false,"settable":true},{"name":"depth","details":[{"kind":"html","content":"<p>The relative nesting depth of the heading, starting from one. This is\ncombined with <code>offset</code> to compute the actual <code>level</code>.</p>\n<p>This is set by the heading syntax, such that <code><span class=\"typ-heading\">== Heading</span></code> creates a\nheading with logical depth of 2, but actual level <code>offset <span class=\"typ-op\">+</span> <span class=\"typ-num\">2</span></code>. If you\nconstruct a heading manually, you should typically prefer this over\nsetting the absolute level.</p>"}],"types":["int"],"strings":[],"default":"<code><span class=\"typ-num\">1</span></code>","positional":false,"named":true,"required":false,"variadic":false,"settable":true},{"name":"offset","details":[{"kind":"html","content":"<p>The starting offset of each heading's <code>level</code>, used to turn its\nrelative <code>depth</code> into its absolute <code>level</code>.</p>"},{"kind":"example","content":{"body":"<div class=\"previewed-code\"><pre><code><span class=\"typ-heading\">= Level 1</span>\n\n<span class=\"typ-key\">#</span><span class=\"typ-key\">set</span> <span class=\"typ-func\">heading</span><span class=\"typ-punct\">(</span>offset<span class=\"typ-punct\">:</span> <span class=\"typ-num\">1</span><span class=\"typ-punct\">,</span> numbering<span class=\"typ-punct\">:</span> <span class=\"typ-str\">&quot;1.1&quot;</span><span class=\"typ-punct\">)</span>\n<span class=\"typ-heading\">= Level 2</span>\n\n<span class=\"typ-func\">#</span><span class=\"typ-func\">heading</span><span class=\"typ-punct\">(</span>offset<span class=\"typ-punct\">:</span> <span class=\"typ-num\">2</span><span class=\"typ-punct\">,</span> depth<span class=\"typ-punct\">:</span> <span class=\"typ-num\">2</span><span class=\"typ-punct\">)</span><span class=\"typ-punct\">[</span>\n  I&#39;m level 4\n<span class=\"typ-punct\">]</span>\n</code></pre><div class=\"preview\"><img src=\"/en-US-v0.14.1/assets/84ab568a4e7e1f030c7a3a8ec0354a2c.png\" alt=\"Preview\"></div></div>","title":null}}],"types":["int"],"strings":[],"default":"<code><span class=\"typ-num\">0</span></code>","positional":false,"named":true,"required":false,"variadic":false,"settable":true},{"name":"numbering","details":[{"kind":"html","content":"<p>How to number the heading. Accepts a\n<a href=\"/en-US-v0.14.1/reference/model/numbering/\">numbering pattern or function</a> taking multiple numbers.</p>"},{"kind":"example","content":{"body":"<div class=\"previewed-code\"><pre><code><span class=\"typ-key\">#</span><span class=\"typ-key\">set</span> <span class=\"typ-func\">heading</span><span class=\"typ-punct\">(</span>numbering<span class=\"typ-punct\">:</span> <span class=\"typ-str\">&quot;1.a.&quot;</span><span class=\"typ-punct\">)</span>\n\n<span class=\"typ-heading\">= A section</span>\n<span class=\"typ-heading\">== A subsection</span>\n<span class=\"typ-heading\">=== A sub-subsection</span>\n</code></pre><div class=\"preview\"><img src=\"/en-US-v0.14.1/assets/76d21794ff33145e127cdaac70f78b6c.png\" alt=\"Preview\"></div></div>","title":null}}],"types":["none","str","function"],"strings":[],"default":"<code><span class=\"typ-key\">none</span></code>","positional":false,"named":true,"required":false,"variadic":false,"settable":true},{"name":"supplement","details":[{"kind":"html","content":"<p>A supplement for the heading.</p>\n<p>For references to headings, this is added before the referenced number.</p>\n<p>If a function is specified, it is passed the referenced heading and\nshould return content.</p>"},{"kind":"example","content":{"body":"<div class=\"previewed-code\"><pre><code><span class=\"typ-key\">#</span><span class=\"typ-key\">set</span> <span class=\"typ-func\">heading</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> supplement<span class=\"typ-punct\">:</span> <span class=\"typ-punct\">[</span>Chapter<span class=\"typ-punct\">]</span><span class=\"typ-punct\">)</span>\n\n<span class=\"typ-heading\">= Introduction</span> <span class=\"typ-label\">&lt;intro&gt;</span>\nIn <span class=\"typ-ref\">@intro</span>, we see how to turn\nSections into Chapters. And\nin <span class=\"typ-ref\">@intro<span class=\"typ-punct\">[</span>Part<span class=\"typ-punct\">]</span></span>, it is done\nmanually.\n</code></pre><div class=\"preview\"><img src=\"/en-US-v0.14.1/assets/3993144e7996642b7d2f45d44c369199.png\" alt=\"Preview\"></div></div>","title":null}}],"types":["none","auto","content","function"],"strings":[],"default":"<code><span class=\"typ-key\">auto</span></code>","positional":false,"named":true,"required":false,"variadic":false,"settable":true},{"name":"outlined","details":[{"kind":"html","content":"<p>Whether the heading should appear in the <a href=\"/en-US-v0.14.1/reference/model/outline/\" title=\"outline\">outline</a>.</p>\n<p>Note that this property, if set to <code><span class=\"typ-key\">true</span></code>, ensures the heading is also\nshown as a bookmark in the exported PDF's outline (when exporting to\nPDF). To change that behavior, use the <code>bookmarked</code> property.</p>"},{"kind":"example","content":{"body":"<div class=\"previewed-code\"><pre><code><span class=\"typ-func\">#</span><span class=\"typ-func\">outline</span><span class=\"typ-punct\">(</span><span class=\"typ-punct\">)</span>\n\n<span class=\"typ-func\">#</span><span class=\"typ-func\">heading</span><span class=\"typ-punct\">[</span>Normal<span class=\"typ-punct\">]</span>\nThis is a normal heading.\n\n<span class=\"typ-func\">#</span><span class=\"typ-func\">heading</span><span class=\"typ-punct\">(</span>outlined<span class=\"typ-punct\">:</span> <span class=\"typ-key\">false</span><span class=\"typ-punct\">)</span><span class=\"typ-punct\">[</span>Hidden<span class=\"typ-punct\">]</span>\nThis heading does not appear\nin the outline.\n</code></pre><div class=\"preview\"><img src=\"/en-US-v0.14.1/assets/ab747af34dccbfd0fc8693f1e700f84e.png\" alt=\"Preview\"></div></div>","title":null}}],"types":["bool"],"strings":[],"default":"<code><span class=\"typ-key\">true</span></code>","positional":false,"named":true,"required":false,"variadic":false,"settable":true},{"name":"bookmarked","details":[{"kind":"html","content":"<p>Whether the heading should appear as a bookmark in the exported PDF's\noutline. Doesn't affect other export formats, such as PNG.</p>\n<p>The default value of <code><span class=\"typ-key\">auto</span></code> indicates that the heading will only\nappear in the exported PDF's outline if its <code>outlined</code> property is set\nto <code><span class=\"typ-key\">true</span></code>, that is, if it would also be listed in Typst's <a href=\"/en-US-v0.14.1/reference/model/outline/\" title=\"outline\">outline</a>.\nSetting this property to either <code><span class=\"typ-key\">true</span></code> (bookmark) or <code><span class=\"typ-key\">false</span></code> (don't\nbookmark) bypasses that behavior.</p>"},{"kind":"example","content":{"body":"<div class=\"previewed-code\"><pre><code><span class=\"typ-func\">#</span><span class=\"typ-func\">heading</span><span class=\"typ-punct\">[</span>Normal heading<span class=\"typ-punct\">]</span>\nThis heading will be shown in\nthe PDF&#39;s bookmark outline.\n\n<span class=\"typ-func\">#</span><span class=\"typ-func\">heading</span><span class=\"typ-punct\">(</span>bookmarked<span class=\"typ-punct\">:</span> <span class=\"typ-key\">false</span><span class=\"typ-punct\">)</span><span class=\"typ-punct\">[</span>Not bookmarked<span class=\"typ-punct\">]</span>\nThis heading won&#39;t be\nbookmarked in the resulting\nPDF.\n</code></pre><div class=\"preview\"><img src=\"/en-US-v0.14.1/assets/fd4bcc50364eb53747e22f371da7368b.png\" alt=\"Preview\"></div></div>","title":null}}],"types":["auto","bool"],"strings":[],"default":"<code><span class=\"typ-key\">auto</span></code>","positional":false,"named":true,"required":false,"variadic":false,"settable":true},{"name":"hanging-indent","details":[{"kind":"html","content":"<p>The indent all but the first line of a heading should have.</p>\n<p>The default value of <code><span class=\"typ-key\">auto</span></code> uses the width of the numbering as indent\nif the heading is aligned at the <a href=\"/en-US-v0.14.1/reference/layout/direction/#definitions-start\">start</a> of the <a href=\"/en-US-v0.14.1/reference/text/text/#parameters-dir\">text\ndirection</a>, and no indent for center and other alignments.</p>"},{"kind":"example","content":{"body":"<div class=\"previewed-code\"><pre><code><span class=\"typ-key\">#</span><span class=\"typ-key\">set</span> <span class=\"typ-func\">heading</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<span class=\"typ-heading\">= A very, very, very, very, very, very long heading</span>\n\n<span class=\"typ-key\">#</span><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\">align</span><span class=\"typ-punct\">(</span>center<span class=\"typ-punct\">)</span>\n<span class=\"typ-heading\">== A very long heading<span class=\"typ-escape\">\\</span> with center alignment</span>\n</code></pre><div class=\"preview\"><img src=\"/en-US-v0.14.1/assets/2dd0ccc419a029d6fbae760e9905b33c.png\" alt=\"Preview\"></div></div>","title":null}}],"types":["auto","length"],"strings":[],"default":"<code><span class=\"typ-key\">auto</span></code>","positional":false,"named":true,"required":false,"variadic":false,"settable":true},{"name":"body","details":[{"kind":"html","content":"<p>The heading's title.</p>"}],"types":["content"],"strings":[],"default":null,"positional":true,"named":false,"required":true,"variadic":false,"settable":false}],"returns":["content"],"scope":[]}}}