From bc0d29ace4cdcec1864d58b1b347080978acb0c7 Mon Sep 17 00:00:00 2001 From: GloamXun Date: Fri, 23 Oct 2026 03:26:53 +0800 Subject: [PATCH] Insert parskip between paragraphs in the paged builder --- crates/texrra-tex-core/src/lib.rs | 48 ++++++++++++++++++++++++++++++- docs/ROUTE_D_PLAN.md | 2 +- docs/TEX_CORE.md | 9 ++++-- 3 files changed, 54 insertions(+), 5 deletions(-) diff --git a/crates/texrra-tex-core/src/lib.rs b/crates/texrra-tex-core/src/lib.rs index 32a8ce1..088bc79 100644 --- a/crates/texrra-tex-core/src/lib.rs +++ b/crates/texrra-tex-core/src/lib.rs @@ -785,8 +785,22 @@ fn document_nodes( let mut nodes = Vec::new(); let mut owners = Vec::new(); let mut items = Vec::new(); + let mut previous_paragraph = false; for (index, unit) in document.units.iter().enumerate() { - for item in &unit.items { + for (position, item) in unit.items.iter().enumerate() { + if position == 0 + && document.par_skip > 0 + && previous_paragraph + && matches!(item, VerticalItem::Paragraph(_)) + { + nodes.push(VerticalNode::Glue(VerticalGlue::new( + document.par_skip, + 0, + 0, + ))); + owners.push(index); + items.push(VerticalItem::Glue(document.par_skip)); + } let node = match item { VerticalItem::Box(vertical_box) => VerticalNode::Box { height: vertical_box.height, @@ -821,6 +835,10 @@ fn document_nodes( owners.push(index); items.push(item.clone()); } + previous_paragraph = unit + .items + .last() + .is_some_and(|item| matches!(item, VerticalItem::Paragraph(_))); } Some((nodes, owners, items)) } @@ -4946,6 +4964,34 @@ mod tests { assert_eq!(engine.pages()[0].sources, vec![(1, source_hash(""))]); } + #[test] + fn paged_layout_inserts_par_skip_between_paragraphs() { + let mut style = ParagraphStyle::default(); + style.line_height = 30; + let mut document = Document::new( + 60, + vec![ + Unit::paragraph_with_style(1, "one", style.clone()), + Unit::paragraph_with_style(2, "two", style), + ], + ); + assert_eq!( + Engine::layout_paged(&document) + .expect("paragraphs are page-buildable") + .pages() + .len(), + 1 + ); + + document.par_skip = 10; + let engine = Engine::layout_paged(&document).expect("paragraphs are page-buildable"); + assert_eq!(engine.pages().len(), 2); + assert!(matches!( + engine.pages()[1].items.first(), + Some(VerticalItem::Paragraph(_)) + )); + } + #[test] fn paged_layout_can_split_one_unit_across_pages() { let document = Document::new( diff --git a/docs/ROUTE_D_PLAN.md b/docs/ROUTE_D_PLAN.md index af665b2..ffb7837 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`). 357 workspace tests are green and no oracle +PDF opt-in with `?engine=route-d`). 358 workspace tests are green and no oracle fixture is ignored. Known gaps, in dependency order: diff --git a/docs/TEX_CORE.md b/docs/TEX_CORE.md index 1b5cc64..6b519c8 100755 --- a/docs/TEX_CORE.md +++ b/docs/TEX_CORE.md @@ -243,8 +243,11 @@ oracle fixture is ignored. `\ifnum`, `\ifodd` and `\ifcase` over the page registers `\pagegoal`, `\pagetotal`, `\pagedepth`, `\pagestretch`, `\pageshrink`, `\vsize`, `\topskip`, `\maxdepth`, `\outputpenalty`, `\pageno` and `\deadcycles`; - `PageFragment` also reports the page's total glue stretch and shrink. It - cannot yet change page goals. Top `Float` + `PageFragment` also reports the page's total glue stretch and shrink. In the + paged builder, `Document::par_skip` is inserted as vertical glue between + consecutive paragraph units and is discarded when it would start a page, + matching TeX's paragraph spacing in vertical lists. The routine cannot yet + change page goals. Top `Float` material is deferred to the next page when it arrives late; bottom floats reserve height on the current page and must satisfy `Document.text_fraction_percent` (default 50%); a page holding only floats @@ -335,7 +338,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 239 unit tests plus seven route-D integration tests and thirteen oracle fixtures. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 357 tests (239 route-D unit, 7 route-D integration, 13 oracle, 71 v1 integration, 20 server, 4 v1 unit, 1 core unit, 2 binary units), with none ignored. v1 remains the live server path. +The crate currently has 240 unit tests plus seven route-D integration tests and thirteen oracle fixtures. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 358 tests (240 route-D unit, 7 route-D integration, 13 oracle, 71 v1 integration, 20 server, 4 v1 unit, 1 core unit, 2 binary units), with none ignored. v1 remains the live server path. ### M0 incremental demo