diff --git a/crates/typst-library/src/math/ctx.rs b/crates/typst-library/src/math/ctx.rs index 4a0959ab2..acd60e48c 100644 --- a/crates/typst-library/src/math/ctx.rs +++ b/crates/typst-library/src/math/ctx.rs @@ -185,8 +185,7 @@ impl<'a, 'b, 'v> MathContext<'a, 'b, 'v> { glyph.into_variant() }; // TeXbook p 155. Large operators are always vertically centered on the axis. - let h = variant.frame.height(); - variant.frame.set_baseline(h / 2.0 + scaled!(self, axis_height)); + variant.center_on_axis(self); variant.into() } else { glyph.into() diff --git a/crates/typst-library/src/math/delimited.rs b/crates/typst-library/src/math/delimited.rs index 99cd6c33b..25ecf623e 100644 --- a/crates/typst-library/src/math/delimited.rs +++ b/crates/typst-library/src/math/delimited.rs @@ -95,9 +95,10 @@ fn scale( }; let short_fall = DELIM_SHORT_FALL.scaled(ctx); - *fragment = - MathFragment::Variant(glyph.stretch_vertical(ctx, height, short_fall)); + let mut stretched = glyph.stretch_vertical(ctx, height, short_fall); + stretched.center_on_axis(ctx); + *fragment = MathFragment::Variant(stretched); if let Some(class) = apply { fragment.set_class(class); } diff --git a/crates/typst-library/src/math/frac.rs b/crates/typst-library/src/math/frac.rs index 0e1f78ccc..cf1d38e9e 100644 --- a/crates/typst-library/src/math/frac.rs +++ b/crates/typst-library/src/math/frac.rs @@ -122,13 +122,15 @@ fn layout( frame.push_frame(denom_pos, denom); if binom { - ctx.push( - GlyphFragment::new(ctx, '(', span).stretch_vertical(ctx, height, short_fall), - ); + let mut left = + GlyphFragment::new(ctx, '(', span).stretch_vertical(ctx, height, short_fall); + left.center_on_axis(ctx); + ctx.push(left); ctx.push(FrameFragment::new(ctx, frame)); - ctx.push( - GlyphFragment::new(ctx, ')', span).stretch_vertical(ctx, height, short_fall), - ); + let mut right = + GlyphFragment::new(ctx, ')', span).stretch_vertical(ctx, height, short_fall); + right.center_on_axis(ctx); + ctx.push(right); } else { frame.push( line_pos, diff --git a/crates/typst-library/src/math/fragment.rs b/crates/typst-library/src/math/fragment.rs index 85fdf6a61..f4efa7f68 100644 --- a/crates/typst-library/src/math/fragment.rs +++ b/crates/typst-library/src/math/fragment.rs @@ -353,6 +353,15 @@ pub struct VariantFragment { pub limits: Limits, } +impl VariantFragment { + /// Vertically adjust the fragment's frame so that it is centered + /// on the axis. + pub fn center_on_axis(&mut self, ctx: &MathContext) { + let h = self.frame.height(); + self.frame.set_baseline(h / 2.0 + scaled!(ctx, axis_height)); + } +} + impl Debug for VariantFragment { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { write!(f, "VariantFragment({:?})", self.c) diff --git a/crates/typst-library/src/math/matrix.rs b/crates/typst-library/src/math/matrix.rs index aaccc3328..3fa53ba09 100644 --- a/crates/typst-library/src/math/matrix.rs +++ b/crates/typst-library/src/math/matrix.rs @@ -295,18 +295,19 @@ fn layout_delimiters( frame.set_baseline(height / 2.0 + axis); if let Some(left) = left { - ctx.push( - GlyphFragment::new(ctx, left, span).stretch_vertical(ctx, target, short_fall), - ); + let mut left = + GlyphFragment::new(ctx, left, span).stretch_vertical(ctx, target, short_fall); + left.center_on_axis(ctx); + ctx.push(left); } ctx.push(FrameFragment::new(ctx, frame)); if let Some(right) = right { - ctx.push( - GlyphFragment::new(ctx, right, span) - .stretch_vertical(ctx, target, short_fall), - ); + let mut right = GlyphFragment::new(ctx, right, span) + .stretch_vertical(ctx, target, short_fall); + right.center_on_axis(ctx); + ctx.push(right); } Ok(()) diff --git a/crates/typst-macros/src/func.rs b/crates/typst-macros/src/func.rs index 4a68e8469..a734d4047 100644 --- a/crates/typst-macros/src/func.rs +++ b/crates/typst-macros/src/func.rs @@ -48,6 +48,7 @@ fn prepare(stream: TokenStream, item: &syn::ItemFn) -> Result { let mut params = vec![]; for input in &sig.inputs { let syn::FnArg::Typed(typed) = input else { + println!("option a"); bail!(input, "self is not allowed here"); }; diff --git a/tests/ref/math/attach-p2.png b/tests/ref/math/attach-p2.png index d956059d5..87e4cfada 100644 Binary files a/tests/ref/math/attach-p2.png and b/tests/ref/math/attach-p2.png differ diff --git a/tests/ref/math/class.png b/tests/ref/math/class.png index dffb6f7a0..f339c4f1c 100644 Binary files a/tests/ref/math/class.png and b/tests/ref/math/class.png differ diff --git a/tests/ref/math/delimited.png b/tests/ref/math/delimited.png index 31d15b410..2788058fd 100644 Binary files a/tests/ref/math/delimited.png and b/tests/ref/math/delimited.png differ diff --git a/tests/ref/math/matrix-alignment.png b/tests/ref/math/matrix-alignment.png index c0acd958a..c3059cfd4 100644 Binary files a/tests/ref/math/matrix-alignment.png and b/tests/ref/math/matrix-alignment.png differ diff --git a/tests/ref/math/matrix.png b/tests/ref/math/matrix.png index bf90e7128..a14758f7a 100644 Binary files a/tests/ref/math/matrix.png and b/tests/ref/math/matrix.png differ diff --git a/tests/ref/math/multiline.png b/tests/ref/math/multiline.png index 19276846d..bfa85b7b6 100644 Binary files a/tests/ref/math/multiline.png and b/tests/ref/math/multiline.png differ diff --git a/tests/ref/math/root.png b/tests/ref/math/root.png index af5c41ea9..8b37ffb39 100644 Binary files a/tests/ref/math/root.png and b/tests/ref/math/root.png differ diff --git a/tests/ref/math/spacing.png b/tests/ref/math/spacing.png index 4767f6f43..10adc7240 100644 Binary files a/tests/ref/math/spacing.png and b/tests/ref/math/spacing.png differ diff --git a/tests/ref/math/style.png b/tests/ref/math/style.png index c9bf5d649..27f0a27d5 100644 Binary files a/tests/ref/math/style.png and b/tests/ref/math/style.png differ