Add binomial math atoms
This commit is contained in:
1 parent
639f5e8f8b
commit
833253a936
2 files changed
+39
No files matched your search
@@ -27,6 +27,10 @@ pub enum MathAtom {
|
||||
Underline {
|
||||
base: Box<MathAtom>,
|
||||
},
|
||||
Binomial {
|
||||
numerator: Box<MathAtom>,
|
||||
denominator: Box<MathAtom>,
|
||||
},
|
||||
Script {
|
||||
base: Box<MathAtom>,
|
||||
sub: Option<Box<MathAtom>>,
|
||||
@@ -201,6 +205,18 @@ pub fn layout_math(atom: &MathAtom, font: &Cmr10Metrics) -> MathBox {
|
||||
depth: base_box.depth,
|
||||
}
|
||||
}
|
||||
MathAtom::Binomial {
|
||||
numerator,
|
||||
denominator,
|
||||
} => {
|
||||
let numerator = layout_math(numerator, font);
|
||||
let denominator = layout_math(denominator, font);
|
||||
MathBox {
|
||||
width: numerator.width.max(denominator.width) + 4 * 65_536,
|
||||
height: numerator.height + denominator.height + 2 * 65_536,
|
||||
depth: denominator.depth,
|
||||
}
|
||||
}
|
||||
MathAtom::Underline { base } => {
|
||||
let base_box = layout_math(base, font);
|
||||
MathBox {
|
||||
@@ -388,6 +404,17 @@ fn parse_atom(chars: &[char], index: usize) -> (MathAtom, usize) {
|
||||
after,
|
||||
)
|
||||
}
|
||||
"binom" | "dbinom" | "tbinom" => {
|
||||
let (numerator, after) = parse_atom(chars, next);
|
||||
let (denominator, after) = parse_atom(chars, after);
|
||||
(
|
||||
MathAtom::Binomial {
|
||||
numerator: Box::new(numerator),
|
||||
denominator: Box::new(denominator),
|
||||
},
|
||||
after,
|
||||
)
|
||||
}
|
||||
"underline" => {
|
||||
let (base, after) = parse_atom(chars, next);
|
||||
(
|
||||
@@ -531,6 +558,15 @@ mod tests {
|
||||
assert!(indexed.height > plain.height);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn binom_stacks_two_arguments() {
|
||||
let font = Cmr10Metrics::default();
|
||||
let binom = layout_math(&parse_math("\\binom{n}{k}"), &font);
|
||||
let single = layout_math(&parse_math("n"), &font);
|
||||
assert!(binom.width >= single.width);
|
||||
assert!(binom.height > single.height);
|
||||
assert!(binom.depth > 0);
|
||||
}
|
||||
#[test]
|
||||
fn named_operators_use_upright_text_widths() {
|
||||
let font = Cmr10Metrics::default();
|
||||
|
||||
Reference in new issue
Block a user