Give big operators display-sized metrics
This commit is contained in:
1 parent
40af634efd
commit
e55b44beac
2 files changed
+34
-1
No files matched your search
@@ -27,6 +27,9 @@ pub enum MathAtom {
|
|||||||
Underline {
|
Underline {
|
||||||
base: Box<MathAtom>,
|
base: Box<MathAtom>,
|
||||||
},
|
},
|
||||||
|
BigOperator {
|
||||||
|
name: String,
|
||||||
|
},
|
||||||
Limits {
|
Limits {
|
||||||
base: Box<MathAtom>,
|
base: Box<MathAtom>,
|
||||||
sub: Option<Box<MathAtom>>,
|
sub: Option<Box<MathAtom>>,
|
||||||
@@ -228,6 +231,18 @@ pub fn layout_math(atom: &MathAtom, font: &Cmr10Metrics) -> MathBox {
|
|||||||
depth: base_box.depth,
|
depth: base_box.depth,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
MathAtom::BigOperator { name } => {
|
||||||
|
let (width, height, depth) = match name.as_str() {
|
||||||
|
"int" => (8, 10, 4),
|
||||||
|
"prod" => (12, 8, 3),
|
||||||
|
_ => (12, 8, 3),
|
||||||
|
};
|
||||||
|
MathBox {
|
||||||
|
width: width * 65_536,
|
||||||
|
height: height * 65_536,
|
||||||
|
depth: depth * 65_536,
|
||||||
|
}
|
||||||
|
}
|
||||||
MathAtom::Limits { base, sub, sup } => {
|
MathAtom::Limits { base, sub, sup } => {
|
||||||
let base = layout_math(base, font);
|
let base = layout_math(base, font);
|
||||||
let sub = sub.as_ref().map(|atom| layout_math(atom, font));
|
let sub = sub.as_ref().map(|atom| layout_math(atom, font));
|
||||||
@@ -512,7 +527,13 @@ fn parse_atom(chars: &[char], index: usize) -> (MathAtom, usize) {
|
|||||||
after,
|
after,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
"sum" | "prod" | "int" | "lim" | "sup" | "inf" => {
|
"sum" | "prod" | "int" => {
|
||||||
|
let base = MathAtom::BigOperator {
|
||||||
|
name: command.clone(),
|
||||||
|
};
|
||||||
|
parse_limits(chars, next, base)
|
||||||
|
}
|
||||||
|
"lim" | "sup" | "inf" => {
|
||||||
let base = MathAtom::Text(command.clone());
|
let base = MathAtom::Text(command.clone());
|
||||||
parse_limits(chars, next, base)
|
parse_limits(chars, next, base)
|
||||||
}
|
}
|
||||||
@@ -754,6 +775,16 @@ mod tests {
|
|||||||
assert_eq!(calligraphic.width, upright.width);
|
assert_eq!(calligraphic.width, upright.width);
|
||||||
assert_eq!(calligraphic.height, upright.height);
|
assert_eq!(calligraphic.height, upright.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn big_operators_are_wider_than_letters() {
|
||||||
|
let font = Cmr10Metrics::default();
|
||||||
|
let sum = layout_math(&parse_math("\\sum"), &font);
|
||||||
|
let letter = layout_math(&parse_math("s"), &font);
|
||||||
|
assert!(sum.width > letter.width);
|
||||||
|
assert!(sum.height > letter.height);
|
||||||
|
assert!(sum.depth > letter.depth);
|
||||||
|
}
|
||||||
#[test]
|
#[test]
|
||||||
fn sum_places_scripts_above_and_below() {
|
fn sum_places_scripts_above_and_below() {
|
||||||
let font = Cmr10Metrics::default();
|
let font = Cmr10Metrics::default();
|
||||||
|
|||||||
@@ -110,6 +110,8 @@ a single cost function.
|
|||||||
- `MathAtom::Accent { accent, base }` parses `\hat`, `\widehat`,
|
- `MathAtom::Accent { accent, base }` parses `\hat`, `\widehat`,
|
||||||
`\tilde`, `\widetilde`, `\bar`, `\overline` and `\vec`; it adds
|
`\tilde`, `\widetilde`, `\bar`, `\overline` and `\vec`; it adds
|
||||||
accent height without changing the base width.
|
accent height without changing the base width.
|
||||||
|
- `MathAtom::BigOperator { name }` gives `\sum`/`\prod` 12pt width and
|
||||||
|
`\int` 8pt width with larger height/depth than text.
|
||||||
- `MathAtom::Limits { base, sub, sup }` gives `\sum`, `\prod`, `\int`,
|
- `MathAtom::Limits { base, sub, sup }` gives `\sum`, `\prod`, `\int`,
|
||||||
`\lim`, `\sup`, `\inf` above/below scripts.
|
`\lim`, `\sup`, `\inf` above/below scripts.
|
||||||
- `MathAtom::Classed { class, body }` implements `\mathord`, `\mathop`,
|
- `MathAtom::Classed { class, body }` implements `\mathord`, `\mathop`,
|
||||||
|
|||||||
Reference in new issue
Block a user