Support stakrel as an overset stack

This commit is contained in:
gloamxun committed 2026-10-20 13:26:49 +08:00
1 parent 51d65e6fad
commit 7802df54a3
2 files changed
+12 -2

No files matched your search

+10 -2
View File
@@ -678,14 +678,14 @@ fn parse_atom(chars: &[char], index: usize) -> (MathAtom, usize) {
(after + 1).min(chars.len()), (after + 1).min(chars.len()),
) )
} }
"overset" | "underset" => { "overset" | "underset" | "stackrel" => {
let (top, after) = parse_atom(chars, next); let (top, after) = parse_atom(chars, next);
let (base, after) = parse_atom(chars, after); let (base, after) = parse_atom(chars, after);
( (
MathAtom::Stack { MathAtom::Stack {
top: Box::new(top), top: Box::new(top),
base: Box::new(base), base: Box::new(base),
above: command == "overset", above: command != "underset",
}, },
after, after,
) )
@@ -999,6 +999,14 @@ mod tests {
assert!(tall.height > plain.height); assert!(tall.height > plain.height);
assert!(tall.width > plain.width); assert!(tall.width > plain.width);
} }
#[test]
fn stackrel_places_its_first_argument_above_the_relation() {
let font = Cmr10Metrics::default();
let plain = layout_math(&parse_math("="), &font);
let stacked = layout_math(&parse_math(r"\stackrel{def}{=}"), &font);
assert!(stacked.height > plain.height);
}
#[test] #[test]
fn overset_and_underset_stack_their_arguments() { fn overset_and_underset_stack_their_arguments() {
let font = Cmr10Metrics::default(); let font = Cmr10Metrics::default();
+2
View File
@@ -212,3 +212,5 @@ for a later overlaid slash.
`Unit::vskip(id, height)` adds a vertical glue item to the page list. `Unit::vskip(id, height)` adds a vertical glue item to the page list.
`Unit::penalty(id, value)` adds a vertical penalty; values <= -10000 force a page break. `Unit::penalty(id, value)` adds a vertical penalty; values <= -10000 force a page break.
`\stackrel{top}{base}` shares the `Stack` layout with `\overset`.