Switched math block syntax from $$ to Tex-style \[ \] and \( \) delimiters with improved rendering and error handling, in PR #5353, by @OEvgeny
Description
This PR enhances mathematical expression support in Web Chat by switching to TeX-style delimiters and introducing robust error handling.
Design
The implementation uses (\[ \] delimiters for block math, \( \) delimiters for inline) with a custom tokenizer and HTML renderer. Block math is rendered in figure tags while inline math uses span tags. Invalid expressions fall back to pre or code tags with an error state, allowing to apply styling if desired. The system uses Katex for rendering with MathML output and includes distinct styling for block and inline displays.
Specific Changes
Created new math extension with:
Custom tokenizer for block and inline math
HTML renderer with fallback on error
Updated markdown renderer to use the new math extension
Added support for inline math expressions
Enhanced CSS styles for math blocks and inline math
Added test cases for:
Basic math notation
Complex equations
Error scenarios
Inline vs block math
Updated sanitization rules to support math-related attributes
-
[x] I have added tests and executed them locally
[x] I have updated CHANGELOG.md
[x] ~I have updated documentation~
Review Checklist
[x] Accessibility reviewed (tab order, content readability, alt text, color contrast)
[x] Browser and platform compatibilities reviewed
[x] CSS styles reviewed (minimal rules, no z-index)
[x] Documents reviewed (docs, samples, live demo)
[x] Internationalization reviewed (strings, unit formatting)
[x] package.json and package-lock.json reviewed
[x] Security reviewed (no data URIs, check for nonce leak)
Changelog Entry
Changed
$$
to Tex-style\[ \]
and\( \)
delimiters with improved rendering and error handling, in PR #5353, by @OEvgenyDescription
This PR enhances mathematical expression support in Web Chat by switching to TeX-style delimiters and introducing robust error handling.
Design
The implementation uses (
\[ \]
delimiters for block math,\( \)
delimiters for inline) with a custom tokenizer and HTML renderer. Block math is rendered infigure
tags while inline math usesspan
tags. Invalid expressions fall back topre
orcode
tags with an error state, allowing to apply styling if desired. The system uses Katex for rendering with MathML output and includes distinct styling for block and inline displays.Specific Changes
-
CHANGELOG.md
Review Checklist
z-index
)package.json
andpackage-lock.json
reviewed