diff options
| author | Max <me@mkor.je> | 2024-11-27 11:16:25 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-11-27 11:16:25 +0000 |
| commit | 578ba640f3666b5dc309ec0a03d6f6d5f2ae14a2 (patch) | |
| tree | 24a4c698c741e53b3d9f33fbbc0d849af94bab1a | |
| parent | c29c96562ddb9caec04088f78f48dcd9cca2c61a (diff) | |
Fix weak spacing being ignored unconditionally in `math.lr` (#5477)
| -rw-r--r-- | crates/typst-layout/src/math/lr.rs | 14 | ||||
| -rw-r--r-- | tests/ref/math-lr-weak-spacing.png | bin | 647 -> 1171 bytes | |||
| -rw-r--r-- | tests/suite/math/delimited.typ | 1 |
3 files changed, 12 insertions, 3 deletions
diff --git a/crates/typst-layout/src/math/lr.rs b/crates/typst-layout/src/math/lr.rs index d195e67d..01a7f4cc 100644 --- a/crates/typst-layout/src/math/lr.rs +++ b/crates/typst-layout/src/math/lr.rs @@ -62,7 +62,7 @@ pub fn layout_lr( } // Handle MathFragment::Variant fragments that should be scaled up. - for fragment in inner_fragments { + for fragment in inner_fragments.iter_mut() { if let MathFragment::Variant(ref mut variant) = fragment { if variant.mid_stretched == Some(false) { variant.mid_stretched = Some(true); @@ -74,10 +74,18 @@ pub fn layout_lr( // Remove weak SpacingFragment immediately after the opening or immediately // before the closing. let mut index = 0; + let opening_exists = inner_fragments + .first() + .is_some_and(|f| f.class() == MathClass::Opening); + let closing_exists = inner_fragments + .last() + .is_some_and(|f| f.class() == MathClass::Closing); fragments.retain(|fragment| { + let discard = (index == start_idx + 1 && opening_exists + || index + 2 == end_idx && closing_exists) + && matches!(fragment, MathFragment::Spacing(_, true)); index += 1; - (index != start_idx + 2 && index + 1 != end_idx) - || !matches!(fragment, MathFragment::Spacing(_, true)) + !discard }); ctx.extend(fragments); diff --git a/tests/ref/math-lr-weak-spacing.png b/tests/ref/math-lr-weak-spacing.png Binary files differindex 871aaa2e..2478ca2a 100644 --- a/tests/ref/math-lr-weak-spacing.png +++ b/tests/ref/math-lr-weak-spacing.png diff --git a/tests/suite/math/delimited.typ b/tests/suite/math/delimited.typ index fc00333d..22674050 100644 --- a/tests/suite/math/delimited.typ +++ b/tests/suite/math/delimited.typ @@ -87,6 +87,7 @@ $ 1/(2 y (x) (2(3)) $ // Test ignoring weak spacing immediately after the opening // and immediately before the closing. $ [#h(1em, weak: true)A(dif x, f(x) dif x)sum#h(1em, weak: true)] $ +$ lr(\[#h(1em, weak: true)lr(A dif x, f(x) dif x\))sum#h(1em, weak:true)a) $ --- math-lr-nested --- // Test nested lr calls. |
