mirror of
https://github.com/typst/typst
synced 2025-05-13 20:46:23 +08:00
Support implicit alignment (#749)
This commit is contained in:
parent
f38989358e
commit
fb99090208
@ -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 |
@ -2,6 +2,7 @@
|
||||
|
||||
---
|
||||
// Test alignment step functions.
|
||||
#set page(width: 225pt)
|
||||
$
|
||||
"a" &= c \
|
||||
&= c + 1 & "By definition" \
|
||||
|
Loading…
x
Reference in New Issue
Block a user