diff options
| author | Alex Saveau <saveau.alexandre@gmail.com> | 2023-04-25 02:22:32 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-04-25 11:22:32 +0200 |
| commit | fb99090208c9aface707f9d4526f411fcb67f705 (patch) | |
| tree | 5aaac5e7bc8f8475b55f8fc1397d0086764125a5 /library | |
| parent | f38989358e768ebe17c5f191cf9026d513e6f6b7 (diff) | |
Support implicit alignment (#749)
Diffstat (limited to 'library')
| -rw-r--r-- | library/src/math/align.rs | 14 |
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, } } |
