注意 / Info
本站经 Typst GmbH 许可,提供 Typst v0.10.0+后期随缘更新 官方文档的翻译,由中文社区维护。建议与官方文档一同阅读,因为可能存在错译、漏译或过时信息。如有意改进翻译内容或网站本身,可在GitHub上提出 Issue、发起 Pull Requests。此外,也欢迎加入「Typst 非官方中文交流群」(QQ 793548390)
This site provides a Chinese translation of the Typst v0.10.0+后期随缘更新 documentation maintained by the “Typst Chinese Community” with permission from Typst GmbH. We recommend using this alongside the official documentation. We welcome contributions through Issues and Pull Requests on our GitHub repository for both translation improvements and website enhancements. Feel free to join our QQ chat group “Typst 非官方中文交流群” (793548390).
Typst文档简体中文版
v0.10.0+后期随缘更新

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:

  • An element function like a heading or figure.
  • A <label>.
  • A more complex selector like heading.where(level: 1).

target
必需参数
必需参数
必需参数在调用函数时必须传入。
位置参数
位置参数
位置参数按顺序传入,不带参数名。

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
必需参数
必需参数
必需参数在调用函数时必须传入。
位置参数
位置参数
位置参数按顺序传入,不带参数名。
变长参数
变长参数
变长参数可以传入多次。

The other selectors to match on.

and

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

others
必需参数
必需参数
必需参数在调用函数时必须传入。
位置参数
位置参数
位置参数按顺序传入,不带参数名。
变长参数
变长参数
变长参数可以传入多次。

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
必需参数
必需参数
必需参数在调用函数时必须传入。
位置参数
位置参数
位置参数按顺序传入,不带参数名。

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
必需参数
必需参数
必需参数在调用函数时必须传入。
位置参数
位置参数
位置参数按顺序传入,不带参数名。

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

转到官方文档(英文)

搜索