diff --git a/packages/tui/CHANGELOG.md b/packages/tui/CHANGELOG.md index 5a23149f4..9f414e921 100644 --- a/packages/tui/CHANGELOG.md +++ b/packages/tui/CHANGELOG.md @@ -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 diff --git a/packages/tui/src/latex.ts b/packages/tui/src/latex.ts index 74cbd060a..3170bf596 100644 --- a/packages/tui/src/latex.ts +++ b/packages/tui/src/latex.ts @@ -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] ?? "")) { diff --git a/packages/tui/test/latex.test.ts b/packages/tui/test/latex.test.ts index a9aca930b..609bb0d64 100644 --- a/packages/tui/test/latex.test.ts +++ b/packages/tui/test/latex.test.ts @@ -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");