Vertically center non-math content in math by default

This commit is contained in:
Laurenz 2023-02-12 21:14:12 +01:00
parent e70fbf5372
commit d689d706ea
4 changed files with 13 additions and 4 deletions

View File

@ -294,7 +294,11 @@ impl LayoutMath for Content {
return node.layout_math(ctx);
}
let frame = ctx.layout_content(self)?;
let mut frame = ctx.layout_content(self)?;
if !frame.has_baseline() {
let axis = scaled!(ctx, axis_height);
frame.set_baseline(frame.height() / 2.0 + axis);
}
ctx.push(FrameFragment::new(ctx, frame).with_spaced(true));
Ok(())

View File

@ -85,6 +85,11 @@ impl Frame {
self.baseline.unwrap_or(self.size.y)
}
/// Whether the frame has a non-default baseline.
pub fn has_baseline(&mut self) -> bool {
self.baseline.is_some()
}
/// Set the frame's baseline from the top.
pub fn set_baseline(&mut self, baseline: Abs) {
self.baseline = Some(baseline);

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.6 KiB

After

Width:  |  Height:  |  Size: 7.7 KiB

View File

@ -6,9 +6,9 @@
$ sum_(i=#emoji.apple)^#emoji.apple.red i + monkey/2 $
---
// Test table above fraction.
$ x := #table(columns: 2)[x][y]/mat(1, 2, 3) $
// Test tables.
$ x := #table(columns: 2)[x][y]/mat(1, 2, 3)
= #table[A][B][C] $
---
// Test non-formula math directly in content.
#math.attach($a$, top: [b])