Skip to content

fix(chat-ui): stop hiding prose between dollar signs behind a math chip - #3180

Open
tkohout wants to merge 1 commit into
generalaction:mainfrom
tkohout:math-symbol-ztjaw
Open

fix(chat-ui): stop hiding prose between dollar signs behind a math chip#3180
tkohout wants to merge 1 commit into
generalaction:mainfrom
tkohout:math-symbol-ztjaw

Conversation

@tkohout

@tkohout tkohout commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Description

The chat transcript parser in @emdash/chat-ui runs remark-math with single-dollar inline math enabled. Any prose between two $ signs (for example a sentence with two prices, "a $580 fee … pays $685") was parsed as a LaTeX expression and then replaced with a static ∑ math mention pill. The pill has no click handler or tooltip, so the text between the dollar signs was simply lost.

Changes:

  • Disable single-dollar math in the chat-ui remark pipeline (singleDollarTextMath: false). Only $$…$$ is treated as math, which matches GitHub and most chat renderers.
  • Render inline $$…$$ math as an inline code run containing the LaTeX source instead of the placeholder chip, so nothing is hidden. Block math already rendered its source as a paragraph and is unchanged.
  • Update the stale tone comments in document.ts and mdast-mention.ts that referred to the math chip.

Not in scope: real KaTeX typesetting in the transcript. The chat renderer pre-measures prose with pretext and has no DOM access at layout time, so inline typesetting needs a separate design. Backslash delimiters (\(…\), \[…\]) are also untouched; they are not recognized as math and markdown escaping strips the backslash, as before.

Related issues

None.

Testing

  • pnpm exec vitest run src/core/markdown/parse.test.ts in packages/chat-ui (35 passed, including two new cases: two dollar amounts survive verbatim; $$E = mc^2$$ becomes an inline code run).
  • pnpm run typecheck in packages/chat-ui.
  • pnpm exec oxlint packages/chat-ui/src/core/markdown and pnpm run format.
  • Manual: dev app on an isolated profile, ACP chat conversation, agent asked to echo a sentence with five dollar amounts and a set of math examples. Verified the rendered transcript before and after with the same message.

Screenshot/Recording (if applicable)

Same assistant message rendered before and after.

Before: every $…$ and $$…$$ span collapses to the chip and the text between the two prices is gone.

before

After: prices and single-dollar text stay literal, $$ inline math shows its source as inline code.

after

Checklist
  • I kept this PR small and focused
  • I ran a self-review before opening this PR
  • I ran the relevant local checks or explained why not
  • I updated docs when behavior or setup changed
  • I added or updated tests when behavior changed, or explained why not
  • I only added comments where the logic is not obvious
  • I used Conventional Commits for commit
    messages and, when possible, the PR title

🤖 Generated with Claude Code

remark-math treated any single-dollar span as inline LaTeX and the chat
transcript parser replaced it with a static '∑ math' pill, so a paragraph
with two prices ("a $580 fee ... pays $685") lost everything between the
dollar signs. The pill had no behavior and hid the text.

- Disable single-dollar math in the chat-ui remark pipeline; only $$ is math.
- Render inline $$ math as an inline code run with the LaTeX source instead
  of a placeholder chip, so nothing is hidden.
- Cover both cases in parse.test.ts.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@greptile-apps

greptile-apps Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 4/5

The PR appears safe to merge, with a non-blocking layout issue for inline math expressions wider than the transcript column.

Findings

  1. P2 Long math expressions overflow
Prompt To Fix All With AI
### Issue 1
packages/chat-ui/src/core/markdown/parse.ts:188
Rendering inline `$$…$$` as one code run makes long LaTeX expressions non-wrapping. Code runs use `break: 'never'` and `whiteSpace: 'pre'` inside a container with visible overflow, so an expression wider than the transcript column spills outside it. This is a non-blocking layout concern, but the source needs a bounded or wrapping presentation because the previous fixed-width `∑ math` chip could not cause this overflow.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

  • Configures remark-math to recognize only multi-dollar inline math.
  • Converts inline math nodes into source-preserving code runs.
  • Adds focused coverage for dollar-denominated prose and inline $$…$$ expressions.
  • Updates mention documentation to remove obsolete math-chip references.
  • Long inline expressions can now overflow because code runs are non-wrapping.

case 'inlineMath': {
const run: InlineMention = { kind: 'mention', label: '∑ math', tone: 'math' };
runs.push(run);
runs.push({ kind: 'code', text: (node as { value: string }).value } satisfies ICode);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Long math expressions overflow

Rendering inline $$…$$ as one code run makes long LaTeX expressions non-wrapping. Code runs use break: 'never' and whiteSpace: 'pre' inside a container with visible overflow, so an expression wider than the transcript column spills outside it. This is a non-blocking layout concern, but the source needs a bounded or wrapping presentation because the previous fixed-width ∑ math chip could not cause this overflow.

Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/chat-ui/src/core/markdown/parse.ts
Line: 188

Comment:
**Long math expressions overflow**

Rendering inline `$$…$$` as one code run makes long LaTeX expressions non-wrapping. Code runs use `break: 'never'` and `whiteSpace: 'pre'` inside a container with visible overflow, so an expression wider than the transcript column spills outside it. This is a non-blocking layout concern, but the source needs a bounded or wrapping presentation because the previous fixed-width `∑ math` chip could not cause this overflow.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant