Skip to content

Bug: KaTeX formula shows raw LaTeX text (DOMPurify strips semantics/annotation tags) #194

Description

@LeeQY1996

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>.

  1. KaTeX generates: <math><semantics><mrow>...</mrow><annotation encoding="application/x-tex">\delta\omega/\omega < 10^{-6}</annotation></semantics></math>
  2. DOMPurify strips <semantics>/<annotation> (not in default allowlist)
  3. Result: <math><mrow>...</mrow>\delta\omega/\omega &lt; 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions