Repository navigation
feat(web): add opt-in rendering for TeX equations - #18202
TheAnimatrix wants to merge 11 commits into
Conversation
# Conflicts: # apps/web/src/components/ChatMarkdown.test.tsx # apps/web/src/components/ChatMarkdown.tsx
- Accept `$$` alone on a line as a display fence, alongside `\[` / `\]`. - Read the math setting once through the renderer context. - Identify formula wrappers by `data-markdown-math` alone. - Drop KaTeX options that restate its defaults; use the catalog for micromark-util-types. - Trim comments and docs.
An unclosed `\[` or `$$` block failed after consuming later lines, which flattened the lists and quotes that followed. Like a fenced code block, it now ends at its closing line or the end of its container, and an unclosed block is shown as source instead of typeset.
ApprovabilityVerdict: Not approved Macroscope's review found this PR not approvable — This PR adds a substantial TeX rendering capability with a custom parser, lazy KaTeX integration, new settings, and cross-cutting clipboard and citation behavior. Although disabled by default and well covered by tests, its size, scope, and persisted product setting warrant human review. You can add or adjust custom eligibility rules. Learn more. |
|
Note This comment is posted by Julius' dot The opt-in setting and lazy loading follow Julius's condition in #1784, but the custom TeX parser and changes to copying and citations still need a scope decision. Does this implementation meet that condition, or should it be narrowed? Please link the maintainer's decision here before review handoff, as required by the scope policy. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk | 🟡 Moderate · up to
|
|
Note Written by Asked for the scope ruling in #9641: #9641 (comment). I'll link the decision here, and narrow the PR if needed, before review handoff. |
Quoting a response, exporting a table to CSV, and pasting rich text used KaTeX's glyph markup for formulas rendered by the selected LaTeX PR (pingdotgg#14574). Each formula now contributes its TeX source as one unit instead. Ported from pingdotgg#18202 by TheAnimatrix, which shares the same rendered-formula wrapper. This fix builds on pingdotgg#14574: remove it before removing that PR from the personal nightly.
Problem
Assistant replies show raw TeX. Fractions, powers, Greek letters and table values are hard to read, which makes T3 Code a poor fit for anyone working with math: researchers, students, engineers, teachers (#9641). Rendering equations would greatly improve it for all of them, and for anyone who meets math in an agent response.
Change
Settings → Appearance → Render math, off by default, in the shared web/desktop Markdown renderer.
\(…\)inline;\[/\]or$$on their own lines for display. Single$, one-line\[…\]and fencedmathblocks stay as written, so currency, shell variables and\[1\]citations are unaffected.markdown-math.ts), registered only when the setting is on and the message contains a candidate delimiter. Off has no parsing or loading cost.packages/sharedor the sanitizer.Scope
This follows Julius's condition in #1784: opt-in, "if it doesn't add too much complexity", without "tons of remark plugins parsing latex." The delimiter set is fixed and documented; it is the forms models emit as standalone math, excluding single
$, which is where currency and code-span bugs arise. Native mobile has a separate renderer and is out of scope.Complexity, for that ruling: 582 runtime lines, 348 of them in one new file (
markdown-math.ts) that imports nothing from the app. The shared renderer changes by 27 lines. Copy and citation code change by 77 lines, all keyed on one data attribute, and can be dropped if that is the preferred scope. The remaining 904 lines are tests. The scope question is open in #9641; the decision will be linked here before review handoff.Related PRs
$inline math; mdast-util-math; edits the shared pipeline$$only; remark-math (8 lockfile packages); edits the sanitizerEarlier attempts (#9204, #9838, #10698) were closed for automatic activation or unapproved scope; #16724 (always on, remark-math + rehype-katex) is closed. This PR is the only one that is opt-in, adds no packages and leaves shared code untouched.
Verification
$$block to the same message: it typesets and copies as\[…\], while$5,$10,`$HOME`and a one-line$$x$$in the same paragraph stay literal.$$cases above, copy/quote/CSV parity across loading states, and failed chunk loads. Web typecheck, lint (no new warnings) and format pass.Dark theme
Replaces #17024, which was closed for not disclosing the model and harness.
Model: Claude Opus 5.5 (
claude-opus-5-5), with Claude Sonnet 5.5 subagents for implementation. Harness: Claude Code in T3 Code.