raw
元素
元素函数可以通过 set 和 show 规则进行样式自定义。
带有可选语法高亮的原始文本。
使用等宽字体逐字显示文本,通常用于将代码嵌入文档中。
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.
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
```
block
是否将原始文本显示在一个单独的块中。
在标记模式中,使用一个反引号会将此值设置为 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"
```
lang
要在其中突出显示语法的语言。
要在其中突出显示语法的语言,用法与 Markdown 代码块类似。 除了 Markdown 中也有的典型编程语言后缀外,它还分别支持 Typst 标记模式和 Typst 脚本模式分别对应的“typ”和“typc”后缀。
默认:none
查看示例
```typ
This is *Typst!*
```
This is ```typ also *Typst*```, but inline!
align
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"
```
syntaxes
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)))))
```
theme
用于语法高亮的主题。主题文件应该使用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"
```
tab-size
以空格为单位的制表符停止的大小。制表符将替换为足够的空格,以与下一个大小的倍数对齐。
默认:2
查看示例
#set raw(tab-size: 8)
```tsv
Year Month Day
2000 2 3
2001 2 1
2002 3 10
```
定义
函数和类型可以有与其关联的定义 (成员或方法)。可以使用 "." 操作符来访问调用它们。
line
一行突出显示的原始文本。
这是由raw
元素合成的助手元素。
它允许您访问行的各种属性,如行号、原始非突出显示的文本、突出显示的文本以及它是否是原始块的第一行或最后一行。
number
原始块内原始行的行号,从 1 开始。
count
The total number of lines in the raw block.
text
The line of raw text.
body
The highlighted raw text.