Accept middle math delimiters

This commit is contained in:
gloamxun committed 2026-10-20 12:58:30 +08:00
1 parent 6769a6e80b
commit ebab0eca05
2 files changed
+12

No files matched your search

+11
View File
@@ -382,6 +382,10 @@ fn parse_atom(chars: &[char], index: usize) -> (MathAtom, usize) {
after,
)
}
"middle" => {
let delimiter = chars.get(next).copied().unwrap_or('|');
(MathAtom::Symbol(delimiter), next + 1)
}
"left" => {
let left = chars.get(next).copied().unwrap_or('(');
let (body, after) = parse_sequence(chars, next + 1, false, true);
@@ -473,6 +477,13 @@ mod tests {
assert!(indexed.height > plain.height);
}
#[test]
fn middle_delimiter_adds_a_symbol() {
let font = Cmr10Metrics::default();
let without = layout_math(&parse_math("\\left(ab\\right)"), &font);
let with = layout_math(&parse_math("\\left(a\\middle|b\\right)"), &font);
assert!(with.width > without.width);
}
#[test]
fn empty_left_delimiter_has_no_width() {
let font = Cmr10Metrics::default();
+1
View File
@@ -104,6 +104,7 @@ overfull ratio 4.11, badness 6942. TeX rejects the underfull candidate under
its tolerance but still emits the moderately overfull 5-word line. Reproducing
this needs a two-pass tolerance algorithm with an emergency overfull pass, not
a single cost function.
- `\middle|` inside `\left...\right` is accepted as a delimiter symbol (not yet stretched).
- `\sqrt[n]{x}` carries an optional degree atom; `\left.` is an empty
delimiter with zero width.
- `MathAtom::Accent { accent, base }` parses `\hat`, `\widehat`,