Skip to content

Commit 03d2ec9

Browse files
authored
Strip trailing line breaks in math equations (typst#750)
1 parent a066a3d commit 03d2ec9

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

library/src/math/row.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,15 @@ impl MathRow {
127127
TIGHT_LEADING.scaled(ctx)
128128
};
129129

130-
let rows: Vec<_> = fragments
130+
let mut rows: Vec<_> = fragments
131131
.split(|frag| matches!(frag, MathFragment::Linebreak))
132132
.map(|slice| Self(slice.to_vec()))
133133
.collect();
134134

135+
if matches!(rows.last(), Some(row) if row.0.is_empty()) {
136+
rows.pop();
137+
}
138+
135139
let width = rows.iter().map(|row| row.width()).max().unwrap_or_default();
136140
let points = alignments(&rows);
137141
let mut frame = Frame::new(Size::zero());

tests/ref/math/multiline.png

5.18 KB
Loading

tests/typ/math/multiline.typ

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,24 @@ $ "abc" &= c \
3333
---
3434
// Test multiline subscript.
3535
$ sum_(n in NN \ n <= 5) n = (5(5+1))/2 = 15 $
36+
37+
---
38+
// Test no trailing line break.
39+
$
40+
"abc" &= c
41+
$
42+
No trailing line break.
43+
44+
---
45+
// Test single trailing line break.
46+
$
47+
"abc" &= c \
48+
$
49+
One trailing line break.
50+
51+
---
52+
// Test multiple trailing line breaks.
53+
$
54+
"abc" &= c \ \ \
55+
$
56+
Multiple trailing line breaks.

0 commit comments

Comments
 (0)