Parse operatorname as upright math text

This commit is contained in:
gloamxun committed 2026-10-20 19:08:16 +08:00
1 parent ab35e280f1
commit f3bbe4098b
1 file changed
+25
+25
View File
@@ -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();