1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
--- eval ---
// Test the eval function.
#test(eval("1 + 2"), 3)
#test(eval("1 + x", scope: (x: 3)), 4)
#test(eval("let x = x + 1; x + 1", scope: (x: 1)), 3)
--- eval-mode ---
// Test evaluation in other modes.
#eval("[_Hello" + " World!_]") \
#eval("_Hello" + " World!_", mode: "markup") \
#eval("RR_1^NN", mode: "math", scope: (RR: math.NN, NN: math.RR))
--- eval-syntax-error-1 ---
// Error: 7-12 expected pattern
#eval("let")
--- eval-in-show-rule ---
#show raw: it => text(font: "PT Sans", eval("[" + it.text + "]"))
Interacting
```
#set text(blue)
Blue #move(dy: -0.15em)[🌊]
```
--- eval-runtime-error ---
// Error: 7-17 cannot continue outside of loop
#eval("continue")
--- eval-syntax-error-2 ---
// Error: 7-12 expected semicolon or line break
#eval("1 2")
--- eval-path-resolve ---
// Test absolute path.
#eval("image(\"/assets/images/tiger.jpg\", width: 50%)")
--- eval-path-resolve-in-show-rule ---
#show raw: it => eval(it.text, mode: "markup")
```
#show emph: image("/assets/images/tiger.jpg", width: 50%)
_Tiger!_
```
--- eval-path-resolve-relative ---
// Test relative path.
#test(eval(`"HELLO" in read("./eval.typ")`.text), true)
--- issue-2055-math-eval ---
// Evaluating a math expr should renders the same as an equation
#eval(mode: "math", "f(a) = cases(a + b\, space space x >= 3,a + b\, space space x = 5)")
$f(a) = cases(a + b\, space space x >= 3,a + b\, space space x = 5)$
|