Repository navigation
Draw a Bot's maths as formulas - #1724
Merged
Merged
Conversation
davidmckayv
requested review from
MikeRyanDev,
dustywusty,
guidovizoso,
mxmzb,
samjulien and
tylerslaton
as code owners
November 16, 2026 18:48
davidmckayv
force-pushed
the
feat/render-maths
branch
from
November 16, 2026 19:01
8f964fe to
a2cd6fb
Compare
A Bot asked for a loan payment answered with LaTeX, and the chat drew it as source with the backslashes of \( and \[ eaten by markdown. Bot text now goes through Streamdown's maths plugin (remark-math and KaTeX) on every surface that draws it: replies, task threads, a task's result line in the conversation that asked, card text, interface markdown, group chats, tool results, run output and learned skills. The model's \( \) and \[ \] are rewritten to the $$ the plugin reads; code, existing $$ maths and single-dollar prices are left as written. The plugin and KaTeX's stylesheet and fonts load with the first formula, as the code plugin does. A set-apart formula scrolls sideways in its own block.
davidmckayv
force-pushed
the
feat/render-maths
branch
from
November 16, 2026 19:12
a2cd6fb to
507695a
Compare
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.
What changes
Maths a Bot writes is drawn as formulas, not LaTeX source. Asked for a loan payment, a Bot answered "calculated using (P r / [1-(1+r)^{-n}])" and a block of
\frac{...}between bare brackets: markdown had eaten the backslashes of\(and\[and drawn the rest as text.BotMarkdowninlib/markdown.tsx, is Streamdown plus its maths plugin (@streamdown/math: remark-math and KaTeX). It replacesStreamdownin replies, task threads, a task's result line in the conversation that asked for it, card text, interface markdown, group chats, tool results, run output and learned skills.lib/maths.tsrewrites\( \)to inline$$ $$, and\[ \]on lines of its own to a$$block at the indent it was written at. Fenced code, inline code and$$already written are left exactly as they are. A single$is never maths (Streamdown's default), so "$25,000" and "$5 to $10" stay prices. A$inside a formula is escaped for KaTeX, and a thousands comma (25,000) is written25{,}000so it does not draw as "25, 000". An opener with no closer in its paragraph stays as written, so while a reply streams a formula draws once it is closed.Versions
@streamdown/math1.0.3 (Streamdown's own maths plugin, released 2026-09-30, about 3.6 million downloads a week) on the installedstreamdown2.6.0. It bringskatex^0.16.27 throughrehype-katex7.0.1, which allows only the 0.16 line, sokatexis pinned at 0.16.47 (2026-05-16, about 44 million downloads a week), the version already in the lockfile, for its stylesheet.Bundle
Production build, before and after:
KaTeX's code, stylesheet and fonts were already in the build behind diagrams; the maths chunk now shares them.
Tests
app/tests/maths-rendering.test.tsx(real browser, added to the CI browser job): one answer with inline\( \), a wide\[ \]block, inline$$, prices and a code block holding$and\(, drawn as a reply, a task's thread, the task's result line and a card's text, in light and dark at 1440 and 390. Every formula is drawn by KaTeX in KaTeX's font, the set-apart one as a block that scrolls sideways at 390, no delimiter or\fracis left on screen, the prices and the code are exactly as written, and the page never scrolls sideways. On main: 16 of 16 fail. On this branch: 32 of 32 pass in Chromium and WebKit.app/tests/maths-delimiters.test.ts: the rewrite on the answers models write, including the loan answer above, prices, code, escaped backslashes and a reply mid-stream.Seen live
A full stack with a local Intelligence, the General Assistant on a real model asked for the monthly payment on a $25,000 loan, once handed to a task and once directly. The same conversation in the app on main and in this branch, in Chromium and WebKit, light and dark, at 1440 and 390 (64 screenshots, all looked at):
\frac{...},\boxed{...}and all, in the reply, the task's thread and the result line.\boxed{}total as a box, the wide ones scrolling inside their own blocks at 390, no page overflow, no font or stylesheet request failing. While the direct answer streamed, it drew prose first and each formula once it closed.