Scan TeX math skips and correct math-unit spacing

This commit is contained in:
gloamxun committed 2026-10-24 12:43:01 +08:00
1 parent cce656a407
commit 03925e3116
4 files changed
+240 -12

No files matched your search

+1 -1
View File
@@ -467,7 +467,7 @@ from the font's MATH assembly parts. `\\left...\\right` target sizing follows
the assignable TeX parameters `\\delimiterfactor` (default 901) and the assignable TeX parameters `\\delimiterfactor` (default 901) and
`\\delimitershortfall` (default 5pt), including local and global assignments. `\\delimitershortfall` (default 5pt), including local and global assignments.
In route-D, math uses Computer Modern metrics from the bundled `cmmi10`, `cmsy10`, `cmex10`, `msbm10` and `eufm10` TFMs and embeds their Type1 programs, so italic letters, relation symbols, big operators, `\mathcal` capitals, `\mathbb` capitals and `\mathfrak` Fraktur letters each paint with their own face. Fractions can be written as `\frac` or with TeX's infix forms (`\over`, `\atop`, `\choose`, `\brace`, `\brack`, `\overwithdelims`, `\atopwithdelims`); only `\over`-style fractions draw a bar and fractions never draw parentheses. `\left`/`\right` choose CMEX delimiter sizes from the body extent using TeX's delimiterfactor and shortfall, `\middle` delimiters are sized with their group, and `\big`/`\Big`/`\bigg`/`\Bigg` paint at their selected CMEX size. `align`/`align*` displays share column widths, right-align even columns at their relations, and number each row (with `\tag`/`\notag` per row); `gather`/`gather*` centre each row instead. In route-D, math uses Computer Modern metrics from the bundled `cmmi10`, `cmsy10`, `cmex10`, `msbm10` and `eufm10` TFMs and embeds their Type1 programs, so italic letters, relation symbols, big operators, `\mathcal` capitals, `\mathbb` capitals and `\mathfrak` Fraktur letters each paint with their own face. Fractions can be written as `\frac` or with TeX's infix forms (`\over`, `\atop`, `\choose`, `\brace`, `\brack`, `\overwithdelims`, `\atopwithdelims`); only `\over`-style fractions draw a bar and fractions never draw parentheses. `\left`/`\right` choose CMEX delimiter sizes from the body extent using TeX's delimiterfactor and shortfall, `\middle` delimiters are sized with their group, and `\big`/`\Big`/`\bigg`/`\Bigg` paint at their selected CMEX size. `align`/`align*` displays share column widths, right-align even columns at their relations, and number each row (with `\tag`/`\notag` per row); `gather`/`gather*` centre each row instead. Inter-atom spacing uses TeX's 3/4/5mu classes (`1mu` is `1/18em`), `\mid` is a relation and `\colon` punctuation, and `\mskip`/`\mkern`/`\mspace`/`\hskip`/`\kern`/`\hspace` scan TeX dimensions, taking the natural width of any `plus`/`minus` parts.
Route-D integration can also be checked against a real TeX page: `cargo test -p texrra-tex-core --test route_d` includes `route_d_page_matches_pdftex_raster_geometry`, which renders the route-D PDF and a pdfTeX Letter page at the same scaled-point geometry, rasterizes both with `pdftoppm`, and compares ink line count plus left, right, and bottom edges. It is skipped when `pdflatex`/`pdftoppm` are unavailable. `route_d_multiline_bands_track_pdftex` extends that check to a wrapped paragraph: the pixel rows that carry ink form one band per TeX line, and every band top, bottom, left edge and (except for the last line, whose width follows the break point) right edge must land within a couple of pixels of the pdfTeX page. Route-D integration can also be checked against a real TeX page: `cargo test -p texrra-tex-core --test route_d` includes `route_d_page_matches_pdftex_raster_geometry`, which renders the route-D PDF and a pdfTeX Letter page at the same scaled-point geometry, rasterizes both with `pdftoppm`, and compares ink line count plus left, right, and bottom edges. It is skipped when `pdflatex`/`pdftoppm` are unavailable. `route_d_multiline_bands_track_pdftex` extends that check to a wrapped paragraph: the pixel rows that carry ink form one band per TeX line, and every band top, bottom, left edge and (except for the last line, whose width follows the break point) right edge must land within a couple of pixels of the pdfTeX page.
+236 -8
View File
@@ -305,12 +305,13 @@ pub fn math_class(character: char) -> MathClass {
} }
} }
/// Width of one math unit at 10pt (TeX's `\thinmuskip` is 3mu). /// TeX's `\thinmuskip` at 10pt: `3mu`, where `1mu` is `1/18em` and `1em`
const THIN_MU: i64 = 3 * 65_536 / 18; /// is 10pt (so one mu is 36,408.9sp).
const THIN_MU: i64 = 3 * 655_360 / 18;
/// Width of `\medmuskip` (4mu plus 2mu minus 4mu at 10pt). /// Width of `\medmuskip` (4mu plus 2mu minus 4mu at 10pt).
const MED_MU: i64 = 4 * 65_536 / 18; const MED_MU: i64 = 4 * 655_360 / 18;
/// Width of `\thickmuskip` (5mu plus 5mu at 10pt). /// Width of `\thickmuskip` (5mu plus 5mu at 10pt).
const THICK_MU: i64 = 5 * 65_536 / 18; const THICK_MU: i64 = 5 * 655_360 / 18;
/// TeX's inter-atom spacing table. /// TeX's inter-atom spacing table.
/// ///
@@ -1215,6 +1216,170 @@ fn math_symbol_command(name: &str) -> Option<char> {
Some(character) Some(character)
} }
/// Scan a TeX dimension at `index`, returning scaled points and the next index.
///
/// `muskip` makes a unitless value a math unit, which is what `\mskip` and
/// `\mkern` require.
fn scan_math_dimension(chars: &[char], index: usize, muskip: bool) -> Option<(i64, usize)> {
let mut at = skip_math_space(chars, index);
let mut negative = false;
if chars.get(at) == Some(&'-') {
negative = true;
at += 1;
} else if chars.get(at) == Some(&'+') {
at += 1;
}
let mut whole = 0i64;
let mut digits = 0u32;
while let Some(digit) = chars.get(at).and_then(|ch| ch.to_digit(10)) {
whole = whole.saturating_mul(10).saturating_add(digit as i64);
at += 1;
digits += 1;
}
let mut fraction = 0i64;
if chars.get(at) == Some(&'.') {
at += 1;
let mut scale = 65_536i64;
while let Some(digit) = chars.get(at).and_then(|ch| ch.to_digit(10)) {
scale /= 10;
fraction += digit as i64 * scale;
at += 1;
digits += 1;
}
}
if digits == 0 {
return None;
}
let mut unit = String::new();
while let Some(ch) = chars.get(at) {
if ch.is_ascii_alphabetic() {
unit.push(*ch);
at += 1;
} else {
break;
}
}
let (numerator, denominator) = match unit.as_str() {
"mu" => (10, 18),
"pt" => (1, 1),
"bp" => (7227, 7200),
"in" => (4_736_286, 65_536),
"cm" => (1_864_679, 65_536),
"mm" => (186_468, 65_536),
"pc" => (786_432, 65_536),
"dd" => (70_124, 65_536),
"cc" => (841_489, 65_536),
"em" => (10, 1),
"ex" => (5, 1),
"sp" => (1, 65_536),
"" if muskip => (10, 18),
"" => (1, 1),
_ => return None,
};
let total = whole.saturating_mul(65_536).saturating_add(fraction);
let value = total.saturating_mul(numerator) / denominator;
Some((if negative { -value } else { value }, at))
}
/// Match a word after skipping math spaces; rejects longer identifiers.
fn math_keyword(chars: &[char], index: usize, word: &str) -> Option<usize> {
let at = skip_math_space(chars, index);
let mut cursor = at;
for expected in word.chars() {
if chars.get(cursor) != Some(&expected) {
return None;
}
cursor += 1;
}
if chars
.get(cursor)
.is_some_and(|character| character.is_ascii_alphabetic())
{
return None;
}
Some(cursor)
}
/// Scan `\mskip`-style dimensions, consuming any `plus`/`minus` parts.
///
/// Only the natural width participates in the layout: math boxes are not
/// glue lists, so stretch and shrink are accepted but not distributed.
fn unbraced_math_space(chars: &[char], index: usize, muskip: bool) -> Option<(i64, usize)> {
let (value, mut at) = scan_math_dimension(chars, index, muskip)?;
let mut seen_plus = false;
let mut seen_minus = false;
loop {
if !seen_plus {
if let Some(after) = math_keyword(chars, at, "plus") {
if let Some((_, next)) = scan_math_dimension(chars, after, muskip) {
at = next;
seen_plus = true;
continue;
}
}
}
if !seen_minus {
if let Some(after) = math_keyword(chars, at, "minus") {
if let Some((_, next)) = scan_math_dimension(chars, after, muskip) {
at = next;
seen_minus = true;
continue;
}
}
}
break;
}
Some((value, at))
}
/// Scan a braced dimension such as `\mspace{18mu}`.
fn braced_math_space(chars: &[char], index: usize, muskip: bool) -> Option<(i64, usize)> {
let at = skip_math_space(chars, index);
if chars.get(at) != Some(&'{') {
return None;
}
let mut depth = 0i64;
let mut end = at;
while end < chars.len() {
match chars[end] {
'{' => depth += 1,
'}' => {
depth -= 1;
if depth == 0 {
break;
}
}
_ => {}
}
end += 1;
}
if depth != 0 {
return None;
}
let (value, _) = scan_math_dimension(&chars[at + 1..end], 0, muskip)?;
Some((value, end + 1))
}
/// Read a math-space command argument, allowing an optional star.
fn math_space_argument(
chars: &[char],
index: usize,
muskip: bool,
braced: bool,
) -> Option<(i64, usize)> {
let at = skip_math_space(chars, index);
let at = if chars.get(at) == Some(&'*') {
skip_math_space(chars, at + 1)
} else {
at
};
if braced {
braced_math_space(chars, at, muskip)
} else {
unbraced_math_space(chars, at, muskip)
}
}
fn parse_atom(chars: &[char], index: usize) -> (MathAtom, usize) { fn parse_atom(chars: &[char], index: usize) -> (MathAtom, usize) {
let mut index = index; let mut index = index;
while chars.get(index) == Some(&'\u{0}') { while chars.get(index) == Some(&'\u{0}') {
@@ -1260,6 +1425,36 @@ fn parse_atom(chars: &[char], index: usize) -> (MathAtom, usize) {
} }
} }
return match command.as_str() { return match command.as_str() {
"mid" => (
MathAtom::Classed {
class: MathClass::Relation,
body: Box::new(MathAtom::Symbol('|')),
},
next,
),
"colon" => (
MathAtom::Classed {
class: MathClass::Punctuation,
body: Box::new(MathAtom::Symbol(':')),
},
next,
),
"mskip" | "mkern" => match math_space_argument(chars, next, true, false) {
Some((width, after)) => (MathAtom::Space(width), after),
None => (MathAtom::Symbol('?'), next),
},
"mspace" => match math_space_argument(chars, next, true, true) {
Some((width, after)) => (MathAtom::Space(width), after),
None => (MathAtom::Symbol('?'), next),
},
"hskip" | "kern" => match math_space_argument(chars, next, false, false) {
Some((width, after)) => (MathAtom::Space(width), after),
None => (MathAtom::Symbol('?'), next),
},
"hspace" => match math_space_argument(chars, next, false, true) {
Some((width, after)) => (MathAtom::Space(width), after),
None => (MathAtom::Symbol('?'), next),
},
"quad" => (MathAtom::Space(655_360), next), "quad" => (MathAtom::Space(655_360), next),
"qquad" => (MathAtom::Space(1_310_720), next), "qquad" => (MathAtom::Space(1_310_720), next),
"lvert" | "rvert" | "vert" => (MathAtom::Symbol('|'), next), "lvert" | "rvert" | "vert" => (MathAtom::Symbol('|'), next),
@@ -2336,6 +2531,39 @@ mod tests {
assert!(quad.width > medium.width); assert!(quad.width > medium.width);
assert!(double.width > quad.width); assert!(double.width > quad.width);
} }
#[test]
fn explicit_math_skips_have_their_natural_width() {
let font = Cmr10Metrics::default();
let plain = layout_math(&parse_math("ab"), &font).width;
let thin = layout_math(&parse_math(r"a\mskip 3mu b"), &font).width;
let mspace = layout_math(&parse_math(r"a\mspace{18mu}b"), &font).width;
let em = layout_math(&parse_math(r"a\hspace{1em}b"), &font).width;
assert_eq!(thin - plain, THIN_MU);
assert_eq!(mspace - plain, 655_360);
assert_eq!(em - plain, 655_360);
}
#[test]
fn math_skips_accept_plus_minus_and_negative_values() {
let font = Cmr10Metrics::default();
let plain = layout_math(&parse_math("ab"), &font).width;
let stretchy = layout_math(&parse_math(r"a\mskip 3mu plus 1mu minus 1mu b"), &font).width;
let tight = layout_math(&parse_math(r"a\mkern-2mu b"), &font).width;
assert_eq!(stretchy - plain, THIN_MU);
assert_eq!(plain - tight, 2 * 655_360 / 18);
}
#[test]
fn mid_spaces_like_a_relation() {
let font = Cmr10Metrics::default();
let mid = layout_math(&parse_math(r"a\mid b"), &font).width;
let bar = layout_math(&parse_math("a|b"), &font).width;
assert_eq!(mid - bar, 2 * THICK_MU);
let colon = layout_math(&parse_math(r"a\colon b"), &font).width;
let relation = layout_math(&parse_math("a:b"), &font).width;
assert!(colon < relation, "\\colon is punctuation, not a relation");
}
#[test] #[test]
fn math_text_preserves_internal_spaces() { fn math_text_preserves_internal_spaces() {
let font = Cmr10Metrics::default(); let font = Cmr10Metrics::default();
@@ -2660,7 +2888,7 @@ mod spacing_class_tests {
fn punctuation_gets_a_thin_space() { fn punctuation_gets_a_thin_space() {
let font = Cmr10Metrics::Math; let font = Cmr10Metrics::Math;
let packed = font.width('a') + font.width(',') + font.width('b'); let packed = font.width('a') + font.width(',') + font.width('b');
assert_eq!(width("a,b") - packed, 3 * 65_536 / 18); assert_eq!(width("a,b") - packed, THIN_MU);
} }
#[test] #[test]
@@ -2676,16 +2904,16 @@ mod spacing_class_tests {
fn relation_and_binary_spacing_stay_distinct() { fn relation_and_binary_spacing_stay_distinct() {
let font = Cmr10Metrics::Math; let font = Cmr10Metrics::Math;
let base = font.width('x') + font.width('+') + font.width('y'); let base = font.width('x') + font.width('+') + font.width('y');
assert_eq!(width("x+y") - base, 2 * (4 * 65_536 / 18)); assert_eq!(width("x+y") - base, 2 * MED_MU);
let relation = font.width('x') + font.width('=') + font.width('y'); let relation = font.width('x') + font.width('=') + font.width('y');
assert_eq!(width("x=y") - relation, 2 * (5 * 65_536 / 18)); assert_eq!(width("x=y") - relation, 2 * THICK_MU);
} }
#[test] #[test]
fn big_operators_are_operator_atoms() { fn big_operators_are_operator_atoms() {
let font = Cmr10Metrics::Math; let font = Cmr10Metrics::Math;
let sum = width(r"\sum"); let sum = width(r"\sum");
assert_eq!(width(r"\sum x") - sum - font.width('x'), 3 * 65_536 / 18); assert_eq!(width(r"\sum x") - sum - font.width('x'), THIN_MU);
} }
} }
+1 -1
View File
@@ -48,7 +48,7 @@ floats (`\floatsep`, `\textfloatsep`, `\intextsep`, `\topfraction`,
`\bottomnumber`, `\totalnumber`), insertion classes (`\skip`, fraction and `\bottomnumber`, `\totalnumber`), insertion classes (`\skip`, fraction and
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`). 568 workspace tests are green and no oracle PDF opt-in with `?engine=route-d`). 571 workspace tests are green and no oracle
fixture is ignored. fixture is ignored.
Status after G1 (P0-P2): the paragraph model reproduces TeX's passes, Status after G1 (P0-P2): the paragraph model reproduces TeX's passes,
+2 -2
View File
@@ -131,7 +131,7 @@ and justification.
| M1 | TeX box/glue/penalty + paragraph builder (`\par`, `\hsize`, `\parindent`) | **partial**: item stream, CMR10 metrics, TeX Live en-US hyphenation, TeX demerits and tolerance passes, `\hangindent`/`\parshape`, `\parfillskip`, sentence spacing, `\spaceskip`/`\xspaceskip`, `\raggedright` (infinite `\rightskip`), `\looseness`, `\baselineskip`/`\lineskip`/`\parskip` interline glue, pdfLaTeX oracle matrix 90-240pt plus register, geometry, `\sfcode`, `\parindent`, `\parshape`, `\leftskip`/`\rightskip`, `\hfil`/`\hfill` glue orders, `\prevgraf` in the output routine, and vertical-glue fixtures | | M1 | TeX box/glue/penalty + paragraph builder (`\par`, `\hsize`, `\parindent`) | **partial**: item stream, CMR10 metrics, TeX Live en-US hyphenation, TeX demerits and tolerance passes, `\hangindent`/`\parshape`, `\parfillskip`, sentence spacing, `\spaceskip`/`\xspaceskip`, `\raggedright` (infinite `\rightskip`), `\looseness`, `\baselineskip`/`\lineskip`/`\parskip` interline glue, pdfLaTeX oracle matrix 90-240pt plus register, geometry, `\sfcode`, `\parindent`, `\parshape`, `\leftskip`/`\rightskip`, `\hfil`/`\hfill` glue orders, `\prevgraf` in the output routine, and vertical-glue fixtures |
| M2 | page builder + `\output`, `\vsize`, `\topskip`, footnotes, floats | **partial**: `\vsize` page goal, `\topskip`, forced penalties, `Insertion` reserve, running `Mark`s, `OutputRoutine` hook, top/bottom `Float` placement; `page::PageBuilder` scores candidate breakpoints with TeX page badness, glue setting (with `\raggedbottom`/`\flushbottom` applied when pages are materialised, and TeX glue orders `\vfil`/`\vfill`/`\vfilll` honoured so only the highest order with stretch is used), `\topskip`/`\maxdepth`, and `Engine::layout_paged` uses it for documents whose units are single vertical items, placing top and bottom floats (with `\floatsep`, a `\bottomfraction` cap and the `\topnumber`/`\bottomnumber`/`\totalnumber` limits, with `\floatpagefraction` deciding when a float-heavy page ships without body) and insertion classes on that path, while in-text floats flow inline as body material; paged layouts replay edits from the edited unit's page and fall back to a full rebuild only when insertions, bottom floats or an interpreted `\output` are present; `\output` is interpreted for a `\shipout`/`\ifdim`/`\ifnum`/`\ifodd`/`\ifcase` subset, and `\mark{...}`/`\marks<n>{...}` writes inside the routine are carried to the following page's mark list with their class; `\pageno`, `\outputpenalty` and `\deadcycles` are readable and assignable registers (`\pageno=...` carries into the next page, and an assigned `\vsize` retargets the pages the routine has not seen yet, even when the document raises insertion material; only a document that defers bottom floats keeps its initial goal, because the carried queue cannot be rebuilt after a retarget), `\ht255`, `\dp255` and `\wd255` expose the page box height, depth and width to the routine, and `\hsize` is readable (and assignable for the rest of the run) while `\wd255` tracks it; route-D sets `\hsize` from its 480pt text measure, insertion class registers `\count<n>`/`\dimen<n>`/`\skip<n>` read the configured multiplier, maximum height and skip of class `n` (with `\count0` reading `\pageno`) and accept assignments that outlive the routine (the paged builder runs the routine after each page, so an assigned `\dimen<n>` or `\count<n>` changes the insertion capacity and reservation of later pages); the configured `\skip<n>` also reserves space above its class once per page in the paged builder, and a `\skip<n>` assignment rebuilds the pages the routine has not seen yet with the new reservation, `\deadcycles` accumulates pages the output routine did not ship and resets on the next shipout, `\maxdeadcycles` (default 25, assignable) makes the page builder ship the page itself once that many dead cycles have accumulated, `PageFragment::penalty` carries the break penalty (`\outputpenalty`: the penalty value when the break landed on a penalty, otherwise 10000, as TeX reports for glue breaks, goal overflow and the final page), and `PageFragment::stretches` records glue stretch per TeX order so `\pagefilstretch`/`\pagefillstretch`/`\pagefilllstretch` are readable in the output routine; `\vbadness` reports the badness of the break that produced the page and `\insertpenalties` the number of insertion items held over from it | | M2 | page builder + `\output`, `\vsize`, `\topskip`, footnotes, floats | **partial**: `\vsize` page goal, `\topskip`, forced penalties, `Insertion` reserve, running `Mark`s, `OutputRoutine` hook, top/bottom `Float` placement; `page::PageBuilder` scores candidate breakpoints with TeX page badness, glue setting (with `\raggedbottom`/`\flushbottom` applied when pages are materialised, and TeX glue orders `\vfil`/`\vfill`/`\vfilll` honoured so only the highest order with stretch is used), `\topskip`/`\maxdepth`, and `Engine::layout_paged` uses it for documents whose units are single vertical items, placing top and bottom floats (with `\floatsep`, a `\bottomfraction` cap and the `\topnumber`/`\bottomnumber`/`\totalnumber` limits, with `\floatpagefraction` deciding when a float-heavy page ships without body) and insertion classes on that path, while in-text floats flow inline as body material; paged layouts replay edits from the edited unit's page and fall back to a full rebuild only when insertions, bottom floats or an interpreted `\output` are present; `\output` is interpreted for a `\shipout`/`\ifdim`/`\ifnum`/`\ifodd`/`\ifcase` subset, and `\mark{...}`/`\marks<n>{...}` writes inside the routine are carried to the following page's mark list with their class; `\pageno`, `\outputpenalty` and `\deadcycles` are readable and assignable registers (`\pageno=...` carries into the next page, and an assigned `\vsize` retargets the pages the routine has not seen yet, even when the document raises insertion material; only a document that defers bottom floats keeps its initial goal, because the carried queue cannot be rebuilt after a retarget), `\ht255`, `\dp255` and `\wd255` expose the page box height, depth and width to the routine, and `\hsize` is readable (and assignable for the rest of the run) while `\wd255` tracks it; route-D sets `\hsize` from its 480pt text measure, insertion class registers `\count<n>`/`\dimen<n>`/`\skip<n>` read the configured multiplier, maximum height and skip of class `n` (with `\count0` reading `\pageno`) and accept assignments that outlive the routine (the paged builder runs the routine after each page, so an assigned `\dimen<n>` or `\count<n>` changes the insertion capacity and reservation of later pages); the configured `\skip<n>` also reserves space above its class once per page in the paged builder, and a `\skip<n>` assignment rebuilds the pages the routine has not seen yet with the new reservation, `\deadcycles` accumulates pages the output routine did not ship and resets on the next shipout, `\maxdeadcycles` (default 25, assignable) makes the page builder ship the page itself once that many dead cycles have accumulated, `PageFragment::penalty` carries the break penalty (`\outputpenalty`: the penalty value when the break landed on a penalty, otherwise 10000, as TeX reports for glue breaks, goal overflow and the final page), and `PageFragment::stretches` records glue stretch per TeX order so `\pagefilstretch`/`\pagefillstretch`/`\pagefilllstretch` are readable in the output routine; `\vbadness` reports the badness of the break that produced the page and `\insertpenalties` the number of insertion items held over from it |
| M3 | `\halign`, `\omit`, `\span`, `\multispan`, booktabs/longtable | **partial**: source parsing, natural column widths, spans, rule rows, 10pt display-list painting and row-level page splitting; the paged builder splits a tall alignment into page-sized row chunks that keep the table's column widths, so long tables continue across pages; `p{width}` paragraph columns wrap cell text and grow row heights, wrapped rows participate in row-level splitting, explicit per-column `\tabskip` glue is honoured through layout, painting and page chunks, and booktabs rules carry their own weights and spans (`\toprule`/`\bottomrule` 0.8pt, `\midrule`/`\cmidrule` 0.5pt, with `\cmidrule(lr){a-b}` trimming and column ranges), `@{}` / `@{\hspace{...}}` column expressions override the inter-column glue, and row-boundary `\noalign{\vskip ...}` glue is honoured by layout, painting and page chunks; longtable head/foot sections (`\endfirsthead`/`\endhead`/`\endfoot`/`\endlastfoot`) are parsed, continuation chunks repeat the head rows and the foot block paints once at the end, LaTeX `tabular` environments are captured and laid out through the same `\halign` path (rules are stripped from the column spec, `p{...}`/`m{...}`/`b{...}` become wrapping columns, `@{}` expressions are ignored for spacing), though `\valign`, nested tables and full tabular parity remain open | | M3 | `\halign`, `\omit`, `\span`, `\multispan`, booktabs/longtable | **partial**: source parsing, natural column widths, spans, rule rows, 10pt display-list painting and row-level page splitting; the paged builder splits a tall alignment into page-sized row chunks that keep the table's column widths, so long tables continue across pages; `p{width}` paragraph columns wrap cell text and grow row heights, wrapped rows participate in row-level splitting, explicit per-column `\tabskip` glue is honoured through layout, painting and page chunks, and booktabs rules carry their own weights and spans (`\toprule`/`\bottomrule` 0.8pt, `\midrule`/`\cmidrule` 0.5pt, with `\cmidrule(lr){a-b}` trimming and column ranges), `@{}` / `@{\hspace{...}}` column expressions override the inter-column glue, and row-boundary `\noalign{\vskip ...}` glue is honoured by layout, painting and page chunks; longtable head/foot sections (`\endfirsthead`/`\endhead`/`\endfoot`/`\endlastfoot`) are parsed, continuation chunks repeat the head rows and the foot block paints once at the end, LaTeX `tabular` environments are captured and laid out through the same `\halign` path (rules are stripped from the column spec, `p{...}`/`m{...}`/`b{...}` become wrapping columns, `@{}` expressions are ignored for spacing), though `\valign`, nested tables and full tabular parity remain open |
| M4 | math lists, scripts, fractions, radicals, accents, delimiters | **partial**: token parser, atom boxes with Computer Modern metrics (italic letters from the bundled `cmmi10`, big operators from `cmex10`, symbols such as `\times`/`\leq`/`\infty` from `cmsy10`, with `cmmi10`, `cmsy10` and `cmex10` glyphs embedded as Type1 outlines), `\left...\right` delimiter selection through CMEX size variants using TeX's delimiterfactor and shortfall, accents and a display-list painter; display formulas wider than the measure are split at top-level binary/relation operators into multiple lines (an approximation of TeX's `\split` behaviour; `align`/`align*` displays share column widths and number each row, while `gather`/`gather*` centre every row); CMEX delimiter size variants back `\big`/`\Big`/`\bigg`/`\Bigg`; inter-atom spacing uses TeX's full atom-class table with binary-operator normalisation; route-D numbers `equation` environments and resolves `\eqref`/`\ref` through their labels; `\tag` overrides the number and `\notag`/`\nonumber` suppress it; math italic letters are embedded as Computer Modern Type1 outlines (`cmmi10`), and math alphabets map `\\mathbf`/`\\mathit`/`\\mathsf`/`\\mathtt` onto the bold, math-italic, sans and mono faces with their TFMs and `\\mathcal` onto the cmsy10 calligraphic capitals; `\mathfrak` maps onto the bundled eufm10 Fraktur letters (embedded as Type1 outlines); infix fractions `\over`, `\atop`, `\choose`, `\brace`, `\brack` and their `withdelims` forms build fractions from the current row, with the bar only for the `\over` forms; `\middle` delimiters are sized with their enclosing `\left`/`\right` group and `\big`/`\Big`/`\bigg`/`\Bigg` paint at their selected CMEX size | | M4 | math lists, scripts, fractions, radicals, accents, delimiters | **partial**: token parser, atom boxes with Computer Modern metrics (italic letters from the bundled `cmmi10`, big operators from `cmex10`, symbols such as `\times`/`\leq`/`\infty` from `cmsy10`, with `cmmi10`, `cmsy10` and `cmex10` glyphs embedded as Type1 outlines), `\left...\right` delimiter selection through CMEX size variants using TeX's delimiterfactor and shortfall, accents and a display-list painter; display formulas wider than the measure are split at top-level binary/relation operators into multiple lines (an approximation of TeX's `\split` behaviour; `align`/`align*` displays share column widths and number each row, while `gather`/`gather*` centre every row); CMEX delimiter size variants back `\big`/`\Big`/`\bigg`/`\Bigg`; inter-atom spacing uses TeX's full atom-class table with binary-operator normalisation, with `1mu` = `1/18em` (a thin space is 3mu = 1.67pt at 10pt); `\mid` is a relation while `\colon` is punctuation; `\mskip`, `\mkern`, `\mspace`, `\hskip`, `\kern` and `\hspace` scan TeX dimensions (`mu`, `pt`, `em`, ...) and contribute their natural width, accepting `plus`/`minus` parts even though math boxes are not glue lists; route-D numbers `equation` environments and resolves `\eqref`/`\ref` through their labels; `\tag` overrides the number and `\notag`/`\nonumber` suppress it; math italic letters are embedded as Computer Modern Type1 outlines (`cmmi10`), and math alphabets map `\\mathbf`/`\\mathit`/`\\mathsf`/`\\mathtt` onto the bold, math-italic, sans and mono faces with their TFMs and `\\mathcal` onto the cmsy10 calligraphic capitals; `\mathfrak` maps onto the bundled eufm10 Fraktur letters (embedded as Type1 outlines); infix fractions `\over`, `\atop`, `\choose`, `\brace`, `\brack` and their `withdelims` forms build fractions from the current row, with the bar only for the `\over` forms; `\middle` delimiters are sized with their enclosing `\left`/`\right` group and `\big`/`\Big`/`\bigg`/`\Bigg` paint at their selected CMEX size |
| M5 | NFSS/TFM metrics, CM/Latin Modern | **partial**: paragraph-level NFSS declarations and inline run composition over the built-in Roman/Bold/Italic/BoldItalic/Mono/Sans faces, per-face Computer Modern TFM metrics, and Type1 (PFB) outline embedding for every built-in face plus `cmmi10` math italics, `cmsy10` math symbols and `cmex10` big operators, with Liberation subsets used only as a fallback for characters outside the Type1 encodings; full NFSS family/shape state and Type1 coverage for arbitrary Unicode remain open | | M5 | NFSS/TFM metrics, CM/Latin Modern | **partial**: paragraph-level NFSS declarations and inline run composition over the built-in Roman/Bold/Italic/BoldItalic/Mono/Sans faces, per-face Computer Modern TFM metrics, and Type1 (PFB) outline embedding for every built-in face plus `cmmi10` math italics, `cmsy10` math symbols and `cmex10` big operators, with Liberation subsets used only as a fallback for characters outside the Type1 encodings; full NFSS family/shape state and Type1 coverage for arbitrary Unicode remain open |
| M6 | class/package execution (`article`, `sn-jnl`) | Overleaf page-count parity | | M6 | class/package execution (`article`, `sn-jnl`) | Overleaf page-count parity |
| M7 | `\special`, PDF XObjects, hyperref annotations | PDF structure parity | | M7 | `\special`, PDF XObjects, hyperref annotations | PDF structure parity |
@@ -367,7 +367,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`) 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`, 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. `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`) 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`, 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. `Engine::edit` preserves the face when reflowing an edited paragraph.
The crate currently has 385 unit tests plus eight route-D integration tests and thirty-five oracle fixtures. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 568 tests (385 route-D unit, 37 engine binary unit, 8 route-D integration, 35 oracle, 71 v1 integration, 27 server, 4 engine unit, 1 core unit), with none ignored. v1 remains the live server path. The crate currently has 388 unit tests plus eight route-D integration tests and thirty-five oracle fixtures. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 571 tests (388 route-D unit, 37 engine binary unit, 8 route-D integration, 35 oracle, 71 v1 integration, 27 server, 4 engine unit, 1 core unit), with none ignored. v1 remains the live server path.
### M0 incremental demo ### M0 incremental demo