Info
This site is generated using the static site generator developed by the Typst Community. Please adjust the text content of this banner according to your usage requirements. At Typst GmbH's request, when publishing documentation, you must clearly indicate that it is non-official and display the version of Typst being documented. For details, refer to Issue #874 on typst/typst.
TypstDocumentEnglish
v0.dev.2025-09-12

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

Parameter
Parameter
Parameters are input values for functions. Specify them in parentheses after the function name.

source
Required
Required
Required parameters must be specified when calling the function.
Positional
Positional
Positional parameters can be set by specifying them in order, omitting the parameter name.

A string of Typst code to evaluate.

mode

The syntactical mode in which the string is parsed.

Available string values:
  • markup

    Evaluate as markup, as in a Typst file.

  • math

    Evaluate as math, as in an equation.

  • code

    Evaluate as code, as after a hash.

Default value:

"code"

Show example
#eval("= Heading", mode: "markup")
#eval("1_2^3", mode: "math")
Preview

scope

A scope of definitions that are made available.

Default value:

(:)

Show example
#eval("x + 1", scope: (x: 2)) \
#eval(
  "abc/xyz",
  mode: "math",
  scope: (
    abc: $a + b + c$,
    xyz: $x + y + z$,
  ),
)
Preview
Open official docs

Search