diff --git a/crates/texrra-tex-core/src/math.rs b/crates/texrra-tex-core/src/math.rs index 04a1582..70cb1aa 100755 --- a/crates/texrra-tex-core/src/math.rs +++ b/crates/texrra-tex-core/src/math.rs @@ -2163,14 +2163,27 @@ fn parse_atom(chars: &[char], index: usize) -> (MathAtom, usize) { } "mathstrut" => (MathAtom::Strut, next), "phantom" | "hphantom" | "vphantom" => { - let (body, after) = parse_atom(chars, next); + let mut after = next; + while chars.get(after) == Some(&'\u{0}') + || chars.get(after).is_some_and(|c| c.is_whitespace()) + { + after += 1; + } + let Some((inner, end)) = read_braced_text(chars, after) else { + return (MathAtom::Symbol('?'), (after + 1).min(chars.len())); + }; + let (horizontal, vertical) = match command.as_str() { + "phantom" => (true, true), + "hphantom" => (true, false), + _ => (false, true), + }; ( MathAtom::Phantom { - body: Box::new(body), - horizontal: command != "vphantom", - vertical: command != "hphantom", + body: Box::new(parse_math(&inner)), + horizontal, + vertical, }, - after, + end, ) } "operatorname" => {