Skip to content

BUG: investigate issue in ExecutableBooks/sphinx-exercise (LaTeX) #297

Open

Description

@mmcky

Hi @mmcky,

This appears to be an interesting bug!

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]

Removing the tags resolves the issue.

Originally posted by @HumphreyYang in QuantEcon/lecture-python-advanced.myst#319 (comment)

Activity

  1. mmcky commented on Apr 2, 2026

    @mmcky
    ContributorAuthor

    @HumphreyYang is this specifically in solution and exercise directives?

  2. HumphreyYang commented on Apr 2, 2026

    @HumphreyYang
    Member

    Many thanks @mmcky!

    I only found this in the solution directory because that's where figures typically are. I can test it in exercise directives as well.

  3. mmcky commented on Nov 10, 2026

    @mmcky
    ContributorAuthor

    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 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.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions