Honour TeX looseness when an alternative line count exists

This commit is contained in:
gloamxun committed 2026-10-23 13:46:32 +08:00
1 parent 96cd98f833
commit a6397fcfef
6 files changed
+219 -99

No files matched your search

+31
View File
@@ -151,6 +151,7 @@ fn route_d_lines_with(
right_skip: 0,
centered: false,
right_aligned: false,
looseness: 0,
par_indent: 0,
line_height: 12 * PT,
..ParagraphStyle::default()
@@ -537,6 +538,36 @@ fn par_shape_matches_pdftex() {
);
}
/// TeX `\\looseness` asks for a different final line count when such a
/// break is feasible within `\\tolerance`; pdfLaTeX is the reference. When
/// the requested count is infeasible TeX still prints a different (alternative
/// optimum) paragraph; route-D keeps the ordinary optimum there, which is
/// covered by the unit tests rather than this oracle.
#[test]
fn looseness_matches_pdftex() {
let width = 120;
let text = "alpha beta gamma delta epsilon zeta eta theta iota kappa \
lambda mu nu xi omicron pi rho sigma tau upsilon phi chi psi omega";
for looseness in [0_i64, 1] {
let prefix = format!("\\tolerance=10000 \\pretolerance=10000 \\looseness={looseness} ");
let Some(reference) = pdftex_lines(&paragraph_fixture_with(text, width, &prefix)) else {
eprintln!("skipping: pdflatex/pdftotext are not installed");
return;
};
let ours = route_d_lines_with(text, f64::from(width), |style| {
style.tolerance = 10_000;
style.pretolerance = 10_000;
style.looseness = looseness;
});
assert_eq!(
ours.len(),
reference.len(),
"looseness {looseness} line count"
);
assert_lines_match(&format!("looseness {looseness}"), &ours, &reference);
}
}
/// Sentence punctuation changes the space factor, so the interword glue and
/// the resulting line breaks must match pdfLaTeX.
#[test]