Skip to content

fix(math): preserve MathML when flattening arXiv equation tables - #376

Open
RovshanMuradov wants to merge 2 commits into
kepano:mainfrom
RovshanMuradov:fix/preserve-equation-mathml
Open

fix(math): preserve MathML when flattening arXiv equation tables#376
RovshanMuradov wants to merge 2 commits into
kepano:mainfrom
RovshanMuradov:fix/preserve-equation-mathml

Conversation

@RovshanMuradov

@RovshanMuradov RovshanMuradov commented Sep 6, 2026

Copy link
Copy Markdown

fix(math): preserve MathML when flattening arXiv equation tables

Why

Flattening arXiv equation tables currently replaces existing MathML with plain LaTeX text. HTML consumers can no longer render the original MathML and must reconstruct it from LaTeX, which may contain unsupported commands.

Change

Clone the existing <math> element instead of creating an empty element and assigning textContent = latex. Keep the existing display and data-latex assignments and subsequent cleanup.

This is a small change in src/standardize.ts, with no new dependencies or public API changes. It does not address the separate HTML wrapper cleanup problem reported in #377.

Example

An equation inside an arXiv-style table:

<table class="ltx_equation"><tr><td>
  <math display="block" alttext="x"><semantics>
    <mi>x</mi>
    <annotation encoding="application/x-tex">x</annotation>
  </semantics></math>
</td></tr></table>

Place this inside an article with surrounding text and extract it with the Node API using LinkeDOM and default standardization (markdown: false). Before this change, the resulting <math data-latex="x"> contains only plain x. Afterward, it retains <semantics><mi>x</mi>…</semantics> while the table wrapper is removed.

Verification

  • All 454 existing default checks pass. The JSDOM run has the same 124 failing cases before and after the change.
  • On ten arXiv articles, the isolated patch preserves structured MathML in 1,889 additional formulas without changing our downstream BlockNote JSON or Markdown.
  • Defuddle's own Markdown is identical on nine articles. On the tenth, only ten whitespace-only lines between display equations disappear.
  • Manual LinkeDOM examples cover nested equation groups, MathML-only and LaTeX-only inputs, and unsafe markup. Formula order is preserved without duplicates; the supplied scripts, event handlers, and javascript: URLs are removed.

These checks establish content preservation, not visual correctness of every formula. The existing no-LaTeX guard is unchanged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant