From 6876935e604364b97b92542f73e23a6a7595083d Mon Sep 17 00:00:00 2001 From: GloamXun Date: Tue, 20 Oct 2026 19:00:01 +0800 Subject: [PATCH] Treat math style declarations as transparent --- crates/texrra-tex-core/src/math.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/crates/texrra-tex-core/src/math.rs b/crates/texrra-tex-core/src/math.rs index dfab6bf..fcb1330 100755 --- a/crates/texrra-tex-core/src/math.rs +++ b/crates/texrra-tex-core/src/math.rs @@ -550,6 +550,13 @@ fn parse_atom(chars: &[char], index: usize) -> (MathAtom, usize) { } } return match command.as_str() { + "displaystyle" | "textstyle" | "scriptstyle" | "scriptscriptstyle" => { + let mut after = next; + while chars.get(after).is_some_and(|ch| ch.is_whitespace()) { + after += 1; + } + parse_atom(chars, after) + } "frac" => { let (numerator, after) = parse_atom(chars, next); let (denominator, after) = parse_atom(chars, after); @@ -1205,6 +1212,15 @@ mod tests { assert!(under.depth > plain.depth); assert_eq!(under.height, plain.height); } + + #[test] + fn math_style_commands_are_transparent() { + let font = Cmr10Metrics::default(); + let plain = layout_math(&parse_math("x"), &font); + let styled = layout_math(&parse_math(r"\displaystyle{x}"), &font); + assert_eq!(plain.width, styled.width); + assert_eq!(plain.height, styled.height); + } #[test] fn binom_stacks_two_arguments() { let font = Cmr10Metrics::default();