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

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

带有可选语法高亮的原始文本。

使用等宽字体逐字显示文本,通常用于将代码嵌入文档中。

Example

Adding `rbx` to `rcx` gives
the desired result.

What is ```rust fn main()``` in Rust
would be ```c int main()``` in C.

```rust
fn main() {
    println!("Hello World!");
}
```

This has ``` `backticks` ``` in it
(but the spaces are trimmed). And
``` here``` the leading space is
also trimmed.
Preview

Syntax

This function also has dedicated syntax. You can enclose text in 1 or 3+ backticks (`) to make it raw. Two backticks produce empty raw text. When you use three or more backticks, you can additionally specify a language tag for syntax highlighting directly after the opening backticks. Within raw blocks, everything (except for the language tag, if applicable) is rendered as is, in particular, there are no escape sequences.

The language tag is an identifier that directly follows the opening backticks only if there are three or more backticks. If your text starts with something that looks like an identifier, but no syntax highlighting is needed, start the text with a single space (which will be trimmed) or use the single backtick syntax. If your text should start or end with a backtick, put a space before or after it (it will be trimmed).

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

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

原始文本块。

你还可以创造性地使用原始块为你的自动化创建自定义语法。

展开例子
// Parse numbers in raw blocks with the
// `mydsl` tag and sum them up.
#show raw.where(lang: "mydsl"): it => {
  let sum = 0
  for part in it.text.split("+") {
    sum += int(part.trim())
  }
  sum
}

```mydsl
1 + 2 + 3 + 4 + 5
```
Preview

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

是否将原始文本显示在一个单独的块中。

在标记模式中,使用一个反引号会将此值设置为 false。 如果包含的内容至少包含一个换行符,则使用三个反引号会将其设置为 true

默认值:

false

展开例子
// Display inline code in a small box
// that retains the correct baseline.
#show raw.where(block: false): box.with(
  fill: luma(240),
  inset: (x: 3pt, y: 0pt),
  outset: (y: 3pt),
  radius: 2pt,
)

// Display block code in a larger block
// with more padding.
#show raw.where(block: true): block.with(
  fill: luma(240),
  inset: 10pt,
  radius: 4pt,
)

With `rg`, you can search through your files quickly.
This example searches the current directory recursively
for the text `Hello World`:

```bash
rg "Hello World"
```
Preview

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

要在其中突出显示语法的语言。

要在其中突出显示语法的语言,用法与 Markdown 代码块类似。 除了 Markdown 中也有的典型编程语言后缀外,它还分别支持 Typst 标记模式和 Typst 脚本模式分别对应的“typ”和“typc”后缀。

默认值:

none

展开例子
```typ
This is *Typst!*
```

This is ```typ also *Typst*```, but inline!
Preview

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

The horizontal alignment that each line in a raw block should have. This option is ignored if this is not a raw block (if specified block: false or single backticks were used in markup mode).

By default, this is set to start, meaning that raw text is aligned towards the start of the text direction inside the block by default, regardless of the current context's alignment (allowing you to center the raw block itself without centering the text inside it, for example).

默认值:

start

展开例子
#set raw(align: center)

```typc
let f(x) = x
code = "centered"
```
Preview

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

One or multiple additional syntax definitions to load. The syntax definitions should be in the sublime-syntax file format.

默认值:

()

展开例子
#set raw(syntaxes: "SExpressions.sublime-syntax")

```sexp
(defun factorial (x)
  (if (zerop x)
    ; with a comment
    1
    (* x (factorial (- x 1)))))
```
Preview

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

用于语法高亮的主题。主题文件应该使用tmTheme文件格式

应用主题仅影响特定突出显示文本的颜色。它不考虑主题的前景和背景属性,因此您可以保留对原始文本颜色的控制。您可以使用text函数自行应用前景颜色,使用填充块应用背景颜色。您还可以使用xml函数从主题中提取这些属性。

默认值:

none

展开例子
#set raw(theme: "halcyon.tmTheme")
#show raw: it => block(
  fill: rgb("#1d2433"),
  inset: 8pt,
  radius: 5pt,
  text(fill: rgb("#a2aabc"), it)
)

```typ
= Chapter 1
#let hi = "Hello World"
```
Preview

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

以空格为单位的制表符停止的大小。制表符将替换为足够的空格,以与下一个大小的倍数对齐。

默认值:

2

展开例子
#set raw(tab-size: 8)
```tsv
Year	Month	Day
2000	2	3
2001	2	1
2002	3	10
```
Preview

定义
定义
这些函数和类型带有附属定义。要访问这种定义,请先写上函数或类型的名称,再加上定义的名称,并用句点在中间分隔。

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

一行突出显示的原始文本。

这是由raw元素合成的助手元素。

它允许您访问行的各种属性,如行号、原始非突出显示的文本、突出显示的文本以及它是否是原始块的第一行或最后一行。

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

原始块内原始行的行号,从 1 开始。

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

The total number of lines in the raw block.

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

The line of raw text.

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

The highlighted raw text.

转到官方文档(英文)

搜索