anthropics / anthropics/claude-code

[Bug] Desktop app: markdown escaping strips `\{`, `\}` and `\\` inside `$$...$$`, breaking all KaTeX cases/matrix rendering

Offen
#92,152 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
area:desktop bug platform:macos
Vorherrschende Sprache
Python
Sterne
145k
Forks
23.1k
PR-Merge-Kennzahlen
PR-Kennzahlen ausstehend

Beschreibung

## Summary

In the Claude Code **desktop app (Code tab)**, `$$...$$` display math normally renders via KaTeX. But the markdown pass appears to run *over the contents of the math block* before the math renderer sees it, consuming CommonMark backslash escapes of ASCII punctuation. When the stripped escape is structurally significant — `\{`, `\}`, or the `\\` row separator — KaTeX then fails to parse and the entire block falls back to raw source text.

The practical effect: **every `cases`, `align`, `matrix`, `pmatrix`, and `bmatrix` environment is broken**, because all of them depend on `\\` as the row separator. Any answer containing a piecewise function or a matrix renders as unreadable raw LaTeX.

This is the desktop-app sibling of #80702 (which is `area:tui`: terminal output, no rendering at all, `\,`/`\;`/`\:`/`\!` spacing macros). Filing separately because the surface and the failure mode differ — here rendering *does* exist and works, and is specifically defeated by the escape stripping.

## Reproduction

Ask Claude any question whose answer needs a piecewise definition, e.g. "what is the projection onto the box `{x : ||x||_inf <= a}`?"

The model emits:

````
$$\big[P_C(x)\big]_i=\min\{\max\{x_i,-a\},\,a\}=
\begin{cases}
a, & x_i>a\\
x_i, & |x_i|\le a\\
-a, & x_i<-a
\end{cases}$$
````

The user sees this, verbatim and unrendered:

````
$$\big[P_C(x)\big]_i=\min{\max{x_i,-a},,a}=
\begin{cases}
a, & x_i>a\
x_i, & |x_i|\le a\
-a, & x_i<-a
\end{cases}$$
````

## Diagnosis

Diffing emitted vs. displayed shows an exact, selective pattern:

| Emitted | Displayed | Survives? |
|---|---|---|
| `\min`, `\max`, `\le`, `\big`, `\begin` | unchanged | yes |
| `\{` | `{` | no |
| `\}` | `}` | no |
| `\,` | `,` | no |
| `\\` | `\` | no |

Backslash + **letters** (LaTeX control words) pass through untouched; backslash + **ASCII punctuation** is unescaped. That is precisely CommonMark's backslash-escape rule — `{`, `}`, `\` and `,` are all in its escapable set, while letters are not. So a markdown unescaping step is being applied inside the math span rather than the span being treated as verbatim.

Losing `\,` is cosmetic. Losing `\{`/`\}` changes meaning (set braces vanish). Losing `\\` is fatal: `cases` collapses to a single malformed row, KaTeX throws, and the block degrades to raw text — which is why the failure looks like "math randomly doesn't render" rather than "spacing is slightly off".

## Expected behavior

Content between `$$` delimiters should be passed to KaTeX verbatim, with markdown backslash-escape processing disabled inside math spans (the standard approach: tokenize math spans before inline markdown processing, as `remark-math` / `rehype-katex` do).

## Actual behavior

Markdown unescaping is applied to the math span contents first, silently corrupting the LaTeX. The model cannot see the corruption in its own output, so it has no way to detect or work around the problem — it keeps emitting correct LaTeX that keeps arriving broken.

## Workarounds a user is forced into

- `\lbrace` / `\rbrace` instead of `\{` / `\}`
- drop `\,`, `\;`, `\:`, `\!` entirely
- avoid `cases` / `align` / matrix environments altogether, rewriting piecewise definitions as markdown bullet lists

These are all lossy, and they require the user to notice the bug and then instruct the model about it in every session.

## Environment

- Claude Code 2.1.220
- Desktop app, Code tab
- macOS 26.6.2 (build 25G83), Apple silicon

## Related

- #80702 — same root cause (markdown escaping applied to math spans), TUI surface
- #65632, #65777, #66467 — inline `$...$` not rendering in desktop/chat; adjacent but distinct, those are about the delimiter not being recognized at all, this one is about the *contents* of a recognized `$$` block being corrupted

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Rechercherichtung

Start by reproducing the provided $$ fixture in the desktop app's Code tab, then trace the markdown pass and KaTeX rendering path mentioned in the report. Verify that math contents preserve \{, \}, \\, and spacing escapes, and that cases, align, and matrix environments render instead of falling back to raw source.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
markdown
Bereich
desktop, frontend
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Aktiv
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
45/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.