Render math in chat messages with KaTeX #4

Merged
colcaroli merged 2 commits from feature/katex-math-rendering into main 2026-08-23 11:13:01 +00:00
Owner

Add a marked extension that tokenizes math delimiters and renders them
with KaTeX: $$ ... $$ / \[ ... \] as block, $ ... $ / \( ... \)
and mid-paragraph $$ ... $$ as inline.

Inline $ ... $ requires a non-space after the opening $, no newline
inside, and a non-digit after the closing $, so prose like "$100 から
$200" is left alone; \$ still escapes a literal dollar sign. Parse
errors fall back to KaTeX's red inline message instead of throwing, and
math whose closing delimiter has not streamed in yet stays plain text.

DOMPurify strips semantics and annotation by default, which would
leak the raw TeX out of KaTeX's MathML output, so both are allowed
explicitly.

Co-Authored-By: Claude Opus 5 noreply@anthropic.com

Add a marked extension that tokenizes math delimiters and renders them with KaTeX: `$$ ... $$` / `\[ ... \]` as block, `$ ... $` / `\( ... \)` and mid-paragraph `$$ ... $$` as inline. Inline `$ ... $` requires a non-space after the opening `$`, no newline inside, and a non-digit after the closing `$`, so prose like "$100 から $200" is left alone; `\$` still escapes a literal dollar sign. Parse errors fall back to KaTeX's red inline message instead of throwing, and math whose closing delimiter has not streamed in yet stays plain text. DOMPurify strips `semantics` and `annotation` by default, which would leak the raw TeX out of KaTeX's MathML output, so both are allowed explicitly. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
colcaroli added 1 commit 2026-08-23 11:12:01 +00:00
Add a marked extension that tokenizes math delimiters and renders them
with KaTeX: `$$ ... $$` / `\[ ... \]` as block, `$ ... $` / `\( ... \)`
and mid-paragraph `$$ ... $$` as inline.

Inline `$ ... $` requires a non-space after the opening `$`, no newline
inside, and a non-digit after the closing `$`, so prose like "$100 から
$200" is left alone; `\$` still escapes a literal dollar sign. Parse
errors fall back to KaTeX's red inline message instead of throwing, and
math whose closing delimiter has not streamed in yet stays plain text.

DOMPurify strips `semantics` and `annotation` by default, which would
leak the raw TeX out of KaTeX's MathML output, so both are allowed
explicitly.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
colcaroli added 1 commit 2026-08-23 11:12:16 +00:00
colcaroli merged commit 5d63a59b86 into main 2026-08-23 11:13:01 +00:00
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: colcaroli/playchat#4