注意:该中文文档为社区驱动的非官网文档,可能存在错译、漏译或过时等问题,请以官网文档 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 中文文档

eval

Evaluates a string as Typst code.

This function should only be used as a last resort.

Example

#eval("1 + 1") \
#eval("(1, 2, 3, 4)").len() \
#eval("*Markup!*", mode: "markup") \
Preview

参数
参数是函数的输入,它们在函数名称后面的括号中传入。

source
str
必需参数位置参数
位置参数按顺序传入,不带名称。

A string of Typst code to evaluate.

The code in the string cannot interact with the file system.

mode
str

The syntactical mode in which the string is parsed.

默认:"code"

查看示例
#eval("= Heading", mode: "markup")
#eval("1_2^3", mode: "math")
Preview

scope

A scope of definitions that are made available.

默认:(:)

查看示例
#eval("x + 1", scope: (x: 2)) \
#eval(
  "abc/xyz",
  mode: "math",
  scope: (
    abc: $a + b + c$,
    xyz: $x + y + z$,
  ),
)
Preview