diff options
| author | Laurenz <laurmaedje@gmail.com> | 2023-02-12 21:14:12 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2023-02-12 21:14:12 +0100 |
| commit | d689d706eaf3079877406e71b0d642623c9eb230 (patch) | |
| tree | ad0a4b27f919d34d83eacb5ca758293a7e6810f9 | |
| parent | e70fbf5372dcf0c9011f0b7799dfa77194401c4f (diff) | |
Vertically center non-math content in math by default
| -rw-r--r-- | library/src/math/mod.rs | 6 | ||||
| -rw-r--r-- | src/doc.rs | 5 | ||||
| -rw-r--r-- | tests/ref/math/content.png | bin | 6731 -> 7871 bytes | |||
| -rw-r--r-- | tests/typ/math/content.typ | 6 |
4 files changed, 13 insertions, 4 deletions
diff --git a/library/src/math/mod.rs b/library/src/math/mod.rs index 85bf56ca..76dcdc2e 100644 --- a/library/src/math/mod.rs +++ b/library/src/math/mod.rs @@ -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(()) @@ -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); diff --git a/tests/ref/math/content.png b/tests/ref/math/content.png Binary files differindex 3476dbc4..46d5ef9b 100644 --- a/tests/ref/math/content.png +++ b/tests/ref/math/content.png diff --git a/tests/typ/math/content.typ b/tests/typ/math/content.typ index b33873d5..dc0ec85c 100644 --- a/tests/typ/math/content.typ +++ b/tests/typ/math/content.typ @@ -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]) |
