Add the mathinner spacing class

This commit is contained in:
gloamxun committed 2026-10-20 13:23:28 +08:00
1 parent 33125d1f16
commit a0bb8be2ac
2 files changed
+13

No files matched your search

+11
View File
@@ -118,6 +118,7 @@ pub enum MathClass {
Open,
Close,
Punctuation,
Inner,
}
pub fn math_class(character: char) -> MathClass {
@@ -144,6 +145,8 @@ fn spacing_mu(left: MathClass, right: MathClass) -> i64 {
(Ordinary, Binary) | (Binary, Ordinary) => 4,
(Ordinary, Relation) | (Relation, Ordinary) => 5,
(Binary, Relation) | (Relation, Binary) => 0,
(Inner, Inner) => 0,
(Inner, _) | (_, Inner) => 3,
(Ordinary, Ordinary) => 0,
_ => 0,
}
@@ -635,6 +638,7 @@ fn parse_atom(chars: &[char], index: usize) -> (MathAtom, usize) {
"mathopen" => MathClass::Open,
"mathclose" => MathClass::Close,
"mathpunct" => MathClass::Punctuation,
"mathinner" => MathClass::Inner,
_ => MathClass::Ordinary,
};
(
@@ -936,6 +940,13 @@ mod tests {
assert!(sum.depth > plain.depth);
}
#[test]
fn mathinner_adds_three_mu_on_both_sides() {
let font = Cmr10Metrics::default();
let plain = layout_math(&parse_math("axb"), &font);
let inner = layout_math(&parse_math(r"a\mathinner{x}b"), &font);
assert!(inner.width > plain.width + 10_000);
}
#[test]
fn mathrel_wrapper_forces_relation_spacing() {
let font = Cmr10Metrics::default();
let plain = layout_math(&parse_math("a+b"), &font);
+2
View File
@@ -204,3 +204,5 @@ for a later overlaid slash.
`\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.
`\mathinner{...}` uses `MathClass::Inner` with 3mu on either side.