Model bmod and pmod math spacing

This commit is contained in:
gloamxun committed 2026-10-20 13:19:28 +08:00
1 parent cd0ec782d5
commit fd3f0ffae5
2 files changed
+28

No files matched your search

+26
View File
@@ -757,6 +757,18 @@ fn parse_atom(chars: &[char], index: usize) -> (MathAtom, usize) {
after,
)
}
"bmod" => (MathAtom::Text("mod".to_owned()), next),
"pmod" => {
let (inner, after) = parse_atom(chars, next);
(
MathAtom::Row(vec![
MathAtom::Text("(mod ".to_owned()),
inner,
MathAtom::Text(")".to_owned()),
]),
after,
)
}
"text" | "mathrm" => {
let mut after = next;
if chars.get(after) == Some(&'{') {
@@ -985,6 +997,20 @@ mod tests {
));
}
#[test]
fn pmod_wraps_its_argument_in_a_mod_row() {
let parsed = parse_math(r"\pmod{n}");
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 == ")"));
}
#[test]
fn negated_atom_keeps_its_base_geometry() {
let font = Cmr10Metrics::default();
+2
View File
@@ -200,3 +200,5 @@ add filled rules to the vertical list; rules consume page height like boxes.
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 ...)`.