Model boxed math atoms
This commit is contained in:
1 parent
a0bb8be2ac
commit
af8a34c2e2
2 files changed
+32
No files matched your search
@@ -30,6 +30,9 @@ pub enum MathAtom {
|
|||||||
Negated {
|
Negated {
|
||||||
base: Box<MathAtom>,
|
base: Box<MathAtom>,
|
||||||
},
|
},
|
||||||
|
Boxed {
|
||||||
|
body: Box<MathAtom>,
|
||||||
|
},
|
||||||
BigOperator {
|
BigOperator {
|
||||||
name: String,
|
name: String,
|
||||||
},
|
},
|
||||||
@@ -340,6 +343,14 @@ pub fn layout_math(atom: &MathAtom, font: &Cmr10Metrics) -> MathBox {
|
|||||||
depth: denominator.depth,
|
depth: denominator.depth,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
MathAtom::Boxed { body } => {
|
||||||
|
let inner = layout_math(body, font);
|
||||||
|
MathBox {
|
||||||
|
width: inner.width + 6 * 65_536,
|
||||||
|
height: inner.height + 3 * 65_536,
|
||||||
|
depth: inner.depth + 3 * 65_536,
|
||||||
|
}
|
||||||
|
}
|
||||||
MathAtom::Negated { base } => {
|
MathAtom::Negated { base } => {
|
||||||
let inner = layout_math(base, font);
|
let inner = layout_math(base, font);
|
||||||
MathBox {
|
MathBox {
|
||||||
@@ -777,6 +788,15 @@ fn parse_atom(chars: &[char], index: usize) -> (MathAtom, usize) {
|
|||||||
after,
|
after,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
"boxed" => {
|
||||||
|
let (body, after) = parse_atom(chars, next);
|
||||||
|
(
|
||||||
|
MathAtom::Boxed {
|
||||||
|
body: Box::new(body),
|
||||||
|
},
|
||||||
|
after,
|
||||||
|
)
|
||||||
|
}
|
||||||
"text" | "mathrm" => {
|
"text" | "mathrm" => {
|
||||||
let mut after = next;
|
let mut after = next;
|
||||||
if chars.get(after) == Some(&'{') {
|
if chars.get(after) == Some(&'{') {
|
||||||
@@ -939,6 +959,16 @@ mod tests {
|
|||||||
assert!(sum.height > plain.height);
|
assert!(sum.height > plain.height);
|
||||||
assert!(sum.depth > plain.depth);
|
assert!(sum.depth > plain.depth);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn boxed_pads_its_body_on_all_sides() {
|
||||||
|
let font = Cmr10Metrics::default();
|
||||||
|
let plain = layout_math(&parse_math("x"), &font);
|
||||||
|
let boxed = layout_math(&parse_math(r"\boxed{x}"), &font);
|
||||||
|
assert_eq!(boxed.width, plain.width + 6 * 65_536);
|
||||||
|
assert_eq!(boxed.height, plain.height + 3 * 65_536);
|
||||||
|
assert_eq!(boxed.depth, plain.depth + 3 * 65_536);
|
||||||
|
}
|
||||||
#[test]
|
#[test]
|
||||||
fn mathinner_adds_three_mu_on_both_sides() {
|
fn mathinner_adds_three_mu_on_both_sides() {
|
||||||
let font = Cmr10Metrics::default();
|
let font = Cmr10Metrics::default();
|
||||||
|
|||||||
@@ -206,3 +206,5 @@ for a later overlaid slash.
|
|||||||
`\pmod{n}` is a `Classed` relation, and `\not` inherits the base atom's math class for spacing.
|
`\pmod{n}` is a `Classed` relation, and `\not` inherits the base atom's math class for spacing.
|
||||||
|
|
||||||
`\mathinner{...}` uses `MathClass::Inner` with 3mu on either side.
|
`\mathinner{...}` uses `MathClass::Inner` with 3mu on either side.
|
||||||
|
|
||||||
|
`\boxed{x}` adds 3pt padding around its body in the math model.
|
||||||
Reference in new issue
Block a user