diff --git a/crates/typst/src/math/row.rs b/crates/typst/src/math/row.rs index 0681752ac..cb909b0bc 100644 --- a/crates/typst/src/math/row.rs +++ b/crates/typst/src/math/row.rs @@ -117,11 +117,19 @@ impl MathRun { } pub fn ascent(&self) -> Abs { - self.iter().map(MathFragment::ascent).max().unwrap_or_default() + self.iter() + .filter(|e| affects_row_height(e)) + .map(|e| e.ascent()) + .max() + .unwrap_or_default() } pub fn descent(&self) -> Abs { - self.iter().map(MathFragment::descent).max().unwrap_or_default() + self.iter() + .filter(|e| affects_row_height(e)) + .map(|e| e.descent()) + .max() + .unwrap_or_default() } pub fn class(&self) -> MathClass { @@ -386,3 +394,7 @@ impl MathRunFrameBuilder { frame } } + +fn affects_row_height(fragment: &MathFragment) -> bool { + !matches!(fragment, MathFragment::Align | MathFragment::Linebreak) +} diff --git a/tests/ref/issue-4187-alignment-point-affects-row-height.png b/tests/ref/issue-4187-alignment-point-affects-row-height.png new file mode 100644 index 000000000..63a5768b7 Binary files /dev/null and b/tests/ref/issue-4187-alignment-point-affects-row-height.png differ diff --git a/tests/suite/math/equation.typ b/tests/suite/math/equation.typ index e7ae677e0..2345de549 100644 --- a/tests/suite/math/equation.typ +++ b/tests/suite/math/equation.typ @@ -256,6 +256,16 @@ $ q &= sum_k ln A \ ], ) +--- issue-4187-alignment-point-affects-row-height --- +// In this bug, a row of "-" only should have a very small height; but +// after adding an alignment point "&", the row gains a larger height. +// We need to test alignment point "&" does not affect a row's height. +#box($ - - $, fill: silver) +#box($ - - $, fill: silver) \ +#box($ a \ - - $, fill: silver) +#box($ &- - \ &a $, fill: silver) +#box($ &a \ &- - $, fill: silver) + --- issue-numbering-hint --- // In this bug, the hint and error messages for an equation // being reference mentioned that it was a "heading" and was