Strip trailing line breaks in math equations (#750)

This commit is contained in:
Alex Saveau 2023-04-13 01:42:03 -07:00 committed by GitHub
parent a066a3d283
commit 03d2ec9f81
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 1 deletions

View File

@ -127,11 +127,15 @@ impl MathRow {
TIGHT_LEADING.scaled(ctx)
};
let rows: Vec<_> = fragments
let mut rows: Vec<_> = fragments
.split(|frag| matches!(frag, MathFragment::Linebreak))
.map(|slice| Self(slice.to_vec()))
.collect();
if matches!(rows.last(), Some(row) if row.0.is_empty()) {
rows.pop();
}
let width = rows.iter().map(|row| row.width()).max().unwrap_or_default();
let points = alignments(&rows);
let mut frame = Frame::new(Size::zero());

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.0 KiB

After

Width:  |  Height:  |  Size: 13 KiB

View File

@ -33,3 +33,24 @@ $ "abc" &= c \
---
// Test multiline subscript.
$ sum_(n in NN \ n <= 5) n = (5(5+1))/2 = 15 $
---
// Test no trailing line break.
$
"abc" &= c
$
No trailing line break.
---
// Test single trailing line break.
$
"abc" &= c \
$
One trailing line break.
---
// Test multiple trailing line breaks.
$
"abc" &= c \ \ \
$
Multiple trailing line breaks.