diff --git a/crates/texrra-tex-core/src/math.rs b/crates/texrra-tex-core/src/math.rs index a2a0d4a..947eb42 100755 --- a/crates/texrra-tex-core/src/math.rs +++ b/crates/texrra-tex-core/src/math.rs @@ -123,6 +123,7 @@ pub enum MathClass { Close, Punctuation, Inner, + Op, } pub fn math_class(character: char) -> MathClass { @@ -151,6 +152,8 @@ fn spacing_mu(left: MathClass, right: MathClass) -> i64 { (Binary, Relation) | (Relation, Binary) => 0, (Inner, Inner) => 0, (Inner, _) | (_, Inner) => 3, + (Op, Op) => 0, + (Op, _) | (_, Op) => 3, (Ordinary, Ordinary) => 0, _ => 0, } @@ -652,7 +655,7 @@ fn parse_atom(chars: &[char], index: usize) -> (MathAtom, usize) { | "mathpunct" | "mathinner" => { let (body, after) = parse_atom(chars, next); let class = match command.as_str() { - "mathop" => MathClass::Ordinary, + "mathop" => MathClass::Op, "mathbin" => MathClass::Binary, "mathrel" => MathClass::Relation, "mathopen" => MathClass::Open, @@ -1037,6 +1040,17 @@ mod tests { assert_eq!(boxed.height, plain.height + 3 * 65_536); assert_eq!(boxed.depth, plain.depth + 3 * 65_536); } + + #[test] + fn mathop_uses_the_operator_spacing_class() { + let MathAtom::Row(atoms) = parse_math(r"\mathop{x}") else { + panic!("expected row") + }; + let MathAtom::Classed { class, .. } = &atoms[0] else { + panic!("expected classed") + }; + assert_eq!(*class, MathClass::Op); + } #[test] fn mathinner_adds_three_mu_on_both_sides() { let font = Cmr10Metrics::default(); diff --git a/docs/TEX_CORE.md b/docs/TEX_CORE.md index 57fa06e..1f78e49 100755 --- a/docs/TEX_CORE.md +++ b/docs/TEX_CORE.md @@ -241,3 +241,5 @@ v1 remains the production renderer; the route-D core is additive and tested inde `\overleftrightarrow` uses U+20E1. `Unit::mark(id, class, text)` and `Unit::float(id, placement, width, height)` are convenience constructors for M2 page items. + + uses the Op spacing class (3mu against ordinary atoms).