Model negated math atoms
This commit is contained in:
1 parent
792621d39b
commit
3639dc0f20
2 files changed
+35
No files matched your search
@@ -27,6 +27,9 @@ pub enum MathAtom {
|
|||||||
Underline {
|
Underline {
|
||||||
base: Box<MathAtom>,
|
base: Box<MathAtom>,
|
||||||
},
|
},
|
||||||
|
Negated {
|
||||||
|
base: Box<MathAtom>,
|
||||||
|
},
|
||||||
BigOperator {
|
BigOperator {
|
||||||
name: String,
|
name: String,
|
||||||
},
|
},
|
||||||
@@ -333,6 +336,14 @@ pub fn layout_math(atom: &MathAtom, font: &Cmr10Metrics) -> MathBox {
|
|||||||
depth: denominator.depth,
|
depth: denominator.depth,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
MathAtom::Negated { base } => {
|
||||||
|
let inner = layout_math(base, font);
|
||||||
|
MathBox {
|
||||||
|
width: inner.width,
|
||||||
|
height: inner.height,
|
||||||
|
depth: inner.depth,
|
||||||
|
}
|
||||||
|
}
|
||||||
MathAtom::Underline { base } => {
|
MathAtom::Underline { base } => {
|
||||||
let base_box = layout_math(base, font);
|
let base_box = layout_math(base, font);
|
||||||
MathBox {
|
MathBox {
|
||||||
@@ -737,6 +748,15 @@ fn parse_atom(chars: &[char], index: usize) -> (MathAtom, usize) {
|
|||||||
}
|
}
|
||||||
(MathAtom::Text(text), after)
|
(MathAtom::Text(text), after)
|
||||||
}
|
}
|
||||||
|
"not" => {
|
||||||
|
let (base, after) = parse_atom(chars, next);
|
||||||
|
(
|
||||||
|
MathAtom::Negated {
|
||||||
|
base: Box::new(base),
|
||||||
|
},
|
||||||
|
after,
|
||||||
|
)
|
||||||
|
}
|
||||||
"text" | "mathrm" => {
|
"text" | "mathrm" => {
|
||||||
let mut after = next;
|
let mut after = next;
|
||||||
if chars.get(after) == Some(&'{') {
|
if chars.get(after) == Some(&'{') {
|
||||||
@@ -964,6 +984,18 @@ mod tests {
|
|||||||
MathAtom::Row(atoms) if matches!(&atoms[0], MathAtom::Text(text) if text == "max")
|
MathAtom::Row(atoms) if matches!(&atoms[0], MathAtom::Text(text) if text == "max")
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn negated_atom_keeps_its_base_geometry() {
|
||||||
|
let font = Cmr10Metrics::default();
|
||||||
|
let plain = layout_math(&parse_math("="), &font);
|
||||||
|
let negated = layout_math(&parse_math("\\not="), &font);
|
||||||
|
assert_eq!(negated.width, plain.width);
|
||||||
|
assert!(matches!(
|
||||||
|
&parse_math("\\not="),
|
||||||
|
MathAtom::Row(atoms) if matches!(&atoms[0], MathAtom::Negated { .. })
|
||||||
|
));
|
||||||
|
}
|
||||||
#[test]
|
#[test]
|
||||||
fn underline_adds_depth_without_changing_width() {
|
fn underline_adds_depth_without_changing_width() {
|
||||||
let font = Cmr10Metrics::default();
|
let font = Cmr10Metrics::default();
|
||||||
|
|||||||
@@ -195,3 +195,6 @@ empty paragraphs.
|
|||||||
column template.
|
column template.
|
||||||
`VerticalItem::Rule { width, height }` and `Unit::rule(id, width, height)`
|
`VerticalItem::Rule { width, height }` and `Unit::rule(id, width, height)`
|
||||||
add filled rules to the vertical list; rules consume page height like boxes.
|
add filled rules to the vertical list; rules consume page height like boxes.
|
||||||
|
|
||||||
|
`\not` becomes `MathAtom::Negated`, preserving the base atom's geometry
|
||||||
|
for a later overlaid slash.
|
||||||
Reference in new issue
Block a user