Place starred operatorname limits below the operator

This commit is contained in:
gloamxun committed 2026-10-20 19:20:18 +08:00
1 parent b8a135d2b6
commit ae8f81b1a2
1 file changed
+17 -2
+17 -2
View File
@@ -993,7 +993,8 @@ fn parse_atom(chars: &[char], index: usize) -> (MathAtom, usize) {
}
"operatorname" => {
let mut after = next;
if chars.get(after) == Some(&'*') {
let starred = chars.get(after) == Some(&'*');
if starred {
after += 1;
}
if chars.get(after) == Some(&'{') {
@@ -1010,7 +1011,12 @@ fn parse_atom(chars: &[char], index: usize) -> (MathAtom, usize) {
if after < chars.len() {
after += 1;
}
(MathAtom::Text(text), after)
let atom = MathAtom::Text(text);
if starred {
parse_limits(chars, after, atom)
} else {
(atom, after)
}
}
"text" | "mathrm" => {
let mut after = next;
@@ -1389,6 +1395,15 @@ mod tests {
MathAtom::Row(atoms) if matches!(&atoms[0], MathAtom::Text(text) if text == "mod")
));
}
#[test]
fn starred_operatorname_takes_limits_below() {
let font = Cmr10Metrics::default();
let plain = layout_math(&parse_math(r"\operatorname*{argmax}"), &font);
let limited = layout_math(&parse_math(r"\operatorname*{argmax}_{x}"), &font);
assert!(limited.depth > plain.depth);
assert!(limited.width >= plain.width);
}
#[test]
fn operatorname_star_does_not_emit_a_symbol() {
let font = Cmr10Metrics::default();