From 56faec60462eff833a24aa6801f00d940750ab5c Mon Sep 17 00:00:00 2001 From: GloamXun Date: Mon, 26 Oct 2026 23:37:14 +0800 Subject: [PATCH] Split colour, link and sized runs at any base size inline_math_segments returned None for every paragraph whose base size was not 10pt, so a 12pt or \Large paragraph kept \textcolor/\href/\textsuperscript delimiters as literal text. Only inline math actually depends on the 10pt metric baseline: build the segments at any size and fall back to literal delimiters only when a math segment is present and the size differs. The existing sized-href test moves from "href is stripped but not linked" to "the sized run keeps its link", and a new 12pt test covers a red run, a link and a superscript in one paragraph with no warnings. --- docs/ROUTE_D_PLAN.md | 2 +- docs/TEX_CORE.md | 7 ++++--- src/route_d.rs | 40 ++++++++++++++++++++++++++++++++++------ 3 files changed, 39 insertions(+), 10 deletions(-) diff --git a/docs/ROUTE_D_PLAN.md b/docs/ROUTE_D_PLAN.md index 66ebd2a..f8890b7 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`). 979 workspace tests are green and no oracle +PDF opt-in with `?engine=route-d`). 980 workspace tests are green and no oracle fixture is ignored. Preview JSON also carries a `warnings` array naming environments route-D cannot lay out and control words that survived layout, so unsupported source is reported instead of being silently typeset. diff --git a/docs/TEX_CORE.md b/docs/TEX_CORE.md index 89c480f..c0d6196 100755 --- a/docs/TEX_CORE.md +++ b/docs/TEX_CORE.md @@ -370,7 +370,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`, `cmssbx10`, `cmssi10`, `cmcsc10`) supplies advances, kerns, ligatures, and italic correction for layout, the display list selects the matching face, and the PDF writes Computer Modern Type1 outlines for each built-in face (`cmr10`/`cmbx10`/`cmti10`/`cmbxti10`/`cmtt10`/`cmss10`/`cmssbx10`/`cmssi10`/`cmcsc10`, plus `cmmi10` for mathematical italic letters, `cmsy10` for math symbols and `cmex10` for big operators), falling back to Liberation subsets only for characters the Type1 encodings cannot address; those fallback glyphs keep their Unicode text under PDF extraction, so accented and Greek words round-trip; Type1 faces carry a ToUnicode CMap built from the requested characters, so glyphs whose names are ambiguous in the Adobe Glyph List (capital Omega, which would otherwise extract as U+2126) keep their intended code points. `Engine::edit` preserves the face when reflowing an edited paragraph. -The crate currently has 434 unit tests plus ten route-D integration tests and forty-two oracle fixtures. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 979 tests (434 route-D unit, 357 engine binary unit, 10 route-D integration, 42 oracle, 71 v1 integration, 60 server, 4 engine unit, 1 core unit), with none ignored. v1 remains the live server path. +The crate currently has 434 unit tests plus ten route-D integration tests and forty-two oracle fixtures. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 980 tests (434 route-D unit, 358 engine binary unit, 10 route-D integration, 42 oracle, 71 v1 integration, 60 server, 4 engine unit, 1 core unit), with none ignored. v1 remains the live server path. ### M0 incremental demo @@ -539,5 +539,6 @@ honest open items against the "feature-complete LaTeX compiler" objective are: as Type1 with per-glyph Liberation fallback; arbitrary NFSS families, font subsetting and broad Unicode coverage (including more than the current Greek fallback) remain open. -- **Inline runs**: colour/link/size segments are only split for 10pt - paragraphs; larger base sizes keep the delimiters literal. +- **Inline runs**: colour/link/sized runs split at any base size; inline math + still falls back to literal delimiters when the paragraph's base size is not + 10pt, because math metrics are measured at 10pt. diff --git a/src/route_d.rs b/src/route_d.rs index 0263713..767e0c7 100755 --- a/src/route_d.rs +++ b/src/route_d.rs @@ -8272,9 +8272,6 @@ fn inline_math_segments( custom: &[(String, [u8; 3])], link_color: Option<[u8; 3]>, ) -> Option> { - if style.font_size != 655_360 { - return None; - } let mut segments = Vec::new(); let mut found_math = false; let mut found_link = false; @@ -8347,6 +8344,13 @@ fn inline_math_segments( } } } + // Math metrics are laid out at 10pt, so a paragraph that mixes math with + // another base size keeps its literal delimiters instead of painting the + // formula at the wrong size. Colour, link and sized runs are safe at any + // base size. + if found_math && style.font_size != 655_360 { + return None; + } (found_math || found_link || found_size || found_color).then_some(segments) } @@ -14263,6 +14267,30 @@ A definition. assert_eq!(document.widow_penalty, 88); } + #[test] + fn inline_colours_and_links_work_at_twelve_point() { + let source = "\\documentclass[12pt]{article}\n\\begin{document}\n\nA \\textcolor{red}{red word} and a \\href{https://example.com}{link} and x\\textsuperscript{2}.\n\n\\end{document}\n"; + let json = preview_json(source).expect("preview"); + let value: serde_json::Value = serde_json::from_str(&json).expect("JSON"); + assert_eq!(value["status"], "ok"); + let svg = value["pages"][0]["svg"].as_str().expect("svg"); + let text: String = svg + .split('>') + .filter_map(|piece| piece.split('<').next()) + .collect::() + .split_whitespace() + .collect(); + assert!(!text.contains("textcolor"), "colour command leaked: {text}"); + assert!(!text.contains("href"), "link command leaked: {text}"); + assert!(text.contains("redword"), "coloured text missing: {text}"); + assert!(text.contains("link"), "link label missing: {text}"); + assert!( + value["warnings"].as_array().is_some_and(Vec::is_empty), + "{}", + value["warnings"] + ); + } + #[test] fn display_math_uses_article_display_skips() { let source = "\\documentclass{article}\n\\begin{document}\n\nBefore.\n\n\\[ x \\]\n\nAfter.\n\n\\end{document}\n"; @@ -15168,7 +15196,7 @@ A definition. } #[test] - fn sized_paragraphs_strip_href_commands() { + fn sized_paragraphs_link_href_commands() { let source = "\\Large Visit \\href{https://example.com}{the site}."; let blocks = paragraphs(source).expect("paragraphs"); let document = build_document(&blocks, &PageGeometry::default()); @@ -15194,8 +15222,8 @@ A definition. } } } - assert_eq!(linked, 0); - assert_eq!(backslashes, 0); + assert!(linked > 0, "sized runs must keep their link"); + assert_eq!(backslashes, 0, "href delimiters leaked"); } #[test]