注意 / 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+后期随缘更新

ref
元素
元素
元素函数可用setshow规则自定义样式。

A reference to a label or bibliography.

Produces a textual reference to a label. For example, a reference to a heading will yield an appropriate string such as "Section 1" for a reference to the first heading. The references are also links to the respective element. Reference syntax can also be used to cite from a bibliography.

Referenceable elements include headings, figures, equations, and footnotes. To create a custom referenceable element like a theorem, you can create a figure of a custom kind and write a show rule for it. In the future, there might be a more direct way to define a custom referenceable element.

If you just want to link to a labelled element and not get an automatic textual reference, consider using the link function instead.

Example

#set heading(numbering: "1.")
#set math.equation(numbering: "(1)")

= Introduction <intro>
Recent developments in
typesetting software have
rekindled hope in previously
frustrated researchers. @distress
As shown in @results, we ...

= Results <results>
We discuss our approach in
comparison with others.

== Performance <perf>
@slow demonstrates what slow
software looks like.
$ O(n) = 2^n $ <slow>

#bibliography("works.bib")
Preview

Syntax

This function also has dedicated syntax: A reference to a label can be created by typing an @ followed by the name of the label (e.g. = Introduction <intro> can be referenced by typing @intro).

To customize the supplement, add content in square brackets after the reference: @intro[Chapter].

Customization

If you write a show rule for references, you can access the referenced element through the element field of the reference. The element may be none even if it exists if Typst hasn't discovered it yet, so you always need to handle that case in your code.

#set heading(numbering: "1.")
#set math.equation(numbering: "(1)")

#show ref: it => {
  let eq = math.equation
  let el = it.element
  if el != none and el.func() == eq {
    // Override equation references.
    numbering(
      el.numbering,
      ..counter(eq).at(el.location())
    )
  } else {
    // Other references as usual.
    it
  }
}

= Beginnings <beginning>
In @beginning we prove @pythagoras.
$ a^2 + b^2 = c^2 $ <pythagoras>
Preview

参数
参数
参数是传给函数的输入,写在函数名后的括号中。

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

The target label that should be referenced.

Can be a label that is defined in the document or an entry from the bibliography.

supplement
可用set规则
可用set规则
可用set规则设置参数,更改后续调用时的默认值。

A supplement for the reference.

For references to headings or figures, this is added before the referenced number. For citations, this can be used to add a page number.

If a function is specified, it is passed the referenced element and should return content.

默认值:

auto

展开例子
#set heading(numbering: "1.")
#set ref(supplement: it => {
  if it.func() == heading {
    "Chapter"
  } else {
    "Thing"
  }
})

= Introduction <intro>
In @intro, we see how to turn
Sections into Chapters. And
in @intro[Part], it is done
manually.
Preview
转到官方文档(英文)

搜索