Repository navigation
Conversation
chphch
force-pushed
the
feat/latex-equation-rendering
branch
4 times, most recently
from
August 28, 2026 00:21
e5d5632 to
784fa52
Compare
chphch
force-pushed
the
feat/latex-equation-rendering
branch
from
October 17, 2026 03:57
784fa52 to
cc5d9b7
Compare
Renders display equations (`$$…$$`, `\[…\]`) on their own line and inline
math (`$…$`, `\(…\)`) within prose, lists, and headers. Mirrors the existing
Mermaid special-block pattern: KaTeX runs inside a react-native-webview on
native and via a lazy `import('katex')` on web.
- Parser: a `math` block type for display equations, and inline math split out
by a single unified tokenizer so `$…$` inside code spans, markdown links, and
bare URLs stays literal, and TeX bodies aren't re-parsed as markdown.
- Currency (`$5`), escaped `\$`, and `$ x $` (space after opener) stay as plain
text. Unclosed/partial `$$` (mid-stream) and trailing-text-after-close fall
through to normal text handling.
- Renderer: on web inline math is a per-span element that flows inside the
native <Text> (selection preserved). RN <Text> can't hold a WebView, so on
native a run containing inline math is rendered as one KaTeX WebView; non-math
runs keep the native <Text> path.
- Hardening: WebView script-context injection escaped, per-element render (no
delimiter text-scan), http(s)-only link gating, and length-capped scanners to
avoid a quadratic blow-up on pathological single-line input.
Unit tests cover block detection, inline splitting, and the
currency/escape/code/link/URL guards.
Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)
Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
chphch
force-pushed
the
feat/latex-equation-rendering
branch
from
October 19, 2026 01:27
cc5d9b7 to
4ecd630
Compare
This branch has not been deployed
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.
Implements #1629.
Renders LaTeX math in the markdown view using KaTeX — display equations (
$$…$$,\[…\]) on their own line, and inline math ($…$,\(…\)) within prose, lists, and headers. It follows the existing Mermaid special-block pattern: KaTeX runs inside areact-native-webviewon native and via a lazyimport('katex')on web, so a message full of equations renders as math instead of raw dollar-sign source. Currency ($5), escaped\$, and$ x $(space after the opener) stay plain text so ordinary prose isn't mangled.How it works
parseMarkdownBlock.ts,parseMarkdownSpans.ts): a newmathblock type for display equations, and inline math split out by a single unified tokenizer so a$inside a`code`span, a[markdown](link), or a bare URL stays literal, and TeX bodies (which contain*,_,\) aren't re-parsed as markdown. Unclosed/partial$$(mid-stream) and trailing-text-after-close fall through to normal text handling.MathView.tsx/MathView.web.tsx):MathBlockfor display equations. On web, inline math is a per-span element that flows inside the normal<Text>, so native text selection is preserved. RN<Text>can't hold a WebView, so on native a text run containing inline math is rendered as one KaTeX WebView; non-math runs keep the native<Text>path.Proof
BEFORE → AFTER on the
dev/messages-demoscreen (a demo agent message containing inline + display LaTeX), captured on Expo web via a throwaway standalonehappy-server(PGlite) + Playwright.BEFORE, the LaTeX shows as raw source (
$\mathcal{L} = -\sum_i y_i \log \hat{y}_i$,$$ \int … $$); AFTER, inline math flows inside the prose and list items and display equations render centered on their own line. The capture also assertsPrices like $5 and $10stays literal text (the currency guard), and that the pre-existing markdown table still renders unchanged.Verification
pnpm typecheckclean. Parser behaviour is pinned by unit tests inparseMarkdownMath.test.tscovering block detection, inline splitting, and the currency / escaped-\$/ inline-code / link / bare-URL guards.