diff --git a/README.md b/README.md index 528c964..2c35236 100644 --- a/README.md +++ b/README.md @@ -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`), 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, 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 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, 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 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 diff --git a/crates/texrra-tex-core/src/lib.rs b/crates/texrra-tex-core/src/lib.rs index 3428c98..94c221d 100644 --- a/crates/texrra-tex-core/src/lib.rs +++ b/crates/texrra-tex-core/src/lib.rs @@ -910,6 +910,13 @@ fn document_nodes( } if let VerticalItem::Paragraph(paragraph) = item { if paragraph.lines.len() > 1 { + // Paragraphs built with fixed-cell styles mix raw units with + // TFM extents; only trust a descent that fits the box. + let depth = if paragraph.height > paragraph.depth { + paragraph.depth + } else { + 0 + }; // TeX breaks pages between lines. Expand a paragraph into // one node per line so the page builder is free to break // inside it; each slice renders as its own single-line @@ -921,9 +928,17 @@ fn document_nodes( } else { None }; + let remaining_depth = if remaining.height > remaining.depth { + remaining.depth + } else { + 0 + }; + // The line grid already budgets the descent; keep the + // grid height and report the descent separately for + // `\pagedepth`/`\maxdepth`. nodes.push(VerticalNode::Box { height: remaining.height, - depth: 0, + depth: remaining_depth, }); owners.push(index); items.push(VerticalItem::Paragraph(remaining.clone())); @@ -958,7 +973,11 @@ fn document_nodes( }, VerticalItem::Paragraph(paragraph) => VerticalNode::Box { height: paragraph.height, - depth: 0, + depth: if paragraph.height > paragraph.depth { + paragraph.depth + } else { + 0 + }, }, VerticalItem::Halign(halign) => VerticalNode::Box { height: halign.height, @@ -5066,6 +5085,7 @@ mod tests { lines, height: 100, width: 50, + depth: 0, font: ParagraphFont::Roman, left_skip: 0, line_indents: vec![0; 10], @@ -6191,6 +6211,38 @@ mod tests { ); } + #[test] + fn output_routine_sees_paragraph_depth() { + let paragraph = Paragraph { + lines: vec![Vec::new()], + height: 8 * 65_536, + width: 5 * 65_536, + depth: 2 * 65_536, + font: ParagraphFont::Roman, + left_skip: 0, + line_indents: vec![0], + line_baselines: vec![8 * 65_536], + centered: false, + right_aligned: false, + }; + let mut document = Document::new( + 300 * 65_536, + vec![Unit::vertical(1, vec![VerticalItem::Paragraph(paragraph)])], + ); + document.max_depth = 5 * 65_536; + document.output_routine = Some("\\ifdim\\pagedepth>0pt\\shipout\\box255\\fi".to_string()); + let deep = Engine::layout_paged(&document).expect("paragraph page"); + assert_eq!(deep.pages().len(), 1, "maxdepth keeps the paragraph depth"); + + document.max_depth = 0; + let capped = Engine::layout_paged(&document).expect("paragraph page"); + assert_eq!(capped.pages().len(), 0, "maxdepth zero drops the depth"); + + document.output_routine = Some("\\ifdim\\pagedepth=0pt\\shipout\\box255\\fi".to_string()); + let zero = Engine::layout_paged(&document).expect("paragraph page"); + assert_eq!(zero.pages().len(), 1); + } + #[test] fn page_prev_graf_counts_the_last_paragraph_lines() { let style = ParagraphStyle { diff --git a/crates/texrra-tex-core/src/page.rs b/crates/texrra-tex-core/src/page.rs index d0706ba..fed0466 100644 --- a/crates/texrra-tex-core/src/page.rs +++ b/crates/texrra-tex-core/src/page.rs @@ -314,8 +314,12 @@ impl PageBuilder { } else { *box_height }; - height += contribution; - depth = *box_depth; + // TeX keeps at most \maxdepth of a box descent below the + // page; deeper material is added to the page height as the + // box is contributed. A following box replaces the current + // page depth, so earlier kept descents are discarded. + height += contribution + (*box_depth - self.max_depth).max(0); + depth = (*box_depth).min(self.max_depth); first_box = false; has_body = true; } diff --git a/crates/texrra-tex-core/src/paragraph.rs b/crates/texrra-tex-core/src/paragraph.rs index 6fcf01c..4b5abb1 100755 --- a/crates/texrra-tex-core/src/paragraph.rs +++ b/crates/texrra-tex-core/src/paragraph.rs @@ -302,6 +302,9 @@ pub struct Paragraph { pub lines: Vec>, pub height: i64, pub width: i64, + /// TeX depth of the paragraph box: the descent of its last line. + #[serde(default)] + pub depth: i64, #[serde(default)] pub font: ParagraphFont, #[serde(default)] @@ -346,11 +349,15 @@ impl Paragraph { Vec::new() }; let tail_height = (self.height - head_height).max(1); + let head_depth = line_extent(self.lines.last().map(Vec::as_slice).unwrap_or(&[])).1; + let tail_depth = line_extent(tail_lines.last().map(Vec::as_slice).unwrap_or(&[])).1; self.height = head_height; + self.depth = head_depth; Paragraph { lines: tail_lines, height: tail_height, width: self.width, + depth: tail_depth, font: self.font, left_skip: self.left_skip, line_indents: tail_indents, @@ -411,6 +418,7 @@ pub fn layout_items(items: &[HorizontalItem], style: &ParagraphStyle) -> Paragra lines: Vec::new(), height: 0, width: 0, + depth: 0, font: ParagraphFont::Roman, left_skip: style.left_skip, line_indents: Vec::new(), @@ -1011,11 +1019,13 @@ pub fn layout_items(items: &[HorizontalItem], style: &ParagraphStyle) -> Paragra line_baselines.push(baseline); } } + let depth = extents.last().map_or(0, |(_, descent)| *descent); Paragraph { // The page builder still budgets paragraphs on the line grid; the // baseline table below carries TeX's interline glue for painting. height: lines.len() as i64 * style.line_height, width: max_width, + depth, lines, font: ParagraphFont::Roman, left_skip: style.left_skip, @@ -1421,6 +1431,63 @@ mod tests { assert_ne!(boxes[0].depth, boxes[1].depth); } + #[test] + fn paragraph_depth_is_the_last_line_descent() { + let font = crate::cmr10::Cmr10Metrics::new(); + let style = ParagraphStyle { + line_width: 400 * 65_536, + ..ParagraphStyle::default() + }; + let paragraph = layout_paragraph_with_font("gyp", &style, &font); + assert_eq!(paragraph.lines.len(), 1); + assert_eq!( + paragraph.depth, + font.depth('p').max(font.depth('y')).max(font.depth('g')) + ); + } + + #[test] + fn split_at_keeps_each_part_last_line_descent() { + let boxed = |character: char, depth: i64| { + HorizontalItem::Box(HorizontalBox { + width: 5 * 65_536, + height: 5 * 65_536, + depth, + character: Some(character), + italic: 0, + }) + }; + let items = vec![ + boxed('a', 0), + HorizontalItem::Glue { + width: 65_536, + stretch: 0, + shrink: 5 * 65_536, + order: 0, + }, + boxed('g', 2 * 65_536), + HorizontalItem::Penalty { + width: 0, + penalty: -10_000, + flagged: false, + }, + boxed('x', 0), + ]; + let style = ParagraphStyle { + line_width: 9 * 65_536, + line_height: 12 * 65_536, + ..ParagraphStyle::default() + }; + let mut paragraph = layout_items(&items, &style); + assert_eq!(paragraph.lines.len(), 2); + let tail = paragraph.split_at(1); + assert_eq!(paragraph.depth, 2 * 65_536); + assert_eq!(tail.depth, 0); + assert_eq!(paragraph.height, 12 * 65_536); + assert_eq!(tail.height, 12 * 65_536); + assert_eq!(paragraph.height + tail.height, 24 * 65_536); + } + #[test] fn cmr10_italic_correction_extends_the_line_width() { let font = crate::cmr10::Cmr10Metrics::default(); diff --git a/crates/texrra-tex-core/tests/oracle.rs b/crates/texrra-tex-core/tests/oracle.rs index 28f24b0..82f0c4c 100644 --- a/crates/texrra-tex-core/tests/oracle.rs +++ b/crates/texrra-tex-core/tests/oracle.rs @@ -314,6 +314,8 @@ fn route_pages_text_with( document.top_skip = top_skip_pt * PT; document.par_skip = par_skip * PT; document.text_float_sep = 0; + // LaTeX's default \maxdepth keeps descents out of the page height. + document.max_depth = 5 * PT; Engine::layout(&document) .pages() .iter() @@ -815,6 +817,7 @@ fn pages_respect_stretchy_vertical_glue_like_pdftex() { let mut document = Document::new(550 * PT, units); document.top_skip = 12 * PT; document.text_float_sep = 0; + document.max_depth = 5 * PT; let engine = Engine::layout_paged(&document).expect("paged layout"); let ours: Vec = engine.pages().iter().map(page_alnum_text).collect(); assert_eq!( @@ -986,6 +989,8 @@ fn top_floats_reserve_page_space_like_pdftex() { let mut document = Document::new(550 * PT, units); document.top_skip = 12 * PT; document.text_float_sep = 20 * PT; + // LaTeX's default \maxdepth keeps 5pt of descent out of the page height. + document.max_depth = 5 * PT; let engine = Engine::layout_paged(&document).expect("top floats are page-buildable"); let ours: Vec = engine.pages().iter().map(page_alnum_text).collect(); assert_eq!( @@ -1066,6 +1071,7 @@ fn footnotes_reserve_page_space_like_pdftex() { document.top_skip = 12 * PT; document.text_float_sep = 0; document.insertion_skip = 12 * PT; + document.max_depth = 5 * PT; let engine = Engine::layout_paged(&document).expect("insertions are page-buildable"); let ours: Vec = engine.pages().iter().map(page_alnum_text).collect(); assert_eq!( diff --git a/docs/ROUTE_D_PLAN.md b/docs/ROUTE_D_PLAN.md index e6a1e1a..7284ffa 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`). 454 workspace tests are green and no oracle +PDF opt-in with `?engine=route-d`). 457 workspace tests are green and no oracle fixture is ignored. Known gaps, in dependency order: @@ -287,7 +287,7 @@ limits, float placement, vertical glue setting and glue orders. `Engine::layout_paged` now feeds it every document whose units are single vertical items (`Document::max_depth` supplies `\maxdepth`) and materialises the chosen fragments as hashed pages; ties go to the breakpoint closest to the page -goal, so overfull pages take the least overfull break. `Document::h_offset` and +goal, so overfull pages take the least overfull break. Paragraph nodes carry their last-line descent as depth, so `\pagedepth` reports it and `\maxdepth` only caps the kept part while the excess moves into the page height; route-D applies LaTeX's 5pt `\maxdepth` default at the source layer, and the page fixtures pin it. `Document::h_offset` and `v_offset` feed the PDF writer's `pdf::PageOrigin`, which translates the page body without moving the sheet; a route-D integration fixture checks the shift with `pdftotext -bbox`. `Document::paper_width`/`paper_height` diff --git a/docs/TEX_CORE.md b/docs/TEX_CORE.md index e13eb97..b657fde 100755 --- a/docs/TEX_CORE.md +++ b/docs/TEX_CORE.md @@ -351,7 +351,7 @@ M5 (partial): display-list text carries `FontFace::{Roman,Bold,Italic,BoldItalic M6 (partial): `DisplayItem::Image` becomes a PDF XObject; `DisplayItem::Link` becomes `/Annots /Subtype /Link /URI`; `DisplayItem::Special` injects raw content-stream operators. SVG previews show images as grey rectangles and specials as comments. -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); `Document::max_depth` feeds TeX's `\maxdepth` into the builder, and among equal-cost breakpoints the candidate closest to the page goal wins, so an overfull page takes the least overfull break. Paragraphs also split across pages at line boundaries, so body material no longer overflows a page as one box. 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 +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); `Document::max_depth` feeds TeX's `\maxdepth` into the builder, and among equal-cost breakpoints the candidate closest to the page goal wins, so an overfull page takes the least overfull break. 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. The scrolling builder's float path remains to be ported. The oracle harness also compares whole pages: nine 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) assert the same page count and the same per-page alphanumeric text as pdfLaTeX at 345pt measure, 550pt `\vsize`, 12pt `\topskip` and 15pt `\parindent`. @@ -361,7 +361,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 300 unit tests plus seven route-D integration tests and thirty-two oracle fixtures. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 454 tests (300 route-D unit, 7 route-D integration, 32 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 303 unit tests plus seven route-D integration tests and thirty-two oracle fixtures. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 457 tests (303 route-D unit, 7 route-D integration, 32 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 diff --git a/src/route_d.rs b/src/route_d.rs index d348510..b5960b8 100755 --- a/src/route_d.rs +++ b/src/route_d.rs @@ -855,6 +855,8 @@ fn build_document(paragraphs: &[SourceParagraph], geometry: &PageGeometry) -> Do }) .collect(); let mut document = Document::new(700 * SCALE, units); + // LaTeX sets \maxdepth=.5\topskip; sources may override it later. + document.max_depth = 5 * SCALE; document.page_breaks = paragraphs .iter() .enumerate()