Skip to content

MathJax formula fails to render when $$ delimiters are split across <span> elements by text editor #5516

@dududuguo

Description

@dududuguo

Describe the bug

When editing math formulas with $$...$$ LaTeX delimiters in draw.io's rich text editor, the browser's contenteditable engine sometimes splits the formula text across multiple <span> elements. This causes MathJax to fail to recognize and render the formula, because MathJax's TeX input processor cannot match $$ delimiter pairs that span across different HTML element boundaries.

To Reproduce

  1. Open draw.io and enable Mathematical Typesetting (Extras → Mathematical Typesetting)
  2. Create a text element and type a LaTeX formula, e.g. $$s_0 \to A_0 h_0$$
  3. Edit the formula — place the cursor in the middle of the formula, delete some characters, then retype them (or copy-paste part of the formula)
  4. After editing, the formula may stop rendering and instead displays as raw LaTeX text

The underlying cause can be seen in the saved .drawio XML. After editing, the cell value changes from a single <span> to multiple <span> elements:

Before editing (renders correctly):

<mxCell value="&lt;span&gt;$$s_0 \to A_0→h_0$$&lt;/span&gt;" />

After editing (fails to render):

<mxCell value="&lt;span style=&quot;text-align: center; text-wrap: nowrap;&quot;&gt;$$s_0 \to A_0&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;text-align: center; text-wrap: nowrap; background-color: initial;&quot;&gt;h_0$$&lt;/span&gt;" />

The opening $$ is in the first <span> and the closing $$ is in the second <span>, so MathJax cannot match them.

Environment

  • draw.io version 26.0.9 (dev)
  • OS: Windows 11
  • Browser: Chrome
  • Browser Version: 134
  • I agree to follow the Code of Conduct that this project adheres to.
  • I have searched the issue tracker for a feature request that matches the one I want to file, without success.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions