Skip to content

Equations with eqnarray and align render as an error under MathJax 4 #42

Description

@redeboer

Since Sphinx 8.2, sphinx.ext.mathjax loads MathJax 4 by default (https://cdn.jsdelivr.net/npm/mathjax@4/tex-mml-chtml.js). MathJax 4 enforces a check that MathJax 3 did not: an AMS equation structure (eqnarray, align, align*, gather, multline) may not be nested inside another one. Both ways in which our notebooks produce display math do exactly that nesting:

  • Sphinx wraps every math block — $$ ... $$ as well as a {math} directive, labelled or not — in \begin{equation}\begin{split} ... \end{split}\end{equation} (see sphinx.util.math.wrap_displaymath).
  • IPython.display.Math wraps its input in $\displaystyle ... $.

The result is that the equation is replaced by a red Erroneous nesting of equation structures on the rendered page. Only inner environments are allowed in these positions: aligned, alignedat, gathered, split, array, pmatrix, cases. Note that the pages still rendered correctly under MathJax 3, so this regression came in silently with a Sphinx upgrade.

Affected

File $$ blocks Math() with a hand-written environment sp.multiline_latex()
docs/005/index.ipynb 1
docs/009/index.ipynb 4
docs/010/index.ipynb 1
docs/011/index.ipynb 7
docs/013/index.ipynb 1
docs/014/index.ipynb 6
docs/015/index.ipynb 3 2 1
docs/017/index.ipynb 1
docs/021/index.ipynb 22 2
docs/024/index.ipynb 1
docs/027/index.ipynb 1
docs/033/index.ipynb 4

Fix

For the Markdown cells and the hand-written Math(R"\begin{eqnarray}...") strings: replace the environment with aligned and collapse eqnarray's three-column alignment &=& to &=.

For sp.multiline_latex() there is no keyword fix — its only environments are align*, eqnarray and IEEEeqnarray, and all three are illegal inside Math(). Replace those calls with ampform.io.aslatex, which renders into aligned: Math(aslatex({lhs: rhs}, terms_per_line=n)).

Since these reports are pinned and rebuilt from their own environments, the fix can be applied file by file.

Activity

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

Metadata

Metadata

Assignees

Labels

🐛 BugSomething isn't working📝 DocsImprovements or additions to documentation

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions