summaryrefslogtreecommitdiff
path: root/library/src
diff options
context:
space:
mode:
authorAlex Saveau <saveau.alexandre@gmail.com>2023-04-25 02:22:32 -0700
committerGitHub <noreply@github.com>2023-04-25 11:22:32 +0200
commitfb99090208c9aface707f9d4526f411fcb67f705 (patch)
tree5aaac5e7bc8f8475b55f8fc1397d0086764125a5 /library/src
parentf38989358e768ebe17c5f191cf9026d513e6f6b7 (diff)
Support implicit alignment (#749)
Diffstat (limited to 'library/src')
-rw-r--r--library/src/math/align.rs14
1 files changed, 10 insertions, 4 deletions
diff --git a/library/src/math/align.rs b/library/src/math/align.rs
index 4e4a76e9..aee89a89 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,
}
}