diff --git a/crates/typst/src/layout/frame.rs b/crates/typst/src/layout/frame.rs index d06cd23da..af1fd5d1a 100644 --- a/crates/typst/src/layout/frame.rs +++ b/crates/typst/src/layout/frame.rs @@ -365,13 +365,13 @@ impl Frame { /// Tools for debugging. impl Frame { /// Add a full size aqua background and a red baseline for debugging. - pub fn debug(mut self) -> Self { - self.debug_in_place(); + pub fn mark_box(mut self) -> Self { + self.mark_box_in_place(); self } - /// Debug in place. - pub fn debug_in_place(&mut self) { + /// Debug in place. Add a full size aqua background and a red baseline for debugging. + pub fn mark_box_in_place(&mut self) { self.insert( 0, Point::zero(), diff --git a/crates/typst/src/math/attach.rs b/crates/typst/src/math/attach.rs index 71074edcb..b641c878d 100644 --- a/crates/typst/src/math/attach.rs +++ b/crates/typst/src/math/attach.rs @@ -243,12 +243,12 @@ fn layout_attachments( (base.width(), base.ascent(), base.descent()); let base_class = base.class().unwrap_or(MathClass::Normal); - let ascent = base_ascent + let mut ascent = base_ascent .max(shift_up + measure!(tr, ascent)) .max(shift_up + measure!(tl, ascent)) .max(shift_up + measure!(t, height)); - let descent = base_descent + let mut descent = base_descent .max(shift_down + measure!(br, descent)) .max(shift_down + measure!(bl, descent)) .max(shift_down + measure!(b, height)); @@ -257,23 +257,27 @@ fn layout_attachments( let pre_sub_width = measure!(bl, width); let pre_width_dif = pre_sup_width - pre_sub_width; // Could be negative. let pre_width_max = pre_sup_width.max(pre_sub_width); - let post_max_width = + let post_width_max = (sup_delta + measure!(tr, width)).max(sub_delta + measure!(br, width)); let (center_frame, base_offset) = attach_top_and_bottom(ctx, base, t, b); - let base_pos = - Point::new(sup_delta + pre_width_max, ascent - base_ascent - base_offset); if [&tl, &bl, &tr, &br].iter().all(|&e| e.is_none()) { ctx.push(FrameFragment::new(ctx, center_frame).with_class(base_class)); return Ok(()); } + ascent.set_max(center_frame.ascent()); + descent.set_max(center_frame.descent()); + let mut frame = Frame::soft(Size::new( - pre_width_max + base_width + post_max_width + scaled!(ctx, space_after_script), + pre_width_max + base_width + post_width_max + scaled!(ctx, space_after_script), ascent + descent, )); frame.set_baseline(ascent); - frame.push_frame(base_pos, center_frame); + frame.push_frame( + Point::new(sup_delta + pre_width_max, frame.ascent() - base_ascent - base_offset), + center_frame, + ); if let Some(tl) = tl { let pos = diff --git a/tests/ref/math/attach-p1.png b/tests/ref/math/attach-p1.png index 41be13133..fa6107292 100644 Binary files a/tests/ref/math/attach-p1.png and b/tests/ref/math/attach-p1.png differ diff --git a/tests/ref/visualize/gradient-math.png b/tests/ref/visualize/gradient-math.png index 825bfc15b..6d9173b59 100644 Binary files a/tests/ref/visualize/gradient-math.png and b/tests/ref/visualize/gradient-math.png differ diff --git a/tests/typ/math/attach-p1.typ b/tests/typ/math/attach-p1.typ index 830ff26e2..5564ec60d 100644 --- a/tests/typ/math/attach-p1.typ +++ b/tests/typ/math/attach-p1.typ @@ -49,7 +49,11 @@ $pi_1(Y), a_f(x), a^zeta (x), a^abs(b)_sqrt(c) \ --- // Test associativity and scaling. $ 1/(V^2^3^4^5), - 1/attach(V, tl: attach(2, tl: attach(3, tl: attach(4, tl: 5)))), + frac( + attach( + limits(V), br: attach(2, br: 3), b: attach(limits(2), b: 3)), + attach( + limits(V), tl: attach(2, tl: 3), t: attach(limits(2), t: 3))), attach(Omega, tl: attach(2, tl: attach(3, tl: attach(4, tl: 5))), tr: attach(2, tr: attach(3, tr: attach(4, tr: 5))),