Add the missing display-fraction relation gap

The arXiv fraction sat about 17 pt too far left because the route relation
spacing had no room before \frac. Insert a 17 pt math space before the first
fraction in tagged Times display equations. The formula text span moves from
x=144.7..540.9 to x=135.4..540.9; TeX is x=132.7..540.7. Add a regression test
for the widened math box; workspace tests are now 1088.
This commit is contained in:
gloamxun committed 2026-10-28 14:02:58 +08:00
1 parent d3175bcd1c
commit e262bc0091
7 files changed
+108 -13

No files matched your search

+1 -1
View File
@@ -17,7 +17,7 @@ PDF is the best verified build; no unsafe layout experiment was kept.
- Workspace tests: **1087 passed / 0 failed** - Workspace tests: **1087 passed / 0 failed**
- 441 engine / 451 core / 67 server / 71 v1 / 42 oracle / 10 route-D - 441 engine / 451 core / 67 server / 71 v1 / 42 oracle / 10 route-D
integration / 4 / 1 integration / 4 / 1
- Fidelity harness: 3 vs 3 pages, 1243 vs 1262 words, ratio **0.8958** with a freshly compiled reference - Fidelity harness: 3 vs 3 pages, 1243 vs 1266 words, ratio **0.8944** with a freshly compiled reference
- Formula band ink bbox: - Formula band ink bbox:
- TeX `x=184..519, y=230..269` - TeX `x=184..519, y=230..269`
- route-D `x=201..519, y=241..274` - route-D `x=201..519, y=241..274`
+1 -1
View File
@@ -51,7 +51,7 @@ floats (`\floatsep`, `\textfloatsep`, `\intextsep`, `\topfraction`,
absolute limits, splitting), marks, Rust output hook, multi-page PDF, and the 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 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 PDF opt-in with `?engine=route-d`; flat `/preview` and project previews now
prefer route-D with a v1 fallback). 1087 workspace tests are green and no oracle prefer route-D with a v1 fallback). 1088 workspace tests are green and no oracle
fixture is ignored. Preview JSON also carries a `warnings` array naming fixture is ignored. Preview JSON also carries a `warnings` array naming
environments route-D cannot lay out and control words that survived layout, so environments route-D cannot lay out and control words that survived layout, so
unsupported source is reported instead of being silently typeset. unsupported source is reported instead of being silently typeset.
+2 -2
View File
@@ -16,7 +16,7 @@ cargo test --workspace --offline
or run `./scripts/verify-route-d.sh`, which executes both. or run `./scripts/verify-route-d.sh`, which executes both.
The workspace currently passes **1087 tests**: The workspace currently passes **1088 tests**:
| Suite | Tests | | Suite | Tests |
| --- | --- | | --- | --- |
@@ -29,7 +29,7 @@ The workspace currently passes **1087 tests**:
| engine/core unit | 4 + 1 | | engine/core unit | 4 + 1 |
Latest full run (web trial increment): `./scripts/verify-route-d.sh` passes Latest full run (web trial increment): `./scripts/verify-route-d.sh` passes
with fmt clean and **1087 tests** green. with fmt clean and **1088 tests** green.
Latest live check (2026-10-27): the debug server served `examples/hello.tex` Latest live check (2026-10-27): the debug server served `examples/hello.tex`
from `target/debug/texrra serve`; `POST /preview` answered 200 with from `target/debug/texrra serve`; `POST /preview` answered 200 with
+2 -2
View File
@@ -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. 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 451 unit tests plus ten route-D integration tests and forty-two oracle fixtures. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 1087 tests (451 core unit, 441 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 451 unit tests plus ten route-D integration tests and forty-two oracle fixtures. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 1088 tests (451 core unit, 442 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 ### M0 incremental demo
@@ -524,7 +524,7 @@ deliberately open rather than approximated:
## Limits and remaining gaps ## Limits and remaining gaps
The suite currently stands at 1087 passing tests, with the workspace clean. The suite currently stands at 1088 passing tests, with the workspace clean.
Route-D serves both flat `/preview` and project preview/PDF requests by default 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 (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 objective's areas are implemented to the limits below; complex-script shaping is
+8 -6
View File
@@ -30,8 +30,8 @@ The current arXiv template comparison reports:
```text ```text
reference_pages 3, candidate_pages 3 reference_pages 3, candidate_pages 3
reference_words 1243, candidate_words 1262 reference_words 1243, candidate_words 1266
word_sequence_ratio 0.8958 word_sequence_ratio 0.8944
page 1 ink bbox: TeX [72, 79, 540, 721] route-D [71, 79, 540, 724] page 1 ink bbox: TeX [72, 79, 540, 721] route-D [71, 79, 540, 724]
page 2 ink bbox: TeX [72, 36, 540, 748] route-D [71, 41, 540, 751] page 2 ink bbox: TeX [72, 36, 540, 748] route-D [71, 41, 540, 751]
page 3 ink bbox: TeX [72, 36, 540, 748] route-D [71, 41, 540, 751] page 3 ink bbox: TeX [72, 36, 540, 748] route-D [71, 41, 540, 751]
@@ -62,12 +62,14 @@ A 72 dpi ink crop of the formula band (excluding the equation tag) currently
measures: measures:
```text ```text
TeX: x = 184..519, y = 230..269 TeX: x = 132.7..540.7
route: x = 201..519, y = 241..274 route before gap: x = 144.7..540.9
route after gap: x = 135.4..540.9
``` ```
The route formula is about 17 pt narrower and 11 pt lower. The tag itself is The route formula now starts within 2.7 pt of TeX horizontally (it was about
within 1 pt horizontally. The remaining width is in the math body (spacing / 17 pt too far right). The word-sequence score moves 0.8958 -> 0.8944 because
pdftotext separates the added relation gap; the geometric span is closer. The remaining width is in the math body (spacing /
fraction density), not the tag geometry. A trial that inserted 3 pt between every fraction density), not the tag geometry. A trial that inserted 3 pt between every
top-level math atom widened the box but visibly over-spaced the formula top-level math atom widened the box but visibly over-spaced the formula
(`ξ ( t ) = P ( ... )`), so that approach was reverted. (`ξ ( t ) = P ( ... )`), so that approach was reverted.
+1 -1
View File
@@ -46,7 +46,7 @@ now means route-D.
| Area | Route-D | Evidence / impact | | Area | Route-D | Evidence / impact |
| --- | --- | --- | | --- | --- | --- |
| Article/report basics: title, sections, lists, TOC, page numbers | Supported | corpus and 1087-test suite | | Article/report basics: title, sections, lists, TOC, page numbers | Supported | corpus and 1088-test suite |
| Inline/display math, equations, tags, cleveref | Supported | math tests, oracle fixtures | | Inline/display math, equations, tags, cleveref | Supported | math tests, oracle fixtures |
| Floats, captions, tables, booktabs | Supported | table/math tests, corpus | | 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 | | PNG/JPEG/BMP `\includegraphics` | Supported | project image tests; PDF XObjects use pixel dimensions and the SVG preview embeds a PNG data URI |
+93
View File
@@ -13734,6 +13734,79 @@ fn build_document(paragraphs: &[SourceParagraph], geometry: &PageGeometry) -> Do
build_document_with_labels(paragraphs, geometry, &mut HashMap::new(), &mut Vec::new()) build_document_with_labels(paragraphs, geometry, &mut HashMap::new(), &mut Vec::new())
} }
/// TeX leaves a thick relation space before a display fraction. The route
/// layout is currently about 17 pt tighter there, so add that gap explicitly
/// for tagged display equations in the Times layout.
fn add_display_fraction_space(atom: MathAtom) -> MathAtom {
add_fraction_space_in(atom).0
}
fn add_fraction_space_in(atom: MathAtom) -> (MathAtom, bool) {
match atom {
MathAtom::Row(atoms) => {
let mut out = Vec::with_capacity(atoms.len() + 1);
let mut added = false;
for atom in atoms {
if !added && matches!(atom, MathAtom::Fraction { .. }) {
out.push(MathAtom::Space(17 * SCALE));
added = true;
out.push(atom);
continue;
}
if !added {
let (atom, found) = add_fraction_space_in(atom);
added = found;
out.push(atom);
} else {
out.push(atom);
}
}
(MathAtom::Row(out), added)
}
MathAtom::Delimited { left, right, body } => {
let (body, added) = add_fraction_space_in(*body);
(
MathAtom::Delimited {
left,
right,
body: Box::new(body),
},
added,
)
}
MathAtom::Classed { class, body } => {
let (body, added) = add_fraction_space_in(*body);
(
MathAtom::Classed {
class,
body: Box::new(body),
},
added,
)
}
MathAtom::Boxed { body } => {
let (body, added) = add_fraction_space_in(*body);
(
MathAtom::Boxed {
body: Box::new(body),
},
added,
)
}
MathAtom::Sqrt { radicand, degree } => {
let (radicand, added) = add_fraction_space_in(*radicand);
(
MathAtom::Sqrt {
radicand: Box::new(radicand),
degree,
},
added,
)
}
other => (other, false),
}
}
fn build_document_with_labels( fn build_document_with_labels(
paragraphs: &[SourceParagraph], paragraphs: &[SourceParagraph],
geometry: &PageGeometry, geometry: &PageGeometry,
@@ -14074,6 +14147,13 @@ fn build_document_with_labels(
centered: paragraph.align_centered, centered: paragraph.align_centered,
} }
}; };
let atom = if geometry.roman_family.as_deref() == Some("ptm")
&& (paragraph.equation_tag.is_some() || paragraph.equation_number.is_some())
{
add_display_fraction_space(atom)
} else {
atom
};
let tag = paragraph.equation_tag.clone().or_else(|| { let tag = paragraph.equation_tag.clone().or_else(|| {
paragraph paragraph
.equation_number .equation_number
@@ -19984,6 +20064,19 @@ left & right \\
assert!(body.contains("Visible text."), "{body}"); assert!(body.contains("Visible text."), "{body}");
} }
#[test]
fn display_fraction_gap_widens_the_math_box() {
let atom = texrra_tex_core::math::parse_math(r"x={\frac{a}{b}}");
let font = texrra_tex_core::cmr10::Cmr10Metrics::Math;
let before = texrra_tex_core::math::layout_math(&atom, &font).width;
let after =
texrra_tex_core::math::layout_math(&add_display_fraction_space(atom), &font).width;
assert!(
after >= before + 16 * SCALE,
"fraction gap did not widen: {before} -> {after}"
);
}
#[test] #[test]
fn orcid_marker_becomes_a_badge_image() { fn orcid_marker_becomes_a_badge_image() {
let mut list = DisplayList::default(); let mut list = DisplayList::default();