# preview, problem with showing floats

In preparing an answer for SE, I suddenly stuck with preview package. LaTeXing the following code:

\documentclass{article}
\usepackage{booktabs}
\usepackage{siunitx}

\usepackage[active,floats,tightpage]{preview}
\setlength\PreviewBorder{5pt}%

\begin{document}
% dummy text ...
\begin{table}
\begin{tabular}{c*{6}{S[table-number-alignment = center,
table-figures-integer = 7]}
}
\toprule
0  & {1} &  {2} & {3} & {4} & {5} \\
\midrule
1 & 11802316.16 & 10270230.14 &  210947.01 & 6716332.35 & 6808728.66 \\
\bottomrule
\end{tabular}
\end{table}
\end{document}


I receive error: Output loop---100 consecutive dead cycles. If I force pdfLaTeX to continue with compilation, it finish with it and gives the following preview:

If I recall correctly, some times ago similar cases work. Meanwhile I only update my MikTeX installation, but between packages I didn't saw preview package. Do have my MWE some error or is there something else in question?

• The problem is that no page is output and the float, by default, has options tbp, so it remains pending waiting for something that triggers flushing the queue, which doesn't arrive. When the output routine has been called \maxdeadcycles times, TeX changes the output routine to the default one (just ship out box 255), so the float finally finds its way on a page. The [h] option to table allows placing the float “here“, so it can be output. – egreg Jun 22 '16 at 22:24
• @egreg, thank you for your explanation! Please, make it as an answer! – Zarko Jun 22 '16 at 22:53

Maybe it will interest someone ... The problem with floats option disappear, if to float environment is added position option h:

\documentclass{article}
\usepackage{booktabs}
\usepackage{siunitx}

\usepackage[active,floats,tightpage]{preview}
\setlength\PreviewBorder{5pt}%

\begin{document}
\begin{table}[h]% with added position option h works as desired
\begin{tabular}{c*{6}{S[table-number-alignment = center,
table-figures-integer = 7]}
}
\toprule
0  & {1} &  {2} & {3} & {4} & {5} \\
\midrule
1 & 11802316.16 & 10270230.14 &  210947.01 & 6716332.35 & 6808728.66 \\
\bottomrule
\end{tabular}
\end{table}
\end{document}


Why this help, I still not understand. Because other options t, b doesn't work.

• Awesome! This saved my day. I think this error was introduced on my system when I upgraded to Ubuntu 15.10; applying your suggestion worked right away. – krlmlr Feb 22 '16 at 21:16
• See egreg's comment on the question for the why. – cfr Jun 22 '16 at 22:50
• @cfr, I sow it (just now), and ask him to make an answer from it. – Zarko Jun 22 '16 at 22:54
• Same solution seems to apply to all other implicitly places commands: tables, figures, itemize, multicols ... I'd worked for me :-) – dsuess Aug 27 '17 at 13:44

Let me quote the TeXbook, bottom of page 254 and top of page 255.

The default output routine, \shipout\box255, illustrates one extreme in which nothing is put into the vertical list that is carried over to the next page. The other extreme is

\output={\unvbox255
\ifnum\outputpenalty<10000 \penalty\outputpenalty\fi}


which ships nothing out and puts everything back onto the main vertical list. (The command \unvbox255 takes the completed page out of its box, and the command \penalty\outputpenalty reinserts the penalty at the chosen breakpoint.) This makes a seamless join between the completed page and the subsequent material, because TeX has still not discarded glue and penalties at the breakpoint when it invokes an \output routine; hence TeX will go back and reconsider the page break. If the \vsize hasn't changed, and if all insertions have been held in place, the same page break will be found; but it will be found much faster than before, because the vertical list has already been constructed—the paragraphing doesn't need to be done again. Of course, an output routine like this makes TeX spin its wheels endlessly, so it is of no use except as an example of an extreme case.

To prevent such looping, your output routine should always make progress of some sort whenever it comes into play. If you make a mistake, TeX may be able to help you diagnose the error, because a special loop-detection mechanism has been built in: There is an internal integer variable called \deadcycles, which is cleared to zero after every \shipout and increased by 1 just before every \output. Thus, \deadcycles keeps track of how many times an output routine has been initiated since the most recent \shipout, unless you change the value of \deadcycles yourself. There's also an integer parameter called \maxdeadcycles, which plain TeX sets to 25. If \deadcycles is greater than or equal to \maxdeadcycles when your output routine is about to be started (i.e., when \deadcycles is about to be increased), TeX issues an error message and performs the default output routine instead of yours.

LaTeX sets \maxdeadcycles to 100.

With a normal document consisting only of a table environment, nothing particular happens. However, preview works by throwing away everything but the chosen pieces, in this case the floats.

It does this using the standard mechanism, but now, being the default positioning of a float tbp, the output routine is called by \end{document} but ships out nothing, because nothing triggers flushing the float queues. So the \deadcycles mechanism enters in the scene; the float can never be positioned, but it is still there, so TeX tries again, failing in the same way.

No matter how high you set the value of \maxdeadcycles, the error will arrive nonetheless, maybe a bit later. At that point, the default output routine is used and the insertions are eventually shipped out.

Solutions: use [htp] as a positioning argument, or add some text outside the float, which will be thrown away, but will allow the float to be positioned.

\documentclass{article}
\usepackage{booktabs}
\usepackage{siunitx}

\usepackage[active,floats,tightpage]{preview}
\setlength\PreviewBorder{5pt}%

\begin{document}

uncommented dummy text

\begin{table}[h]
\begin{tabular}{
c
*{6}{
S[table-number-alignment = center,
table-format=8.2
]
}
}
\toprule
0  & {1} &  {2} & {3} & {4} & {5} \\
\midrule
1 & 11802316.16 & 10270230.14 &  210947.01 & 6716332.35 & 6808728.66 \\
\bottomrule
\end{tabular}
\end{table}

\end{document}


(I fixed the table specifications.)

On the other hand, you get the same result much more easily with standalone:

\documentclass[border=5]{standalone}
\usepackage{booktabs}
\usepackage{siunitx}

\begin{document}

\begin{tabular}{
c
*{6}{
S[table-number-alignment = center,
table-format=8.2
]
}
}
\toprule
0  & {1} &  {2} & {3} & {4} & {5} \\
\midrule
1 & 11802316.16 & 10270230.14 &  210947.01 & 6716332.35 & 6808728.66 \\
\bottomrule
\end{tabular}

\end{document}