Dollar signs ($) parsed as LaTeX math inside backtick code spans, corrupting rendered text

Resolved 💬 4 comments Opened Jun 1, 2026 by nevyn Closed Jun 2, 2026

What's Wrong?

In the Claude Code desktop/GUI chat renderer, $ characters are treated as LaTeX/KaTeX math delimiters even inside inline code spans (backtick-delimited). Two $ on a line pair up and everything between them is typeset as math: spaces are collapsed, ** becomes ∗∗, and the $ delimiters are consumed and disappear.

This violates CommonMark: the contents of an inline code span are literal text, and no other inline construct (emphasis, links, autolinks, etc.) is recognized inside backticks. Math delimiters must not be either.

Real example

The assistant wrote (correctly, in markdown source):

...whether `${CLAUDE_SKILL_DIR}` expands in model-issued Bash calls...
Per the docs, `${CLAUDE_SKILL_DIR}` is specifically "the skill's subdirectory..."

The first $ opened a math span, the second $ closed it, and the entire region between them rendered as serif math-italic with whitespace collapsed ("expandsinmodel", "issuedBashcalls"). The second ${CLAUDE_SKILL_DIR} rendered as {CLAUDE_SKILL_DIR} — the $ had been eaten as the closing delimiter. (Screenshot below.)

What Should Happen

$ inside a backtick code span renders as a literal $, with all surrounding text and whitespace intact. Math detection must run after / with respect for code-span boundaries.

Steps to Reproduce

  1. In the GUI chat, have the assistant output a line containing two backtick code spans that each include a $, e.g. ${FOO} ... ${BAR}.
  2. Observe that the text between the two $ renders as KaTeX math instead of literal text.

Related

#33620 reported the general "$ triggers LaTeX math" corruption but was closed NOT_PLANNED by the stale-bot (and is now locked). This issue narrows it to the clear spec-violation: math rendering inside inline code spans. Shell-variable syntax (${VAR}, $PATH) makes this hit constantly in a coding tool.

Version / Platform

  • Claude Code 2.1.159, macOS 26.3.1, desktop GUI chat renderer
  • Model: Opus

_(Screenshot of the corrupted render to be attached.)_

View original on GitHub ↗

This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗