fix(tui): handle LaTeX control spaces across line endings

This commit is contained in:
Armin Ronacher 2026-08-11 23:19:24 +02:00
parent 2a9b4ebc68
commit 534bcbffb7
3 changed files with 20 additions and 0 deletions

View file

@ -15,6 +15,7 @@
- Fixed fullscreen transcript search snapping back to the current match during manual scrolling and fragmented SGR mouse input leaking into the search query.
- Fixed required LaTeX arguments starting on a new line being parsed as empty ([#7760](https://github.com/earendil-works/pi/issues/7760)).
- Fixed LaTeX control spaces split across line endings causing complete expressions to fall back to raw source.
## [0.84.1] - 2026-08-07

View file

@ -920,6 +920,13 @@ class LatexParser {
let command = "";
const first = this.source[this.position] ?? "";
if (first === "\n" || first === "\r") {
this.position++;
if (first === "\r" && this.source[this.position] === "\n") {
this.position++;
}
return " ";
}
if (/[A-Za-z]/.test(first)) {
const start = this.position;
while (this.position < this.source.length && /[A-Za-z]/.test(this.source[this.position] ?? "")) {

View file

@ -415,6 +415,18 @@ R\left(\frac{\pi}{4}\right)
assert.strictEqual(renderLatex(String.raw`\det(A)`), "det(A)");
});
it("treats a backslash followed by a line ending as control space", () => {
const source = String.raw`\boxed{
(1,1,1),\ (1,1,2),\ (1,2,5),\ (1,5,13),\ (2,5,29),\
(1,13,34),\ (1,34,89)
}.`;
assert.strictEqual(
renderLatex(source, { display: true }),
"[(1,1,1), (1,1,2), (1,2,5), (1,5,13), (2,5,29), (1,13,34), (1,34,89)].",
);
assert.strictEqual(renderLatex("a\\\r\nb"), "a b");
});
it("stacks operator limits in display mode", () => {
assert.strictEqual(renderLatex(String.raw`\sum_{i=0}^n x_i`, { display: true }), " n\n ∑ xᵢ\ni=0");
assert.strictEqual(renderLatex(String.raw`\min_{x\in X} f(x)`, { display: true }), "min f(x)\nx∈X");