[Tex/LaTex] Very large tcolorbox

tcolorbox

I have a very large breakable tcolorbox

\documentclass{article}

\usepackage{blindtext}
\usepackage{tcolorbox}
\tcbuselibrary{breakable}

\begin{document}

\begin{tcolorbox}[breakable]
\blindtext[150]
\end{tcolorbox}

\end{document}

that exceeds the maximal dimension and causes the following error.

! Dimension too large.
<argument> \ht \tcb@upperbox 
                             +\dp \tcb@upperbox 
l.11 \end{tcolorbox}

When I use the batchmode as suggested for a very large mdframed environment I get a document with a single page and a colorbox that does not surround the content. The tcolorbox documentation states the following

The box content is a TEX \vbox register which has a restricted capacity`.
Therefore, you cannot place hundreds of pages inside a tcolorbox.

What is the appropriate way of dealing with very large color boxes?

Edit

To add some context as there might as well be a better solution for my problem, I have a large list of small paragraphs (probably one or two lines). I don't know statically how many there are or how long a single paragraph is. I would like to put these paragraphs one after the other on a page as long as they fit and make a page break otherwise. The content of each page should be surrounded by a box. In fact, I additionally would like to separate each pair of consecutive paragraphs by a separator as described here. I also looked for multi page tabular environments but did not find a fit either.

Best Answer

It took some time and help from others, namely egreg and Heiko Oberdiek, to find a suitable solution, but now I have one.

I made a new enhanced version of tcolorbox which is at the time of writing 3.10pre1 (2014/07/16). It's a pre-version available at GitHub, but it will be compatible to an official CTAN version to appear later.

With this new version, the normal breakable tcolorbox content length is extended from about 16384pt by factor 4 to about 65536pt. If needed, this maximum can be extended by an option key as far as compiler memory allows.

As a consequence, your example compiles without any problem. Without any further tweaks, also the following compiles:

\documentclass{article}

\usepackage{blindtext,pgffor}
\usepackage{tcolorbox}
\tcbuselibrary{breakable}

\begin{document}

\begin{tcolorbox}[breakable]
\foreach \n in {1,...,455}
  {\textbf{\color{red}(\n)} \blindtext[1]\par}
\end{tcolorbox}

\end{document}

This compiles to a document with 125 pages.

This number of pages is depending on actual the size of a single-page tcolorbox. But it should be save for other cases with say up to 100 pages of boxed content.

This limit can be overcome using the new option breakable=unlimited which uses another algorithm. This algorithm is not perfect but could influence a single interline space every 65536pt (I would say: that's not too bad...). Since a breakable tcolorbox is a \box which is completely processed in memory, the compiler memory is the next limit. Using pdflatex with MiKTeX, the following example compiles without tweaks on my system:

\documentclass{article}

\usepackage{blindtext,pgffor}
\usepackage{tcolorbox}
\tcbuselibrary{breakable}

\begin{document}

\begin{tcolorbox}[breakable=unlimited]
\foreach \n in {1,...,1300}
  {\textbf{\color{red}(\n)} \blindtext[1]\par}
\end{tcolorbox}

\end{document}

This compiles to a document with 355 pages.

Again, the number of pages depends on the geometry and also on the content of the boxes.

If that's not enough, the compiler memory could be increased. I took the heavy hammer (MiKTeX dependend) I use for monstrous documents, i.e.

pdflatex --pool-size=10000000 --max-strings=500000 --save-size=50000 --extra-mem-bot=4000000 --extra-mem-top=4000000 jobname.tex

With that hammer, the following code compiles on my system:

\documentclass{article}

\usepackage{blindtext,pgffor}
\usepackage{tcolorbox}
\tcbuselibrary{breakable}

\begin{document}

\begin{tcolorbox}[breakable=unlimited]
\foreach \n in {1,...,5000}
  {\textbf{\color{red}(\n)} \blindtext[1]\par}
\end{tcolorbox}

\end{document}

This compiles to a document with 1364 pages.

Related Question