diff --git a/crates/typst-library/src/layout/mod.rs b/crates/typst-library/src/layout/mod.rs index ace5cd6e2..d9e8ec9aa 100644 --- a/crates/typst-library/src/layout/mod.rs +++ b/crates/typst-library/src/layout/mod.rs @@ -266,6 +266,7 @@ fn realize_block<'a>( // These elements implement `Layout` but still require a flow for // proper layout. if content.can::() + && !content.is::() && !content.is::() && !content.is::() && !content.is::() diff --git a/crates/typst-library/src/math/ctx.rs b/crates/typst-library/src/math/ctx.rs index b9aef711c..c992c0ebf 100644 --- a/crates/typst-library/src/math/ctx.rs +++ b/crates/typst-library/src/math/ctx.rs @@ -149,6 +149,12 @@ impl<'a, 'b, 'v> MathContext<'a, 'b, 'v> { Ok(self.layout_fragment(elem)?.into_frame()) } + pub fn layout_box(&mut self, boxed: &BoxElem) -> SourceResult { + Ok(boxed + .layout(self.vt, self.outer.chain(&self.local), self.regions)? + .into_frame()) + } + pub fn layout_content(&mut self, content: &Content) -> SourceResult { Ok(content .layout(self.vt, self.outer.chain(&self.local), self.regions)? diff --git a/crates/typst-library/src/math/mod.rs b/crates/typst-library/src/math/mod.rs index 578064bae..3ae3f23aa 100644 --- a/crates/typst-library/src/math/mod.rs +++ b/crates/typst-library/src/math/mod.rs @@ -457,18 +457,20 @@ impl LayoutMath for Content { return Ok(()); } + if let Some(boxed) = self.to::() { + let frame = ctx.layout_box(boxed)?; + ctx.push(FrameFragment::new(ctx, frame).with_spaced(true)); + return Ok(()); + } + if let Some(elem) = self.with::() { return elem.layout_math(ctx); } let mut frame = ctx.layout_content(self)?; if !frame.has_baseline() { - if self.is::() { - frame.set_baseline(frame.height()); - } else { - let axis = scaled!(ctx, axis_height); - frame.set_baseline(frame.height() / 2.0 + axis); - } + let axis = scaled!(ctx, axis_height); + frame.set_baseline(frame.height() / 2.0 + axis); } ctx.push(FrameFragment::new(ctx, frame).with_spaced(true)); diff --git a/tests/ref/bugs/block-width-box.png b/tests/ref/bugs/block-width-box.png new file mode 100644 index 000000000..9cb27a5de Binary files /dev/null and b/tests/ref/bugs/block-width-box.png differ diff --git a/tests/typ/bugs/block-width-box.typ b/tests/typ/bugs/block-width-box.typ new file mode 100644 index 000000000..a039bc666 --- /dev/null +++ b/tests/typ/bugs/block-width-box.typ @@ -0,0 +1,6 @@ +// Test box in 100% width block. + +--- +#block(width: 100%, fill: red, box("a box")) + +#block(width: 100%, fill: red, [#box("a box") #box()])