You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
BUG: investigate issue in ExecutableBooks/sphinx-exercise (LaTeX) #297
When meta tags are used in the solution, as in the example below:
```{code-cell} ipython3
---
mystnb:
figure:
caption: Asymptotic bias of Cagan's estimator for different $\lambda$
name: fig-cagan-bias-lambda
---
The PDF builder produces the following error:
! LaTeX Error: Not in outer par mode.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
l.47746 \begin{figure}[htbp]
?
! Emergency stop.
...
l.47746 \begin{figure}[htbp]
Sphinx's own admonitions increment self.no_latex_floats, which makes visit_figure write \begin{figure}[H]. sphinx-exercise opens the same sphinxadmonition box without touching that counter, so a captioned figure inside it is written as a floating \begin{figure}[htbp], which LaTeX rejects with "Not in outer par mode".
To answer the question above: exercise directives are affected too, not just solution (the reproduction covers exercise, solution and gated solution-start/solution-end). sphinx-proof follows the same pattern, so theorem and proof boxes are probably affected as well.
Until a fixed release is pinned, the workaround is unchanged: drop the mystnb figure metadata from cells inside solutions. This has come up in QuantEcon/lecture-python.myst#1101, #1110 and #1119.
Activity
mmcky commentedon Apr 2, 2026
@HumphreyYang is this specifically in
solutionandexercisedirectives?HumphreyYang commentedon Apr 2, 2026
Many thanks @mmcky!
I only found this in the
solutiondirectory because that's where figures typically are. I can test it inexercisedirectives as well.mmcky commentedon Nov 10, 2026
Root cause found and filed upstream as executablebooks/sphinx-exercise#94, with a minimal reproduction and a verified patch.
Sphinx's own admonitions increment
self.no_latex_floats, which makesvisit_figurewrite\begin{figure}[H]. sphinx-exercise opens the samesphinxadmonitionbox without touching that counter, so a captioned figure inside it is written as a floating\begin{figure}[htbp], which LaTeX rejects with "Not in outer par mode".To answer the question above:
exercisedirectives are affected too, not justsolution(the reproduction coversexercise,solutionand gatedsolution-start/solution-end). sphinx-proof follows the same pattern, so theorem and proof boxes are probably affected as well.Until a fixed release is pinned, the workaround is unchanged: drop the
mystnbfigure metadata from cells inside solutions. This has come up in QuantEcon/lecture-python.myst#1101, #1110 and #1119.Upgrade sphinx-exercise to 1.2.2 and restore figure captions in solut…