selector
A filter for selecting elements within the document.
You can construct a selector in the following ways:
- you can use an element function
- you can filter for an element function with specific fields
- you can use a string or regular expression
- you can use a
<label>
- you can use a
location
- call the
selector
constructor to convert any of the above types into a selector value and use the methods below to refine it
Selectors are used to apply styling rules to elements. You can also use selectors to query the document for certain types of elements.
Furthermore, you can pass a selector to several of Typst's built-in functions to configure their behaviour. One such example is the outline where it can be used to change which elements are listed within the outline.
Multiple selectors can be combined using the methods shown below. However, not all kinds of selectors are supported in all places, at the moment.
Example
#locate(loc => query(
heading.where(level: 1)
.or(heading.where(level: 2)),
loc,
))
= This will be found
== So will this
=== But this will not.

构造函数参数参数是传给函数的输入,写在函数名后的括号中。
Turns a value into a selector. The following values are accepted:
- An element function like a
heading
orfigure
. - A
<label>
. - A more complex selector like
heading.where(level: 1)
.
定义定义这些函数和类型带有附属定义。要访问这种定义,请先写上函数或类型的名称,再加上定义的名称,并用句点在中间分隔。
or
Selects all elements that match this or any of the other selectors.
and
Selects all elements that match this and all of the the other selectors.
before
Returns a modified selector that will only match elements that occur
before the first match of end
.
after
Returns a modified selector that will only match elements that occur
after the first match of start
.