提示:本教程存在过时问题,更详细教程请阅读 小蓝书Typst 中文社区导航 FAQ
注意:该中文文档为社区驱动的非官网文档,可能存在错译、漏译或过时等问题,请以官网文档 Documentation 为准,如发现错漏,也欢迎 您的贡献镜像)。Typst 非官方中文交流 QQ 群:793548390
Warning: the Chinese document is a community-driven non-official document, there may be mistranslation, omission or outdated problems, please refer to the official website documentation.
Typst 中文文档

selector

A filter for selecting elements within the document.

You can construct a selector in the following ways:

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.
Preview

构造函数
如果类型具有构造函数,可以像函数一样调用它来创建一个该类型的值。

Turns a value into a selector. The following values are accepted:

target
str regex label selector location function
必需参数位置参数
位置参数按顺序传入,不带名称。

Can be an element function like a heading or figure, a <label> or a more complex selector like heading.where(level: 1).

定义
函数和类型可以有与其关联的定义 (成员或方法)。可以使用 "." 操作符来访问调用它们。

or

Selects all elements that match this or any of the other selectors.

others
label selector function
必需参数位置参数
位置参数按顺序传入,不带名称。
可变参数
可变参数可以多次传入。

The other selectors to match on.

and

Selects all elements that match this and all of the the other selectors.

others
label selector function
必需参数位置参数
位置参数按顺序传入,不带名称。
可变参数
可变参数可以多次传入。

The other selectors to match on.

before

Returns a modified selector that will only match elements that occur before the first match of end.

end
label selector function
必需参数位置参数
位置参数按顺序传入,不带名称。

The original selection will end at the first match of end.

inclusive

Whether end itself should match or not. This is only relevant if both selectors match the same type of element. Defaults to true.

默认:true

after

Returns a modified selector that will only match elements that occur after the first match of start.

start
label selector function
必需参数位置参数
位置参数按顺序传入,不带名称。

The original selection will start at the first match of start.

inclusive

Whether start itself should match or not. This is only relevant if both selectors match the same type of element. Defaults to true.

默认:true