{"route":"/en-US-v0.13.1/reference/foundations/selector/","title":"Selector","description":"Documentation for the Selector type.","part":null,"outline":[{"id":"summary","name":"Summary","children":[]},{"id":"example","name":"Example","children":[]},{"id":"constructor","name":"Constructor","children":[{"id":"constructor-target","name":"target","children":[]}]},{"id":"definitions","name":"Definitions","children":[{"id":"definitions-or","name":"Or","children":[{"id":"definitions-or-others","name":"others","children":[]}]},{"id":"definitions-and","name":"And","children":[{"id":"definitions-and-others","name":"others","children":[]}]},{"id":"definitions-before","name":"Before","children":[{"id":"definitions-before-end","name":"end","children":[]},{"id":"definitions-before-inclusive","name":"inclusive","children":[]}]},{"id":"definitions-after","name":"After","children":[{"id":"definitions-after-start","name":"start","children":[]},{"id":"definitions-after-inclusive","name":"inclusive","children":[]}]}]}],"body":{"kind":"type","content":{"name":"selector","title":"Selector","keywords":[],"oneliner":"A filter for selecting elements within the document.","details":"<p>A filter for selecting elements within the document.</p>\n<p>You can construct a selector in the following ways:</p>\n<ul>\n<li>you can use an element <a href=\"/en-US-v0.13.1/reference/foundations/function/\" title=\"function\">function</a></li>\n<li>you can filter for an element function with\n<a href=\"/en-US-v0.13.1/reference/foundations/function/#definitions-where\">specific fields</a></li>\n<li>you can use a <a href=\"/en-US-v0.13.1/reference/foundations/str/\">string</a> or <a href=\"/en-US-v0.13.1/reference/foundations/regex/\">regular expression</a></li>\n<li>you can use a <a href=\"/en-US-v0.13.1/reference/foundations/label/\"><code><span class=\"typ-label\">&lt;label&gt;</span></code></a></li>\n<li>you can use a <a href=\"/en-US-v0.13.1/reference/introspection/location/\" title=\"`location`\"><code>location</code></a></li>\n<li>call the <a href=\"/en-US-v0.13.1/reference/foundations/selector/\" title=\"`selector`\"><code>selector</code></a> constructor to convert any of the above types into a\nselector value and use the methods below to refine it</li>\n</ul>\n<p>Selectors are used to <a href=\"/en-US-v0.13.1/reference/styling/#show-rules\">apply styling rules</a> to\nelements. You can also use selectors to <a href=\"/en-US-v0.13.1/reference/introspection/query/\" title=\"query\">query</a> the document for certain\ntypes of elements.</p>\n<p>Furthermore, you can pass a selector to several of Typst's built-in\nfunctions to configure their behaviour. One such example is the <a href=\"/en-US-v0.13.1/reference/model/outline/\" title=\"outline\">outline</a>\nwhere it can be used to change which elements are listed within the outline.</p>\n<p>Multiple selectors can be combined using the methods shown below. However,\nnot all kinds of selectors are supported in all places, at the moment.</p>\n<h2 id=\"example\">Example</h2>\n<div class=\"previewed-code\"><pre><code><span class=\"typ-key\">#</span><span class=\"typ-key\">context</span> <span class=\"typ-func\">query</span><span class=\"typ-punct\">(</span>\n  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\">1</span><span class=\"typ-punct\">)</span>\n    <span class=\"typ-punct\">.</span><span class=\"typ-func\">or</span><span class=\"typ-punct\">(</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>\n<span class=\"typ-punct\">)</span>\n\n<span class=\"typ-heading\">= This will be found</span>\n<span class=\"typ-heading\">== So will this</span>\n<span class=\"typ-heading\">=== But this will not.</span>\n</code></pre><div class=\"preview\"><img src=\"/en-US-v0.13.1/assets/496fb688b3f52c8190d084ec07b2c611.png\" alt=\"Preview\"></div></div>","constructor":{"path":[],"name":"selector","title":"Construct","keywords":[],"oneliner":"Turns a value into a selector. The following values are accepted:","element":false,"contextual":false,"deprecation":null,"details":"<p>Turns a value into a selector. The following values are accepted:</p>\n<ul>\n<li>An element function like a <code>heading</code> or <code>figure</code>.</li>\n<li>A <code><span class=\"typ-label\">&lt;label&gt;</span></code>.</li>\n<li>A more complex selector like <code>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\">1</span><span class=\"typ-punct\">)</span></code>.</li>\n</ul>","example":null,"self":false,"params":[{"name":"target","details":"<p>Can be an element function like a <code>heading</code> or <code>figure</code>, a <code><span class=\"typ-label\">&lt;label&gt;</span></code>\nor a more complex selector like <code>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\">1</span><span class=\"typ-punct\">)</span></code>.</p>","example":null,"types":["str","regex","label","selector","location","function"],"strings":[],"default":null,"positional":true,"named":false,"required":true,"variadic":false,"settable":false}],"returns":["selector"],"scope":[]},"scope":[{"path":["selector"],"name":"or","title":"Or","keywords":[],"oneliner":"Selects all elements that match this or any of the other selectors.","element":false,"contextual":false,"deprecation":null,"details":"<p>Selects all elements that match this or any of the other selectors.</p>","example":null,"self":true,"params":[{"name":"others","details":"<p>The other selectors to match on.</p>","example":null,"types":["str","regex","label","selector","location","function"],"strings":[],"default":null,"positional":true,"named":false,"required":true,"variadic":true,"settable":false}],"returns":["selector"],"scope":[]},{"path":["selector"],"name":"and","title":"And","keywords":[],"oneliner":"Selects all elements that match this and all of the other selectors.","element":false,"contextual":false,"deprecation":null,"details":"<p>Selects all elements that match this and all of the other selectors.</p>","example":null,"self":true,"params":[{"name":"others","details":"<p>The other selectors to match on.</p>","example":null,"types":["str","regex","label","selector","location","function"],"strings":[],"default":null,"positional":true,"named":false,"required":true,"variadic":true,"settable":false}],"returns":["selector"],"scope":[]},{"path":["selector"],"name":"before","title":"Before","keywords":[],"oneliner":"Returns a modified selector that will only match elements that occur","element":false,"contextual":false,"deprecation":null,"details":"<p>Returns a modified selector that will only match elements that occur\nbefore the first match of <code>end</code>.</p>","example":null,"self":true,"params":[{"name":"end","details":"<p>The original selection will end at the first match of <code>end</code>.</p>","example":null,"types":["label","selector","location","function"],"strings":[],"default":null,"positional":true,"named":false,"required":true,"variadic":false,"settable":false},{"name":"inclusive","details":"<p>Whether <code>end</code> itself should match or not. This is only relevant if\nboth selectors match the same type of element. Defaults to <code><span class=\"typ-key\">true</span></code>.</p>","example":null,"types":["bool"],"strings":[],"default":"<code><span class=\"typ-key\">true</span></code>","positional":false,"named":true,"required":false,"variadic":false,"settable":false}],"returns":["selector"],"scope":[]},{"path":["selector"],"name":"after","title":"After","keywords":[],"oneliner":"Returns a modified selector that will only match elements that occur","element":false,"contextual":false,"deprecation":null,"details":"<p>Returns a modified selector that will only match elements that occur\nafter the first match of <code>start</code>.</p>","example":null,"self":true,"params":[{"name":"start","details":"<p>The original selection will start at the first match of <code>start</code>.</p>","example":null,"types":["label","selector","location","function"],"strings":[],"default":null,"positional":true,"named":false,"required":true,"variadic":false,"settable":false},{"name":"inclusive","details":"<p>Whether <code>start</code> itself should match or not. This is only relevant\nif both selectors match the same type of element. Defaults to\n<code><span class=\"typ-key\">true</span></code>.</p>","example":null,"types":["bool"],"strings":[],"default":"<code><span class=\"typ-key\">true</span></code>","positional":false,"named":true,"required":false,"variadic":false,"settable":false}],"returns":["selector"],"scope":[]}]}}}