Accept tfrac, dfrac and cfrac as fraction aliases

This commit is contained in:
gloamxun committed 2026-10-20 19:07:28 +08:00
1 parent 4de329c327
commit ab35e280f1
1 file changed
+12 -1
+12 -1
View File
@@ -588,7 +588,7 @@ fn parse_atom(chars: &[char], index: usize) -> (MathAtom, usize) {
}
parse_atom(chars, after)
}
"frac" => {
"frac" | "tfrac" | "dfrac" | "cfrac" => {
let (numerator, after) = parse_atom(chars, next);
let (denominator, after) = parse_atom(chars, after);
(MathAtom::fraction(numerator, denominator), after)
@@ -1247,6 +1247,17 @@ mod tests {
assert_eq!(under.height, plain.height);
}
#[test]
fn fraction_style_aliases_match_frac() {
let font = Cmr10Metrics::default();
let plain = layout_math(&parse_math(r"\frac{a}{b}"), &font);
for command in ["tfrac", "dfrac", "cfrac"] {
let source = format!(r"\{command}{{a}}{{b}}");
let boxed = layout_math(&parse_math(&source), &font);
assert_eq!(plain.width, boxed.width);
assert_eq!(plain.height, boxed.height);
}
}
#[test]
fn math_spacing_commands_have_expected_widths() {
let font = Cmr10Metrics::default();