From 676eb7f32340ed0a66eec59e8f74d5e9409b35d3 Mon Sep 17 00:00:00 2001 From: GloamXun Date: Wed, 28 Oct 2026 08:28:17 +0800 Subject: [PATCH] Keep sum superscripts above the operator Large-operator limits used the ordinary-base superscript gap, which could leave N just below the sum baseline. Use a negative gap for large operators so both limits straddle the operator, and add a unit test asserting the subscript is below and the superscript above the base within 12pt. Test count is 1080. --- crates/texrra-tex-core/src/math.rs | 28 ++++++++++++++++++++++++++++ crates/texrra-tex-core/src/render.rs | 7 ++++++- docs/ROUTE_D_PLAN.md | 2 +- docs/ROUTE_D_STATUS.md | 4 ++-- docs/TEX_CORE.md | 4 ++-- docs/WEB_ROUTE_D_EXPERIMENT.md | 4 ++-- 6 files changed, 41 insertions(+), 8 deletions(-) diff --git a/crates/texrra-tex-core/src/math.rs b/crates/texrra-tex-core/src/math.rs index 6ea3f14..acc2580 100755 --- a/crates/texrra-tex-core/src/math.rs +++ b/crates/texrra-tex-core/src/math.rs @@ -3912,6 +3912,34 @@ mod tagged_equation_tests { assert_eq!(tagged.height, plain.height.max(7 * 65_536)); assert_eq!(tagged.depth, plain.depth.max(2 * 65_536)); } + #[test] + fn display_sum_limits_sit_close_to_the_operator() { + let atom = parse_math(r"\sum_{i=1}^{N}"); + let unit = crate::Unit::math(1, atom, &Cmr10Metrics::default()); + let document = crate::Document::new(700 * 65_536, vec![unit]); + let engine = crate::Engine::layout(&document); + let display = engine.pages()[0].display_list(); + let find = |text: &str| { + display + .items + .iter() + .find_map(|item| match item { + crate::render::DisplayItem::Text { text: value, y, .. } if value == text => { + Some(*y) + } + _ => None, + }) + .unwrap_or_else(|| panic!("no {text} glyph")) + }; + let base = find("∑"); + let sub = find("i"); + let sup = find("N"); + assert!(sub > base, "subscript {sub} above base {base}"); + assert!(sup < base, "superscript {sup} below base {base}"); + let gap = (sub - base) as f64 / 65_536.0; + assert!(gap < 12.0, "sum limit gap {gap} pt"); + } + #[test] fn whitespace_before_a_script_still_attaches() { let atom = parse_math(r"\alpha _{i}"); diff --git a/crates/texrra-tex-core/src/render.rs b/crates/texrra-tex-core/src/render.rs index f37edec..4af613a 100755 --- a/crates/texrra-tex-core/src/render.rs +++ b/crates/texrra-tex-core/src/render.rs @@ -1591,11 +1591,16 @@ impl Page { let small = (size as f64 * 0.7) as i64; if let Some(sup) = sup { let sup_box = math::script_metrics(math::layout_math(sup, font)); + let sup_gap = if Self::large_operator(base) { + -96_993 + } else { + 96_993 + }; Self::paint_math( sup, font, x + (base_box.width - sup_box.width).max(0) / 2, - baseline - base_box.height - sup_box.depth + 96_993, + baseline - base_box.height - sup_box.depth + sup_gap, small, list, ); diff --git a/docs/ROUTE_D_PLAN.md b/docs/ROUTE_D_PLAN.md index c874283..3a31969 100644 --- a/docs/ROUTE_D_PLAN.md +++ b/docs/ROUTE_D_PLAN.md @@ -51,7 +51,7 @@ floats (`\floatsep`, `\textfloatsep`, `\intextsep`, `\topfraction`, 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`; flat `/preview` and project previews now -prefer route-D with a v1 fallback). 1079 workspace tests are green and no oracle +prefer route-D with a v1 fallback). 1080 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/ROUTE_D_STATUS.md b/docs/ROUTE_D_STATUS.md index 0f58700..595b132 100755 --- a/docs/ROUTE_D_STATUS.md +++ b/docs/ROUTE_D_STATUS.md @@ -16,7 +16,7 @@ cargo test --workspace --offline or run `./scripts/verify-route-d.sh`, which executes both. -The workspace currently passes **1079 tests**: +The workspace currently passes **1080 tests**: | Suite | Tests | | --- | --- | @@ -29,7 +29,7 @@ The workspace currently passes **1079 tests**: | engine/core unit | 4 + 1 | Latest full run (web trial increment): `./scripts/verify-route-d.sh` passes -with fmt clean and **1079 tests** green. +with fmt clean and **1080 tests** green. Latest live check (2026-10-27): the debug server served `examples/hello.tex` from `target/debug/texrra serve`; `POST /preview` answered 200 with diff --git a/docs/TEX_CORE.md b/docs/TEX_CORE.md index 89262cb..530c25d 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 448 unit tests plus ten route-D integration tests and forty-two oracle fixtures. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 1079 tests (448 core unit, 436 engine binary unit, 10 route-D integration, 42 oracle, 71 v1 integration, 67 server, 4 engine unit, 1 core unit), with none ignored. The flat `/preview` endpoint and the project preview/PDF endpoints now try route-D first and fall back to v1 on error (`?engine=v1` or `TEXRRA_ENGINE=v1` forces v1; flat and project responses carry `X-Preview-Engine`, naming the engine used). A geometry-less project now defaults to Letter, matching pdfLaTeX, where the old v1 path used A4. +The crate currently has 449 unit tests plus ten route-D integration tests and forty-two oracle fixtures. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 1080 tests (449 core unit, 436 engine binary unit, 10 route-D integration, 42 oracle, 71 v1 integration, 67 server, 4 engine unit, 1 core unit), with none ignored. The flat `/preview` endpoint and the project preview/PDF endpoints now try route-D first and fall back to v1 on error (`?engine=v1` or `TEXRRA_ENGINE=v1` forces v1; flat and project responses carry `X-Preview-Engine`, naming the engine used). A geometry-less project now defaults to Letter, matching pdfLaTeX, where the old v1 path used A4. ### M0 incremental demo @@ -524,7 +524,7 @@ deliberately open rather than approximated: ## Limits and remaining gaps -The suite currently stands at 1079 passing tests, with the workspace clean. +The suite currently stands at 1080 passing tests, with the workspace clean. Route-D serves both flat `/preview` and project preview/PDF requests by default (automatic v1 fallback; `?engine=v1` or `TEXRRA_ENGINE=v1` opts out). The objective's areas are implemented to the limits below; complex-script shaping is diff --git a/docs/WEB_ROUTE_D_EXPERIMENT.md b/docs/WEB_ROUTE_D_EXPERIMENT.md index 4e48fe4..04a3f84 100644 --- a/docs/WEB_ROUTE_D_EXPERIMENT.md +++ b/docs/WEB_ROUTE_D_EXPERIMENT.md @@ -46,7 +46,7 @@ now means route-D. | Area | Route-D | Evidence / impact | | --- | --- | --- | -| Article/report basics: title, sections, lists, TOC, page numbers | Supported | corpus and 1079-test suite | +| Article/report basics: title, sections, lists, TOC, page numbers | Supported | corpus and 1080-test suite | | Inline/display math, equations, tags, cleveref | Supported | math tests, oracle fixtures | | Floats, captions, tables, booktabs | Supported | table/math tests, corpus | | PNG/JPEG/BMP `\includegraphics` | Supported | project image tests; PDF XObjects use pixel dimensions and the SVG preview embeds a PNG data URI | @@ -148,7 +148,7 @@ PDF was rendered page-by-page next to the route-D output. | Citations | natbib author-year `(Kour and Saabne, 2014a; …)` | author-year `(Kour and Saabne, 2014a; Keshet et al., 2016)` for `.bib`; numeric for unlabeled inline bibliographies | | Table | booktabs rules, `Size (µm)`, `~100`, `10^6` | centred with rules; `Size (µm)`, `~100`, `10⁶` | | Figure | framed rule box above the caption | centred framed rule body (raster) on page 3 | -| Display equation | fully typeset fraction/product/sum | approximate body; fraction box uses full extents, sum limits sit close to large operators, subscripts attach even after a space, and the tag is at the right margin | +| Display equation | fully typeset fraction/product/sum | approximate body; fraction box uses full extents, large-operator limits straddle the operator closely, subscripts attach even after a space, and the tag is at the right margin | | References | author-year, italic venue, DOI link | author-year entries; DOI appended when present in the .bib | | Float order | figure/table on page 3 with section 3.4 | figure/table on page 3 above 3.3/3.4 |