mirror of
https://github.com/typst/typst
synced 2025-05-14 04:56:26 +08:00
Fix weak spacing being ignored unconditionally in math.lr
(#5477)
This commit is contained in:
parent
c29c96562d
commit
578ba640f3
@ -62,7 +62,7 @@ pub fn layout_lr(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Handle MathFragment::Variant fragments that should be scaled up.
|
// 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 let MathFragment::Variant(ref mut variant) = fragment {
|
||||||
if variant.mid_stretched == Some(false) {
|
if variant.mid_stretched == Some(false) {
|
||||||
variant.mid_stretched = Some(true);
|
variant.mid_stretched = Some(true);
|
||||||
@ -74,10 +74,18 @@ pub fn layout_lr(
|
|||||||
// Remove weak SpacingFragment immediately after the opening or immediately
|
// Remove weak SpacingFragment immediately after the opening or immediately
|
||||||
// before the closing.
|
// before the closing.
|
||||||
let mut index = 0;
|
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| {
|
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 += 1;
|
||||||
(index != start_idx + 2 && index + 1 != end_idx)
|
!discard
|
||||||
|| !matches!(fragment, MathFragment::Spacing(_, true))
|
|
||||||
});
|
});
|
||||||
|
|
||||||
ctx.extend(fragments);
|
ctx.extend(fragments);
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 647 B After Width: | Height: | Size: 1.1 KiB |
@ -87,6 +87,7 @@ $ 1/(2 y (x) (2(3)) $
|
|||||||
// Test ignoring weak spacing immediately after the opening
|
// Test ignoring weak spacing immediately after the opening
|
||||||
// and immediately before the closing.
|
// and immediately before the closing.
|
||||||
$ [#h(1em, weak: true)A(dif x, f(x) dif x)sum#h(1em, weak: true)] $
|
$ [#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 ---
|
--- math-lr-nested ---
|
||||||
// Test nested lr calls.
|
// Test nested lr calls.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user