anthropics / anthropics/claude-code

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

オープン
#92,152 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る
area:desktop bug platform:macos
主要言語
Python
スター
145k
フォーク
23.1k
PR マージ指標
PR 指標を取得中

説明

## 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

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

評価

技術スタック
markdown
領域
desktop, frontend
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
活発
明瞭さ
おおむね明確
初心者へのやさしさ
45/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。