diff --git a/library/src/math/align.rs b/library/src/math/align.rs index 4e4a76e97..aee89a893 100644 --- a/library/src/math/align.rs +++ b/library/src/math/align.rs @@ -28,13 +28,13 @@ pub(super) fn alignments(rows: &[MathRow]) -> AlignmentResult { for row in rows { let mut width = Abs::zero(); let mut alignment_index = 0; + for fragment in row.iter() { if matches!(fragment, MathFragment::Align) { if alignment_index < widths.len() { widths[alignment_index].set_max(width); } else { - widths.push(width); - pending_width = Abs::zero(); + widths.push(width.max(pending_width)); } width = Abs::zero(); alignment_index += 1; @@ -42,7 +42,13 @@ pub(super) fn alignments(rows: &[MathRow]) -> AlignmentResult { width += fragment.width(); } } - pending_width.set_max(width); + if widths.is_empty() { + pending_width.set_max(width); + } else if alignment_index < widths.len() { + widths[alignment_index].set_max(width); + } else { + widths.push(width.max(pending_width)); + } } let mut points = widths; @@ -51,7 +57,7 @@ pub(super) fn alignments(rows: &[MathRow]) -> AlignmentResult { points[i] += prev; } AlignmentResult { - width: points.last().copied().unwrap_or_default() + pending_width, + width: points.last().copied().unwrap_or(pending_width), points, } } diff --git a/tests/ref/math/alignment.png b/tests/ref/math/alignment.png index 917c49e11..5d7560e1b 100644 Binary files a/tests/ref/math/alignment.png and b/tests/ref/math/alignment.png differ diff --git a/tests/ref/math/matrix-alignment.png b/tests/ref/math/matrix-alignment.png index 1449553da..b15412d69 100644 Binary files a/tests/ref/math/matrix-alignment.png and b/tests/ref/math/matrix-alignment.png differ diff --git a/tests/typ/math/alignment.typ b/tests/typ/math/alignment.typ index 8f12971f2..177e01887 100644 --- a/tests/typ/math/alignment.typ +++ b/tests/typ/math/alignment.typ @@ -2,6 +2,7 @@ --- // Test alignment step functions. +#set page(width: 225pt) $ "a" &= c \ &= c + 1 & "By definition" \