diff --git a/crates/texrra-tex-core/src/math.rs b/crates/texrra-tex-core/src/math.rs index 72dbb59..60eb2c4 100755 --- a/crates/texrra-tex-core/src/math.rs +++ b/crates/texrra-tex-core/src/math.rs @@ -158,6 +158,7 @@ fn atom_class(atom: &MathAtom) -> MathClass { MathAtom::Symbol(character) => math_class(*character), MathAtom::Classed { class, .. } => *class, MathAtom::Row(atoms) => atoms.last().map(atom_class).unwrap_or(MathClass::Ordinary), + MathAtom::Negated { base } => atom_class(base), _ => MathClass::Ordinary, } } @@ -761,11 +762,14 @@ fn parse_atom(chars: &[char], index: usize) -> (MathAtom, usize) { "pmod" => { let (inner, after) = parse_atom(chars, next); ( - MathAtom::Row(vec![ - MathAtom::Text("(mod ".to_owned()), - inner, - MathAtom::Text(")".to_owned()), - ]), + MathAtom::Classed { + class: MathClass::Relation, + body: Box::new(MathAtom::Row(vec![ + MathAtom::Text("(mod ".to_owned()), + inner, + MathAtom::Text(")".to_owned()), + ])), + }, after, ) } @@ -1003,12 +1007,13 @@ mod tests { let MathAtom::Row(atoms) = parsed else { panic!("expected row") }; - let MathAtom::Row(inner) = &atoms[0] else { - panic!("expected inner row") - }; - assert_eq!(inner.len(), 3); - assert!(matches!(&inner[0], MathAtom::Text(text) if text == "(mod ")); - assert!(matches!(&inner[2], MathAtom::Text(text) if text == ")")); + assert!(matches!( + &atoms[0], + MathAtom::Classed { + class: MathClass::Relation, + .. + } + )); } #[test] diff --git a/docs/TEX_CORE.md b/docs/TEX_CORE.md index 0ff8aa5..84334fc 100755 --- a/docs/TEX_CORE.md +++ b/docs/TEX_CORE.md @@ -202,3 +202,5 @@ for a later overlaid slash. `\noalign{...}` material in a halign source is skipped while rows are scanned. `\bmod`/`\pmod{n}` parse to upright `mod` rows, with `\pmod` wrapping its argument in `(mod ...)`. + +`\pmod{n}` is a `Classed` relation, and `\not` inherits the base atom's math class for spacing.