Support implicit alignment (#749)

This commit is contained in:
Alex Saveau 2023-04-25 02:22:32 -07:00 committed by GitHub
parent f38989358e
commit fb99090208
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 4 deletions

View File

@ -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,
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.3 KiB

After

Width:  |  Height:  |  Size: 7.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 15 KiB

View File

@ -2,6 +2,7 @@
---
// Test alignment step functions.
#set page(width: 225pt)
$
"a" &= c \
&= c + 1 & "By definition" \