diff --git a/crates/texrra-tex-core/tests/route_d.rs b/crates/texrra-tex-core/tests/route_d.rs index 6b3c45a..5f5f6fb 100755 --- a/crates/texrra-tex-core/tests/route_d.rs +++ b/crates/texrra-tex-core/tests/route_d.rs @@ -410,3 +410,78 @@ fn accented_text_round_trips_through_pdf_extraction() { "got {text:?}" ); } + +#[test] +fn route_d_text_matches_pdftex_extraction() { + use std::process::Command; + + fn available(command: &str, arg: &str) -> bool { + Command::new(command) + .arg(arg) + .stdout(std::process::Stdio::null()) + .stderr(std::process::Stdio::null()) + .status() + .is_ok_and(|status| status.success()) + } + if !available("pdflatex", "--version") || !available("pdftotext", "-v") { + return; + } + + fn extract(pdf: &std::path::Path) -> String { + let output = Command::new("pdftotext") + .arg(pdf) + .arg("-") + .output() + .expect("pdftotext"); + String::from_utf8_lossy(&output.stdout) + .split_whitespace() + .collect::>() + .join(" ") + } + + let body = + "The quick brown fox jumps over the lazy dog. Pack my box with five dozen liquor jugs."; + let document = Document::new( + 61, + vec![Unit::paragraph_with_style( + 1, + body, + ParagraphStyle::default(), + )], + ); + let engine = Engine::layout(&document); + let lists: Vec<_> = engine + .pages() + .iter() + .map(|page| page.display_list()) + .collect(); + let route_pdf = std::env::temp_dir().join(format!("texrra-words-{}.pdf", std::process::id())); + std::fs::write(&route_pdf, display_lists_to_pdf(&lists, 792)).expect("write route PDF"); + + let dir = std::env::temp_dir().join(format!("texrra-pdftex-{}", std::process::id())); + let _ = std::fs::remove_dir_all(&dir); + std::fs::create_dir_all(&dir).expect("temp dir"); + let tex = dir.join("control.tex"); + let source = [ + "\\documentclass[10pt]{article}", + "\\pagestyle{empty}", + "\\begin{document}", + "\\noindent ", + body, + "\\end{document}", + ] + .concat(); + std::fs::write(&tex, source).expect("write tex"); + let status = Command::new("pdflatex") + .current_dir(&dir) + .args(["-interaction=nonstopmode", "control.tex"]) + .status() + .expect("pdflatex"); + assert!(status.success(), "pdflatex failed"); + + let route = extract(&route_pdf); + let control = extract(&dir.join("control.pdf")); + let _ = std::fs::remove_file(&route_pdf); + let _ = std::fs::remove_dir_all(&dir); + assert_eq!(route, control); +} diff --git a/docs/TEX_CORE.md b/docs/TEX_CORE.md index d4d9071..bac3f42 100755 --- a/docs/TEX_CORE.md +++ b/docs/TEX_CORE.md @@ -270,7 +270,7 @@ M3 (partial): `Unit::halign` normalizes column widths, intercolumn gaps, row hei Math coverage includes fractions/roots, scripts, `\left...\right` with body-scaled delimiters, `\middle`, `\big`/`\Big`/`\bigg`/`\Bigg` and their `l`/`r` forms, control-sequence delimiters, accents (dot/check/breve/acute/grave/ring), `\text`/`\mathrm`, `\overbrace`/`\underbrace`, `\overset`/`\underset`, `\binom`, `\cancel`/`\bcancel`/`\xcancel`, `\bmod`/`\pmod`, fence symbols, `\operatorname*` and `\mathop` limits. -The crate currently has 165 unit tests plus four route-D integration tests. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 261 tests (165 route-D unit, 4 route-D integration, 71 v1 integration, 19 server, 4 v1 unit, 1 core unit, 2 binary units). v1 remains the live server path. +The crate currently has 165 unit tests plus five route-D integration tests. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 262 tests (165 route-D unit, 5 route-D integration, 71 v1 integration, 19 server, 4 v1 unit, 1 core unit, 2 binary units). v1 remains the live server path. ### M0 incremental demo