diff --git a/crates/texrra-tex-core/src/lib.rs b/crates/texrra-tex-core/src/lib.rs index 5e5a911..e4c334f 100644 --- a/crates/texrra-tex-core/src/lib.rs +++ b/crates/texrra-tex-core/src/lib.rs @@ -976,6 +976,33 @@ fn document_nodes( continue; } } + if let VerticalItem::Halign(halign) = item { + let capacity = (document.page_goal - document.top_skip) + .max(halign.line_height) + .max(1); + let chunks = halign.split_for_height(capacity); + if chunks.len() > 1 { + // TeX breaks a long alignment at row boundaries; each + // chunk becomes its own vertical node with a zero glue + // between them so the page builder can break there. + let last = chunks.len() - 1; + for (chunk_index, chunk) in chunks.into_iter().enumerate() { + nodes.push(VerticalNode::Box { + height: chunk.height, + depth: 0, + }); + owners.push(index); + items.push(VerticalItem::Halign(chunk)); + if chunk_index < last { + nodes.push(VerticalNode::Glue(VerticalGlue::new(0, 0, 0))); + owners.push(index); + items.push(VerticalItem::Glue(0)); + } + } + previous_paragraph = false; + continue; + } + } let node = match item { VerticalItem::Box(vertical_box) => VerticalNode::Box { height: vertical_box.height, @@ -6142,6 +6169,44 @@ mod tests { assert_eq!(layout.pages()[0].items.len(), 1); assert_eq!(layout.pages()[1].items.len(), 1); } + #[test] + fn paged_layout_splits_a_tall_halign_across_pages() { + let mut rows = Vec::new(); + for n in 0..30_u64 { + rows.push(HalignRow { + cells: vec![ + HalignCell { + text: format!("r{n}"), + span: 1, + alignment: CellAlignment::Left, + }, + HalignCell { + text: "value".to_owned(), + span: 1, + alignment: CellAlignment::Left, + }, + ], + rule: false, + }); + } + let document = Document::new(300 * 65_536, vec![Unit::halign(0, rows, 2, 0)]); + let engine = Engine::layout_paged(&document).expect("paged"); + assert!(engine.pages().len() > 1, "pages: {}", engine.pages().len()); + let mut rows_seen = 0; + let mut widths = Vec::new(); + for page in engine.pages() { + for item in &page.items { + if let VerticalItem::Halign(halign) = item { + rows_seen += halign.rows.len(); + widths.push(halign.column_widths.clone()); + } + } + } + assert_eq!(rows_seen, 30); + assert!(!widths.is_empty()); + assert!(widths.windows(2).all(|pair| pair[0] == pair[1])); + } + #[test] fn checkpoint_round_trips_through_serde() { let engine = Engine::layout(&document()); diff --git a/docs/ROUTE_D_PLAN.md b/docs/ROUTE_D_PLAN.md index b58a7a9..ed04896 100644 --- a/docs/ROUTE_D_PLAN.md +++ b/docs/ROUTE_D_PLAN.md @@ -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`). 476 workspace tests are green and no oracle +PDF opt-in with `?engine=route-d`). 477 workspace tests are green and no oracle fixture is ignored. Status after G1 (P0-P2): the paragraph model reproduces TeX's passes, @@ -60,7 +60,7 @@ table in [`TEX_CORE.md`](TEX_CORE.md) lists the evidence per milestone. Remaining gaps: -1. `\halign` handles spans/omit/templates but not the full TeX column algorithm; +1. `\halign` handles spans/omit/templates and row-level page splitting (chunks keep the table's column widths), but not the full TeX column algorithm (`p{width}` cells, `\tabskip` arrays, booktabs/longtable, multi-line cells); 2. math is a compact subset without the CM math fonts (`cmmi`, `cmsy`, `cmex`), display-math line breaking or `\mathchoice`-level styling; 3. text fonts are Liberation, not Computer Modern; Type1 fonts are not embeddable diff --git a/docs/TEX_CORE.md b/docs/TEX_CORE.md index 19d1ab8..809fcde 100755 --- a/docs/TEX_CORE.md +++ b/docs/TEX_CORE.md @@ -130,7 +130,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, and `\mark{...}`/`\marks{...}` writes inside the routine are carried to the following page's mark list with their class; `\pageno`, `\outputpenalty` and `\deadcycles` are readable and assignable registers (`\pageno=...` carries into the next page, and an assigned `\vsize` retargets the pages the routine has not seen yet, even when the document raises insertion material; only a document that defers bottom floats keeps its initial goal, because the carried queue cannot be rebuilt after a retarget), `\ht255`, `\dp255` and `\wd255` expose the page box height, depth and width to the routine, and `\hsize` is readable (and assignable for the rest of the run) while `\wd255` tracks it; route-D sets `\hsize` from its 480pt text measure, insertion class registers `\count`/`\dimen`/`\skip` read the configured multiplier, maximum height and skip of class `n` (with `\count0` reading `\pageno`) and accept assignments that outlive the routine (the paged builder runs the routine after each page, so an assigned `\dimen` or `\count` changes the insertion capacity and reservation of later pages); the configured `\skip` also reserves space above its class once per page in the paged builder, and a `\skip` assignment rebuilds the pages the routine has not seen yet with the new reservation, `\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 | +| 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; the paged builder splits a tall alignment into page-sized row chunks that keep the table's column widths, so long tables continue across pages; no booktabs/longtable, `p{width}` cells or `\tabskip` arrays 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 | | M6 | class/package execution (`article`, `sn-jnl`) | Overleaf page-count parity | @@ -367,7 +367,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 319 unit tests plus seven route-D integration tests and thirty-five oracle fixtures. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 476 tests (319 route-D unit, 7 route-D integration, 35 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 320 unit tests plus seven route-D integration tests and thirty-five oracle fixtures. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 477 tests (320 route-D unit, 7 route-D integration, 35 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