diff --git a/crates/typst/src/math/root.rs b/crates/typst/src/math/root.rs index 6a7604452..66707c59d 100644 --- a/crates/typst/src/math/root.rs +++ b/crates/typst/src/math/root.rs @@ -70,8 +70,20 @@ fn layout( let raise_factor = percent!(ctx, radical_degree_bottom_raise_percent); // Layout radicand. - let cramped = style_cramped(); - let radicand = ctx.layout_into_frame(radicand, styles.chain(&cramped))?; + let radicand = { + let cramped = style_cramped(); + let styles = styles.chain(&cramped); + let run = ctx.layout_into_run(radicand, styles)?; + let multiline = run.is_multiline(); + let mut radicand = run.into_fragment(ctx, styles).into_frame(); + if multiline { + // Align the frame center line with the math axis. + radicand.set_baseline( + radicand.height() / 2.0 + scaled!(ctx, styles, axis_height), + ); + } + radicand + }; // Layout root symbol. let target = radicand.height() + thickness + gap; diff --git a/crates/typst/src/math/row.rs b/crates/typst/src/math/row.rs index 60afe64e5..cafffdc51 100644 --- a/crates/typst/src/math/row.rs +++ b/crates/typst/src/math/row.rs @@ -353,7 +353,7 @@ impl MathRun { items } - fn is_multiline(&self) -> bool { + pub fn is_multiline(&self) -> bool { self.iter().any(|frag| matches!(frag, MathFragment::Linebreak)) } } diff --git a/tests/ref/math-root-large-body.png b/tests/ref/math-root-large-body.png index b8d9edfbd..203636471 100644 Binary files a/tests/ref/math-root-large-body.png and b/tests/ref/math-root-large-body.png differ diff --git a/tests/suite/math/root.typ b/tests/suite/math/root.typ index a690802e1..df339fa80 100644 --- a/tests/suite/math/root.typ +++ b/tests/suite/math/root.typ @@ -30,6 +30,7 @@ $ sqrt([|x|]^2 + [|y|]^2) < [|z|] $ $ v = sqrt((1/2) / (4/5)) = root(3, (1/2/3) / (4/5/6)) = root(4, ((1/2) / (3/4)) / ((1/2) / (3/4))) $ +$ v = sqrt(a +\ b) $ --- math-root-large-index --- // Test large index.