Documentation

evalGo to source

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") \

Parameters

eval() → any

source
str
RequiredPositional
Question mark

A string of Typst code to evaluate.

modeDefault: "code"

The syntactical mode in which the string is parsed.

ExpandView example
#eval("= Heading", mode: "markup")
#eval("1_2^3", mode: "math")
VariantDetails
"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.

scopeDefault: (:)

A scope of definitions that are made available.

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