Report page badness and held-over insertions to the output routine

This commit is contained in:
gloamxun committed 2026-10-24 00:02:46 +08:00
1 parent bf31936146
commit 01ed1b7c21
5 files changed
+89 -6

No files matched your search

+1 -1
View File
@@ -590,7 +590,7 @@ execution, service and incrementality targets) is in
The first M7 service integration is available as `POST /api/route-d/preview`, with PDF export at `POST /api/route-d/pdf`.
It accepts blank-line-separated source with a small `\section`/`\textbf`/`\emph`/display-math/list subset, lays it out with the route-D page
builder, and returns the v1-compatible preview shape plus per-page hashes and
SVG. Route-D paragraphs are laid out with CMR10 advances, kerns and ligatures; runs of two or three hyphens become en/em dashes, the breaker follows TeX's `\pretolerance`/`\tolerance`/`\emergencystretch` passes with demerits (falling back to TeX's overfull fill when no feasible break exists), and the PDF `/W` array reports the same advances, so extracted text keeps word boundaries. Non-final lines bake their justification into the glue widths, so the PDF and the SVG preview are flush to the measure instead of showing natural spaces; with `\raggedright` (`ParagraphStyle::ragged_right`) lines keep their natural widths and fill greedily, because `\rightskip` carries an infinite `fil`. Interline spacing follows TeX (`\baselineskip` unless `\lineskiplimit` forces `\lineskip`), and `Document::par_skip` adds `\parskip` between paragraph units. `page::PageBuilder` selects page breaks by TeX's badness-plus-penalty cost, including glue setting with TeX orders (normal/`\vfil`/`\vfill`/`\vfilll`), `\topskip` and `Document::max_depth` (`\maxdepth`, with each paragraph's last-line descent exposed as `\pagedepth` and only the part beyond `\maxdepth` added to the page height), and breaks ties toward the page closest to the goal; `Engine::layout_paged` exposes it for documents of box/glue/penalty/mark/float/insertion units, expanding each paragraph into one node per line with a zero-width interline breakpoint, and route-D previews and PDFs run through it; insertion classes are placed through the same builder, with per-class limits, held-over material and `Document::split_top_skip` (`\splittopskip`, default 10pt) at the top of each continuation, with `Document::split_max_depth` (`\splitmaxdepth`, `\maxdimen` by default) clamping the first continued box's depth and moving the excess into its height, while `Engine::layout` keeps the scrolling builder as the non-paged fallback; paged layouts replay edits from the edited page, falling back to a full rebuild when insertions or an `\output` routine are present. `Document::output_routine` runs an interpreted `\output` program (`\shipout\box255`, `\relax`, `\message`, `\ifdim`, `\ifnum` and `\ifodd` over page registers; `\pageno`, `\outputpenalty` and `\deadcycles` are readable, and each page fragment records the penalty that broke it and how much stretch each glue order carries, so `\pagefilstretch`, `\pagefillstretch` and `\pagefilllstretch` are readable) over those paged fragments, so a routine can drop pages it does not ship, or ship only the pages it wants based on the break penalty or page number. Embedded text fonts are subset per document to the glyphs actually used (retaining glyph IDs and composite components), and each subset carries a ToUnicode CMap covering its used characters. `Document::h_offset` and `v_offset` (`\hoffset`/`\voffset`) shift the exported
SVG. Route-D paragraphs are laid out with CMR10 advances, kerns and ligatures; runs of two or three hyphens become en/em dashes, the breaker follows TeX's `\pretolerance`/`\tolerance`/`\emergencystretch` passes with demerits (falling back to TeX's overfull fill when no feasible break exists), and the PDF `/W` array reports the same advances, so extracted text keeps word boundaries. Non-final lines bake their justification into the glue widths, so the PDF and the SVG preview are flush to the measure instead of showing natural spaces; with `\raggedright` (`ParagraphStyle::ragged_right`) lines keep their natural widths and fill greedily, because `\rightskip` carries an infinite `fil`. Interline spacing follows TeX (`\baselineskip` unless `\lineskiplimit` forces `\lineskip`), and `Document::par_skip` adds `\parskip` between paragraph units. `page::PageBuilder` selects page breaks by TeX's badness-plus-penalty cost, including glue setting with TeX orders (normal/`\vfil`/`\vfill`/`\vfilll`), `\topskip` and `Document::max_depth` (`\maxdepth`, with each paragraph's last-line descent exposed as `\pagedepth` and only the part beyond `\maxdepth` added to the page height), and breaks ties toward the later breakpoint (TeX's `<=` update), shipping the least overfull break only when nothing fits; `Engine::layout_paged` exposes it for documents of box/glue/penalty/mark/float/insertion units, expanding each paragraph into one node per line with a zero-width interline breakpoint, and route-D previews and PDFs run through it; insertion classes are placed through the same builder, with per-class limits, held-over material and `Document::split_top_skip` (`\splittopskip`, default 10pt) at the top of each continuation, with `Document::split_max_depth` (`\splitmaxdepth`, `\maxdimen` by default) clamping the first continued box's depth and moving the excess into its height, while `Engine::layout` keeps the scrolling builder as the non-paged fallback; paged layouts replay edits from the edited page, falling back to a full rebuild when insertions or an `\output` routine are present. `Document::output_routine` runs an interpreted `\output` program (`\shipout\box255`, `\relax`, `\message`, `\ifdim`, `\ifnum` and `\ifodd` over page registers; `\pageno`, `\outputpenalty`, `\deadcycles`, `\vbadness` (the break's badness) and `\insertpenalties` (insertion items held over) are readable, and each page fragment records the penalty that broke it and how much stretch each glue order carries, so `\pagefilstretch`, `\pagefillstretch` and `\pagefilllstretch` are readable) over those paged fragments, so a routine can drop pages it does not ship, or ship only the pages it wants based on the break penalty or page number. Embedded text fonts are subset per document to the glyphs actually used (retaining glyph IDs and composite components), and each subset carries a ToUnicode CMap covering its used characters. `Document::h_offset` and `v_offset` (`\hoffset`/`\voffset`) shift the exported
page body through `pdf::PageOrigin`, leaving the sheet size unchanged, while
`Document::paper_width`/`paper_height` (`\paperwidth`/`\paperheight`, default US
Letter) set the MediaBox and the preview page box; the route-D endpoints read
+66
View File
@@ -1990,6 +1990,8 @@ impl Engine {
let mut page_fill_stretches = Vec::new();
let mut page_filll_stretches = Vec::new();
let mut page_shrinks = Vec::new();
let mut page_badnesses = Vec::new();
let mut page_insert_penalties = Vec::new();
let mut page_goals: Vec<i64> = Vec::new();
let mut held: BTreeMap<u8, Vec<VerticalItem>> = BTreeMap::new();
let fragments = builder.build_with_deferred_bottom_floats(&nodes);
@@ -2009,6 +2011,7 @@ impl Engine {
})
.collect();
let mut sources = Vec::new();
let mut insert_penalties = 0_i64;
let mut insertions: BTreeMap<u8, Insertion> = BTreeMap::new();
let mut used: BTreeMap<u8, i64> = BTreeMap::new();
@@ -2047,6 +2050,7 @@ impl Engine {
);
attach_insertion(&mut insertions, &mut used, class, accepted, reserved);
if !remainder.is_empty() {
insert_penalties += remainder.len() as i64;
held.entry(class).or_default().extend(remainder);
}
}
@@ -2079,6 +2083,8 @@ impl Engine {
page_fill_stretches.push(fragment.stretches[2]);
page_filll_stretches.push(fragment.stretches[3]);
page_shrinks.push(fragment.shrink);
page_badnesses.push(fragment.badness);
page_insert_penalties.push(insert_penalties);
}
// Insertion material that did not fit its class limit on the page where
@@ -2111,6 +2117,8 @@ impl Engine {
page_fill_stretches.push(0);
page_filll_stretches.push(0);
page_shrinks.push(0);
page_badnesses.push(10_000);
page_insert_penalties.push(0);
}
if let Some(source) = &document.output_routine {
let program = output::OutputProgram::parse(source).ok()?;
@@ -2139,6 +2147,7 @@ impl Engine {
page_fill_stretch: page_fill_stretches.get(index).copied().unwrap_or(0),
page_filll_stretch: page_filll_stretches.get(index).copied().unwrap_or(0),
page_shrink: page_shrinks.get(index).copied().unwrap_or(0),
vbadness: page_badnesses.get(index).copied().unwrap_or(10_000),
vsize: document.page_goal,
top_skip: document.top_skip,
max_depth: document.max_depth,
@@ -2150,6 +2159,7 @@ impl Engine {
pageno,
deadcycles,
prev_graf: page_prev_graf(&page),
insert_penalties: page_insert_penalties.get(index).copied().unwrap_or(0),
};
let forced = deadcycles >= document.max_deadcycles.max(0);
if forced {
@@ -2338,6 +2348,7 @@ impl Engine {
page_fill_stretch: fragment.stretches[2],
page_filll_stretch: fragment.stretches[3],
page_shrink: fragment.shrink,
vbadness: fragment.badness,
vsize: goal,
top_skip: document.top_skip,
max_depth: document.max_depth,
@@ -2347,6 +2358,7 @@ impl Engine {
insertion_dimens,
insertion_skips,
prev_graf: page_prev_graf(&page),
insert_penalties: 0,
pageno,
deadcycles,
};
@@ -3227,6 +3239,60 @@ mod tests {
assert_eq!(engine.pages().len(), 1);
}
#[test]
fn output_routine_sees_page_break_badness() {
// The first page overfills the 50pt goal, so its break is maximally
// bad; the second page fits exactly. Only the overfull page ships.
let mut document = Document::new(
50,
vec![
Unit::rule(1, 0, 60),
Unit::penalty(2, 0),
Unit::rule(3, 0, 50),
],
);
document.output_routine = Some(r"\ifnum\vbadness=10000\shipout\box255\fi".to_owned());
let engine = Engine::layout_paged(&document).expect("paged");
assert_eq!(engine.pages().len(), 1);
}
#[test]
fn output_routine_sees_insertion_penalties() {
// The class limit fits one 20pt item, so the second is held over and
// reported through \insertpenalties.
let mut document = Document::new(
200,
vec![
Unit::rule(1, 0, 20),
Unit::insertion(
2,
0,
40,
vec![
VerticalItem::Rule {
width: 0,
height: 20,
},
VerticalItem::Rule {
width: 0,
height: 20,
},
],
),
],
);
document.insertion_classes = vec![InsertionClass {
number: 0,
fraction_percent: 100,
max_height: Some(20),
skip: None,
multiplier: 1000,
}];
document.output_routine = Some(r"\ifnum\insertpenalties=1\shipout\box255\fi".to_owned());
let engine = Engine::layout_paged(&document).expect("paged");
assert_eq!(engine.pages().len(), 1);
}
#[test]
fn output_routine_can_force_an_early_page_break() {
struct BreakAfterTwo {
+16
View File
@@ -30,6 +30,8 @@ pub struct OutputContext {
pub page_filll_stretch: i64,
/// TeX `\pageshrink`: shrink of the vertical glue so far.
pub page_shrink: i64,
/// TeX `\vbadness`: badness of the break that produced the page.
pub vbadness: i64,
/// TeX `\vsize`: the configured page height.
pub vsize: i64,
/// TeX `\topskip`.
@@ -47,6 +49,8 @@ pub struct OutputContext {
pub max_deadcycles: i64,
/// TeX `\prevgraf`: lines in the paragraph most recently broken.
pub prev_graf: i64,
/// TeX `\insertpenalties`: insertion items held over from the page.
pub insert_penalties: i64,
/// TeX `\count<n>` for insertion class `n`: the insertion multiplier.
pub insertion_counts: [i64; 256],
/// TeX `\dimen<n>` for insertion class `n`: the class' maximum size.
@@ -66,6 +70,7 @@ impl Default for OutputContext {
page_fill_stretch: 0,
page_filll_stretch: 0,
page_shrink: 0,
vbadness: 0,
vsize: 0,
top_skip: 0,
max_depth: 0,
@@ -74,6 +79,7 @@ impl Default for OutputContext {
deadcycles: 0,
max_deadcycles: 25,
prev_graf: 0,
insert_penalties: 0,
// TeX's default insertion multiplier is 1000.
insertion_counts: [1000; 256],
insertion_dimens: [0; 256],
@@ -298,6 +304,8 @@ enum IntegerRegister {
PageNo,
DeadCycles,
MaxDeadCycles,
VBadness,
InsertPenalties,
OutputPenalty,
PrevGraf,
InsertionCount(u8),
@@ -313,6 +321,8 @@ impl Integer {
IntegerRegister::MaxDeadCycles => context.max_deadcycles,
IntegerRegister::OutputPenalty => context.output_penalty,
IntegerRegister::PrevGraf => context.prev_graf,
IntegerRegister::VBadness => context.vbadness,
IntegerRegister::InsertPenalties => context.insert_penalties,
IntegerRegister::InsertionCount(class) => context.insertion_counts[class as usize],
},
}
@@ -726,6 +736,8 @@ fn parse_integer(tokens: &[Token], index: &mut usize) -> Result<Integer, String>
"maxdeadcycles" => IntegerRegister::MaxDeadCycles,
"outputpenalty" => IntegerRegister::OutputPenalty,
"prevgraf" => IntegerRegister::PrevGraf,
"vbadness" => IntegerRegister::VBadness,
"insertpenalties" => IntegerRegister::InsertPenalties,
"count" => {
*index += 1;
if matches!(
@@ -949,6 +961,8 @@ fn read_integer(context: &OutputContext, register: IntegerRegister) -> i64 {
IntegerRegister::MaxDeadCycles => context.max_deadcycles,
IntegerRegister::OutputPenalty => context.output_penalty,
IntegerRegister::PrevGraf => context.prev_graf,
IntegerRegister::VBadness => context.vbadness,
IntegerRegister::InsertPenalties => context.insert_penalties,
IntegerRegister::InsertionCount(class) => context.insertion_counts[class as usize],
}
}
@@ -963,6 +977,8 @@ fn write_integer(context: &mut OutputContext, register: IntegerRegister, value:
IntegerRegister::InsertionCount(class) => {
context.insertion_counts[class as usize] = value;
}
// Read-only for the output routine: the parser never assigns them.
IntegerRegister::VBadness | IntegerRegister::InsertPenalties => {}
}
}
+3 -2
View File
@@ -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`). 464 workspace tests are green and no oracle
PDF opt-in with `?engine=route-d`). 466 workspace tests are green and no oracle
fixture is ignored.
Known gaps, in dependency order:
@@ -79,7 +79,8 @@ source-level `\hyphenation{...}` exceptions and `\parshape` measures,
floats, `\bottomfraction` cap); in-text floats flow inline, so every
float placement goes through the paged builder, and the interpreted
`\output` subset handles `\shipout`, `\ifdim` and `\ifnum` over page
registers such as `\pageno`, `\outputpenalty` and `\deadcycles`;
registers such as `\pageno`, `\outputpenalty`, `\deadcycles`, `\vbadness` and
`\insertpenalties`;
3. `\insert` classes are TeX registers addressed by number (`\count<n>`,
`\dimen<n>`, `\skip<n>`, with `\count0` aliasing `\pageno`) and the
interpreted output routine can assign `\pageno`, `\deadcycles`,
+3 -3
View File
@@ -128,7 +128,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, bottom floats 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, `\maxdeadcycles` (default 25, assignable) makes the page builder ship the page itself once that many dead cycles have accumulated, `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 |
| 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, bottom floats 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, `\maxdeadcycles` (default 25, assignable) makes the page builder ship the page itself once that many dead cycles have accumulated, `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; `\vbadness` reports the badness of the break that produced the page and `\insertpenalties` the number of insertion items held over from it |
| 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 |
@@ -358,7 +358,7 @@ M6 (partial): `DisplayItem::Image` becomes a PDF XObject; `DisplayItem::Link` be
M2 (partial): `Page::display_list_with_goal(page_goal)` places insertion material at `page_goal - insertion_height`, adds a 0.4pt separator above footnotes, splits oversized insertions at item boundaries, and paints top/bottom floats from their vertical `content` at the page edges; empty floats keep a dimension rectangle. Floats also size themselves from content, respect `text_fraction_percent`, respect `top_fraction_percent` (TeX `\topfraction`, default 70%) and `bottom_fraction_percent` (TeX `\bottomfraction`, default 30%), and can take a dedicated float page. The incremental edit path applies the same float fractions, float number limits, insertion-class limits and per-class `skip` rules as full layout. `Document::float_sep` (TeX `\floatsep`, default 12pt) reserves a gap between stacked floats of the same placement in both paths. `Document::text_float_sep` (TeX `\textfloatsep`, default 20pt) reserves exactly one gap between the float block and the body text on a page that has both, again in both paths; `Page::display_list_with_layout(page_goal, text_float_sep)` applies the same gap when rendering, while `display_list_with_goal` stays gap-free for callers that do not know the document settings. Float material at the top of a page starts at the top margin: `\topskip` is consumed only by body text, matching TeX float pages. A `[t]` float seen while a page is already being filled is installed at the top of that same page, exactly as TeX's `\@toplist` does: the page height gains the float plus one `\textfloatsep` (or `\floatsep` between stacked floats), so the body stops earlier instead of the float waiting for the next page; only a break before the float moves it forward. `FloatPlacement::Here` models `[h]` floats: they keep their place in the body flow with `Document::in_text_sep` (TeX `\intextsep`, default 12pt) above and below, move to the next page when they do not fit, and count against `\totalnumber`. The page stores the float's `gap_after` so the display list advances the flow by the same amount the builder reserved. A standalone `page::PageBuilder` implements TeX's candidate-breakpoint cost model (page badness from accumulated glue stretch/shrink plus break penalties, `\topskip` for the first box, `\maxdepth` depth shifting) with unit tests covering overfull avoidance, exact glue filling, forced and costed breaks, `\topskip`, `\maxdepth`, marks, insertion limits and top-float placement; every fragment records the penalty that broke it. `Engine::layout_paged` now builds pages through it for documents whose units are single vertical items (boxes, rules, paragraphs, math, haligns, glue, penalties, marks and insertion classes, including per-class limits and held-over material; held-over material starts with `Document::split_top_skip` (TeX `\splittopskip`, default 10pt) when the class capacity can also hold its first item, and `Document::split_max_depth` (TeX `\splitmaxdepth`, `\maxdimen` by default) clamps the first held box's depth while moving the excess into its height); `Document::max_depth` feeds TeX's `\maxdepth` into the builder, and among equal-cost breakpoints the later candidate wins, matching the page builder's `least_page_cost` update with `<=`, so a page can take a later break even when it overfills the goal slightly; when no break fits within the glue shrink, the least overfull break is used instead. Paragraphs also split across pages at line boundaries, so body material no longer overflows a page as one box. Paragraph boxes carry TeX depth: each node reports its last line's descent, so `\pagedepth` sees it, and the builder adds every box descent beyond `\maxdepth` to the page height while keeping the rest as page depth (TeX's per-box rule); route-D sources default `\maxdepth` to LaTeX's 5pt (0.5\topskip), and the page fixtures set it explicitly. A standalone `\smallskip`, `\medskip`, `\bigskip` or `\vskip` line between paragraphs becomes the following unit's `space_before` glue, carrying TeX's width plus its `plus`/`minus` parts (`\smallskip` is 3pt plus 1pt minus 1pt, and so on). Both page builders reserve it, the paged builder gets a real breakpoint with the glue's stretch and shrink, and edits preserve all three components; the command no longer leaks into the paragraph text. `Document::h_offset` and `v_offset` (TeX `\hoffset`/`\voffset`, default zero) feed `pdf::PageOrigin`, and `display_lists_to_pdf_with_paper` translates the page body without moving the sheet; a route-D fixture checks a 10pt/20pt shift against `pdftotext -bbox`, and
preview pages apply the same offsets to their display list so the editor and
PDF agree. `Document::paper_width` and `paper_height` (TeX `\paperwidth`/`\paperheight`, default US Letter) set the PDF MediaBox and the preview page box, and both route-D endpoints strip leading `\hoffset`/`\voffset`/`\paperwidth`/`\paperheight`/`\vsize`/`\textheight` dimension assignments from the source (preamble included) and apply them, and the same pass reads `\parindent`, `\parskip`, `\baselineskip`, `\leftskip`, `\rightskip`, `\emergencystretch`, `\tolerance`, `\pretolerance`, `\hangindent`/`\hangafter`, `\spaceskip`/`\xspaceskip` and `\frenchspacing` into the paragraph styles; body paragraphs are measured with CMR10/per-face TFM advances rather than fixed cells; `\textheight` wins over `\vsize` because LaTeX resets `\vsize` from `\textheight` on every page, and project previews reuse the same geometry parsing. `Engine::top_mark`, `first_mark` and `bot_mark` implement TeX's carried mark registers per class. `Document::output_routine` runs an interpreted `\output` program over the paged fragments (`output::OutputProgram`: `\shipout\box255`, `\relax`, `\message`, `\ifdim`, `\ifnum`, `\ifodd` and `\ifcase` over the page registers, now including `\pageno`, `\outputpenalty`, `\deadcycles` and `\maxdeadcycles`), dropping pages the routine does not ship. Assignments such as `\pageno=10`, `\deadcycles=0`, `\count2=2000`, `\dimen2=30pt`, `\skip2=6pt` and `\vsize=300pt` mutate the per-page context; `\advance`, `\multiply` and `\divide` adjust those registers in place (`\advance\pageno by 2`, `\divide\deadcycles by 2`, `\advance\dimen2 by 5pt`), and an arithmetic `\vsize` change retargets later pages exactly like an assignment; `\pageno` and the insertion registers keep their assigned values for later pages, since TeX's output registers are global; Route-D sources map a standalone `\newpage` or `\clearpage` onto `Document::page_breaks`, so the next paragraph starts on a fresh page (the paged builder turns each break into a `-10000` penalty node); for documents without insertions or floats the paged builder runs the routine after each page, so an assigned `\vsize` sets the goal of the pages the routine has not seen yet. The `\pagegoal` register handed to the output routine is reduced by the insertion space reserved on that page. Paged layouts record the node index that starts each page, so `Engine::edit` on a paged layout reuses the sealed prefix and rebuilds only from the edited unit's page onward; an interpreted `\output` routine still forces a full rebuild, and an edit whose replay would begin before the first insertion does too, because held-over material and dropped pages move page boundaries. A document that contains a bottom float likewise rebuilds in full: a deferred float is carried on the page fragment, and a suffix replay starting at a page boundary cannot recover that queue. The scrolling builder's float path remains to be ported. The oracle harness also compares whole pages: ten page fixtures (single-line paragraphs, `\parskip=6pt`, multi-line paragraphs split across pages, a 300pt `\textheight`, a 30pt `\topskip`, a forced `\newpage`, stretchy `\vskip` glue between paragraphs, footnotes raised with `\footnotetext`, and a `[t]` float that reserves its height plus `\textfloatsep` on the page it appears, and `[b]` floats that fit or defer to the next page) assert the same page count and the same per-page alphanumeric text as pdfLaTeX at 345pt measure, 550pt `\vsize`, 12pt `\topskip` and 15pt `\parindent`.
PDF agree. `Document::paper_width` and `paper_height` (TeX `\paperwidth`/`\paperheight`, default US Letter) set the PDF MediaBox and the preview page box, and both route-D endpoints strip leading `\hoffset`/`\voffset`/`\paperwidth`/`\paperheight`/`\vsize`/`\textheight` dimension assignments from the source (preamble included) and apply them, and the same pass reads `\parindent`, `\parskip`, `\baselineskip`, `\leftskip`, `\rightskip`, `\emergencystretch`, `\tolerance`, `\pretolerance`, `\hangindent`/`\hangafter`, `\spaceskip`/`\xspaceskip` and `\frenchspacing` into the paragraph styles; body paragraphs are measured with CMR10/per-face TFM advances rather than fixed cells; `\textheight` wins over `\vsize` because LaTeX resets `\vsize` from `\textheight` on every page, and project previews reuse the same geometry parsing. `Engine::top_mark`, `first_mark` and `bot_mark` implement TeX's carried mark registers per class. `Document::output_routine` runs an interpreted `\output` program over the paged fragments (`output::OutputProgram`: `\shipout\box255`, `\relax`, `\message`, `\ifdim`, `\ifnum`, `\ifodd` and `\ifcase` over the page registers, now including `\pageno`, `\outputpenalty`, `\deadcycles` and `\maxdeadcycles`), dropping pages the routine does not ship. Assignments such as `\pageno=10`, `\deadcycles=0`, `\count2=2000`, `\dimen2=30pt`, `\skip2=6pt` and `\vsize=300pt` mutate the per-page context; `\advance`, `\multiply` and `\divide` adjust those registers in place (`\advance\pageno by 2`, `\divide\deadcycles by 2`, `\advance\dimen2 by 5pt`), and an arithmetic `\vsize` change retargets later pages exactly like an assignment; `\pageno` and the insertion registers keep their assigned values for later pages, since TeX's output registers are global; Route-D sources map a standalone `\newpage` or `\clearpage` onto `Document::page_breaks`, so the next paragraph starts on a fresh page (the paged builder turns each break into a `-10000` penalty node); for documents without insertions or floats the paged builder runs the routine after each page, so an assigned `\vsize` sets the goal of the pages the routine has not seen yet. The `\pagegoal` register handed to the output routine is reduced by the insertion space reserved on that page. `\vbadness` carries the page's break badness and `\insertpenalties` counts insertion items the class limits held over, so an output routine can react to overfull breaks or split insertions. Paged layouts record the node index that starts each page, so `Engine::edit` on a paged layout reuses the sealed prefix and rebuilds only from the edited unit's page onward; an interpreted `\output` routine still forces a full rebuild, and an edit whose replay would begin before the first insertion does too, because held-over material and dropped pages move page boundaries. A document that contains a bottom float likewise rebuilds in full: a deferred float is carried on the page fragment, and a suffix replay starting at a page boundary cannot recover that queue. The scrolling builder's float path remains to be ported. The oracle harness also compares whole pages: ten page fixtures (single-line paragraphs, `\parskip=6pt`, multi-line paragraphs split across pages, a 300pt `\textheight`, a 30pt `\topskip`, a forced `\newpage`, stretchy `\vskip` glue between paragraphs, footnotes raised with `\footnotetext`, and a `[t]` float that reserves its height plus `\textfloatsep` on the page it appears, and `[b]` floats that fit or defer to the next page) assert the same page count and the same per-page alphanumeric text as pdfLaTeX at 345pt measure, 550pt `\vsize`, 12pt `\topskip` and 15pt `\parindent`.
M3 (partial): `Unit::halign` normalizes column widths, intercolumn gaps, row heights and cell text widths to scaled points; the painter uses 10pt glyphs in 12pt rows. Rules and spans are painted; tall tables split at row boundaries (`Halign::split_for_height`) with column widths preserved.
@@ -366,7 +366,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 308 unit tests plus seven route-D integration tests and thirty-four oracle fixtures. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 464 tests (308 route-D unit, 7 route-D integration, 34 oracle, 71 v1 integration, 26 server, 4 v1 unit, 1 core unit, 13 binary units), with none ignored. v1 remains the live server path.
The crate currently has 310 unit tests plus seven route-D integration tests and thirty-four oracle fixtures. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 466 tests (310 route-D unit, 7 route-D integration, 34 oracle, 71 v1 integration, 26 server, 4 v1 unit, 1 core unit, 13 binary units), with none ignored. v1 remains the live server path.
### M0 incremental demo