Add explicit big delimiter sizes

This commit is contained in:
gloamxun committed 2026-10-20 13:04:06 +08:00
1 parent a6cf56da6c
commit 3fb2b57f21
2 files changed
+49

No files matched your search

+47
View File
@@ -27,6 +27,10 @@ pub enum MathAtom {
Underline { Underline {
base: Box<MathAtom>, base: Box<MathAtom>,
}, },
SizedDelimiter {
delimiter: char,
size: u8,
},
Stack { Stack {
top: Box<MathAtom>, top: Box<MathAtom>,
base: Box<MathAtom>, base: Box<MathAtom>,
@@ -214,6 +218,23 @@ pub fn layout_math(atom: &MathAtom, font: &Cmr10Metrics) -> MathBox {
depth: base_box.depth, depth: base_box.depth,
} }
} }
MathAtom::SizedDelimiter { delimiter, size } => {
let extent = match *size {
1 => 8 * 65_536,
2 => 11 * 65_536,
3 => 14 * 65_536,
_ => 17 * 65_536,
};
MathBox {
width: if *delimiter == '.' {
0
} else {
(extent as f64 * 0.35) as i64
},
height: extent,
depth: 2 * 65_536,
}
}
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);
@@ -430,6 +451,24 @@ fn parse_atom(chars: &[char], index: usize) -> (MathAtom, usize) {
after, after,
) )
} }
"big" | "bigl" | "bigr" | "Big" | "Bigl" | "Bigr" | "bigg" | "biggl" | "biggr"
| "Bigg" | "Biggl" | "Biggr" => {
let size = match command.as_str() {
"big" | "bigl" | "bigr" => 1,
"Big" | "Bigl" | "Bigr" => 2,
"bigg" | "biggl" | "biggr" => 3,
_ => 4,
};
let mut after = next;
while after < chars.len() && chars[after].is_whitespace() {
after += 1;
}
let delimiter = chars.get(after).copied().unwrap_or('.');
(
MathAtom::SizedDelimiter { delimiter, size },
(after + 1).min(chars.len()),
)
}
"overset" | "underset" => { "overset" | "underset" => {
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);
@@ -606,6 +645,14 @@ mod tests {
assert!(indexed.height > plain.height); assert!(indexed.height > plain.height);
} }
#[test]
fn big_delimiters_get_progressively_taller() {
let font = Cmr10Metrics::default();
let big = layout_math(&parse_math("\\big("), &font);
let bigg = layout_math(&parse_math("\\Bigg("), &font);
assert!(bigg.height > big.height);
assert!(bigg.width > big.width);
}
#[test] #[test]
fn tall_delimiters_grow_with_their_body() { fn tall_delimiters_grow_with_their_body() {
let font = Cmr10Metrics::default(); let font = Cmr10Metrics::default();
+2
View File
@@ -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::SizedDelimiter { delimiter, size }` parses
`\big`/`\Big`/`\bigg`/`\Bigg` (and `l`/`r` variants); extents are 8/11/14/17pt.
- `MathAtom::Stack { top, base, above }` parses `\overset`/`\underset`; - `MathAtom::Stack { top, base, above }` parses `\overset`/`\underset`;
the decoration contributes 1pt of extra separation. the decoration contributes 1pt of extra separation.
- `MathAtom::Brace { base, above }` parses `\overbrace`/`\underbrace` and - `MathAtom::Brace { base, above }` parses `\overbrace`/`\underbrace` and