diff options
| author | Laurenz <laurmaedje@gmail.com> | 2023-04-19 10:38:03 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2023-04-19 11:06:52 +0200 |
| commit | f8966f9e867dc72080355342aab64734f70ac4f7 (patch) | |
| tree | 9713d316b31e913b9edd5eca73410f81457aaf76 /library/src/math | |
| parent | d10b53df0b487036b0d639b6033f4568648cfff1 (diff) | |
Fix realize in math
Diffstat (limited to 'library/src/math')
| -rw-r--r-- | library/src/math/fragment.rs | 6 | ||||
| -rw-r--r-- | library/src/math/mod.rs | 13 | ||||
| -rw-r--r-- | library/src/math/stretch.rs | 1 |
3 files changed, 17 insertions, 3 deletions
diff --git a/library/src/math/fragment.rs b/library/src/math/fragment.rs index d85bd33c..1d13e3b7 100644 --- a/library/src/math/fragment.rs +++ b/library/src/math/fragment.rs @@ -148,6 +148,7 @@ pub struct GlyphFragment { pub font_size: Abs, pub class: Option<MathClass>, pub span: Span, + pub meta: Vec<Meta>, } impl GlyphFragment { @@ -194,6 +195,7 @@ impl GlyphFragment { _ => unicode_math_class::class(c), }, span, + meta: MetaElem::data_in(ctx.styles()), } } @@ -231,6 +233,7 @@ impl GlyphFragment { }; let size = Size::new(self.width, self.ascent + self.descent); let mut frame = Frame::new(size); + frame.meta_iter(self.meta); frame.set_baseline(self.ascent); frame.push(Point::with_y(self.ascent), FrameItem::Text(item)); frame @@ -273,8 +276,9 @@ pub struct FrameFragment { } impl FrameFragment { - pub fn new(ctx: &MathContext, frame: Frame) -> Self { + pub fn new(ctx: &MathContext, mut frame: Frame) -> Self { let base_ascent = frame.ascent(); + frame.meta(ctx.styles(), false); Self { frame, font_size: ctx.size, diff --git a/library/src/math/mod.rs b/library/src/math/mod.rs index 97e5548e..9c8a9cdf 100644 --- a/library/src/math/mod.rs +++ b/library/src/math/mod.rs @@ -344,9 +344,18 @@ impl LayoutMath for EquationElem { impl LayoutMath for Content { fn layout_math(&self, ctx: &mut MathContext) -> SourceResult<()> { + // Directly layout the body of nested equations instead of handling it + // like a normal equation so that things like this work: + // ``` + // #let my = $pi$ + // $ my r^2 $ + // ``` + if let Some(elem) = self.to::<EquationElem>() { + return elem.layout_math(ctx); + } + if let Some(realized) = ctx.realize(self)? { - realized.layout_math(ctx)?; - return Ok(()); + return realized.layout_math(ctx); } if let Some(children) = self.to_sequence() { diff --git a/library/src/math/stretch.rs b/library/src/math/stretch.rs index 226f3f4e..bb454022 100644 --- a/library/src/math/stretch.rs +++ b/library/src/math/stretch.rs @@ -162,6 +162,7 @@ fn assemble( let mut frame = Frame::new(size); let mut offset = Abs::zero(); frame.set_baseline(baseline); + frame.meta_iter(base.meta); for (fragment, advance) in selected { let pos = if horizontal { |
