From 3639dc0f20ddb97f44f69f3886466253b23f8495 Mon Sep 17 00:00:00 2001 From: GloamXun Date: Tue, 20 Oct 2026 13:16:54 +0800 Subject: [PATCH] Model negated math atoms --- crates/texrra-tex-core/src/math.rs | 32 ++++++++++++++++++++++++++++++ docs/TEX_CORE.md | 3 +++ 2 files changed, 35 insertions(+) diff --git a/crates/texrra-tex-core/src/math.rs b/crates/texrra-tex-core/src/math.rs index 4573765..2a120c2 100755 --- a/crates/texrra-tex-core/src/math.rs +++ b/crates/texrra-tex-core/src/math.rs @@ -27,6 +27,9 @@ pub enum MathAtom { Underline { base: Box, }, + Negated { + base: Box, + }, BigOperator { name: String, }, @@ -333,6 +336,14 @@ pub fn layout_math(atom: &MathAtom, font: &Cmr10Metrics) -> MathBox { depth: denominator.depth, } } + MathAtom::Negated { base } => { + let inner = layout_math(base, font); + MathBox { + width: inner.width, + height: inner.height, + depth: inner.depth, + } + } MathAtom::Underline { base } => { let base_box = layout_math(base, font); MathBox { @@ -737,6 +748,15 @@ fn parse_atom(chars: &[char], index: usize) -> (MathAtom, usize) { } (MathAtom::Text(text), after) } + "not" => { + let (base, after) = parse_atom(chars, next); + ( + MathAtom::Negated { + base: Box::new(base), + }, + after, + ) + } "text" | "mathrm" => { let mut after = next; if chars.get(after) == Some(&'{') { @@ -964,6 +984,18 @@ mod tests { MathAtom::Row(atoms) if matches!(&atoms[0], MathAtom::Text(text) if text == "max") )); } + + #[test] + fn negated_atom_keeps_its_base_geometry() { + let font = Cmr10Metrics::default(); + let plain = layout_math(&parse_math("="), &font); + let negated = layout_math(&parse_math("\\not="), &font); + assert_eq!(negated.width, plain.width); + assert!(matches!( + &parse_math("\\not="), + MathAtom::Row(atoms) if matches!(&atoms[0], MathAtom::Negated { .. }) + )); + } #[test] fn underline_adds_depth_without_changing_width() { let font = Cmr10Metrics::default(); diff --git a/docs/TEX_CORE.md b/docs/TEX_CORE.md index 8b275fb..705be85 100755 --- a/docs/TEX_CORE.md +++ b/docs/TEX_CORE.md @@ -195,3 +195,6 @@ empty paragraphs. column template. `VerticalItem::Rule { width, height }` and `Unit::rule(id, width, height)` add filled rules to the vertical list; rules consume page height like boxes. + +`\not` becomes `MathAtom::Negated`, preserving the base atom's geometry +for a later overlaid slash.