Make only alphabetic text continuable

This commit is contained in:
Laurenz 2025-03-31 10:37:55 +02:00
parent dbdc8ea069
commit 438fe42bf7
3 changed files with 5 additions and 8 deletions

View File

@ -271,12 +271,9 @@ fn math_expr_prec(p: &mut Parser, min_prec: usize, stop: SyntaxKind) {
} }
SyntaxKind::Text | SyntaxKind::MathText | SyntaxKind::MathShorthand => { SyntaxKind::Text | SyntaxKind::MathText | SyntaxKind::MathShorthand => {
continuable = !p.at(SyntaxKind::MathShorthand) // `a(b)/c` parses as `(a(b))/c` if `a` is continuable.
&& !p.current_text().chars().all(char::is_numeric) continuable = math_class(p.current_text()) == Some(MathClass::Alphabetic)
&& matches!( || p.current_text().chars().all(char::is_alphabetic);
math_class(p.current_text()),
None | Some(MathClass::Alphabetic)
);
if !maybe_delimited(p) { if !maybe_delimited(p) {
p.eat(); p.eat();
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.4 KiB

After

Width:  |  Height:  |  Size: 3.5 KiB

View File

@ -37,8 +37,8 @@ $ 1/2/3 = (1/2)/3 = 1/(2/3) $
// Test precedence. // Test precedence.
$ a_1/b_2, 1/f(x), zeta(x)/2, "foo"[|x|]/2 \ $ a_1/b_2, 1/f(x), zeta(x)/2, "foo"[|x|]/2 \
1.2/3.7, 2.3^3.4 \ 1.2/3.7, 2.3^3.4 \
🏳️‍🌈[x]/2, f [x]/2, phi [x]/2, 🏳️‍🌈 [x]/2 \ f [x]/2, phi [x]/2 \
+[x]/2, 1(x)/2, 2[x]/2 \ +[x]/2, 1(x)/2, 2[x]/2, 🏳️‍🌈[x]/2 \
(a)b/2, b(a)[b]/2 \ (a)b/2, b(a)[b]/2 \
n!/2, 5!/2, n !/2, 1/n!, 1/5! $ n!/2, 5!/2, n !/2, 1/n!, 1/5! $