diff options
| author | Max <max@mkor.je> | 2025-03-11 10:18:15 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-03-11 10:18:15 +0000 |
| commit | 96f695737174449cbd9efbf4954b676b9bb35056 (patch) | |
| tree | 0a636b4d436f38267bdde5aa7ae74276648fb49d | |
| parent | 3650859ae8823f47c9f50db6ad5ed52a0477bf15 (diff) | |
Fix `math.root` frame size (#6021)
| -rw-r--r-- | crates/typst-layout/src/math/root.rs | 8 | ||||
| -rw-r--r-- | tests/ref/math-root-frame-size-index.png | bin | 0 -> 902 bytes | |||
| -rw-r--r-- | tests/suite/math/root.typ | 6 |
3 files changed, 11 insertions, 3 deletions
diff --git a/crates/typst-layout/src/math/root.rs b/crates/typst-layout/src/math/root.rs index a6b5c03d..c7f41488 100644 --- a/crates/typst-layout/src/math/root.rs +++ b/crates/typst-layout/src/math/root.rs @@ -85,14 +85,15 @@ pub fn layout_root( ascent.set_max(shift_up + index.ascent()); } - let radicand_x = sqrt_offset + sqrt.width(); + let sqrt_x = sqrt_offset.max(Abs::zero()); + let radicand_x = sqrt_x + sqrt.width(); let radicand_y = ascent - radicand.ascent(); let width = radicand_x + radicand.width(); let size = Size::new(width, ascent + descent); // The extra "- thickness" comes from the fact that the sqrt is placed // in `push_frame` with respect to its top, not its baseline. - let sqrt_pos = Point::new(sqrt_offset, radicand_y - gap - thickness); + let sqrt_pos = Point::new(sqrt_x, radicand_y - gap - thickness); let line_pos = Point::new(radicand_x, radicand_y - gap - (thickness / 2.0)); let radicand_pos = Point::new(radicand_x, radicand_y); @@ -100,7 +101,8 @@ pub fn layout_root( frame.set_baseline(ascent); if let Some(index) = index { - let index_pos = Point::new(kern_before, ascent - index.ascent() - shift_up); + let index_x = -sqrt_offset.min(Abs::zero()) + kern_before; + let index_pos = Point::new(index_x, ascent - index.ascent() - shift_up); frame.push_frame(index_pos, index); } diff --git a/tests/ref/math-root-frame-size-index.png b/tests/ref/math-root-frame-size-index.png Binary files differnew file mode 100644 index 00000000..41d4df2e --- /dev/null +++ b/tests/ref/math-root-frame-size-index.png diff --git a/tests/suite/math/root.typ b/tests/suite/math/root.typ index df339fa8..b70b4b9b 100644 --- a/tests/suite/math/root.typ +++ b/tests/suite/math/root.typ @@ -44,3 +44,9 @@ $ root(2, x) quad $ √2^3 = sqrt(2^3) $ $ √(x+y) quad ∛x quad ∜x $ $ (√2+3) = (sqrt(2)+3) $ + +--- math-root-frame-size-index --- +// Test size of final frame when there is an index. +$ a root(, 3) & a root(., 3) \ + a sqrt(3) & a root(2, 3) \ + a root(#h(-1em), 3) & a root(123, 3) $ |
