diff --git a/library/src/math/row.rs b/library/src/math/row.rs index 261723033..ce9bc94a3 100644 --- a/library/src/math/row.rs +++ b/library/src/math/row.rs @@ -127,11 +127,15 @@ impl MathRow { TIGHT_LEADING.scaled(ctx) }; - let rows: Vec<_> = fragments + let mut rows: Vec<_> = fragments .split(|frag| matches!(frag, MathFragment::Linebreak)) .map(|slice| Self(slice.to_vec())) .collect(); + if matches!(rows.last(), Some(row) if row.0.is_empty()) { + rows.pop(); + } + let width = rows.iter().map(|row| row.width()).max().unwrap_or_default(); let points = alignments(&rows); let mut frame = Frame::new(Size::zero()); diff --git a/tests/ref/math/multiline.png b/tests/ref/math/multiline.png index 94ef11964..50f611b2a 100644 Binary files a/tests/ref/math/multiline.png and b/tests/ref/math/multiline.png differ diff --git a/tests/typ/math/multiline.typ b/tests/typ/math/multiline.typ index 1d268faee..4f42ea63a 100644 --- a/tests/typ/math/multiline.typ +++ b/tests/typ/math/multiline.typ @@ -33,3 +33,24 @@ $ "abc" &= c \ --- // Test multiline subscript. $ sum_(n in NN \ n <= 5) n = (5(5+1))/2 = 15 $ + +--- +// Test no trailing line break. +$ +"abc" &= c +$ +No trailing line break. + +--- +// Test single trailing line break. +$ +"abc" &= c \ +$ +One trailing line break. + +--- +// Test multiple trailing line breaks. +$ +"abc" &= c \ \ \ +$ +Multiple trailing line breaks.