Parse substack into stacked math rows
This commit is contained in:
1 parent
60949cf91c
commit
f18fc5187f
2 files changed
+31
No files matched your search
@@ -59,6 +59,7 @@ pub enum MathAtom {
|
|||||||
delimiter: char,
|
delimiter: char,
|
||||||
size: u8,
|
size: u8,
|
||||||
},
|
},
|
||||||
|
StackLines(Vec<MathAtom>),
|
||||||
Stack {
|
Stack {
|
||||||
top: Box<MathAtom>,
|
top: Box<MathAtom>,
|
||||||
base: Box<MathAtom>,
|
base: Box<MathAtom>,
|
||||||
@@ -314,6 +315,14 @@ pub fn layout_math(atom: &MathAtom, font: &Cmr10Metrics) -> MathBox {
|
|||||||
depth: 2 * 65_536,
|
depth: 2 * 65_536,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
MathAtom::StackLines(rows) => {
|
||||||
|
let boxes: Vec<MathBox> = rows.iter().map(|atom| layout_math(atom, font)).collect();
|
||||||
|
MathBox {
|
||||||
|
width: boxes.iter().map(|b| b.width).max().unwrap_or(0),
|
||||||
|
height: boxes.iter().map(|b| b.height).sum(),
|
||||||
|
depth: boxes.last().map_or(0, |b| b.depth),
|
||||||
|
}
|
||||||
|
}
|
||||||
MathAtom::Stack { top, base, above } => {
|
MathAtom::Stack { top, base, above } => {
|
||||||
let top = layout_math(top, font);
|
let top = layout_math(top, font);
|
||||||
let base = layout_math(base, font);
|
let base = layout_math(base, font);
|
||||||
@@ -678,6 +687,19 @@ fn parse_atom(chars: &[char], index: usize) -> (MathAtom, usize) {
|
|||||||
(after + 1).min(chars.len()),
|
(after + 1).min(chars.len()),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
"substack" => {
|
||||||
|
let mut after = next;
|
||||||
|
if chars.get(after) == Some(&'{') {
|
||||||
|
after += 1;
|
||||||
|
}
|
||||||
|
let start = after;
|
||||||
|
while after < chars.len() && chars[after] != '}' {
|
||||||
|
after += 1;
|
||||||
|
}
|
||||||
|
let content: String = chars[start..after].iter().collect();
|
||||||
|
let rows = content.split("\\\\").map(parse_math).collect();
|
||||||
|
(MathAtom::StackLines(rows), (after + 1).min(chars.len()))
|
||||||
|
}
|
||||||
"overset" | "underset" | "stackrel" => {
|
"overset" | "underset" | "stackrel" => {
|
||||||
let (top, after) = parse_atom(chars, next);
|
let (top, after) = parse_atom(chars, next);
|
||||||
let (base, after) = parse_atom(chars, after);
|
let (base, after) = parse_atom(chars, after);
|
||||||
@@ -1036,6 +1058,13 @@ mod tests {
|
|||||||
assert!(tall.width > plain.width);
|
assert!(tall.width > plain.width);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn substack_stacks_multiple_rows() {
|
||||||
|
let font = Cmr10Metrics::default();
|
||||||
|
let plain = layout_math(&parse_math("a"), &font);
|
||||||
|
let stacked = layout_math(&parse_math(r"\substack{a\\b}"), &font);
|
||||||
|
assert!(stacked.height > plain.height);
|
||||||
|
}
|
||||||
#[test]
|
#[test]
|
||||||
fn overbrace_accepts_a_superscript_label() {
|
fn overbrace_accepts_a_superscript_label() {
|
||||||
let font = Cmr10Metrics::default();
|
let font = Cmr10Metrics::default();
|
||||||
|
|||||||
@@ -233,3 +233,5 @@ for a later overlaid slash.
|
|||||||
| M7 incremental integration | partial | edit replay + page hashes, not wired into v1 preview |
|
| M7 incremental integration | partial | edit replay + page hashes, not wired into v1 preview |
|
||||||
|
|
||||||
v1 remains the production renderer; the route-D core is additive and tested independently.
|
v1 remains the production renderer; the route-D core is additive and tested independently.
|
||||||
|
|
||||||
|
`\substack{a\\b}` parses each row and stacks them as `MathAtom::StackLines`.
|
||||||
Reference in new issue
Block a user