Support native e-TeX middle delimiters and math segments

This commit is contained in:
gloamxun committed 2026-11-29 02:05:21 +08:00
1 parent e3be6dcd09
commit 91bb864d8c
8 files changed
+134 -27

No files matched your search

@@ -98,13 +98,13 @@ impl Executor {
PaintSource::token(origin),
))
}
fn left_right(
fn math_delimiter(
&mut self,
opening: bool,
command: Primitive,
span: Span,
files: &mut impl SourceProvider,
) -> Result<(), Error> {
if opening {
if command == Primitive::Left {
if self.math.len() >= self.limits.input_depth.min(32) {
return self.fail("native math nesting capacity exceeded");
}
@@ -116,14 +116,28 @@ impl Executor {
} else {
let b = self.math.last().unwrap();
if b.left.is_none() || b.depth != self.state.group_depth() {
if command == Primitive::Middle {
return self.fail(r"Extra \middle.");
}
return self.fail("unmatched native right delimiter");
}
let (right, source) = self.scan_delimiter(files)?;
let (value, source) = self.scan_delimiter(files)?;
if command == Primitive::Middle {
let b = self.math.last_mut().unwrap();
b.finish_segment();
b.nodes.push(MathNode::MiddleDelimiter { value, source });
// Middle ends the current delimiter group and starts another.
// The math list survives, while local assignments and delayed
// tokens follow the ordinary rules for closing a group.
self.finish_group(GroupKind::MathLeft, span, files)?;
self.begin_group(GroupKind::MathLeft, files)?;
return Ok(());
}
let b = self.math.pop().unwrap();
let span = b.span;
let mut nodes = b.finish();
nodes.push(MathNode::Delimiter {
value: right,
value,
opening: false,
source,
});
@@ -625,7 +639,7 @@ impl Executor {
let r = self.scan_rule(false, TokenOrigin::from(token), files)?;
self.math.last_mut().unwrap().nodes.push(MathNode::Rule(r));
}
Left | Right => self.left_right(*p == Left, token.span, files)?,
Left | Middle | Right => self.math_delimiter(*p, token.span, files)?,
Umathchar | Umathcharnum | Udelimiter => {
let code = self.scan_unicode_math_code(*p != Umathcharnum, files)?;
let (class, c) = self.explicit_math_code(code)?;