Report TeX outputpenalty for glue breaks
This commit is contained in:
1 parent
94559ee431
commit
8007fd1b6c
5 files changed
+31
-8
No files matched your search
@@ -1933,7 +1933,7 @@ impl Engine {
|
||||
page.insertions = insertions.into_values().collect();
|
||||
page.seal_in_place();
|
||||
pages.push(page);
|
||||
page_penalties.push(0);
|
||||
page_penalties.push(10_000);
|
||||
page_depths.push(0);
|
||||
page_stretches.push(0);
|
||||
page_fil_stretches.push(0);
|
||||
@@ -1971,7 +1971,7 @@ impl Engine {
|
||||
vsize: document.page_goal,
|
||||
top_skip: document.top_skip,
|
||||
max_depth: document.max_depth,
|
||||
output_penalty: page_penalties.get(index).copied().unwrap_or(0),
|
||||
output_penalty: page_penalties.get(index).copied().unwrap_or(10_000),
|
||||
insertion_counts,
|
||||
insertion_dimens,
|
||||
insertion_skips,
|
||||
|
||||
@@ -990,6 +990,17 @@ mod tests {
|
||||
assert_eq!(program.shipout_count(&mut forced).unwrap(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ifnum_recognises_glue_break_penalties() {
|
||||
let program =
|
||||
OutputProgram::parse(r"\ifnum\outputpenalty=10000\shipout\box255\fi").unwrap();
|
||||
let mut context = context(0);
|
||||
context.output_penalty = 10_000;
|
||||
assert_eq!(program.shipout_count(&mut context).unwrap(), 1);
|
||||
context.output_penalty = 150;
|
||||
assert_eq!(program.shipout_count(&mut context).unwrap(), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ifodd_ships_even_page_numbers_only() {
|
||||
let program = OutputProgram::parse(r"\ifodd\pageno\shipout\box255\else\relax\fi").unwrap();
|
||||
|
||||
@@ -95,8 +95,9 @@ pub struct PageFragment {
|
||||
pub end: usize,
|
||||
/// TeX's page cost for the breakpoint: badness plus penalty.
|
||||
pub cost: i64,
|
||||
/// Penalty that produced this break: a forced penalty value, the chosen
|
||||
/// candidate's penalty, or zero for the final page.
|
||||
/// TeX `\outputpenalty` for this break: the penalty value when the page
|
||||
/// broke at a penalty, otherwise 10000 (glue break, goal overflow or the
|
||||
/// final page, exactly as TeX reports it).
|
||||
pub penalty: i64,
|
||||
/// Badness of the page height against the page goal.
|
||||
pub badness: i64,
|
||||
@@ -656,6 +657,7 @@ impl PageBuilder {
|
||||
} else {
|
||||
0
|
||||
};
|
||||
let penalty = if penalty == 0 { 10_000 } else { penalty };
|
||||
PageFragment {
|
||||
start,
|
||||
end,
|
||||
@@ -736,7 +738,17 @@ mod tests {
|
||||
let pages = builder.build(&nodes);
|
||||
assert_eq!(pages.len(), 2);
|
||||
assert_eq!(pages[0].penalty, -10_000);
|
||||
assert_eq!(pages[1].penalty, 0);
|
||||
assert_eq!(pages[1].penalty, 10_000);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn glue_breaks_report_a_ten_thousand_penalty() {
|
||||
let builder = PageBuilder::new(100);
|
||||
let nodes = vec![box_(80, 0), glue(0, 0, 0), box_(80, 0)];
|
||||
let pages = builder.build(&nodes);
|
||||
assert_eq!(pages.len(), 2);
|
||||
assert_eq!(pages[0].penalty, 10_000);
|
||||
assert_eq!(pages[1].penalty, 10_000);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -48,7 +48,7 @@ floats (`\floatsep`, `\textfloatsep`, `\intextsep`, `\topfraction`,
|
||||
`\bottomnumber`, `\totalnumber`), insertion classes (`\skip`, fraction and
|
||||
absolute limits, splitting), marks, Rust output hook, multi-page PDF, and the
|
||||
route-D service endpoints (`/api/route-d/preview|pdf|edit`, project preview and
|
||||
PDF opt-in with `?engine=route-d`). 439 workspace tests are green and no oracle
|
||||
PDF opt-in with `?engine=route-d`). 440 workspace tests are green and no oracle
|
||||
fixture is ignored.
|
||||
|
||||
Known gaps, in dependency order:
|
||||
|
||||
+2
-2
@@ -125,7 +125,7 @@ and justification.
|
||||
| --- | --- | --- |
|
||||
| M0 | vertical list, page builder, checkpoint, page hash, edit demo | edit on page 2 rebuilds only page 2 |
|
||||
| M1 | TeX box/glue/penalty + paragraph builder (`\par`, `\hsize`, `\parindent`) | **partial**: item stream, CMR10 metrics, TeX Live en-US hyphenation, TeX demerits and tolerance passes, `\hangindent`/`\parshape`, `\parfillskip`, sentence spacing, `\spaceskip`/`\xspaceskip`, `\raggedright` (infinite `\rightskip`), `\looseness`, `\baselineskip`/`\lineskip`/`\parskip` interline glue, pdfLaTeX oracle matrix 90-240pt plus register, geometry, `\sfcode`, `\parindent`, `\parshape`, `\leftskip`/`\rightskip`, `\hfil`/`\hfill` glue orders, `\prevgraf` in the output routine, and vertical-glue fixtures |
|
||||
| M2 | page builder + `\output`, `\vsize`, `\topskip`, footnotes, floats | **partial**: `\vsize` page goal, `\topskip`, forced penalties, `Insertion` reserve, running `Mark`s, `OutputRoutine` hook, top/bottom `Float` placement; `page::PageBuilder` scores candidate breakpoints with TeX page badness, glue setting (with `\raggedbottom`/`\flushbottom` applied when pages are materialised, and TeX glue orders `\vfil`/`\vfill`/`\vfilll` honoured so only the highest order with stretch is used), `\topskip`/`\maxdepth`, and `Engine::layout_paged` uses it for documents whose units are single vertical items, placing top and bottom floats (with `\floatsep`, a `\bottomfraction` cap and the `\topnumber`/`\bottomnumber`/`\totalnumber` limits, with `\floatpagefraction` deciding when a float-heavy page ships without body) and insertion classes on that path, while in-text floats flow inline as body material; paged layouts replay edits from the edited unit's page and fall back to a full rebuild only when insertions or an interpreted `\output` are present; `\output` is interpreted for a `\shipout`/`\ifdim`/`\ifnum`/`\ifodd`/`\ifcase` subset; `\pageno`, `\outputpenalty` and `\deadcycles` are readable and assignable registers (`\pageno=...` carries into the next page, and an assigned `\vsize` retargets later pages when the document has no insertions or floats), `\ht255` and `\dp255` expose the page box height and depth to the routine, insertion class registers `\count<n>`/`\dimen<n>`/`\skip<n>` read the configured multiplier, maximum height and skip of class `n` (with `\count0` reading `\pageno`) and accept assignments for the duration of the routine, `\deadcycles` accumulates pages the output routine did not ship and resets on the next shipout, `PageFragment::penalty` carries the break penalty, and `PageFragment::stretches` records glue stretch per TeX order so `\pagefilstretch`/`\pagefillstretch`/`\pagefilllstretch` are readable in the output routine |
|
||||
| M2 | page builder + `\output`, `\vsize`, `\topskip`, footnotes, floats | **partial**: `\vsize` page goal, `\topskip`, forced penalties, `Insertion` reserve, running `Mark`s, `OutputRoutine` hook, top/bottom `Float` placement; `page::PageBuilder` scores candidate breakpoints with TeX page badness, glue setting (with `\raggedbottom`/`\flushbottom` applied when pages are materialised, and TeX glue orders `\vfil`/`\vfill`/`\vfilll` honoured so only the highest order with stretch is used), `\topskip`/`\maxdepth`, and `Engine::layout_paged` uses it for documents whose units are single vertical items, placing top and bottom floats (with `\floatsep`, a `\bottomfraction` cap and the `\topnumber`/`\bottomnumber`/`\totalnumber` limits, with `\floatpagefraction` deciding when a float-heavy page ships without body) and insertion classes on that path, while in-text floats flow inline as body material; paged layouts replay edits from the edited unit's page and fall back to a full rebuild only when insertions or an interpreted `\output` are present; `\output` is interpreted for a `\shipout`/`\ifdim`/`\ifnum`/`\ifodd`/`\ifcase` subset; `\pageno`, `\outputpenalty` and `\deadcycles` are readable and assignable registers (`\pageno=...` carries into the next page, and an assigned `\vsize` retargets later pages when the document has no insertions or floats), `\ht255` and `\dp255` expose the page box height and depth to the routine, insertion class registers `\count<n>`/`\dimen<n>`/`\skip<n>` read the configured multiplier, maximum height and skip of class `n` (with `\count0` reading `\pageno`) and accept assignments for the duration of the routine, `\deadcycles` accumulates pages the output routine did not ship and resets on the next shipout, `PageFragment::penalty` carries the break penalty (`\outputpenalty`: the penalty value when the break landed on a penalty, otherwise 10000, as TeX reports for glue breaks, goal overflow and the final page), and `PageFragment::stretches` records glue stretch per TeX order so `\pagefilstretch`/`\pagefillstretch`/`\pagefilllstretch` are readable in the output routine |
|
||||
| M3 | `\halign`, `\omit`, `\span`, `\multispan`, booktabs/longtable | **partial**: source parsing, natural column widths, spans, rule rows, 10pt display-list painting and row-level page splitting; no booktabs/longtable parity yet |
|
||||
| M4 | math lists, scripts, fractions, radicals, accents, delimiters | **partial**: token parser, atom boxes with CMR10 metrics, delimiter scaling, accents and a display-list painter; no CMEX size variants or TeX math spacing classes yet |
|
||||
| M5 | NFSS/TFM metrics, CM/Latin Modern | same line/page breaks as reference |
|
||||
@@ -355,7 +355,7 @@ Math coverage includes fractions/roots, scripts, `\left...\right` with body-scal
|
||||
|
||||
Paragraph units carry a `ParagraphFont`; `Unit::paragraph_with_face` and `Unit::paragraph_with_style_and_face` select Roman, bold, italic, mono, or sans. The corresponding Computer Modern TFM (`cmr10`, `cmbx10`, `cmti10`, `cmbxti10`, `cmtt10`, `cmss10`) supplies advances, kerns, ligatures, and italic correction for layout, while the display list and PDF select the matching Liberation face. `Engine::edit` preserves the face when reflowing an edited paragraph.
|
||||
|
||||
The crate currently has 289 unit tests plus seven route-D integration tests and twenty-seven oracle fixtures. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 439 tests (292 route-D unit, 7 route-D integration, 27 oracle, 71 v1 integration, 26 server, 4 v1 unit, 1 core unit, 11 binary units), with none ignored. v1 remains the live server path.
|
||||
The crate currently has 289 unit tests plus seven route-D integration tests and twenty-seven oracle fixtures. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 440 tests (294 route-D unit, 7 route-D integration, 27 oracle, 71 v1 integration, 26 server, 4 v1 unit, 1 core unit, 11 binary units), with none ignored. v1 remains the live server path.
|
||||
|
||||
### M0 incremental demo
|
||||
|
||||
|
||||
Reference in new issue
Block a user