From f3bbe4098b89dc65d4b7cacf579026c67b14febf Mon Sep 17 00:00:00 2001 From: GloamXun Date: Tue, 20 Oct 2026 19:08:16 +0800 Subject: [PATCH] Parse operatorname as upright math text --- crates/texrra-tex-core/src/math.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/crates/texrra-tex-core/src/math.rs b/crates/texrra-tex-core/src/math.rs index 0465b25..050d45e 100755 --- a/crates/texrra-tex-core/src/math.rs +++ b/crates/texrra-tex-core/src/math.rs @@ -916,6 +916,24 @@ fn parse_atom(chars: &[char], index: usize) -> (MathAtom, usize) { after, ) } + "operatorname" => { + let mut after = next; + if chars.get(after) == Some(&'{') { + after += 1; + } + let start = after; + while after < chars.len() && chars[after] != '}' { + after += 1; + } + let text: String = chars[start..after] + .iter() + .map(|ch| if *ch == '\u{0}' { ' ' } else { *ch }) + .collect(); + if after < chars.len() { + after += 1; + } + (MathAtom::Text(text), after) + } "text" | "mathrm" => { let mut after = next; if chars.get(after) == Some(&'{') { @@ -1247,6 +1265,13 @@ mod tests { assert_eq!(under.height, plain.height); } + #[test] + fn operatorname_becomes_upright_text() { + let font = Cmr10Metrics::default(); + let long = layout_math(&parse_math(r"\operatorname{argmax}"), &font); + let short = layout_math(&parse_math(r"\operatorname{arg}"), &font); + assert!(long.width > short.width); + } #[test] fn fraction_style_aliases_match_frac() { let font = Cmr10Metrics::default();