Problem
Mathematical formulas display both rendered output and raw LaTeX source text simultaneously.
Example: δω/ω < 10⁻⁶ renders as δω/ω<10−6δω/ω<10−6.
Root Cause
DOMPurify v3.4.11 strips <semantics> and <annotation> tags from KaTeX MathML output, but KEEP_CONTENT: true (default) preserves the LaTeX source text as a visible child node of <math>.
- KaTeX generates:
<math><semantics><mrow>...</mrow><annotation encoding="application/x-tex">\delta\omega/\omega < 10^{-6}</annotation></semantics></math>
- DOMPurify strips
<semantics>/<annotation> (not in default allowlist)
- Result:
<math><mrow>...</mrow>\delta\omega/\omega < 10^{-6}</math> — LaTeX visible as text
Fix
DOMPurify.sanitize(html, { ADD_TAGS: ["semantics", "annotation", "annotation-xml"] });
Environment
- OpenScience v1.3.4, KaTeX v0.16.27/v0.17.0, DOMPurify v3.4.11, Linux x86-64
Problem
Mathematical formulas display both rendered output and raw LaTeX source text simultaneously.
Example:
δω/ω < 10⁻⁶renders asδω/ω<10−6δω/ω<10−6.Root Cause
DOMPurify v3.4.11 strips
<semantics>and<annotation>tags from KaTeX MathML output, butKEEP_CONTENT: true(default) preserves the LaTeX source text as a visible child node of<math>.<math><semantics><mrow>...</mrow><annotation encoding="application/x-tex">\delta\omega/\omega < 10^{-6}</annotation></semantics></math><semantics>/<annotation>(not in default allowlist)<math><mrow>...</mrow>\delta\omega/\omega < 10^{-6}</math>— LaTeX visible as textFix
Environment