fix(chat-ui): stop hiding prose between dollar signs behind a math chip - #3180
Open
tkohout wants to merge 1 commit into
Open
fix(chat-ui): stop hiding prose between dollar signs behind a math chip#3180tkohout wants to merge 1 commit into
tkohout wants to merge 1 commit into
Conversation
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>
Contributor
The PR appears safe to merge, with a non-blocking layout issue for inline math expressions wider than the transcript column. Findings
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.
|
| 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); |
Contributor
There was a problem hiding this 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.
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!
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.
Description
The chat transcript parser in
@emdash/chat-uirunsremark-mathwith 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∑ mathmention pill. The pill has no click handler or tooltip, so the text between the dollar signs was simply lost.Changes:
singleDollarTextMath: false). Only$$…$$is treated as math, which matches GitHub and most chat renderers.$$…$$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.tonecomments indocument.tsandmdast-mention.tsthat 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.tsinpackages/chat-ui(35 passed, including two new cases: two dollar amounts survive verbatim;$$E = mc^2$$becomes an inline code run).pnpm run typecheckinpackages/chat-ui.pnpm exec oxlint packages/chat-ui/src/core/markdownandpnpm run format.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.After: prices and single-dollar text stay literal,
$$inline math shows its source as inline code.Checklist
messages and, when possible, the PR title
🤖 Generated with Claude Code