Compare commits
17
Commits
c6743e2f9e
...
91f9d76b16
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
91f9d76b16 | ||
|
|
e1ae10f2ce | ||
|
|
bf4e758fba | ||
|
|
e34558efb8 | ||
|
|
96b40c1c2e | ||
|
|
a9f3cab8dc | ||
|
|
828b9716a1 | ||
|
|
a89277fe1a | ||
|
|
7cd221e7a9 | ||
|
|
59308eb01a | ||
|
|
eabebfa687 | ||
|
|
13b85b542a | ||
|
|
16a795bca2 | ||
|
|
2c81e7cb44 | ||
|
|
9efd2b61be | ||
|
|
01b3f518cb | ||
|
|
8fef7df187 |
No files matched your search
@@ -7758,6 +7758,7 @@ mod tests {
|
||||
left_skip: 0,
|
||||
line_indents: vec![0; 10],
|
||||
line_baselines: (0..10).map(|line| 8 + line * 10).collect(),
|
||||
line_scales: Vec::new(),
|
||||
centered: false,
|
||||
right_aligned: false,
|
||||
};
|
||||
@@ -9468,6 +9469,7 @@ b & 2 \\
|
||||
left_skip: 0,
|
||||
line_indents: vec![0],
|
||||
line_baselines: vec![8 * 65_536],
|
||||
line_scales: Vec::new(),
|
||||
centered: false,
|
||||
right_aligned: false,
|
||||
};
|
||||
|
||||
@@ -136,6 +136,11 @@ fn default_font_size() -> i64 {
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct ParagraphStyle {
|
||||
pub line_width: i64,
|
||||
/// Bounded line expansion in thousandths, microtype-like. A line may be
|
||||
/// broken up to `line_width * (1000 + line_expansion) / 1000` and is
|
||||
/// compressed back to the real measure when painted.
|
||||
#[serde(default)]
|
||||
pub line_expansion: i64,
|
||||
/// Left skip inserted before every line (`\leftskip`).
|
||||
pub left_skip: i64,
|
||||
/// Right skip reserved at the end of every line (`\rightskip`).
|
||||
@@ -299,16 +304,22 @@ impl ParagraphStyle {
|
||||
}
|
||||
}
|
||||
|
||||
fn line_target(&self, line: usize) -> i64 {
|
||||
pub fn line_measure(&self, line: usize) -> i64 {
|
||||
let (_, width) = self.line_geometry(line);
|
||||
(width - self.left_skip - self.right_skip).max(1) - self.par_indent_for(line)
|
||||
}
|
||||
|
||||
fn line_target(&self, line: usize) -> i64 {
|
||||
let measure = self.line_measure(line);
|
||||
(measure * (1000 + self.line_expansion) / 1000).max(measure)
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for ParagraphStyle {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
line_width: 400,
|
||||
line_expansion: 0,
|
||||
left_skip: 0,
|
||||
right_skip: 0,
|
||||
hang_indent: 0,
|
||||
@@ -559,6 +570,10 @@ pub struct Paragraph {
|
||||
/// Baseline of each line relative to the top of the paragraph box.
|
||||
#[serde(default)]
|
||||
pub line_baselines: Vec<i64>,
|
||||
/// Horizontal compression per line (thousandths), used by the bounded
|
||||
/// expansion model when a line was broken against an expanded measure.
|
||||
#[serde(default)]
|
||||
pub line_scales: Vec<i64>,
|
||||
#[serde(default)]
|
||||
pub centered: bool,
|
||||
#[serde(default)]
|
||||
@@ -597,6 +612,11 @@ impl Paragraph {
|
||||
let tail_depth = line_extent(tail_lines.last().map(Vec::as_slice).unwrap_or(&[])).1;
|
||||
self.height = head_height;
|
||||
self.depth = head_depth;
|
||||
let tail_scales = if self.line_scales.len() > lines {
|
||||
self.line_scales.split_off(lines)
|
||||
} else {
|
||||
Vec::new()
|
||||
};
|
||||
Paragraph {
|
||||
lines: tail_lines,
|
||||
height: tail_height,
|
||||
@@ -607,6 +627,7 @@ impl Paragraph {
|
||||
left_skip: self.left_skip,
|
||||
line_indents: tail_indents,
|
||||
line_baselines: tail_baselines,
|
||||
line_scales: tail_scales,
|
||||
centered: self.centered,
|
||||
right_aligned: self.right_aligned,
|
||||
}
|
||||
@@ -778,6 +799,7 @@ pub fn layout_items(items: &[HorizontalItem], style: &ParagraphStyle) -> Paragra
|
||||
left_skip: style.left_skip,
|
||||
line_indents: Vec::new(),
|
||||
line_baselines: Vec::new(),
|
||||
line_scales: Vec::new(),
|
||||
centered: style.centered,
|
||||
right_aligned: style.right_aligned,
|
||||
};
|
||||
@@ -1436,6 +1458,27 @@ pub fn layout_items(items: &[HorizontalItem], style: &ParagraphStyle) -> Paragra
|
||||
}
|
||||
}
|
||||
let depth = extents.last().map_or(0, |(_, descent)| *descent);
|
||||
let line_scales: Vec<i64> = lines
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(index, line)| {
|
||||
let actual = style.line_measure(index).max(1);
|
||||
let natural: i64 = line
|
||||
.iter()
|
||||
.map(|item| match item {
|
||||
HorizontalItem::Box(box_item) => box_item.width,
|
||||
HorizontalItem::Glue { width, .. } => *width,
|
||||
HorizontalItem::Penalty { width, .. } => *width,
|
||||
HorizontalItem::Discretionary { .. } => 0,
|
||||
})
|
||||
.sum();
|
||||
if natural > actual {
|
||||
(actual * 1000 / natural).clamp(900, 1000)
|
||||
} else {
|
||||
1000
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
Paragraph {
|
||||
// The page builder still budgets paragraphs on the line grid; the
|
||||
// baseline table below carries TeX's interline glue for painting.
|
||||
@@ -1452,6 +1495,7 @@ pub fn layout_items(items: &[HorizontalItem], style: &ParagraphStyle) -> Paragra
|
||||
left_skip: style.left_skip,
|
||||
line_indents,
|
||||
line_baselines,
|
||||
line_scales,
|
||||
centered: style.centered,
|
||||
right_aligned: style.right_aligned,
|
||||
}
|
||||
@@ -2142,6 +2186,37 @@ mod tests {
|
||||
.count()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bounded_expansion_records_per_line_scales() {
|
||||
let text = "alpha beta gamma delta epsilon zeta eta theta iota kappa lambda mu";
|
||||
let base = ParagraphStyle {
|
||||
line_width: 180,
|
||||
..ParagraphStyle::default()
|
||||
};
|
||||
let expanded = ParagraphStyle {
|
||||
line_width: 180,
|
||||
line_expansion: 30,
|
||||
..ParagraphStyle::default()
|
||||
};
|
||||
let plain = layout_paragraph(text, &base);
|
||||
let stretched = layout_paragraph(text, &expanded);
|
||||
assert!(stretched.lines.len() <= plain.lines.len());
|
||||
assert_eq!(stretched.line_scales.len(), stretched.lines.len());
|
||||
assert!(
|
||||
stretched
|
||||
.line_scales
|
||||
.iter()
|
||||
.all(|scale| (900..=1000).contains(scale)),
|
||||
"{:?}",
|
||||
stretched.line_scales
|
||||
);
|
||||
assert!(
|
||||
stretched.line_scales.iter().any(|scale| *scale < 1000),
|
||||
"no line was compressed: {:?}",
|
||||
stretched.line_scales
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn font_size_scales_glyphs_and_line_spacing() {
|
||||
let font = crate::cmr10::Cmr10Metrics::Roman;
|
||||
|
||||
@@ -1613,7 +1613,7 @@ impl Page {
|
||||
x + (base_box.width - sub_box.width).max(0) / 2,
|
||||
baseline
|
||||
+ if Self::large_operator(base) {
|
||||
0
|
||||
-4 * 65_536
|
||||
} else {
|
||||
math::intrinsic_depth(base, font)
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ use texrra_tex_core::{
|
||||
fn body_style() -> ParagraphStyle {
|
||||
let font = Cmr10Metrics::default();
|
||||
ParagraphStyle {
|
||||
line_expansion: 0,
|
||||
font_size: 10 * 65_536,
|
||||
line_width: 480 * 65_536,
|
||||
left_skip: 0,
|
||||
@@ -214,6 +215,7 @@ fn route_d_page_matches_pdftex_raster_geometry() {
|
||||
std::fs::create_dir_all(&root).expect("create raster dir");
|
||||
|
||||
let style = ParagraphStyle {
|
||||
line_expansion: 0,
|
||||
font_size: 10 * 65_536,
|
||||
line_width: 480 * 65_536,
|
||||
left_skip: 0,
|
||||
@@ -395,6 +397,7 @@ fn route_d_two_pages_match_pdftex_raster_geometry() {
|
||||
std::fs::create_dir_all(&root).expect("create raster dir");
|
||||
|
||||
let style = ParagraphStyle {
|
||||
line_expansion: 0,
|
||||
font_size: 10 * 65_536,
|
||||
line_width: 480 * 65_536,
|
||||
left_skip: 0,
|
||||
@@ -791,6 +794,7 @@ fn route_d_multiline_bands_track_pdftex() {
|
||||
let text = "alpha beta gamma delta epsilon zeta eta theta iota kappa lambda mu";
|
||||
|
||||
let style = ParagraphStyle {
|
||||
line_expansion: 0,
|
||||
font_size: 10 * 65_536,
|
||||
line_width: 150 * 65_536,
|
||||
left_skip: 0,
|
||||
|
||||
@@ -1,60 +1,32 @@
|
||||
# Route-D 59-round acceptance snapshot
|
||||
# Route-D scoped acceptance
|
||||
|
||||
## Verified build
|
||||
|
||||
- Engine `d28e21e`
|
||||
- Web `e14b7aa`
|
||||
- Workspace tests: **1089 passed / 0 failed**
|
||||
- Fidelity against a freshly compiled fixture: 3 vs 3 pages, 1243 vs 1266
|
||||
words, ratio **0.8944**
|
||||
- Warm arXiv preview: **32–50 ms** in the final run (17.7–21.8 ms in an
|
||||
earlier run); cold start 173–500 ms depending on cache state
|
||||
- Page ink bboxes:
|
||||
- page 1: `[71,79,540,724]` vs `[72,79,540,721]`
|
||||
- page 2: `[71,41,540,751]` vs `[72,36,540,748]`
|
||||
- page 3: `[71,41,540,751]` vs `[72,36,540,748]`
|
||||
- Workspace tests: **1094 passed / 0 failed**
|
||||
- Fidelity against a freshly compiled fixture: 3 vs 3 pages, 1243 vs 1264
|
||||
words, ratio **0.8999**
|
||||
- Warm arXiv preview: 19–21 ms; cold 64 ms
|
||||
- 2.1 paragraph: six lines
|
||||
- 3.3 Tables: page 2 (heading, body, booktabs URL)
|
||||
- figure/table floats: page 3
|
||||
- 3.4 Lists and References: page 3
|
||||
- article-basic raster hash unchanged after the Times page-flow changes
|
||||
|
||||
## Objective status
|
||||
|
||||
### 1. Display-math geometry — partial
|
||||
|
||||
- Equation tag: route `y=175.49`, TeX `174.90`, horizontal `x=528.1`.
|
||||
- Formula text span: route `135.4..540.9`, TeX `132.7..540.7` after the
|
||||
17 pt relation gap before `\frac`.
|
||||
- CMMI/CMSY Type1 math is embedded even in TrueType Times PDFs.
|
||||
- Still approximate: internal fraction density, script/limit vertical spacing,
|
||||
and the formula body's lower edge.
|
||||
|
||||
### 2. ORCID icon — done as a generated badge
|
||||
|
||||
- 32x32 green badge with white `iD`, PDF XObject plus SVG data URI.
|
||||
- Two badges appear in the author block.
|
||||
- Not the original ORCID vector logo.
|
||||
|
||||
### 3. Float/page placement — partial
|
||||
|
||||
- Times table column metrics fixed; page-3 right edge is 540.
|
||||
- `3.3 Tables` remains on page 3 while the reference has it at the bottom of
|
||||
page 2.
|
||||
- 2.1 remains seven lines vs six.
|
||||
- Page 2 body still gains about one line from the absence of `microtype`
|
||||
expansion. Baseline/heading-space experiments reduced the offset but did not
|
||||
move 3.3 and were reverted.
|
||||
|
||||
## Commits worth keeping
|
||||
## Formula
|
||||
|
||||
```text
|
||||
e262bc0 Add the missing display-fraction relation gap
|
||||
d28e21e Use arxiv.sty display skips in Times math
|
||||
049365d Use Times metrics for table column widths
|
||||
ba61faf Format BibTeX entries like unsrtnat
|
||||
c742e21 Render ORCID markers as badge images
|
||||
b7a8637 Compile a trustworthy TeX reference for fidelity checks
|
||||
route: x=135.4..540.9, y=170.3..191.5
|
||||
TeX: x=132.7..540.7, y=170.3..188.5
|
||||
```
|
||||
|
||||
## Recommendation
|
||||
Large-operator lower limits were raised 4 pt, removing most of the vertical
|
||||
overshoot without colliding with the fraction rule. Residual: the fraction rule
|
||||
is still about 31 pt shorter than TeX (horizontal density); the denominator is
|
||||
still 3 pt deeper.
|
||||
|
||||
The next goal should not keep tuning vertical glue. It should implement a
|
||||
bounded text-expansion model (microtype-like) or accept the page-flow residual.
|
||||
The current build is the best verified version and should be the acceptance
|
||||
baseline.
|
||||
## Residual scope
|
||||
|
||||
- ORCID is a generated badge, not the original vector logo.
|
||||
- Times top floats are deferred to the unit-stream end: a scoped arXiv policy,
|
||||
not a full TeX float algorithm.
|
||||
- Formula fraction internal width remains approximate.
|
||||
@@ -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). 1089 workspace tests are green and no oracle
|
||||
prefer route-D with a v1 fallback). 1094 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.
|
||||
|
||||
@@ -16,7 +16,7 @@ cargo test --workspace --offline
|
||||
|
||||
or run `./scripts/verify-route-d.sh`, which executes both.
|
||||
|
||||
The workspace currently passes **1089 tests**:
|
||||
The workspace currently passes **1094 tests**:
|
||||
|
||||
| Suite | Tests |
|
||||
| --- | --- |
|
||||
@@ -29,7 +29,7 @@ The workspace currently passes **1089 tests**:
|
||||
| engine/core unit | 4 + 1 |
|
||||
|
||||
Latest full run (web trial increment): `./scripts/verify-route-d.sh` passes
|
||||
with fmt clean and **1089 tests** green.
|
||||
with fmt clean and **1094 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
|
||||
|
||||
Executable
+283
@@ -0,0 +1,283 @@
|
||||
# Scoped route-D fidelity goal
|
||||
|
||||
Start baseline: engine `c6743e2`, 1089 tests, fidelity 0.8944 against
|
||||
`/tmp/texrra-arxiv-reference/template.pdf` (freshly compiled), warm preview
|
||||
32–50 ms.
|
||||
|
||||
## Scope
|
||||
|
||||
1. **Page 2/3 flow** — implement a bounded microtype-like text-width
|
||||
expansion/line-fit model for Times body text so 2.1 is six lines and
|
||||
`3.3 Tables` returns to the bottom of page 2.
|
||||
2. **Display-math internal geometry** — fraction density and sum/script
|
||||
vertical spacing, checked with the arXiv equation bbox.
|
||||
3. **Float placement** — verify the arXiv and article samples without
|
||||
regressing the Times table column fix.
|
||||
|
||||
## Acceptance
|
||||
|
||||
- 2.1 paragraph: six lines.
|
||||
- `3.3 Tables` on page 2.
|
||||
- Page ink bbox no regression; page 3 right edge 540.
|
||||
- Formula tag `y≈174.9`, formula text span close to `x=132.7..540.7`.
|
||||
- At least 1089 tests; warm arXiv preview under 100 ms.
|
||||
- Fresh TeX-vs-route comparison and fidelity score in the final report.
|
||||
|
||||
## Rejected approaches
|
||||
|
||||
- Vertical glue/space_before swaps: moved sections but never fit 3.3 and
|
||||
lowered the fidelity score.
|
||||
- Uniform 1%/3% body font shrink (9.9/9.7 pt): 3.3 stayed on page 3.
|
||||
- Uniform 3 pt spaces between every top-level math atom: visually over-spaced.
|
||||
|
||||
## Planned model
|
||||
|
||||
A line-level bounded expansion model: allow a small, symmetric glyph-width
|
||||
expansion window during line breaking (microtype-like), record the chosen
|
||||
expansion per line, and apply the same factor when painting PDF/SVG text. This
|
||||
keeps line targets and glyph advances consistent instead of adding overflow or
|
||||
collapsing interword glue.
|
||||
|
||||
|
||||
## First result
|
||||
|
||||
- Added `ParagraphStyle.line_expansion` (thousandths), per-line `line_scales`
|
||||
on `Paragraph`, and renderer x-advance compression.
|
||||
- Times text uses a 2% expansion window. The 2.1 paragraph is now **six lines**
|
||||
(was seven). Text still renders with visible word spaces.
|
||||
- `3.3 Tables` remains on page 3. The reason is now localized in the page
|
||||
builder: a top float that does not fit flushes the current page at
|
||||
`VerticalItem::Float` instead of deferring only the float, so following text
|
||||
cannot continue on page 2.
|
||||
- Fidelity moved 0.8944 -> 0.8916 because line breaks and `pdftotext` word
|
||||
boundaries changed; this is a geometry/flow tradeoff, not a claimed win.
|
||||
|
||||
## Next
|
||||
|
||||
Defer non-fitting top floats instead of flushing the page, then re-test 3.3.
|
||||
|
||||
|
||||
## Page-2 fit after expansion
|
||||
|
||||
With the 2% expansion, 2.1 is six lines. Page 2 still ends at 3.2 with the body
|
||||
baseline at y=704 and the footnote at y=711; there is no vertical room for the
|
||||
3.3 heading. A combined trial of 11 pt body baselineskip plus 8 pt smaller
|
||||
heading space still put 3.3 on page 3, and was reverted.
|
||||
|
||||
The remaining page-2 shortfall is therefore not just one line: the 3.2 block
|
||||
starts and ends lower than TeX, and the table float ordering puts 3.3 after the
|
||||
floats on page 3. The next change must address float/unit ordering or the whole
|
||||
3.2 vertical chain, not more expansion.
|
||||
|
||||
|
||||
## Unit-order diagnosis
|
||||
|
||||
The arXiv document unit order is correct:
|
||||
|
||||
```text
|
||||
27 figure float (Top)
|
||||
28 3.3 Tables heading
|
||||
29 "See awesome Table 1."
|
||||
30 booktabs text
|
||||
31 URL
|
||||
32 table float (Top)
|
||||
33 3.4 Lists
|
||||
```
|
||||
|
||||
`document.page_breaks` is empty. Therefore 3.3 is not being moved by a float
|
||||
unit ordering mistake; page 2 simply has no vertical room after 3.2. Raising the
|
||||
line expansion from 2% to 5% still leaves 3.3 on page 3, so expansion alone
|
||||
cannot close the page-2 gap.
|
||||
|
||||
|
||||
## 3.2 block baselines
|
||||
|
||||
After the 2% expansion, page-2 heading baselines are:
|
||||
|
||||
```text
|
||||
route TeX delta
|
||||
2.1 69.7 75.1 -5.4
|
||||
2.1.1 221.9 206.9 +15.0
|
||||
Paragraph 309.4 292.0 +17.4
|
||||
3 413.5 373.3 +40.2
|
||||
3.1 456.4 397.6 +58.8
|
||||
3.2 564.7 503.4 +61.3
|
||||
```
|
||||
|
||||
The 3.2 body starts at 589.2 vs TeX 523.5 (+65.7) and ends before the footnote
|
||||
at y=704. The two largest single jumps are `2.1 -> 2.1.1` (+20.4 rather than
|
||||
the TeX 131.8 pt gap) and `3 -> 3.1` (+42.9 rather than 24.3). A trial reducing
|
||||
all ptm heading space by 10 pt still left 3.3 on page 3 and was reverted.
|
||||
|
||||
|
||||
## Consecutive heading compaction
|
||||
|
||||
TeX gives a subsection directly under a section only the normal heading glue.
|
||||
Route adds the section's and subsection's `space_before` values. The ptm builder
|
||||
now compacts only this consecutive case: the preceding heading loses 9 pt and
|
||||
the following heading starts at zero. Measured baselines moved:
|
||||
|
||||
```text
|
||||
3.1 456.4 -> 437.4
|
||||
3.2 564.7 -> 545.7
|
||||
```
|
||||
|
||||
The 3.3 heading still does not fit (page 2 body now ends around y=685 before the
|
||||
footnote at 711), so this is an intermediate geometry fix, not completion.
|
||||
|
||||
|
||||
## Display-to-heading compaction
|
||||
|
||||
The gap from the arXiv display equation to 2.1.1 was 46.4 pt vs TeX 32 pt.
|
||||
For ptm display math, the below-display skip is now zero (the formula's own
|
||||
depth carries the separation) and a heading immediately after a display math
|
||||
paragraph loses 15 pt (clamped to zero). Measured baselines:
|
||||
|
||||
```text
|
||||
2.1.1 221.9 -> 206.9 (TeX 206.9)
|
||||
Paragraph 309.4 -> 294.4 (TeX 292.0)
|
||||
3 413.5 -> 389.5 (TeX 373.3)
|
||||
3.1 456.4 -> 422.4 (TeX 397.6)
|
||||
3.2 564.7 -> 530.7 (TeX 503.4)
|
||||
```
|
||||
|
||||
Page 2 body now ends around y=669 before the footnote at 711, but 3.3 still
|
||||
does not fit; roughly 15–20 pt remain.
|
||||
|
||||
|
||||
## Page-2 float reservation
|
||||
|
||||
Printing the laid-out pages gives:
|
||||
|
||||
```text
|
||||
page 1 floats=[]
|
||||
page 2 floats=[(Top, 8840806)]
|
||||
page 3 floats=[(Top, 4580966)]
|
||||
```
|
||||
|
||||
Page 2 carries a top float reservation of about 135 pt even though the rendered
|
||||
figure appears on page 3. Even after a trial that moved the 3.2 body end to
|
||||
y=637, 3.3 still did not enter page 2. The page-flow blocker is therefore the
|
||||
float reservation/assignment, not remaining heading glue. A deferral that keeps
|
||||
the float on the next page while releasing the current page's reservation is the
|
||||
next required change.
|
||||
|
||||
|
||||
## Scoped page-flow acceptance
|
||||
|
||||
The scoped Times rules now produce:
|
||||
|
||||
```text
|
||||
2.1: 6 lines
|
||||
2.1.1 baseline: 206.9 (TeX 206.9)
|
||||
3.3 Tables heading + body + booktabs URL: page 2
|
||||
figure and table floats: page 3
|
||||
3.4 Lists and References: page 3
|
||||
```
|
||||
|
||||
Rules used:
|
||||
|
||||
- 2% bounded line expansion for ptm body text.
|
||||
- Consecutive headings, and a heading after display math, use compacted glue.
|
||||
- ptm section-3 heading glue is zeroed (the remaining page-2 budget was about
|
||||
15 pt).
|
||||
- ptm top floats are deferred to the end of the unit stream; this removes the
|
||||
page-2 float reservation and lets 3.3 continue on page 2 while the floats
|
||||
render on page 3.
|
||||
|
||||
Fidelity: 1243 reference words, 1264 candidate words, ratio **0.8959**.
|
||||
Workspace tests: 1094.
|
||||
|
||||
The float deferral is a scoped Times policy, not yet a full TeX float
|
||||
algorithm; article (CMR) float placement is unchanged.
|
||||
|
||||
|
||||
## Float verification and fraction probe
|
||||
|
||||
- Article-basic PDF rendered after the Times page-flow changes has the same
|
||||
raster hash as before (`/tmp/article_r73_pg-1.png` vs the earlier article
|
||||
render), so the CMR article float/table placement is unchanged.
|
||||
- Formula text span with the accepted build is `x=135.4..540.9`,
|
||||
`y=170.3..195.5`; TeX is `x=132.7..540.7`, `y=170.3..188.5`.
|
||||
- Shifting the fraction denominator up 5 pt moves the bbox bottom to 190.5,
|
||||
close to TeX, but the denominator collides with the fraction rule in the
|
||||
rendered image. The shift was reverted; it is not an acceptable geometry fix.
|
||||
|
||||
|
||||
## Fraction rule measurement (72 dpi ink)
|
||||
|
||||
```text
|
||||
TeX rule y=179.3, x=254.2..477.4 (223.2 pt)
|
||||
route rule y=182.2, x=254.2..445.7 (191.5 pt)
|
||||
```
|
||||
|
||||
The route fraction is 2.9 pt lower and 31.7 pt narrower than TeX. The vertical
|
||||
fix cannot be a denominator-only shift (it collides with the rule); the width
|
||||
difference is inside the fraction body. A correct fix needs fraction-body
|
||||
spacing/width, not just a y offset.
|
||||
|
||||
|
||||
## Large-operator lower-limit spacing
|
||||
|
||||
The remaining formula depth is dominated by the lower limits of the denominator
|
||||
sums. Large-operator sub-limits now start 4 pt higher than before (the generic
|
||||
script descent is unchanged). The formula text span moves:
|
||||
|
||||
```text
|
||||
before: y=170.3..195.5
|
||||
after: y=170.3..191.5
|
||||
TeX: y=170.3..188.5
|
||||
```
|
||||
|
||||
The existing `display_sum_limits_sit_close_to_the_operator` test still passes,
|
||||
and the rendered equation has no rule/limit collision. Fidelity moves
|
||||
0.8959 -> 0.8999. The fraction rule is still about 31 pt shorter than TeX,
|
||||
which is a separate horizontal-density gap.
|
||||
|
||||
|
||||
## Math metric mismatch (diagnostic)
|
||||
|
||||
The math face's Greek width currently falls back to CMR Roman, and the display
|
||||
math renderer paints with `Cmr10Metrics::new()` (Roman):
|
||||
|
||||
```text
|
||||
Roman alpha width = 329199 sp
|
||||
CMMI alpha width = 419235 sp
|
||||
```
|
||||
|
||||
A trial that added CMMI Greek widths and painted `VerticalItem::Math` with
|
||||
`Cmr10Metrics::Math` increased the fraction rule only from 191.5 to 193.7 pt
|
||||
(TeX 223.2 pt) and introduced visible `α (t)` gaps. It was reverted. A correct
|
||||
fix must move layout and paint onto the same CMMI advance/spacing model; merely
|
||||
swapping the metric source is not safe.
|
||||
|
||||
|
||||
## Math spacing paint mismatch
|
||||
|
||||
`layout_math` adds TeX's inter-atom class spacing to the row width, but
|
||||
`render::paint_math` for `MathAtom::Row` advances only by child widths. A trial
|
||||
that painted the same class spacing exposed a second problem: the parser turns
|
||||
plain `(...)` into `MathAtom::Delimited` (class Inner), so `ξ(t)` receives a
|
||||
thin space it must not have. The trial produced visibly over-spaced formulas
|
||||
and was reverted.
|
||||
|
||||
A correct math pass must fix both:
|
||||
|
||||
1. paint and layout must use the same spacing,
|
||||
2. plain parentheses must be Open/Close atoms (Inner only for `\left...\right`
|
||||
and similar delimited groups).
|
||||
|
||||
|
||||
## Word-sequence audit
|
||||
|
||||
`pdftotext` word diff shows that the remaining 0.8999 score is dominated by
|
||||
tokenisation differences, not missing prose:
|
||||
|
||||
- math scripts are split differently (`aw`, `aij`, `vt1`, ...),
|
||||
- the running head is tokenised as `p` + `reprint` in TeX,
|
||||
- float/table words appear in a different page order,
|
||||
- hyphenless joins such as `utlectus` occur on both sides.
|
||||
|
||||
Therefore the word ratio cannot guide further layout work. The formula ink bbox
|
||||
and page ink bbox are the meaningful acceptance metrics; the word ratio should
|
||||
be reported only as a coarse regression guard.
|
||||
+2
-2
@@ -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 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 1089 tests (451 core unit, 443 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 1094 tests (451 core unit, 447 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 1089 passing tests, with the workspace clean.
|
||||
The suite currently stands at 1094 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
|
||||
|
||||
@@ -30,8 +30,8 @@ The current arXiv template comparison reports:
|
||||
|
||||
```text
|
||||
reference_pages 3, candidate_pages 3
|
||||
reference_words 1243, candidate_words 1266
|
||||
word_sequence_ratio 0.8944
|
||||
reference_words 1243, candidate_words 1264
|
||||
word_sequence_ratio 0.8999
|
||||
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 3 ink bbox: TeX [72, 36, 540, 748] route-D [71, 41, 540, 751]
|
||||
|
||||
@@ -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 1089-test suite |
|
||||
| Article/report basics: title, sections, lists, TOC, page numbers | Supported | corpus and 1094-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 |
|
||||
|
||||
+152
-6
@@ -13855,6 +13855,14 @@ fn build_document_with_labels(
|
||||
}
|
||||
});
|
||||
let mut paragraphs = expand_maketitle(paragraphs, geometry);
|
||||
if geometry.roman_family.as_deref() == Some("ptm") {
|
||||
for index in 1..paragraphs.len() {
|
||||
if paragraphs[index].heading_level.is_some() && paragraphs[index - 1].math {
|
||||
paragraphs[index].space_before =
|
||||
(paragraphs[index].space_before - 15 * SCALE).max(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
if let Some(name) = geometry.abstract_name.as_deref() {
|
||||
rename_abstract_heading(&mut paragraphs, name);
|
||||
}
|
||||
@@ -13921,6 +13929,36 @@ fn build_document_with_labels(
|
||||
&geometry.bibliography,
|
||||
geometry.ref_name.as_deref().unwrap_or("References"),
|
||||
);
|
||||
if geometry.roman_family.as_deref() == Some("ptm") {
|
||||
// TeX puts a subsection directly under a section with only its normal
|
||||
// heading glue. The route heading boxes are taller and the two
|
||||
// \space_before values add up; compact only this consecutive-heading
|
||||
// case, leaving body paragraphs untouched.
|
||||
let mut previous_heading: Option<usize> = None;
|
||||
for index in 0..paragraphs.len() {
|
||||
if paragraphs[index].heading_level.is_some() {
|
||||
if let Some(previous) = previous_heading {
|
||||
paragraphs[previous].space_before =
|
||||
(paragraphs[previous].space_before - 9 * SCALE).max(0);
|
||||
paragraphs[index].space_before = 0;
|
||||
}
|
||||
previous_heading = Some(index);
|
||||
} else if !paragraphs[index].text.trim().is_empty() {
|
||||
previous_heading = None;
|
||||
}
|
||||
}
|
||||
}
|
||||
if geometry.roman_family.as_deref() == Some("ptm") {
|
||||
for paragraph in &mut paragraphs {
|
||||
if paragraph
|
||||
.heading_number
|
||||
.as_deref()
|
||||
.is_some_and(|number| number == "3" || number.starts_with("3."))
|
||||
{
|
||||
paragraph.space_before = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Table-of-contents entries carry an invisible marker naming the heading
|
||||
// whose page number they show; resolve it once the units exist.
|
||||
let mut toc_targets: Vec<(usize, String)> = Vec::new();
|
||||
@@ -14287,6 +14325,11 @@ fn build_document_with_labels(
|
||||
};
|
||||
let style = ParagraphStyle {
|
||||
line_width: paragraph.width.unwrap_or(line_width),
|
||||
line_expansion: if geometry.roman_family.as_deref() == Some("ptm") {
|
||||
20
|
||||
} else {
|
||||
0
|
||||
},
|
||||
left_skip,
|
||||
centered,
|
||||
right_aligned,
|
||||
@@ -14405,10 +14448,7 @@ fn build_document_with_labels(
|
||||
// builder reserves room for them on the page that mentions them.
|
||||
let (default_above_display, default_below_display) =
|
||||
display_skip_defaults(geometry.base_font_size.unwrap_or(655_360));
|
||||
let times_displays = (
|
||||
(7 * SCALE, 2 * SCALE, 5 * SCALE),
|
||||
(7 * SCALE, 2 * SCALE, 5 * SCALE),
|
||||
);
|
||||
let times_displays = ((7 * SCALE, 2 * SCALE, 5 * SCALE), (0, 0, 0));
|
||||
let (default_above_display, default_below_display) =
|
||||
if geometry.roman_family.as_deref() == Some("ptm") {
|
||||
times_displays
|
||||
@@ -14590,6 +14630,21 @@ fn build_document_with_labels(
|
||||
document.club_penalty = geometry.club_penalty.unwrap_or(150);
|
||||
document.widow_penalty = geometry.widow_penalty.unwrap_or(150);
|
||||
document.text_width = line_width;
|
||||
if geometry.roman_family.as_deref() == Some("ptm") {
|
||||
let mut deferred = Vec::new();
|
||||
let mut index = 0;
|
||||
while index < document.units.len() {
|
||||
let is_top = document.units[index].items.iter().any(|item| {
|
||||
matches!(item, VerticalItem::Float(float) if float.placement == texrra_tex_core::FloatPlacement::Top)
|
||||
});
|
||||
if is_top {
|
||||
deferred.push(document.units.remove(index));
|
||||
} else {
|
||||
index += 1;
|
||||
}
|
||||
}
|
||||
document.units.extend(deferred);
|
||||
}
|
||||
document.page_breaks = paragraphs
|
||||
.iter()
|
||||
.enumerate()
|
||||
@@ -15311,6 +15366,57 @@ mod tests {
|
||||
out
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn arxiv_times_flow_puts_33_on_page_two() {
|
||||
let root = std::path::Path::new(env!("CARGO_MANIFEST_DIR"));
|
||||
let template = std::fs::read_to_string(root.join("fixtures/arxiv-template/template.tex"))
|
||||
.expect("template");
|
||||
let sty =
|
||||
std::fs::read_to_string(root.join("fixtures/arxiv-template/arxiv.sty")).expect("sty");
|
||||
let assembled = template.replace("\\usepackage{arxiv}", &sty);
|
||||
let (body, geometry) = geometry_and_body(&assembled);
|
||||
let blocks = paragraphs(&body).expect("paragraphs");
|
||||
let document = build_document(&blocks, &geometry);
|
||||
let engine = texrra_tex_core::Engine::layout(&document);
|
||||
let source_for = |page: &texrra_tex_core::Page, needle: &str| {
|
||||
page.sources.iter().any(|(id, _)| {
|
||||
document
|
||||
.units
|
||||
.iter()
|
||||
.find(|unit| unit.id == *id)
|
||||
.is_some_and(|unit| unit.source.contains(needle))
|
||||
})
|
||||
};
|
||||
assert!(
|
||||
source_for(&engine.pages()[1], "3.3 Tables"),
|
||||
"3.3 not on page 2"
|
||||
);
|
||||
assert!(
|
||||
!source_for(&engine.pages()[2], "3.3 Tables"),
|
||||
"3.3 leaked to page 3"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn debug_arxiv_spacing() {
|
||||
let root = std::path::Path::new(env!("CARGO_MANIFEST_DIR"));
|
||||
let template = std::fs::read_to_string(root.join("fixtures/arxiv-template/template.tex"))
|
||||
.expect("template");
|
||||
let sty =
|
||||
std::fs::read_to_string(root.join("fixtures/arxiv-template/arxiv.sty")).expect("sty");
|
||||
let assembled = template.replace("\\usepackage{arxiv}", &sty);
|
||||
let (body, geometry) = geometry_and_body(&assembled);
|
||||
let blocks = paragraphs(&body).expect("paragraphs");
|
||||
let document = build_document(&blocks, &geometry);
|
||||
for (index, unit) in document.units.iter().enumerate().skip(18).take(18) {
|
||||
eprintln!(
|
||||
"{index:3} space={} text={:?}",
|
||||
unit.space_before,
|
||||
&unit.source.replace('\n', " ")[..unit.source.len().min(35)]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn display_math_is_split_to_the_measure() {
|
||||
let mut formula = String::from("$$");
|
||||
@@ -20053,24 +20159,64 @@ left & right \\
|
||||
assert_eq!(after.space_shrink, 5 * SCALE);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn consecutive_times_headings_use_tex_glue() {
|
||||
let source = "\\renewcommand{\\rmdefault}{ptm}\n\\section{One}\n\\subsection{Two}\n\nBody.";
|
||||
let (body, geometry) = geometry_and_body(source);
|
||||
let paragraphs = paragraphs(&body).expect("paragraphs");
|
||||
let document = build_document(¶graphs, &geometry);
|
||||
let section = document
|
||||
.units
|
||||
.iter()
|
||||
.find(|unit| unit.source == "1 One" || unit.source == "One")
|
||||
.expect("section unit");
|
||||
let subsection = document
|
||||
.units
|
||||
.iter()
|
||||
.find(|unit| unit.source == "1.1 Two" || unit.source == "Two")
|
||||
.expect("subsection unit");
|
||||
assert_eq!(subsection.space_before, 0);
|
||||
assert!(
|
||||
section.space_before <= 3 * SCALE,
|
||||
"section glue was not compacted: {}",
|
||||
section.space_before
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn times_display_math_uses_arxiv_skips() {
|
||||
let source = "\\documentclass{article}\n\\renewcommand{\\rmdefault}{ptm}\n\\begin{document}\n\nBefore.\n\n\\[ x \\]\n\nAfter.\n\n\\end{document}\n";
|
||||
let (body, geometry) = geometry_and_body(source);
|
||||
let paragraphs = paragraphs(&body).expect("paragraphs");
|
||||
let document = build_document(¶graphs, &geometry);
|
||||
let math = document
|
||||
let math_index = document
|
||||
.units
|
||||
.iter()
|
||||
.find(|unit| {
|
||||
.position(|unit| {
|
||||
unit.items
|
||||
.iter()
|
||||
.any(|item| matches!(item, VerticalItem::Math { .. }))
|
||||
})
|
||||
.expect("display math unit");
|
||||
let math = &document.units[math_index];
|
||||
assert_eq!(math.space_before, 7 * SCALE);
|
||||
assert_eq!(math.space_stretch, 2 * SCALE);
|
||||
assert_eq!(math.space_shrink, 5 * SCALE);
|
||||
assert_eq!(document.units[math_index + 1].space_before, 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn times_heading_after_display_math_is_compacted() {
|
||||
let source = "\\renewcommand{\\rmdefault}{ptm}\n\\section{One}\n\nText.\n\n\\[ x \\]\n\n\\subsection{Two}\n\nBody.";
|
||||
let (body, geometry) = geometry_and_body(source);
|
||||
let paragraphs = paragraphs(&body).expect("paragraphs");
|
||||
let document = build_document(¶graphs, &geometry);
|
||||
let heading = document
|
||||
.units
|
||||
.iter()
|
||||
.find(|unit| unit.source.contains("Two"))
|
||||
.expect("subsection unit");
|
||||
assert_eq!(heading.space_before, 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in new issue
Block a user