Penalize runts (#1858)

This commit is contained in:
Matt Fellenz 2023-08-08 02:27:15 -07:00 committed by GitHub
parent da8367e189
commit f56060c1b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 0 deletions

View File

@ -908,6 +908,7 @@ fn linebreak_optimized<'a>(vt: &Vt, p: &'a Preparation<'a>, width: Abs) -> Vec<L
// Cost parameters.
const HYPH_COST: Cost = 0.5;
const RUNT_COST: Cost = 0.5;
const CONSECUTIVE_DASH_COST: Cost = 300.0;
const MAX_COST: Cost = 1_000_000.0;
const MIN_RATIO: f64 = -1.0;
@ -984,6 +985,11 @@ fn linebreak_optimized<'a>(vt: &Vt, p: &'a Preparation<'a>, width: Abs) -> Vec<L
ratio.powi(3).abs()
};
// Penalize runts.
if k == i + 1 && eof {
cost += RUNT_COST;
}
// Penalize hyphens.
if hyphen {
cost += HYPH_COST;

Binary file not shown.

Before

Width:  |  Height:  |  Size: 41 KiB

After

Width:  |  Height:  |  Size: 19 KiB

View File

@ -31,3 +31,12 @@ D E F #linebreak(justify: true)
#set page(width: 155pt)
#set par(justify: true)
This text can be fitted in one line.
---
// Test that runts are avoided when it's not too costly to do so.
#set page(width: 124pt)
#set par(justify: true)
#for i in range(0, 20) {
"a b c "
}
#"d"