fix(math): escape currency dollars so they aren't parsed as LaTeX math#180
Merged
Conversation
…s math in Markdown Signed-off-by: Logan Nguyen <lg.131.dev@gmail.com>
Signed-off-by: Logan Nguyen <lg.131.dev@gmail.com>
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.
Summary
LLM/user text like
raise $1M ... reach $1Mwas parsed byremark-mathas one giant inline-math run, rendered by KaTeX in a nowrap serif block that blew the chat window out horizontally.This adds
escapeCurrencyDollars, a deterministic syntax-level pass applied at the single markdown chokepoint (MarkdownRenderer), plus a CSS structural backstop.Changes
src/utils/escapeCurrencyDollars.ts— escapes a$immediately followed by a digit ($5,$1M,$1,000,$10.50) soremark-mathtreats it as literal text. Genuine inline math ($E=mc^2$,$\alpha$) and all$$...$$block math are untouched. Fenced code blocks (``` / ~~~) and inline code spans (any backtick run length) are left byte-for-byte intact. Pure and idempotent.src/components/MarkdownRenderer.tsx— applies the escape tocontentbefore Streamdown, protecting every caller (user, assistant, thinking, update notes) uniformly.src/App.css—.katex-displayhorizontal containment so any wide equation (or anything that slips the filter) scrolls inside its own box instead of growing the window. The vertical axis is intentionally left to flow so tall display math (matrices, large integrals, stacked fractions) is never clipped.escapeCurrencyDollars(fast paths, currency forms, genuine math, code regions, streaming/unclosed fences) and aMarkdownRendererregression test for the reported bug.Documented trade-off
Digit-led inline math like
$2x$is indistinguishable from currency at the syntax level and is rendered as readable literal text rather than typeset. There is no reliable syntactic rule that separates the two; the CSS backstop guarantees layout integrity regardless.Validation
bun run test:all:coverage— 1341 frontend tests pass, coverage gate clean.bun run validate-build— lint + format + typecheck + build, zero warnings/errors.🤖 Generated with Claude Code