Skip to content

feat(web): add opt-in math rendering to user messages - #2829

Open
wedone wants to merge 2 commits into
HKUDS:devfrom
wedone:feat/user-message-math
Open

wedone wants to merge 2 commits into
HKUDS:devfrom
wedone:feat/user-message-math

Conversation

@wedone

@wedone wedone commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

Description

User messages in chat are rendered as literal text while assistant replies go through Markdown/KaTeX. When a learner writes a formula, they see the raw $...$ source in their own bubble.

This adds an opt-in, math-only renderer for sent user messages:

  • A new Appearance → Chat messages → Math in my messages toggle, off by default.
  • Only explicit $...$ and $$...$$ delimiters are rendered with KaTeX.
  • Prose, line breaks, code spans/fences, prices ($5 和 $10, $5-$10) and $PATH stay literal.
  • The stored, sent, copied and edited content is unchanged: the setting only changes presentation.
  • KaTeX is loaded through a dynamic import, so the default-off path adds no chat bundle cost.

The preference is a browser-local display setting (global across sessions on that browser). Keeping it out of the server settings contract keeps this change small; it can be promoted to UiSettings later if cross-device sync is wanted.

Related Issues

  • No matching open issue or PR found in the pre-submission search.

Module(s) Affected

  • web (Frontend)
  • tests

Checklist

  • This PR targets dev.
  • I have read and followed the contribution guidelines.
  • My code follows the project's coding standards.
  • I have added relevant tests for my changes.
  • No storage schema, API, configuration or dependency changes are required.

Additional Notes

  • New tests: tests/user-message-math.spec.tsx (segmentation, prices/code staying literal, KaTeX rendering, and the bubble switching when the preference changes).
  • Checks run locally: npm run test:unit -- tests/user-message-math.spec.tsx, npm run test:unit -- tests/consultation-message-reference.spec.tsx tests/partner-archives-markdown.spec.tsx, npm run typecheck, npx eslint on the changed files, npm run architecture:check, npm run i18n:parity, npm run i18n:audit.
  • pre-commit is not installed in this environment, so the equivalent checks above were run directly.

Render explicit $...$ and $$...$$ formulas in the learner's own chat bubbles with KaTeX when they enable Appearance -> Chat messages -> Math in my messages. The preference is off by default and stored locally.

Only explicit math delimiters are interpreted; prose, code spans/fences, prices and the content sent to the model stay untouched.
Replace the lookbehind regexes with a delimiter scanner, guard non-string content, and wrap the optional renderer in an error boundary that falls back to literal text.

This branch has not been deployed

No deployments
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