Give mathop its own spacing class

This commit is contained in:
gloamxun committed 2026-10-20 13:35:00 +08:00
1 parent 6116bf3553
commit 10ba5c7243
2 files changed
+17 -1

No files matched your search

+15 -1
View File
@@ -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();
+2
View File
@@ -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).