Skip to content

Equations from multiline_latex render as an error under MathJax 4 #585

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

docs/usage.ipynb, docs/usage/binned-fit.ipynb and docs/usage/caching.ipynb each call sp.multiline_latex() and pass the result to Math(), which produces $\displaystyle \begin{align*} ... $.

Fix

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

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

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions