Repository navigation
Conversation
… silently Issue #2 reported that `flashtex-render` returns *zero* diagnostics for `Let $a + $x^2$ + b$ hold.`, for `\[...\]` in a `tabular` cell and for `\text{...}` without amsmath -- 15 of the 22 caret-context cases diverging from pdflatex. Re-measuring against pdflatex found two separate things, and only the second one is an engine bug. **The 15 was a measurement bug.** `scripts/caret_context_oracle.py` (PR #350) reads `json.loads(out.read_text()).get("diagnostics", [])` from the `--v2` file. That file is an envelope -- `{id, payload, protocol_version, type}` -- and the diagnostics live under `payload`, so the read returned `[]` for every case, including the ones the engine diagnosed correctly. Read from the right key, the compiler already reported an error for 13 of those 15. The fix there is one line in that script and belongs to that branch; noted on the issue. **Eleven cases were genuinely silent**, across the whole family of "LaTeX pdflatex refuses", and this commit closes them: | what | pdflatex | now | |---|---|---| | `\(` / `\)` anywhere | `! LaTeX Error: Bad math environment delimiter` | lexed as inline-math delimiters; a misplaced one is diagnosed like `\[`/`\]` | | `\[...\]` / `\begin{equation}` in a table entry or a `\caption` | `! Missing $ inserted` | `restricted horizontal mode`, set inline | | `\text{...}` without amsmath | `! Undefined control sequence` | `\text requires \usepackage{amsmath}` | | a bare `&` outside any alignment | `! Misplaced alignment tab character &` | the same, naming `\&` | | `\\` in vertical mode | `! LaTeX Error: There's no line here to end` | the same, naming `\vspace` | `\(...\)` was not only undiagnosed but *mis-set*: the delimiters lexed as literal parentheses, so `\(x^2\)` -- ordinary LaTeX -- printed "(x2)" as text. Diagnosing a misplaced one was half the fix; it now sets real inline math. Every expectation was taken from pdfTeX 3.141592653-2.6-1.40.27 (TeX Live 2025) rather than assumed, which changed the design three times: * a `\section` title and a `\footnote` accept a display -- both set their argument as a paragraph -- so `restricted_hbox` deliberately does not count them. A mode flag that simply meant "inside a command argument" would have been wrong. * `\noindent \\ text` compiles: `\noindent` leaves TeX in horizontal mode without typesetting anything, hence `paragraph_forced`. Testing `para` emptiness alone would have flagged valid input. * `Let $a + $$x^2$$ + b$ hold.` compiles, as alternating inline formulas. All three are pinned as controls in `tests/pdflatex_rejects.rs`, next to the 17 rejected cases, precisely because they are the cases where the obvious guess is wrong. Recovery is unchanged by design: pdflatex reports every one of these and then recovers, producing a PDF anyway (none is fatal outside `-halt-on-error`), so each diagnostic here carries a `recovery`, a span and a code, and the page still builds. `a_diagnosed_document_still_produces_content` asserts that. The bare-`&` rule distinguishes `\&` from `&` by span width rather than by text -- the lexer gives both the same one-character `Word` -- and stays silent whenever a word's span is wider than its own bytes (an escape, or macro expansion, whose span points at the invocation). Erring towards silence there is deliberate: a false "misplaced &" on a document that compiles is worse than a missed one. Measured, `crates/compiler` against pdflatex over 79 probes (the 22 caret-context naive insertions plus 57 written for the families named in the issue, 15 of them valid-LaTeX controls): 68 agreeing before, 78 after. All 15 caret-context cases pdflatex rejects are now diagnosed. The one remaining divergence is pre-existing and honest: `$a \footnote{x} b$` compiles in pdflatex and this compiler reports `\footnote is not supported in math mode` -- an `unsupported_feature`, not a false syntax error. Real-world corpus, all 22 fixtures, this build against a control build of `origin/main` in the same directory: **zero newly reported diagnostics** and identical page counts, including `hyperref-toc`, `listings-manual` and `siunitx-tables`, the ones most at risk from the `&` and `\\` rules. Three `math.rs` unit tests moved from `MathPackages::KERNEL` to amsmath. They are about `\text`'s spacing and undelimited-argument behaviour, not about whether `\text` is defined -- without the package it is not, and the new diagnostic would have masked what they assert. This does not reach `flashtex-render`, which builds against `vendor/compiler`; that needs a re-pin, which this branch deliberately does not make. Implementation-Agent: claude-opus-5 (linux-primary, engine diagnostics lane) Commit-Executor: claude-opus-5 (direct git, Cursor usage limit in effect) Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
This was referenced Sep 14, 2026
This was referenced Sep 15, 2026
Contributor
Author
|
Closed under the old-engine freeze (DESIGN.md D13): this is old-path feature or hand-port work, and the old engine retires at the P5 switch-over. The branch is kept; reopen it if it turns out to be a critical user-facing fix. — kabir-claude (Commander), nightly review 2026-09-30 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue #2 reported that
flashtex-renderreturns zero diagnostics forLet $a + $x^2$ + b$ hold., for\[…\]in atabularcell and for\text{…}without amsmath — 15 of the 22 caret-context cases diverging from pdflatex, so we could not use our own engine as an oracle.Re-measuring against pdflatex found two separate things, and only the second is an engine bug.
The 15 was a measurement bug
scripts/caret_context_oracle.py(on #350's branch) readsfrom the
--v2file. That file is an envelope —{id, payload, protocol_version, type}— and diagnostics live underpayload. The read returned[]for every case, the diagnosed ones included. Verified directly: on the nested-math caseflashtex-renderprintsRead from
payload.diagnostics, the engine already reported an error for 13 of those 15. The one-line fix belongs to #350's branch; it is on the issue.Eleven cases were genuinely silent
Across the whole family the issue names, and this PR closes them:
\(/\)anywhere! LaTeX Error: Bad math environment delimiter\[/\]\[…\]/\begin{equation}in a table entry or a\caption! Missing $ insertedrestricted horizontal mode, set inline\text{…}without amsmath! Undefined control sequence\text requires \usepackage{amsmath}&outside any alignment! Misplaced alignment tab character &\&\\in vertical mode! LaTeX Error: There's no line here to end\vspace\(…\)was not only undiagnosed but mis-set: the delimiters lexed as literal parentheses, so\(x^2\)— ordinary LaTeX — printed “(x2)” as text with no complaint. Diagnosing a misplaced one was half the fix; it now sets real inline math.The oracle changed the design three times
Every expectation came from pdfTeX 3.141592653-2.6-1.40.27 (TeX Live 2025), not from reasoning about TeX, and three of my guesses were wrong:
\sectiontitle and a\footnoteaccept a display. Both set their argument as a paragraph. Sorestricted_hboxcounts a table entry and\caption(which measures its text in an\sbox) and deliberately not those. A flag meaning “inside a command argument” would have flagged valid documents.\noindent \\ textcompiles.\noindentleaves TeX in horizontal mode without typesetting anything — henceparagraph_forced. Testing paragraph emptiness alone would have been a false positive.Let $a + $$x^2$$ + b$ hold.compiles, as alternating inline formulas.All three are pinned as controls in
tests/pdflatex_rejects.rsnext to the 17 rejected cases, precisely because they are where the obvious guess is wrong.Recovery is unchanged, by design
pdflatex reports every one of these and then recovers, producing a PDF anyway — none is fatal outside
-halt-on-error. So the severity match is “error, and keep rendering”: each diagnostic carries arecovery, a span and acode, and the page still builds.a_diagnosed_document_still_produces_contentasserts exactly that.The bare-
&rule tells\&from&by span width, not by text — the lexer gives both the same one-characterWord— and stays silent whenever a word's span is wider than its own bytes (an escape, or macro expansion, whose span points at the invocation). Erring towards silence there is deliberate: a false “misplaced &” on a document that compiles is worse than a missed one.Measured
crates/compileragainst pdflatex over 79 probes — the 22 caret-context naive insertions plus 57 written for the families in the issue, 15 of them valid-LaTeX controls:All 15 of 15 caret-context cases pdflatex rejects are now diagnosed. The single remaining divergence is pre-existing and honest:
$a \footnote{x} b$compiles in pdflatex, and this compiler reports\footnote is not supported in math mode— anunsupported_feature, not a false syntax error.Real-world corpus, all 22 fixtures, this build against a control build of
origin/mainin the same directory: zero newly reported diagnostics, identical page counts —hyperref-toc,listings-manualandsiunitx-tablesincluded, the three most at risk from the&and\\rules. So no fixture turned out to be invalid LaTeX: none of them gained a diagnostic at all.Tests
crates/compilersuite green. Threemath.rsunit tests moved fromMathPackages::KERNELto amsmath — they are about\text's spacing and undelimited-argument behaviour, not about whether\textis defined; without the package it is not, and the new diagnostic would have masked what they assert.Gates
crates/compilersuite green ·crates/render-pipeline226 passed / 0 failed · amsmath 59/59 · amssymb 38/39 · tabular 106/106 · HW1 3 pages, HW2 3 pages, 0 errors, both viaflashtex-renderand both matching pdflatex.One note on HW2, because I got it wrong in an earlier report and it is a fixture other lanes gate against.
flashtex-rendersets HW2 on 3 pages;flashtex-compiler's own layout sets it on 4. That is a pre-existing difference between the two producers, already tracked by the#[ignore]dcrates/compiler/tests/hw2_gate.rs, and neither number moves here. The corpus A/B in this PR drivesflashtex-compilerdeliberately — it is the crate being changed, andflashtex-renderreadsvendor/compilerand so cannot see the change — but its page column is a control-vs-branch comparison, not the HW gate.Reach
This does not reach
flashtex-render, which builds againstvendor/compiler. A re-pin is needed for that, and this branch deliberately does not make one. The pipeline half — the display list flattening every compilercodeto the literal string"compiler", which destroys thesyntax_error/unsupported_featuredistinction before a consumer sees it — is split out separately.Draft.
🤖 Generated with Claude Code
https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu