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)).
Since Sphinx 8.2,
sphinx.ext.mathjaxloads 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:$$ ... $$as well as a{math}directive, labelled or not — in\begin{equation}\begin{split} ... \end{split}\end{equation}(seesphinx.util.math.wrap_displaymath).IPython.display.Mathwraps 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.ipynbanddocs/usage/caching.ipynbeach callsp.multiline_latex()and pass the result toMath(), which produces$\displaystyle \begin{align*} ... $.Fix
There is no keyword fix: the only environments
sp.multiline_latex()offers arealign*,eqnarrayandIEEEeqnarray, and all three are illegal insideMath(). Replace the calls withampform.io.aslatex, which renders intoaligned:Math(aslatex({lhs: rhs}, terms_per_line=n)).