From 8c42f2de2f37b4566c38716f9bf742ba552c0f1e Mon Sep 17 00:00:00 2001 From: texrra Date: Sat, 24 Oct 2026 12:28:30 +0800 Subject: [PATCH] Add Fraktur letters, infix fractions and middle delimiters - bundle eufm10 (TFM + Type1), add the MathFraktur face and map \mathfrak onto it, including PDF embedding and width lookup; - parse TeX's infix fractions (\over, \atop, \choose, \brace, \brack, \overwithdelims, \atopwithdelims): the rest of the current row becomes the denominator, ar records whether a rule is drawn, and the painter no longer emits parentheses (a \frac painter bug) and only draws the bar for \over forms; - add MathAtom::Middle, size top-level middle delimiters with the enclosing \left/\right group through the CMEX size classes, and paint SizedDelimiter at its selected size instead of the base glyph; - skip the parser's '\u{0}' math spaces before \big, \middle, \left and the withdelims delimiters, so \big ( parses like \big(. 560 workspace tests (381 route-D unit). --- README.md | 2 + assets/fonts/eufm10.pfb | Bin 0 -> 21098 bytes crates/texrra-tex-core/assets/eufm10.tfm | Bin 0 -> 1040 bytes crates/texrra-tex-core/src/cmr10.rs | 81 ++++--- crates/texrra-tex-core/src/lib.rs | 106 +++++++++ crates/texrra-tex-core/src/math.rs | 264 ++++++++++++++++++++++- crates/texrra-tex-core/src/pdf.rs | 32 ++- crates/texrra-tex-core/src/render.rs | 78 ++++--- docs/ROUTE_D_PLAN.md | 2 +- docs/TEX_CORE.md | 6 +- 10 files changed, 499 insertions(+), 72 deletions(-) create mode 100644 assets/fonts/eufm10.pfb create mode 100644 crates/texrra-tex-core/assets/eufm10.tfm diff --git a/README.md b/README.md index e55d872..8fbf4c0 100644 --- a/README.md +++ b/README.md @@ -467,6 +467,8 @@ from the font's MATH assembly parts. `\\left...\\right` target sizing follows the assignable TeX parameters `\\delimiterfactor` (default 901) and `\\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. + 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 float placement mirrors TeX fractions: diff --git a/assets/fonts/eufm10.pfb b/assets/fonts/eufm10.pfb new file mode 100644 index 0000000000000000000000000000000000000000..abd2df836c3f6243e14ef00b98a985effa5229d2 GIT binary patch literal 21098 zcmb5U1yG#Z(k_fcaEG7+!QBZ22=49<0}Sr&?gV#&1Shz=1^3|Y1h?QCawq$oZ?pIJ z->ScE0mD4KdUZc<%j#7y{*WU`5D=7PiYkmkCU!<3aXVXQMph;kUVxaIxEw1BfQ5yf z3H*adNvUe#Yz_J!IU=Px$kEBd&X)Hd8X}G$pfgw|3Umf5%Guchq+M(Qtn2_*HeMDM z@Hc>sg_RX->Mun*M_z!C4am{L7-$QS13H_7Y{0vXfz|*OJ7Wuwvj-xjh@HKMqlKBd zGcVxpw*VSrS^z5#4>tqY8Vk>#S60^l2SWfFK67VhdtPQ{H#avXpp6rgouiomEd#*K z!r2_43~~ZFx`Ipqe*yuJ2ik!C8we&uN`R`lh0}i)RP0Qh-GGiD09ascVGOc$0&j7# zH32ySz|R3tk&*={*n@2Uqb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%JyIkpJ1z6)l< zWtdG*VK(#J=78Dmh1qcgX6IdGluX0@_&nUt=aL(-O~#>o;>wx+6o#7% zPQ0~hmJ*+1!1yd|b`NZ!N!aB8BsB_Ysdag)e7JDG1kW$)lhcp&G_{{kzMma_l= literal 0 HcmV?d00001 diff --git a/crates/texrra-tex-core/src/cmr10.rs b/crates/texrra-tex-core/src/cmr10.rs index edc54a8..4cdd95c 100644 --- a/crates/texrra-tex-core/src/cmr10.rs +++ b/crates/texrra-tex-core/src/cmr10.rs @@ -19,6 +19,8 @@ pub enum Cmr10Metrics { MathCalligraphic, /// Blackboard-bold capitals from msbm10 (`\mathbb`). MathBlackboard, + /// Euler Fraktur letters from eufm10 (`\mathfrak`). + MathFraktur, /// Math face: italic letters from cmmi10, big operators from cmex10. Math, } @@ -33,6 +35,7 @@ static CMMI10_TFM: &[u8] = include_bytes!("../assets/cmmi10.tfm"); static CMEX10_TFM: &[u8] = include_bytes!("../assets/cmex10.tfm"); static CMSY10_TFM: &[u8] = include_bytes!("../assets/cmsy10.tfm"); static MSBM10_TFM: &[u8] = include_bytes!("../assets/msbm10.tfm"); +static EUFM10_TFM: &[u8] = include_bytes!("../assets/eufm10.tfm"); static CMR10_METRICS: OnceLock = OnceLock::new(); static CMBX10_METRICS: OnceLock = OnceLock::new(); @@ -44,6 +47,7 @@ static CMMI10_METRICS: OnceLock = OnceLock::new(); static CMEX10_METRICS: OnceLock = OnceLock::new(); static CMSY10_METRICS: OnceLock = OnceLock::new(); static MSBM10_METRICS: OnceLock = OnceLock::new(); +static EUFM10_METRICS: OnceLock = OnceLock::new(); fn parse(bytes: &[u8]) -> TfmMetrics { TfmMetrics::parse(bytes).expect("embedded TFM must be valid") @@ -105,6 +109,14 @@ fn math_blackboard_metrics() -> &'static TfmMetrics { MSBM10_METRICS.get_or_init(parse_blackboard) } +fn parse_fraktur() -> TfmMetrics { + parse(EUFM10_TFM) +} + +fn math_fraktur_metrics() -> &'static TfmMetrics { + EUFM10_METRICS.get_or_init(parse_fraktur) +} + fn metrics_for(font: Cmr10Metrics) -> &'static TfmMetrics { match font { Cmr10Metrics::Roman => CMR10_METRICS.get_or_init(parse_roman), @@ -116,6 +128,7 @@ fn metrics_for(font: Cmr10Metrics) -> &'static TfmMetrics { Cmr10Metrics::Math => CMR10_METRICS.get_or_init(parse_roman), Cmr10Metrics::MathCalligraphic => CMSY10_METRICS.get_or_init(parse_math_symbol), Cmr10Metrics::MathBlackboard => MSBM10_METRICS.get_or_init(parse_blackboard), + Cmr10Metrics::MathFraktur => EUFM10_METRICS.get_or_init(parse_fraktur), } } @@ -148,6 +161,7 @@ impl Cmr10Metrics { 7 => Self::Math, 8 => Self::Math, 9 => Self::MathBlackboard, + 10 => Self::MathFraktur, _ => Self::Roman, } } @@ -157,14 +171,12 @@ impl Cmr10Metrics { } pub fn width(&self, character: char) -> i64 { - if *self == Self::MathCalligraphic { - if character.is_ascii_uppercase() { - return self.metrics().width(character); - } - return Self::Math.width(character); - } - if *self == Self::MathBlackboard { - if character.is_ascii_uppercase() { + if matches!( + *self, + Self::MathCalligraphic | Self::MathBlackboard | Self::MathFraktur + ) { + let capital_only = *self != Self::MathFraktur; + if character.is_ascii_uppercase() || (!capital_only && character.is_ascii_lowercase()) { return self.metrics().width(character); } return Self::Math.width(character); @@ -194,14 +206,12 @@ impl Cmr10Metrics { } pub fn height(&self, character: char) -> i64 { - if *self == Self::MathCalligraphic { - if character.is_ascii_uppercase() { - return self.metrics().height(character); - } - return Self::Math.height(character); - } - if *self == Self::MathBlackboard { - if character.is_ascii_uppercase() { + if matches!( + *self, + Self::MathCalligraphic | Self::MathBlackboard | Self::MathFraktur + ) { + let capital_only = *self != Self::MathFraktur; + if character.is_ascii_uppercase() || (!capital_only && character.is_ascii_lowercase()) { return self.metrics().height(character); } return Self::Math.height(character); @@ -224,14 +234,12 @@ impl Cmr10Metrics { } pub fn depth(&self, character: char) -> i64 { - if *self == Self::MathCalligraphic { - if character.is_ascii_uppercase() { - return self.metrics().depth(character); - } - return Self::Math.depth(character); - } - if *self == Self::MathBlackboard { - if character.is_ascii_uppercase() { + if matches!( + *self, + Self::MathCalligraphic | Self::MathBlackboard | Self::MathFraktur + ) { + let capital_only = *self != Self::MathFraktur; + if character.is_ascii_uppercase() || (!capital_only && character.is_ascii_lowercase()) { return self.metrics().depth(character); } return Self::Math.depth(character); @@ -254,14 +262,12 @@ impl Cmr10Metrics { } pub fn italic(&self, character: char) -> i64 { - if *self == Self::MathCalligraphic { - if character.is_ascii_uppercase() { - return self.metrics().italic(character); - } - return Self::Math.italic(character); - } - if *self == Self::MathBlackboard { - if character.is_ascii_uppercase() { + if matches!( + *self, + Self::MathCalligraphic | Self::MathBlackboard | Self::MathFraktur + ) { + let capital_only = *self != Self::MathFraktur; + if character.is_ascii_uppercase() || (!capital_only && character.is_ascii_lowercase()) { return self.metrics().italic(character); } return Self::Math.italic(character); @@ -388,6 +394,17 @@ pub fn math_blackboard_width(character: char) -> Option { None } +/// Advance width of an `eufm10` Fraktur letter. +pub fn math_fraktur_width(character: char) -> Option { + if character.is_ascii_alphabetic() { + let width = math_fraktur_metrics().width(character); + if width > 0 { + return Some(width); + } + } + None +} + /// Advance width of a `cmex10` glyph addressed by a Unicode n-ary operator. pub fn math_extension_width(character: char) -> Option { math_extension_slot(character) diff --git a/crates/texrra-tex-core/src/lib.rs b/crates/texrra-tex-core/src/lib.rs index 81201d4..047826b 100644 --- a/crates/texrra-tex-core/src/lib.rs +++ b/crates/texrra-tex-core/src/lib.rs @@ -4235,6 +4235,29 @@ mod tests { ))); } + #[test] + fn mathfrak_paints_with_the_eufm_face() { + use crate::render::{DisplayItem, FontFace}; + let document = Document::new( + 1_000_000, + vec![Unit::math( + 1, + crate::math::parse_math("\\mathfrak{A}"), + &Cmr10Metrics::Math, + )], + ); + let engine = Engine::layout(&document); + let list = engine.pages()[0].display_list(); + assert!(list.items.iter().any(|item| matches!( + item, + DisplayItem::Text { + text, + font: FontFace::MathFraktur, + .. + } if text == "A" + ))); + } + #[test] fn edit_on_second_page_only_rebuilds_second_page() { let mut document = document(); @@ -6328,6 +6351,48 @@ mod tests { assert!(svg.contains("font-family=\"monospace\">face3")); } + #[test] + fn big_delimiters_paint_at_their_selected_size() { + let atom = crate::math::parse_math("\\big("); + let document = Document::new( + 400, + vec![Unit::math(1, atom, &crate::cmr10::Cmr10Metrics::new())], + ); + let engine = Engine::layout(&document); + let list = engine.pages()[0].display_list(); + let size = list + .items + .iter() + .find_map(|item| match item { + DisplayItem::Text { text, size, .. } if text == "(" => Some(*size), + _ => None, + }) + .expect("big paren should be painted"); + assert!(size > 655_360, "expected a larger glyph, got {size}"); + } + + #[test] + fn middle_delimiters_paint_larger_than_the_base_glyph() { + let atom = crate::math::parse_math( + "\\left( \\frac{\\frac{a}{b}}{\\frac{c}{d}} \\middle\\{ c \\right)", + ); + let document = Document::new( + 400, + vec![Unit::math(1, atom, &crate::cmr10::Cmr10Metrics::new())], + ); + let engine = Engine::layout(&document); + let list = engine.pages()[0].display_list(); + let size = list + .items + .iter() + .find_map(|item| match item { + DisplayItem::Text { text, size, .. } if text == "{" => Some(*size), + _ => None, + }) + .expect("middle brace should be painted"); + assert!(size > 655_360, "expected a larger glyph, got {size}"); + } + #[test] fn binomial_is_painted_with_parentheses() { let document = Document::new( @@ -6459,6 +6524,47 @@ mod tests { assert!(svg.contains(">x")); } + #[test] + fn fractions_paint_a_rule_without_parentheses() { + let atom = crate::math::parse_math("\\frac{a}{b}"); + let document = Document::new( + 400, + vec![Unit::math(1, atom, &crate::cmr10::Cmr10Metrics::new())], + ); + let engine = Engine::layout(&document); + let list = engine.pages()[0].display_list(); + assert!( + !list.items.iter().any(|item| matches!( + item, + DisplayItem::Text { text, .. } if text == "(" || text == ")" + )), + "fractions must not paint parentheses: {:?}", + list.items + ); + assert!( + list.items + .iter() + .any(|item| matches!(item, DisplayItem::Rule { .. })) + ); + } + + #[test] + fn atop_paints_without_a_fraction_rule() { + let atom = crate::math::parse_math("a \\atop b"); + let document = Document::new( + 400, + vec![Unit::math(1, atom, &crate::cmr10::Cmr10Metrics::new())], + ); + let engine = Engine::layout(&document); + let list = engine.pages()[0].display_list(); + assert!( + !list + .items + .iter() + .any(|item| matches!(item, DisplayItem::Rule { .. })) + ); + } + #[test] fn big_operators_paint_with_the_cmex_face() { let atom = crate::math::parse_math("\\sum_{i=1}^{n}"); diff --git a/crates/texrra-tex-core/src/math.rs b/crates/texrra-tex-core/src/math.rs index 86c4eb8..2f023cd 100755 --- a/crates/texrra-tex-core/src/math.rs +++ b/crates/texrra-tex-core/src/math.rs @@ -15,6 +15,7 @@ pub enum MathAlphabet { Mono, Calligraphic, Blackboard, + Fraktur, } #[derive(Clone, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)] @@ -85,6 +86,8 @@ pub enum MathAtom { delimiter: char, size: u8, }, + /// A `\middle` delimiter; TeX sizes it with the enclosing `\left`/`\right`. + Middle(char), StackLines(Vec), Stack { top: Box, @@ -107,9 +110,16 @@ pub enum MathAtom { Fraction { numerator: Box, denominator: Box, + /// Whether TeX draws the fraction bar (`\over` vs `\atop`). + #[serde(default = "fraction_bar_default")] + bar: bool, }, } +fn fraction_bar_default() -> bool { + true +} + impl MathAtom { pub fn symbol(character: char) -> Self { Self::Symbol(character) @@ -127,6 +137,7 @@ impl MathAtom { Self::Fraction { numerator: Box::new(numerator), denominator: Box::new(denominator), + bar: true, } } } @@ -309,6 +320,7 @@ pub(crate) fn alphabet_metrics(font: Cmr10Metrics, alphabet: MathAlphabet) -> Cm } MathAlphabet::Calligraphic => Cmr10Metrics::MathCalligraphic, MathAlphabet::Blackboard => Cmr10Metrics::MathBlackboard, + MathAlphabet::Fraktur => Cmr10Metrics::MathFraktur, } } @@ -566,6 +578,7 @@ pub fn layout_math(atom: &MathAtom, font: &Cmr10Metrics) -> MathBox { } } } + MathAtom::Middle(delimiter) => layout_math(&MathAtom::Symbol(*delimiter), font), MathAtom::StackLines(rows) => { let boxes: Vec = rows.iter().map(|atom| layout_math(atom, font)).collect(); MathBox { @@ -672,6 +685,7 @@ pub fn layout_math(atom: &MathAtom, font: &Cmr10Metrics) -> MathBox { MathAtom::Fraction { numerator, denominator, + .. } => { let numerator_box = layout_math(numerator, font); let denominator_box = layout_math(denominator, font); @@ -702,6 +716,97 @@ pub fn parse_math(input: &str) -> MathAtom { atom } +/// An infix fraction command such as `\over`, `\atop` or `\choose`. +/// +/// Returns the fraction bar flag, optional delimiters and the index after the +/// command (and its delimiters). +fn infix_fraction(chars: &[char], index: usize) -> Option<(bool, Option<(char, char)>, usize)> { + if chars.get(index) != Some(&'\\') { + return None; + } + let mut cursor = index + 1; + let mut command = String::new(); + while let Some(&ch) = chars.get(cursor) { + if ch.is_ascii_alphabetic() { + command.push(ch); + cursor += 1; + } else { + break; + } + } + match command.as_str() { + "over" => Some((true, None, cursor)), + "atop" => Some((false, None, cursor)), + "choose" => Some((false, Some(('(', ')')), cursor)), + "brace" => Some((false, Some(('{', '}')), cursor)), + "brack" => Some((false, Some(('[', ']')), cursor)), + "overwithdelims" | "atopwithdelims" => { + while chars.get(cursor) == Some(&'\u{0}') { + cursor += 1; + } + let (left, after_left) = parse_delimiter(chars, cursor); + let mut cursor = after_left; + while chars.get(cursor) == Some(&'\u{0}') { + cursor += 1; + } + let (right, after_right) = parse_delimiter(chars, cursor); + Some(( + command == "overwithdelims", + Some((left, right)), + after_right, + )) + } + _ => None, + } +} + +fn skip_math_space(chars: &[char], mut index: usize) -> usize { + while chars.get(index) == Some(&'\u{0}') { + index += 1; + } + index +} + +/// The `cmex10` size class (0 for the base glyph) that covers `delta`. +pub(crate) fn delimiter_size(delimiter: char, delta: i64) -> u8 { + if delimiter == '.' { + return 0; + } + let font = Cmr10Metrics::default(); + let base = font.height(delimiter) + font.depth(delimiter); + let need = ((delta * 901) / 1000).max(delta - 5 * 65_536).max(0); + if base >= need && base > 0 { + return 0; + } + for size in 1..=4 { + if let Some(metrics) = cmex_delimiter(delimiter, size) { + if metrics.1 + metrics.2 >= need { + return size; + } + } + } + 4 +} + +/// Replace top-level `\middle` atoms with sized delimiters. +fn size_middle_delimiters(body: MathAtom, delta: i64) -> MathAtom { + match body { + MathAtom::Row(atoms) => MathAtom::Row( + atoms + .into_iter() + .map(|atom| match atom { + MathAtom::Middle(delimiter) => MathAtom::SizedDelimiter { + delimiter, + size: delimiter_size(delimiter, delta), + }, + other => other, + }) + .collect(), + ), + other => other, + } +} + fn is_right_command(chars: &[char], index: usize) -> bool { chars.get(index) == Some(&'\\') && chars.get(index + 1) == Some(&'r') @@ -762,6 +867,30 @@ fn parse_sequence( if stop_at_right && is_right_command(chars, index) { break; } + let mut probe = index; + while chars.get(probe) == Some(&'\u{0}') { + probe += 1; + } + if let Some((bar, delimiters, after)) = infix_fraction(chars, probe) { + // TeX's infix fractions consume everything collected so far in the + // current group; the rest of the group becomes the denominator. + let numerator = MathAtom::Row(std::mem::take(&mut atoms)); + let (denominator, end) = parse_sequence(chars, after, stop_at_brace, stop_at_right); + let fraction = MathAtom::Fraction { + numerator: Box::new(numerator), + denominator: Box::new(denominator), + bar, + }; + let atom = match delimiters { + Some((left, right)) => MathAtom::Delimited { + left, + right, + body: Box::new(fraction), + }, + None => fraction, + }; + return (MathAtom::Row(vec![atom]), end); + } let (mut atom, mut next) = parse_atom(chars, index); let mut sub = None; let mut sup = None; @@ -1151,10 +1280,7 @@ fn parse_atom(chars: &[char], index: usize) -> (MathAtom, usize) { "bigg" | "biggl" | "biggr" => 3, _ => 4, }; - let mut after = next; - while after < chars.len() && chars[after].is_whitespace() { - after += 1; - } + let after = skip_math_space(chars, next); let (delimiter, after) = parse_delimiter(chars, after); (MathAtom::SizedDelimiter { delimiter, size }, after) } @@ -1319,8 +1445,9 @@ fn parse_atom(chars: &[char], index: usize) -> (MathAtom, usize) { ) } "middle" => { - let (delimiter, after) = parse_delimiter(chars, next); - (MathAtom::Symbol(delimiter), after) + let after = skip_math_space(chars, next); + let (delimiter, after) = parse_delimiter(chars, after); + (MathAtom::Middle(delimiter), after) } "max" | "min" | "log" | "ln" | "sin" | "cos" | "tan" | "cot" | "sec" | "csc" | "exp" | "det" | "dim" | "ker" | "hom" | "arg" | "deg" | "gcd" => { @@ -1350,6 +1477,7 @@ fn parse_atom(chars: &[char], index: usize) -> (MathAtom, usize) { "mathtt" => Some(MathAlphabet::Mono), "mathcal" => Some(MathAlphabet::Calligraphic), "mathbb" => Some(MathAlphabet::Blackboard), + "mathfrak" => Some(MathAlphabet::Fraktur), _ => None, }; match alphabet { @@ -1433,8 +1561,11 @@ fn parse_atom(chars: &[char], index: usize) -> (MathAtom, usize) { (MathAtom::Text(text), after) } "left" => { - let (left, body_start) = parse_delimiter(chars, next); + let body_start = skip_math_space(chars, next); + let (left, body_start) = parse_delimiter(chars, body_start); let (body, after) = parse_sequence(chars, body_start, false, true); + let body_box = layout_math(&body, &Cmr10Metrics::default()); + let body = size_middle_delimiters(body, body_box.height + body_box.depth); let mut after = after; // Consume `\right` and its delimiter. if is_right_command(chars, after) { @@ -1586,6 +1717,25 @@ mod tests { ); } + #[test] + fn mathfrak_uses_fraktur_widths() { + let font = Cmr10Metrics::default(); + let fraktur = layout_math(&parse_math("\\mathfrak{A}"), &font); + let upright = layout_math(&parse_math("\\mathrm{A}"), &font); + let blackboard = layout_math(&parse_math("\\mathbb{A}"), &font); + assert_ne!(fraktur.width, upright.width); + assert_eq!( + fraktur.width, + crate::cmr10::math_fraktur_width('A').expect("eufm has Fraktur capitals") + ); + let lower = layout_math(&parse_math("\\mathfrak{a}"), &font); + assert_eq!( + lower.width, + crate::cmr10::math_fraktur_width('a').expect("eufm has Fraktur lowercase") + ); + assert_ne!(fraktur.width, blackboard.width); + } + #[test] fn smash_can_target_only_the_top_or_bottom() { let font = Cmr10Metrics::default(); @@ -1686,6 +1836,49 @@ mod tests { assert!(bigg.height > big.height); assert!(bigg.width > big.width); } + #[test] + fn middle_delimiters_follow_the_group_extent() { + let atom = parse_math("\\left( \\frac{\\frac{a}{b}}{\\frac{c}{d}} \\middle\\{ c \\right)"); + let MathAtom::Row(atoms) = &atom else { + panic!("expected a row"); + }; + let MathAtom::Delimited { body, .. } = &atoms[0] else { + panic!("expected a delimited group, got {:?}", atoms[0]); + }; + let MathAtom::Row(parts) = &**body else { + panic!("expected a row"); + }; + let middle = parts + .iter() + .find_map(|atom| match atom { + MathAtom::SizedDelimiter { delimiter, size } if *delimiter == '{' => Some(*size), + _ => None, + }) + .expect("middle delimiter should have been sized"); + assert!(middle >= 1, "expected a CMEX variant, got size {middle}"); + } + + #[test] + fn middle_outside_left_right_stays_a_plain_delimiter() { + let atom = parse_math("a \\middle| b"); + let MathAtom::Row(atoms) = &atom else { + panic!("expected a row"); + }; + assert!( + atoms + .iter() + .any(|atom| matches!(atom, MathAtom::Middle('|'))) + ); + } + + #[test] + fn big_delimiters_allow_math_spaces() { + let font = Cmr10Metrics::default(); + let spaced = layout_math(&parse_math("\\big ("), &font); + let compact = layout_math(&parse_math("\\big("), &font); + assert_eq!(spaced, compact); + } + #[test] fn tall_delimiters_grow_with_their_body() { let font = Cmr10Metrics::default(); @@ -2082,6 +2275,63 @@ mod tests { assert!(matches!(&atoms[0], MathAtom::Script { sup: Some(_), .. })); } + #[test] + fn infix_fractions_consume_the_current_row() { + let atom = parse_math("a + b \\over c + d"); + let MathAtom::Row(atoms) = atom else { + panic!("expected a row"); + }; + assert_eq!(atoms.len(), 1); + let MathAtom::Fraction { + numerator, + denominator, + bar, + } = &atoms[0] + else { + panic!("expected a fraction, got {:?}", atoms[0]); + }; + assert!(*bar); + assert!(matches!(**numerator, MathAtom::Row(ref row) if row.len() == 3)); + assert!(matches!(**denominator, MathAtom::Row(ref row) if row.len() == 3)); + } + + #[test] + fn atop_and_choose_use_their_own_forms() { + let atom = parse_math("a \\atop b"); + let MathAtom::Row(atoms) = &atom else { + panic!("expected a row"); + }; + assert!(matches!(&atoms[0], MathAtom::Fraction { bar: false, .. })); + let choose = parse_math("n \\choose k"); + let MathAtom::Row(atoms) = &choose else { + panic!("expected a row"); + }; + assert!(matches!( + &atoms[0], + MathAtom::Delimited { + left: '(', + right: ')', + body, + } if matches!(**body, MathAtom::Fraction { bar: false, .. }) + )); + } + + #[test] + fn over_with_delims_keeps_the_requested_delimiters() { + let atom = parse_math("a \\overwithdelims [ ] b"); + let MathAtom::Row(atoms) = &atom else { + panic!("expected a row"); + }; + assert!(matches!( + &atoms[0], + MathAtom::Delimited { + left: '[', + right: ']', + body, + } if matches!(**body, MathAtom::Fraction { bar: true, .. }) + )); + } + #[test] fn parse_fraction_and_sqrt() { let atom = parse_math("\\frac{a}{b} + \\sqrt{x}"); diff --git a/crates/texrra-tex-core/src/pdf.rs b/crates/texrra-tex-core/src/pdf.rs index 2b367be..b709a9e 100755 --- a/crates/texrra-tex-core/src/pdf.rs +++ b/crates/texrra-tex-core/src/pdf.rs @@ -16,7 +16,7 @@ use crate::cmr10::Cmr10Metrics; use crate::render::{DisplayItem, DisplayList, FontFace}; use crate::type1::Type1Font; -const FACE_COUNT: usize = 10; +const FACE_COUNT: usize = 11; fn deflate(bytes: &[u8]) -> Vec { let mut encoder = ZlibEncoder::new(Vec::new(), Compression::default()); @@ -92,6 +92,12 @@ static FULL_FACES: [PdfFace; FACE_COUNT] = [ italic_angle: 0, font: OnceLock::new(), }, + PdfFace { + bytes: include_bytes!("../../../assets/fonts-subset/LiberationSerif-Regular.ttf"), + base: "LiberationSerif-MathFraktur", + italic_angle: 0, + font: OnceLock::new(), + }, ]; static MIN_FACES: [PdfFace; FACE_COUNT] = [ @@ -155,6 +161,12 @@ static MIN_FACES: [PdfFace; FACE_COUNT] = [ italic_angle: 0, font: OnceLock::new(), }, + PdfFace { + bytes: include_bytes!("../../../assets/fonts-subset-min/LiberationSerif-Regular.ttf"), + base: "LiberationSerif-MathFraktur", + italic_angle: 0, + font: OnceLock::new(), + }, ]; fn minimal_text_char(ch: char) -> bool { @@ -287,6 +299,7 @@ fn font_resource(font: FontFace) -> &'static str { FontFace::MathSymbol => "F8", FontFace::MathExtension => "F9", FontFace::MathBlackboard => "F10", + FontFace::MathFraktur => "F11", } } @@ -312,6 +325,7 @@ fn type1_bytes(slot: usize) -> Option<&'static [u8]> { Some(include_bytes!("../../../assets/fonts/cmsy10.pfb")), Some(include_bytes!("../../../assets/fonts/cmex10.pfb")), Some(include_bytes!("../../../assets/fonts/msbm10.pfb")), + Some(include_bytes!("../../../assets/fonts/eufm10.pfb")), ]; PFBS[slot] } @@ -967,6 +981,22 @@ mod type1_pdf_tests { assert!(text.contains("(\\101)"), "{text}"); } + #[test] + fn mathfrak_letters_embed_eufm10() { + let mut list = hello_list(); + list.items[0] = DisplayItem::Text { + x: 0, + y: 800_000, + size: 655_360, + text: "A".to_string(), + font: FontFace::MathFraktur, + }; + let pdf = write(&[list]); + let text = String::from_utf8_lossy(&pdf); + assert!(text.contains("/BaseFont /EUFM10"), "{text}"); + assert!(text.contains("(\\101)"), "{text}"); + } + #[test] fn mathcal_letters_embed_cmsy10() { let mut list = hello_list(); diff --git a/crates/texrra-tex-core/src/render.rs b/crates/texrra-tex-core/src/render.rs index ee34f99..61da567 100755 --- a/crates/texrra-tex-core/src/render.rs +++ b/crates/texrra-tex-core/src/render.rs @@ -27,6 +27,8 @@ pub enum FontFace { MathExtension, /// Computer Modern blackboard bold (`msbm10`). MathBlackboard, + /// Euler Fraktur (`eufm10`). + MathFraktur, } #[derive(Clone, Debug, PartialEq, Eq)] @@ -700,6 +702,7 @@ impl Page { math::MathAlphabet::Mono => FontFace::Mono, math::MathAlphabet::Calligraphic => FontFace::MathSymbol, math::MathAlphabet::Blackboard => FontFace::MathBlackboard, + math::MathAlphabet::Fraktur => FontFace::MathFraktur, }; let mut cursor = x; for character in text.chars() { @@ -774,41 +777,37 @@ impl Page { MathAtom::Fraction { numerator, denominator, + bar, } => { let num = math::layout_math(numerator, font); let den = math::layout_math(denominator, font); - let width = num.width.max(den.width); - let bracket = (size as f64 * 1.2) as i64; - let inner_x = x + (width - num.width) / 2 + 2 * 65_536; - Self::paint_math(numerator, font, inner_x, baseline - 8 * 65_536, size, list); + let clearance = 2 * 65_536; + let rule_width = num.width.max(den.width) + clearance; + let bar_y = baseline - clearance; + if *bar { + list.push(DisplayItem::Rule { + x, + y: bar_y, + width: rule_width, + height: 26_214, + }); + } Self::paint_math( - denominator, + numerator, font, - x + (width - den.width) / 2 + 2 * 65_536, - baseline + 12 * 65_536, + x + (rule_width - num.width) / 2, + bar_y - clearance - num.depth, + size, + list, + ); + Self::paint_math( + denominator, + font, + x + (rule_width - den.width) / 2, + bar_y + clearance + den.height, size, list, ); - list.push(DisplayItem::Text { - font: FontFace::Roman, - x, - y: baseline, - size: bracket, - text: "(".to_string(), - }); - list.push(DisplayItem::Text { - font: FontFace::Roman, - x: x + width + 4 * 65_536, - y: baseline, - size: bracket, - text: ")".to_string(), - }); - list.push(DisplayItem::Rule { - x, - y: baseline - 2 * 65_536, - width, - height: 26_214, - }); } MathAtom::Sqrt { radicand, degree } => { let box_ = math::layout_math(radicand, font); @@ -1095,7 +1094,30 @@ impl Page { } } } - MathAtom::SizedDelimiter { delimiter, .. } => { + MathAtom::SizedDelimiter { + delimiter, + size: step, + } => { + let base_extent = font.height(*delimiter) + font.depth(*delimiter); + let extent = crate::cmr10::cmex_delimiter(*delimiter, *step) + .map(|(_, height, depth)| height + depth); + let (glyph_size, shift) = match extent { + Some(extent) if base_extent > 0 && extent > base_extent => { + let scale = extent as f64 / base_extent as f64; + let glyph_size = (size as f64 * scale) as i64; + (glyph_size, ((glyph_size - size) as f64 * 0.35) as i64) + } + _ => (size, 0), + }; + list.push(DisplayItem::Text { + font: FontFace::Roman, + x, + y: baseline + shift, + size: glyph_size, + text: delimiter.to_string(), + }); + } + MathAtom::Middle(delimiter) => { list.push(DisplayItem::Text { font: FontFace::Roman, x, diff --git a/docs/ROUTE_D_PLAN.md b/docs/ROUTE_D_PLAN.md index 5705dca..65dc90a 100644 --- a/docs/ROUTE_D_PLAN.md +++ b/docs/ROUTE_D_PLAN.md @@ -48,7 +48,7 @@ floats (`\floatsep`, `\textfloatsep`, `\intextsep`, `\topfraction`, `\bottomnumber`, `\totalnumber`), insertion classes (`\skip`, fraction and 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`). 544 workspace tests are green and no oracle +PDF opt-in with `?engine=route-d`). 560 workspace tests are green and no oracle fixture is ignored. Status after G1 (P0-P2): the paragraph model reproduces TeX's passes, diff --git a/docs/TEX_CORE.md b/docs/TEX_CORE.md index a0780b1..d756165 100755 --- a/docs/TEX_CORE.md +++ b/docs/TEX_CORE.md @@ -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 | | 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{...}` 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`/`\dimen`/`\skip` 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` or `\count` changes the insertion capacity and reservation of later pages); the configured `\skip` also reserves space above its class once per page in the paged builder, and a `\skip` 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 | -| 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 explicit approximation of TeX's `\split`/`align` behaviour); 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 | +| 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 explicit approximation of TeX's `\split`/`align` behaviour); 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 | | 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 | | M7 | `\special`, PDF XObjects, hyperref annotations | PDF structure parity | @@ -330,7 +330,7 @@ for a later overlaid slash. | M1 horizontal/paragraphs | partial | boxes/glue/penalties, CMR10 metrics, TeX Live en-US hyphenation, TeX demerits and tolerance passes, `\hangindent`/`\parshape`, `\parfillskip`, sentence spacing with default and custom `\sfcode`/`\frenchspacing`, explicit `\spaceskip`/`\xspaceskip`, `\baselineskip`/`\lineskip`/`\parskip` interline glue, pdfTeX oracle matrix 90-240pt plus register, geometry and vertical-glue fixtures | | M2 vertical/page builder | partial | vsize, topskip, insertions, marks, Rust output hook, top/bottom floats, float-page/text fractions, rules, vskip, penalties; `page::PageBuilder` scores breakpoints with page badness and penalties and models `\topskip`/`\maxdepth`; `Engine::layout_paged` builds pages through it for documents made of box/glue/penalty/mark vertical material (a unit may span pages), while in-text floats flow inline through the page builder; paged layouts replay edits from the edited page (insertions, bottom floats and interpreted `\output` force a full rebuild), and insertions are placed through the builder too; `\output` interpreted for a `\shipout`/`\ifdim`/`\ifnum` register subset over page globals and `\outputpenalty`/`\pageno`/`\deadcycles` | | M3 halign | partial | natural columns, spans, omit, hline rows, templates, noalign skip, rules; no PDF painter | -| M4 math | partial | atoms, scripts, fractions, roots, delimiters, accents, operators, classes, braces, boxed, negated; no math painter/shrink wrapping | +| M4 math | partial | atoms, scripts, fractions (including infix `\over`/`\atop`/`\choose`), roots, delimiters, accents, operators, classes, braces, boxed, negated, math alphabets (incl. `\mathcal`, `\mathbb` and `\mathfrak`); no math painter/shrink wrapping | | M5 NFSS/TFM | partial | runtime `cmr10.tfm` widths/heights/depths/kern pairs and ff/fi/fl/ffi/ffl ligatures; text faces embed Liberation Serif/Mono as Type0 CID fonts with Identity-H, ToUnicode and width arrays; used faces embed per-document TrueType glyf subsets that keep the original glyph IDs, include composite components, and carry a matching ToUnicode CMap; ASCII documents use the compact tier; no Base-14 dependency; SVG carries family/weight/style; route-D PDFs embed Knuth's Computer Modern Type1 programs (cmr10/cmbx10/cmti10/cmbxti10/cmtt10/cmss10) as `/Subtype /Type1` fonts with `/FontFile` (`Length1/2/3`), `/Encoding /Differences` and TFM `/Widths`, falling back per face to Liberation when the program does not encode every character | | M6 specials/XObject | partial | raw specials, RGB image XObjects, URI link annotations; class/package execution absent | | M7 incremental integration | partial | route-D preview/PDF/edit endpoints plus opt-in `?engine=route-d` project preview, content-based page hashes and section/emphasis/display-math/itemize/enumerate/description/quote/center/flushright mapping; editor toggle in `texrra-web`; inline math pending | @@ -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. -The crate currently has 365 unit tests plus eight route-D integration tests and thirty-five oracle fixtures. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 544 tests (365 route-D unit, 33 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 381 unit tests plus eight route-D integration tests and thirty-five oracle fixtures. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 560 tests (381 route-D unit, 33 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