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 | |
| parent | f38989358e768ebe17c5f191cf9026d513e6f6b7 (diff) | |
Support implicit alignment (#749)
| -rw-r--r-- | library/src/math/align.rs | 14 | ||||
| -rw-r--r-- | tests/ref/math/alignment.png | bin | 6413 -> 8064 bytes | |||
| -rw-r--r-- | tests/ref/math/matrix-alignment.png | bin | 15027 -> 15065 bytes | |||
| -rw-r--r-- | tests/typ/math/alignment.typ | 1 |
4 files changed, 11 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, } } diff --git a/tests/ref/math/alignment.png b/tests/ref/math/alignment.png Binary files differindex 917c49e1..5d7560e1 100644 --- a/tests/ref/math/alignment.png +++ b/tests/ref/math/alignment.png diff --git a/tests/ref/math/matrix-alignment.png b/tests/ref/math/matrix-alignment.png Binary files differindex 1449553d..b15412d6 100644 --- a/tests/ref/math/matrix-alignment.png +++ b/tests/ref/math/matrix-alignment.png diff --git a/tests/typ/math/alignment.typ b/tests/typ/math/alignment.typ index 8f12971f..177e0188 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" \ |
