diff --git a/crates/typst-layout/src/math/run.rs b/crates/typst-layout/src/math/run.rs index b5e855188..c9772c66f 100644 --- a/crates/typst-layout/src/math/run.rs +++ b/crates/typst-layout/src/math/run.rs @@ -319,6 +319,24 @@ impl MathRun { let mut iter = self.0.into_iter().peekable(); while let Some(fragment) = iter.next() { + if let MathFragment::Fractional(fr) = fragment { + if !empty { + let mut frame_prev = + std::mem::replace(&mut frame, Frame::soft(Size::zero())); + + finalize_frame(&mut frame_prev, x, ascent, descent); + items.push(InlineItem::Frame(frame_prev)); + empty = true; + + x = Abs::zero(); + ascent = Abs::zero(); + descent = Abs::zero(); + } + + items.push(InlineItem::Fractional(fr)); + continue; + } + let class = fragment.class(); let y = fragment.ascent(); diff --git a/tests/ref/math-spacing-fractional-inline.png b/tests/ref/math-spacing-fractional-inline.png new file mode 100644 index 000000000..7ca0a5c59 Binary files /dev/null and b/tests/ref/math-spacing-fractional-inline.png differ diff --git a/tests/ref/math-spacing-mixed-inline.png b/tests/ref/math-spacing-mixed-inline.png new file mode 100644 index 000000000..ed3be05e6 Binary files /dev/null and b/tests/ref/math-spacing-mixed-inline.png differ diff --git a/tests/suite/math/spacing.typ b/tests/suite/math/spacing.typ index 55dcc2333..464805c82 100644 --- a/tests/suite/math/spacing.typ +++ b/tests/suite/math/spacing.typ @@ -87,6 +87,22 @@ Hello $#box(width: 40%)$ world \ $mtext("Hello") #h(40%) space mtext("world")$ \ $mtext("Hello") #box(width: 40%) mtext("world")$ +--- math-spacing-fractional-inline --- +// Test fractional spacing in inline math. +Hello #h(1fr) world \ +Hello $#h(1fr)$ world + +x #h(1fr) y \ +$x #h(1fr) y$ + +Blah #h(1.5fr) long$#h(0.5fr) x - #h(1fr) y$ line. \ +Blah #h(1.5fr) long $#h(0.5fr) x - #h(1fr) y$ line. + +--- math-spacing-mixed-inline --- +// Test mixture of different kinds of spacing in inline math. +Some #h(30%) inline $x + #h(5%) y - #h(1fr) sum_(1 #h(1fr) 2) $ spacing #h(2fr) blah. +Long $(a #h(1fr) z) #h(1em, weak: true)$ #h(1%) $#h(0.5fr) sqrt(1 + #h(0.5fr) y)$. + --- issue-1052-math-number-spacing --- // Test spacing after numbers in math. $