Support xrightarrow and xleftarrow

The amsmath extensible arrows were unknown, so their labels fell back to plain
text. The math parser now reads \xrightarrow/\xleftarrow, an optional [below]
label, and the above label, and builds nested Stack atoms around the arrow
symbol: above stacks upward, an optional below label stacks downward.

The math test compares the bare arrow with the labeled form (width/height grow)
and with the two-label form (total height plus depth grows).
This commit is contained in:
gloamxun committed 2026-10-27 03:18:20 +08:00
1 parent 8307fc8918
commit 4068366190
4 files changed
+54 -6

No files matched your search

+48
View File
@@ -2313,6 +2313,43 @@ fn parse_atom(chars: &[char], index: usize) -> (MathAtom, usize) {
let rows = content.split("\\\\").map(parse_math).collect();
(MathAtom::StackLines(rows), (after + 1).min(chars.len()))
}
"xrightarrow" | "xleftarrow" => {
let mut after = next;
let mut below = None;
if chars.get(after) == Some(&'[') {
let start = after + 1;
let mut end = start;
while end < chars.len() && chars[end] != ']' {
end += 1;
}
if end < chars.len() {
below = Some(parse_math(&chars[start..end].iter().collect::<String>()));
after = end + 1;
}
}
let (above, after) = parse_atom(chars, after);
let arrow = MathAtom::Symbol(if command == "xrightarrow" {
'\u{2192}'
} else {
'\u{2190}'
});
let base = match below {
Some(below) => MathAtom::Stack {
top: Box::new(below),
base: Box::new(arrow),
above: false,
},
None => arrow,
};
(
MathAtom::Stack {
top: Box::new(above),
base: Box::new(base),
above: true,
},
after,
)
}
"overset" | "underset" | "stackrel" => {
let (top, after) = parse_atom(chars, next);
let (base, after) = parse_atom(chars, after);
@@ -3469,6 +3506,17 @@ mod tests {
assert_eq!(plain.width, styled.width);
assert_eq!(plain.height, styled.height);
}
#[test]
fn xrightarrow_stacks_its_label() {
let font = Cmr10Metrics::default();
let arrow = layout_math(&parse_math("\\rightarrow"), &font);
let labeled = layout_math(&parse_math("\\xrightarrow{abc}"), &font);
assert!(labeled.width >= arrow.width);
assert!(labeled.height > arrow.height);
let below = layout_math(&parse_math("\\xrightarrow[below]{above}"), &font);
assert!(below.height + below.depth > labeled.height + labeled.depth);
}
#[test]
fn boldsymbol_maps_to_the_bold_alphabet() {
let font = Cmr10Metrics::default();
+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
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). 1043 workspace tests are green and no oracle
prefer route-D with a v1 fallback). 1044 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.
+2 -2
View File
@@ -14,11 +14,11 @@ cargo fmt --all -- --check
cargo test --workspace --offline
```
The workspace currently passes **1043 tests**:
The workspace currently passes **1044 tests**:
| Suite | Tests |
| --- | --- |
| route-D unit (engine) | 438 |
| route-D unit (engine) | 439 |
| engine binary unit | 414 |
| server integration | 63 |
| v1 integration | 71 |
+3 -3
View File
@@ -366,11 +366,11 @@ PDF agree. `Document::paper_width` and `paper_height` (TeX `\paperwidth`/`\paper
M3 (partial): `Unit::halign` normalizes column widths, intercolumn gaps, row heights and cell text widths to scaled points; the painter uses 10pt glyphs in 12pt rows. Rules and spans are painted; tall tables split at row boundaries (`Halign::split_for_height`) with column widths preserved.
Math coverage includes fractions/roots, scripts, `\left...\right` with body-scaled delimiters, `\middle`, `\big`/`\Big`/`\bigg`/`\Bigg` and their `l`/`r` forms, control-sequence delimiters, accents (dot/check/breve/acute/grave/ring), `\text`/`\mathrm`, `\overbrace`/`\underbrace`, `\overset`/`\underset`, `\binom`, `\cancel`/`\bcancel`/`\xcancel`, `\bmod`/`\pmod`, fence symbols, `\operatorname*` and `\mathop` limits, and `\ensuremath{...}` lays its body out as math and re-enters text otherwise.
Math coverage includes fractions/roots, scripts, `\left...\right` with body-scaled delimiters, `\middle`, `\big`/`\Big`/`\bigg`/`\Bigg` and their `l`/`r` forms, control-sequence delimiters, accents (dot/check/breve/acute/grave/ring), `\text`/`\mathrm`, `\overbrace`/`\underbrace`, `\overset`/`\underset`, `\xrightarrow`/`\xleftarrow` with an optional below label, `\binom`, `\cancel`/`\bcancel`/`\xcancel`, `\bmod`/`\pmod`, fence symbols, `\operatorname*` and `\mathop` limits, and `\ensuremath{...}` lays its body out as math and re-enters text otherwise.
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 437 unit tests plus ten route-D integration tests and forty-two oracle fixtures. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 1043 tests (438 route-D unit, 414 engine binary unit, 10 route-D integration, 42 oracle, 71 v1 integration, 63 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; the flat response carries `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 437 unit tests plus ten route-D integration tests and forty-two oracle fixtures. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 1044 tests (439 route-D unit, 414 engine binary unit, 10 route-D integration, 42 oracle, 71 v1 integration, 63 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; the flat response carries `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 1043 passing tests, with the workspace clean.
The suite currently stands at 1044 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