diff options
| author | Max <me@mkor.je> | 2024-09-26 11:40:25 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-09-26 11:40:25 +0000 |
| commit | f8f95e5c21352937a0771cd158d0202b552d277e (patch) | |
| tree | cf56edc58a9735bdbfcf3314337b96ed017d1f5a | |
| parent | 320c28844f4e2686ab1bedfc507c9c7babafed63 (diff) | |
Extend hint for unknown variables in math (#5038)
| -rw-r--r-- | crates/typst/src/foundations/scope.rs | 11 | ||||
| -rw-r--r-- | tests/suite/math/call.typ | 6 |
2 files changed, 17 insertions, 0 deletions
diff --git a/crates/typst/src/foundations/scope.rs b/crates/typst/src/foundations/scope.rs index b64c478c..c5c65485 100644 --- a/crates/typst/src/foundations/scope.rs +++ b/crates/typst/src/foundations/scope.rs @@ -137,6 +137,17 @@ fn unknown_variable_math(var: &str, in_global: bool) -> HintedString { res.hint(eco_format!( "`{var}` is not available directly in math, try adding a hash before it: `#{var}`", )); + } else { + res.hint(eco_format!( + "if you meant to display multiple letters as is, try adding spaces between each letter: `{}`", + var.chars() + .flat_map(|c| [' ', c]) + .skip(1) + .collect::<EcoString>() + )); + res.hint(eco_format!( + "or if you meant to display this as text, try placing it in quotes: `\"{var}\"`" + )); } res diff --git a/tests/suite/math/call.typ b/tests/suite/math/call.typ index 03747f58..bd66c400 100644 --- a/tests/suite/math/call.typ +++ b/tests/suite/math/call.typ @@ -81,6 +81,12 @@ $ bx(x y) &&quad bx(x (y z)) &quad bx(x y^z) \ $ +--- math-call-unknown-var-hint --- +// Error: 4-6 unknown variable: ab +// Hint: 4-6 if you meant to display multiple letters as is, try adding spaces between each letter: `a b` +// Hint: 4-6 or if you meant to display this as text, try placing it in quotes: `"ab"` +$ 5ab $ + --- issue-3774-math-call-empty-2d-args --- $ mat(;,) $ // Add some whitespace/trivia: |
