0

How can I avoid exceeding TeX's maximum memory when typesetting long tcolorboxes.

I have some really long license codes that are wrapped by a tcolorbox environment. Unfortunately, some licenses causes TeX to run out of memory when they are long enough. I tried avoiding this by breaking up the algorithm at each shipout using the breakable=true parameter. I even tried the currently experimental breakable=unlimited. Below is a simulation of the file using generated lipsum text.

Code

\documentclass{article}
\usepackage{fontspec}
\usepackage{lipsum}
\usepackage[most]{tcolorbox} % support for colorful boxes
\tcbuselibrary{breakable}

\newcounter{examplecounter}
\def\examplecolor{blue!10!black}
\def\examplename{Example}

\NewDocumentEnvironment{susexample}{ O{} }
{
\colorlet{colexam}{\examplecolor} % The maximal total height of the upper and of the lower part of normal breakable tcolorboxes is about 65536pt (ca. 2300cm).
\newtcolorbox[use counter=examplecounter]{examplebox}{%
  % Example Frame Start
  empty,% Empty previously set parameters
  breakable=unlimited, % Set max height of boxes to experimental unlimited. normally 65536pt or about 90 pages. Stops algorithm after each page.
  title={\examplename: #1},% use \thetcbcounter to access the ithexample counter text
  % Attaching a box requires an overlay
  attach boxed title to top left,
  % Ensures proper line breaking in longer titles
  minipage boxed title,
  % (boxed title style requires an overlay)
  boxed title style={empty,size=minimal,toprule=0pt,top=4pt,left=3mm,overlay={}},
  coltitle=colexam,fonttitle=\bfseries,
  before=\par\medskip\noindent,parbox=false,boxsep=0pt,left=3mm,right=0mm,top=2pt,breakable,pad at break=0mm,
    before upper=\csname @totalleftmargin\endcsname0pt, % Use instead of parbox=true. This ensures parskip is inherited by box.
  % Handles box when it exists on one page only
  overlay unbroken={\draw[colexam,line width=.5pt] ([xshift=-0pt]title.north west) -- ([xshift=-0pt]frame.south west); },
  % Handles multipage box: first page
  overlay first={\draw[colexam,line width=.5pt] ([xshift=-0pt]title.north west) -- ([xshift=-0pt]frame.south west); },
  % Handles multipage box: middle page
  overlay middle={\draw[colexam,line width=.5pt] ([xshift=-0pt]frame.north west) -- ([xshift=-0pt]frame.south west); },
  % Handles multipage box: last page
  overlay last={\draw[colexam,line width=.5pt] ([xshift=-0pt]frame.north west) -- ([xshift=-0pt]frame.south west); },%
  }
\begin{examplebox}[breakable=unlimited]}
{\end{examplebox}\endlist}

\begin{document}
\newcount\n
\n=0
\begin{susexample}
  \loop
  \ifnum\n<5000
  \lipsum[1]
  \repeat
\end{susexample}
\end{document}

Crashes with:

Linux 2.6.32-573.el6.x86_64 GNU/Linux on Red Hat Enterprise Linux 6.

! TeX capacity exceeded, sorry [main memory size=5000000].

  • 1
    The documentation warns you that the memory will quite problably have to be increased. Beside this: A layout with a simple line at the side can certainly be done easier than by tcolorbox. Why don't you use a suitable page style? – Ulrike Fischer Apr 4 '16 at 8:21
  • 1
    You cannot avoid the memory problem for VERY long multipage boxes, but you can push the limit using something like in the answer to tex.stackexchange.com/questions/7953/…. Maybe, Ulrikes suggestion is more suitable in your situation? – Thomas F. Sturm Apr 4 '16 at 8:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.