Add underline math atoms
This commit is contained in:
1 parent
053468875e
commit
b11fc864f2
2 files changed
+31
No files matched your search
@@ -24,6 +24,9 @@ pub enum MathAtom {
|
|||||||
accent: char,
|
accent: char,
|
||||||
base: Box<MathAtom>,
|
base: Box<MathAtom>,
|
||||||
},
|
},
|
||||||
|
Underline {
|
||||||
|
base: Box<MathAtom>,
|
||||||
|
},
|
||||||
Script {
|
Script {
|
||||||
base: Box<MathAtom>,
|
base: Box<MathAtom>,
|
||||||
sub: Option<Box<MathAtom>>,
|
sub: Option<Box<MathAtom>>,
|
||||||
@@ -198,6 +201,14 @@ pub fn layout_math(atom: &MathAtom, font: &Cmr10Metrics) -> MathBox {
|
|||||||
depth: base_box.depth,
|
depth: base_box.depth,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
MathAtom::Underline { base } => {
|
||||||
|
let base_box = layout_math(base, font);
|
||||||
|
MathBox {
|
||||||
|
width: base_box.width,
|
||||||
|
height: base_box.height,
|
||||||
|
depth: base_box.depth + 2 * 65_536,
|
||||||
|
}
|
||||||
|
}
|
||||||
MathAtom::Script { base, sub, sup } => {
|
MathAtom::Script { base, sub, sup } => {
|
||||||
let base_box = layout_math(base, font);
|
let base_box = layout_math(base, font);
|
||||||
let sub_box = sub.as_deref().map(|atom| layout_math(atom, font));
|
let sub_box = sub.as_deref().map(|atom| layout_math(atom, font));
|
||||||
@@ -377,6 +388,15 @@ fn parse_atom(chars: &[char], index: usize) -> (MathAtom, usize) {
|
|||||||
after,
|
after,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
"underline" => {
|
||||||
|
let (base, after) = parse_atom(chars, next);
|
||||||
|
(
|
||||||
|
MathAtom::Underline {
|
||||||
|
base: Box::new(base),
|
||||||
|
},
|
||||||
|
after,
|
||||||
|
)
|
||||||
|
}
|
||||||
"bar" | "overline" => {
|
"bar" | "overline" => {
|
||||||
let (base, after) = parse_atom(chars, next);
|
let (base, after) = parse_atom(chars, next);
|
||||||
(
|
(
|
||||||
@@ -507,6 +527,15 @@ mod tests {
|
|||||||
assert!(indexed.height > plain.height);
|
assert!(indexed.height > plain.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn underline_adds_depth_without_changing_width() {
|
||||||
|
let font = Cmr10Metrics::default();
|
||||||
|
let plain = layout_math(&parse_math("x"), &font);
|
||||||
|
let underlined = layout_math(&parse_math("\\underline{x}"), &font);
|
||||||
|
assert_eq!(underlined.width, plain.width);
|
||||||
|
assert!(underlined.depth > plain.depth);
|
||||||
|
assert_eq!(underlined.height, plain.height);
|
||||||
|
}
|
||||||
#[test]
|
#[test]
|
||||||
fn math_text_uses_upright_character_widths() {
|
fn math_text_uses_upright_character_widths() {
|
||||||
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::Underline { base }` parses `\underline{...}` and adds 2pt depth
|
||||||
|
without changing width or height.
|
||||||
- `MathAtom::Text(String)` parses `\text{...}` and `\mathrm{...}`;
|
- `MathAtom::Text(String)` parses `\text{...}` and `\mathrm{...}`;
|
||||||
widths use upright CMR glyphs and spaces use the font space width.
|
widths use upright CMR glyphs and spaces use the font space width.
|
||||||
- `MathAtom::Delimited { left, right, body }` and `\left...\right`
|
- `MathAtom::Delimited { left, right, body }` and `\left...\right`
|
||||||
|
|||||||
Reference in new issue
Block a user