代码

代码

排版长文本时,如何避免超出 TeX 的最大内存tcolorbox

我有一些非常长的许可证代码,它们被 tcolorbox 环境包装起来。不幸的是,有些许可证在足够长时会导致 TeX 内存耗尽。我尝试通过使用参数在每次发货时分解算法来避免这种情况breakable=true。我甚至尝试了当前实验性的breakable=unlimited。下面是使用生成的 lipsum 文本对文件的模拟。

代码

\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}

崩溃原因:

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

!TeX 容量超出,抱歉 [主内存大小=5000000]。

相关内容