From 3df21201c2487254b46a38b844b3533cdc60ceb6 Mon Sep 17 00:00:00 2001 From: GloamXun Date: Fri, 23 Oct 2026 13:10:40 +0800 Subject: [PATCH] Verify parindent, parshape and skips against pdfLaTeX --- crates/texrra-tex-core/tests/oracle.rs | 85 ++++++++++++++++++++++++++ docs/ROUTE_D_PLAN.md | 2 +- docs/TEX_CORE.md | 4 +- 3 files changed, 88 insertions(+), 3 deletions(-) diff --git a/crates/texrra-tex-core/tests/oracle.rs b/crates/texrra-tex-core/tests/oracle.rs index 2d5bf9d..401ae4a 100644 --- a/crates/texrra-tex-core/tests/oracle.rs +++ b/crates/texrra-tex-core/tests/oracle.rs @@ -355,6 +355,19 @@ fn paragraph_fixture_with(text: &str, width_pt: u32, prefix: &str) -> String { ) } +/// Like `paragraph_fixture_with`, but leaves the first-line indent active so +/// `\parindent` fixtures can exercise it. +fn indented_paragraph_fixture(text: &str, width_pt: u32, prefix: &str) -> String { + format!( + "\\documentclass[10pt]{{article}}\n\ + \\pdfpagewidth=612bp \\pdfpageheight=792bp\n\ + \\pagestyle{{empty}}\n\ + \\begin{{document}}\n\ + \\hsize={width_pt}pt \\parindent=0pt {prefix}{text}\\par\n\ + \\end{{document}}\n" + ) +} + const WORDS: &str = "alpha beta gamma delta epsilon zeta eta theta iota kappa lambda mu"; fn compare_fixture(text: &str, width_pt: u32) { @@ -402,6 +415,21 @@ fn ragged_right_matches_pdftex() { }); } +/// `\leftskip` plus `\rightskip` narrow the measure exactly like pdfLaTeX, +/// so the line breaks and relative word positions must match. +#[test] +fn left_skip_and_right_skip_match_pdftex() { + compare_fixture_with( + WORDS, + 150, + "\\leftskip=20pt \\rightskip=30pt\\relax ", + |style| { + style.left_skip = 20 * PT; + style.right_skip = 30 * PT; + }, + ); +} + /// `\hangindent`/`\hangafter` shift the affected lines and narrow their /// measure exactly like pdfLaTeX. #[test] @@ -452,6 +480,63 @@ fn parfillskip_without_fil_justifies_the_last_line() { assert_lines_match("parfillskip 120pt", &ours, &reference); } +/// `\parindent` only narrows the first line; the break positions must match +/// pdfLaTeX with the indent active. +#[test] +fn par_indent_matches_pdftex() { + let width = 120; + let Some(reference) = pdftex_lines(&indented_paragraph_fixture( + WORDS, + width, + "\\parindent=30pt ", + )) else { + eprintln!("skipping: pdflatex/pdftotext are not installed"); + return; + }; + let ours = route_d_lines_with(WORDS, f64::from(width), |style| { + style.par_indent = 30 * PT; + }); + assert_lines_match("parindent 120pt", &ours, &reference); + assert!(ours.len() >= 3, "fixture must span at least three lines"); +} + +/// `\parshape` gives each line its own indent and measure, repeating the last +/// pair once the list is exhausted. +#[test] +fn par_shape_matches_pdftex() { + let width = 150; + let text = format!("{WORDS} {WORDS}"); + let prefix = "\\parshape=3 0pt 120pt 20pt 100pt 40pt 80pt "; + let Some(reference) = pdftex_lines(¶graph_fixture_with(&text, width, prefix)) else { + eprintln!("skipping: pdflatex/pdftotext are not installed"); + return; + }; + let ours = route_d_lines_with(&text, f64::from(width), |style| { + style.par_shape = vec![(0, 120 * PT), (20 * PT, 100 * PT), (40 * PT, 80 * PT)]; + }); + assert_lines_match("parshape 150pt", &ours, &reference); + assert!(ours.len() >= 5, "fixture must span at least five lines"); + let steps: Vec = ours + .windows(2) + .map(|pair| pair[1].start - pair[0].start) + .collect(); + assert!( + (steps[0] - 20.0).abs() <= 0.1, + "second line starts at {}", + steps[0] + ); + assert!( + (steps[1] - 20.0).abs() <= 0.1, + "third line starts at {}", + steps[1] + ); + assert!( + steps[2].abs() <= 0.1, + "later lines repeat the last indent: {}", + steps[2] + ); +} + /// Sentence punctuation changes the space factor, so the interword glue and /// the resulting line breaks must match pdfLaTeX. #[test] diff --git a/docs/ROUTE_D_PLAN.md b/docs/ROUTE_D_PLAN.md index 5889514..301c512 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`). 410 workspace tests are green and no oracle +PDF opt-in with `?engine=route-d`). 413 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 729c468..7f3fc45 100755 --- a/docs/TEX_CORE.md +++ b/docs/TEX_CORE.md @@ -115,7 +115,7 @@ and justification. | Milestone | Content | Acceptance | | --- | --- | --- | | 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` and vertical-glue fixtures; generic fil glue and `\prevgraf` next | +| 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` and vertical-glue fixtures; generic fil glue and `\prevgraf` next | | 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), insertion class registers `\count`/`\dimen`/`\skip` 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 | | 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 | @@ -346,7 +346,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 282 unit tests plus seven route-D integration tests and nineteen oracle fixtures. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 410 tests (282 route-D unit, 7 route-D integration, 19 oracle, 71 v1 integration, 24 server, 4 v1 unit, 1 core unit, 2 binary units), with none ignored. v1 remains the live server path. +The crate currently has 282 unit tests plus seven route-D integration tests and twenty-two oracle fixtures. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 413 tests (282 route-D unit, 7 route-D integration, 22 oracle, 71 v1 integration, 24 server, 4 v1 unit, 1 core unit, 2 binary units), with none ignored. v1 remains the live server path. ### M0 incremental demo