summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLU Jialin <luxxxlucy@gmail.com>2023-09-11 16:47:08 +0800
committerGitHub <noreply@github.com>2023-09-11 10:47:08 +0200
commitd056280165b981ef7a11f5bfb02417ef96760352 (patch)
tree3d835552f4b018dfe3714a88ef59ddaebbfe59ad
parent71dccde031dedc285042257c7e16bafb152dde58 (diff)
Wrap into an equation when a Math expr is evaluated (#2081)
-rw-r--r--crates/typst/src/eval/mod.rs7
-rw-r--r--tests/ref/bugs/math-eval.pngbin0 -> 2610 bytes
-rw-r--r--tests/typ/bugs/math-eval.typ5
3 files changed, 9 insertions, 3 deletions
diff --git a/crates/typst/src/eval/mod.rs b/crates/typst/src/eval/mod.rs
index fffedc9f..a6fd5e17 100644
--- a/crates/typst/src/eval/mod.rs
+++ b/crates/typst/src/eval/mod.rs
@@ -202,9 +202,10 @@ pub fn eval_string(
EvalMode::Markup => {
Value::Content(root.cast::<ast::Markup>().unwrap().eval(&mut vm)?)
}
- EvalMode::Math => {
- Value::Content(root.cast::<ast::Math>().unwrap().eval(&mut vm)?)
- }
+ EvalMode::Math => Value::Content((vm.items.equation)(
+ root.cast::<ast::Math>().unwrap().eval(&mut vm)?,
+ false,
+ )),
};
// Handle control flow.
diff --git a/tests/ref/bugs/math-eval.png b/tests/ref/bugs/math-eval.png
new file mode 100644
index 00000000..cdfd4cce
--- /dev/null
+++ b/tests/ref/bugs/math-eval.png
Binary files differ
diff --git a/tests/typ/bugs/math-eval.typ b/tests/typ/bugs/math-eval.typ
new file mode 100644
index 00000000..31450b8d
--- /dev/null
+++ b/tests/typ/bugs/math-eval.typ
@@ -0,0 +1,5 @@
+// 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)$