5

I have a script that generates a number of figures and puts them in the appendix of a report, e.g.

Appendix
********

.. figure:: images/generated/image_1.png
.. figure:: images/generated/image_2.png
.. figure:: images/generated/image_3.png
... etc

It looks like after a large number (~50) of images, my pdflatex command will hang, and point to one of the graphics in my .tex file around here

...
\begin(figure)[htbp]
\centering
\noindent\sphinxincludegraphics{{image_49}.png}
\end{figure}

\begin(figure)[htbp]
\centering
\noindent\sphinxincludegraphics{{image_50}.png} <--- here
\end{figure}

\begin(figure)[htbp]
\centering
\noindent\sphinxincludegraphics{{image_51}.png}
\end{figure}
...

When pdflatex fails I can't really figure out what to make from the console output, I get a number of these lines which seem to be good news

<image_48.png, id=451, 411.939pt x 327.3831pt>
File: image_48.png Graphic file (type png)
<use image_48.png>
Package pdftex.def Info: image_48.png  used on input line 1251.
(pdftex.def)             Requested size: 411.93797pt x 327.3823pt.

<image_49.png, id=452, 411.939pt x 327.3831pt>
File: image_49.png Graphic file (type png)     
<use image_49.png>
Package pdftex.def Info: image_49.png  used on input line 1257.
(pdftex.def)             Requested size: 411.93797pt x 327.3823pt.

Then after the last successful image (~50) it starts outputting

! Output loop---100 consecutive dead cycles.
\end@float ...loatpenalty <-\@Mii \penalty -\@Miv
                                                  \@tempdima \prevdepth \vbo...
l.1258 \end{figure}

I've concluded that your \output is awry; it never does a
\shipout, so I'm shipping \box255 out myself. Next time
increase \maxdeadcycles if you want me to be more patient!

[9
! Undefined control sequence.
\reserved@a ->\@nil

l.1258 \end{figure}

The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

If all I do is reduce the number of figures, it will run and produce a pdf without issue. Is there a hard limit to the number of images a section can have? Is there somewhere else I can look in the build log to narrow down why this is happening?

Cory Kramer
  • 114,268
  • 16
  • 167
  • 218

3 Answers3

11

This seemed to be a combination of a couple things.

The first symptom was essentially an error caused by too many unprocessed floats. The fix for this was to add the following to the babel element of latex_elements

\usepackage[maxfloats=256]{morefloats}

The second symptom was complaining about Output loop---100 consecutive dead cycles. so the fix was simply to increase the number of cycles

\maxdeadcycles=1000

After these two adjustments, the pdflatex command will finish successfully now, even with a large number of figures.

Cory Kramer
  • 114,268
  • 16
  • 167
  • 218
  • an alternative is to use rather ``image`` directive in place of ``figure``. You can add the ``:align: center`` option to each such ``image`` directive in order to get the default centering behaviour of ``figure`` in PDF output. The sole difference in output will be that there will be less vertical whitespace between successive graphics (both in PDF and HTML). By the way, for HTML, the ``figure`` does not horizontally center by default (at least with classic and alabaster themes as I tested now), which is at odds with PDF output where it centers per default. –  Jan 01 '19 at 10:32
  • another alternative is to stick with the many successive ``figure`` but add ``'figure_align': 'H',`` to [latex_elements](http://www.sphinx-doc.org/en/master/usage/configuration.html#confval-latex_elements). However this is a global setting for Sphinx LaTeX writer, there is no easy way to have it active only locally (afaik). –  Jan 01 '19 at 11:40
  • My original usecase was actually using the `plot` directive since the figures are generated using matplotlib. However after trying to isolate the problem I found the same issue with both `image` and `figure` directives too. – Cory Kramer Jan 01 '19 at 13:16
  • I would be very interested into an example with `image`: the Sphinx LaTeX writer a priori does not use LaTeX `figure` environment then, so the problem as your reported about too many unprocessed floats should not have arisen. –  Jan 01 '19 at 13:29
0

I had this problem and the above suggestions did not work. I was however able to get it to run just fine by inserting subsections which may or may not compatible with your objectives. The script generates code as follows which is then input into another code snippet to preview the generated images, ( I'm generating svg plots from c++, converting to png, and previewing essentially raw data for selection into later plots that go into an actual document not just a collection of images )

\subsection{svghappy2.tyrosine.png}
\begin{figure}[htbp]
\testplot{svghappy2_tyrosine.png}
\caption{svghappy2.tyrosine.png}
\end{figure}

\subsection{svghappy2.valine.png}
\begin{figure}[htbp]
\testplot{svghappy2_valine.png}
\caption{svghappy2.valine.png}
\end{figure}
0

As the problem arises from the compiler having hard time to set all the images. Splitting between them would help. As @mike-marchywka noted sections may do the trick, but so would other things, such as \pagebreak or \FloatBarrier from placeins

borgr
  • 20,175
  • 6
  • 25
  • 35