Support directional smash options
This commit is contained in:
1 parent
c311938129
commit
e650177585
2 files changed
+39
-4
No files matched your search
@@ -558,12 +558,36 @@ fn parse_atom(chars: &[char], index: usize) -> (MathAtom, usize) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
"smash" => {
|
"smash" => {
|
||||||
let (body, after) = parse_atom(chars, next);
|
let mut cursor = next;
|
||||||
|
while cursor < chars.len() && chars[cursor].is_whitespace() {
|
||||||
|
cursor += 1;
|
||||||
|
}
|
||||||
|
let mut top = true;
|
||||||
|
let mut bottom = true;
|
||||||
|
if chars.get(cursor) == Some(&'[') {
|
||||||
|
let mut end = cursor + 1;
|
||||||
|
while end < chars.len() && chars[end] != ']' {
|
||||||
|
match chars[end] {
|
||||||
|
't' => {
|
||||||
|
top = true;
|
||||||
|
bottom = false;
|
||||||
|
}
|
||||||
|
'b' => {
|
||||||
|
top = false;
|
||||||
|
bottom = true;
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
end += 1;
|
||||||
|
}
|
||||||
|
cursor = (end + 1).min(chars.len());
|
||||||
|
}
|
||||||
|
let (body, after) = parse_atom(chars, cursor);
|
||||||
(
|
(
|
||||||
MathAtom::Smash {
|
MathAtom::Smash {
|
||||||
body: Box::new(body),
|
body: Box::new(body),
|
||||||
top: true,
|
top,
|
||||||
bottom: true,
|
bottom,
|
||||||
},
|
},
|
||||||
after,
|
after,
|
||||||
)
|
)
|
||||||
@@ -828,6 +852,16 @@ mod tests {
|
|||||||
assert_eq!(calligraphic.height, upright.height);
|
assert_eq!(calligraphic.height, upright.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn smash_can_target_only_the_top_or_bottom() {
|
||||||
|
let font = Cmr10Metrics::default();
|
||||||
|
let top = layout_math(&parse_math("\\smash[t]{x}"), &font);
|
||||||
|
let bottom = layout_math(&parse_math("\\smash[b]{x}"), &font);
|
||||||
|
assert_eq!(top.height, 0);
|
||||||
|
assert!(top.depth > 0);
|
||||||
|
assert!(bottom.height > 0);
|
||||||
|
assert_eq!(bottom.depth, 0);
|
||||||
|
}
|
||||||
#[test]
|
#[test]
|
||||||
fn smash_removes_height_but_keeps_width() {
|
fn smash_removes_height_but_keeps_width() {
|
||||||
let font = Cmr10Metrics::default();
|
let font = Cmr10Metrics::default();
|
||||||
|
|||||||
+2
-1
@@ -113,7 +113,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::Smash { body, top, bottom }` implements `\smash` (zero height/depth).
|
- `MathAtom::Smash { body, top, bottom }` implements `\smash` and
|
||||||
|
`\smash[t]`/`\smash[b]`.
|
||||||
- `MathAtom::Phantom { body, horizontal, vertical }` implements
|
- `MathAtom::Phantom { body, horizontal, vertical }` implements
|
||||||
`\phantom`, `\hphantom`, `\vphantom` dimension-only boxes.
|
`\phantom`, `\hphantom`, `\vphantom` dimension-only boxes.
|
||||||
- `MathAtom::BigOperator { name }` gives `\sum`/`\prod` 12pt width and
|
- `MathAtom::BigOperator { name }` gives `\sum`/`\prod` 12pt width and
|
||||||
|
|||||||
Reference in new issue
Block a user