Add support for fractional spacing in inline math

This commit is contained in:
mkorje 2025-05-31 00:12:53 +10:00
parent fb9db2e695
commit ce746528b3
No known key found for this signature in database
4 changed files with 34 additions and 0 deletions

View File

@ -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();

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

@ -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.
$