From 55bc5f4c940c86377f1ffe25b42fdb01a6827358 Mon Sep 17 00:00:00 2001 From: Max Date: Sun, 23 Feb 2025 11:28:24 +0000 Subject: [PATCH] Make math shorthands noncontinuable (#5925) --- crates/typst-syntax/src/parser.rs | 9 +++++---- tests/ref/math-shorthands-noncontinuable.png | Bin 0 -> 475 bytes tests/suite/math/syntax.typ | 5 +++++ 3 files changed, 10 insertions(+), 4 deletions(-) create mode 100644 tests/ref/math-shorthands-noncontinuable.png diff --git a/crates/typst-syntax/src/parser.rs b/crates/typst-syntax/src/parser.rs index e187212da..c5d13c8b3 100644 --- a/crates/typst-syntax/src/parser.rs +++ b/crates/typst-syntax/src/parser.rs @@ -271,10 +271,11 @@ fn math_expr_prec(p: &mut Parser, min_prec: usize, stop: SyntaxKind) { } SyntaxKind::Text | SyntaxKind::MathText | SyntaxKind::MathShorthand => { - continuable = matches!( - math_class(p.current_text()), - None | Some(MathClass::Alphabetic) - ); + continuable = !p.at(SyntaxKind::MathShorthand) + && matches!( + math_class(p.current_text()), + None | Some(MathClass::Alphabetic) + ); if !maybe_delimited(p) { p.eat(); } diff --git a/tests/ref/math-shorthands-noncontinuable.png b/tests/ref/math-shorthands-noncontinuable.png new file mode 100644 index 0000000000000000000000000000000000000000..2f1ad1d14e0ebda63769157fe6a64631dfe58a31 GIT binary patch literal 475 zcmV<10VMv3P)LBEL@~mBuQWyMo>h%CY9761u02MG_@Qx zNm5Z8=fpv+UoiJT-FGuDvw0Smd+zA~qI7VW!yM)?CG6I?KurPr7jBGuE$I%VUVB2D(T@AvTS9$n7S&jjwZk@Yt{W{Hq;&9BN(G8cHT|SwLGrPxe zP=(}Hk1U(3c-niIlHzCF1FwJy%pZIKrjfx&3d5s9fAkE?u2W_@GSiPaKVXVkjKqFc zUs^FK+Sf_)K$--$8)y6^F!)?R0^j&+&lGTQePXOa0oS0ympu;uF}NYrp+Es2nVj_j z3RoOTxR!_(`ju-EcqGtSWd>hWerhD<9tURd%c|j{Rrhx`^UA{)jyrp^<@7qS*~$#= zv5?eSw%SmpD+~Z~9@9`5mS9k9)#A1`h2N?PQ&JcXOI_f_BI-BtEJvo=GJ6=ra{fs) ztDQznf<0WXV2Gc^=wwtNfqmKO0tpPZERew3w}%h~?DLK5`Lf4h4s-Y)z~4s$EOM5) RtCj!&002ovPDHLkV1k2W)8YUC literal 0 HcmV?d00001 diff --git a/tests/suite/math/syntax.typ b/tests/suite/math/syntax.typ index cd1124c37..7091d908c 100644 --- a/tests/suite/math/syntax.typ +++ b/tests/suite/math/syntax.typ @@ -13,6 +13,11 @@ $ underline(f' : NN -> RR) \ 1 - 0 thick &..., ) $ +--- math-shorthands-noncontinuable --- +// Test that shorthands are not continuable. +$ x >=(y) / z \ + x >= (y) / z $ + --- math-common-symbols --- // Test common symbols. $ dot \ dots \ ast \ tilde \ star $