stack size
Heiko Oberdiek
oberdiek@ruf.uni-freiburg.de
Wed, 24 Nov 1999 11:54:09 +0100
At 11:14 24.11.1999 +0100, Peer Rappolt wrote:
>How to increase the stack size of TeX ?
texmf.cnf: stack_size
After changing you should rebuild the formats.
Before changing you should check, whether the cause is not a wrong
written recursion:
\documentclass{minimal}
\newcounter{dummy}
\setcounter{dummy}{500}
\newcommand{\bsp}{%
\ifnum\value{dummy}=0
\typeout{end of recursion}%
\else
\typeout{\thedummy}%
\addtocounter{dummy}{-1}%
\bsp
\fi
}
\begin{document}
\bsp
\end{document}
This example is limited to the input stack size. There are two tricks
to avoid this:
1. With the \expandafter trick the \if construct is finished before
the next recursive call of \bsp
\newcommand{\bsp}{%
\ifnum\value{dummy}=0
\typeout{end of recursion}%
\else
\typeout{\thedummy}%
\addtocounter{dummy}{-1}%
\expandafter\bsp
\fi
}
2. Often it is not possible to use \expandafter. For example, it is
not possible to jump over an unknown number of tokens, introduced
by #1, #2, ...
In this cases the ReturnAfter(Else)Fi-Trick can be used:
\newcommand{\bsp}[1]{%
\ifnum\value{dummy}=0
\typeout{end of recursion}%
\else
\ReturnAfterFi{%
\typeout{\thedummy}%
\addtocounter{dummy}{-1}%
\bsp{#1}
}%
\fi
}
\def\ReturnAfterFi#1\fi{\fi#1}
\def\ReturnAfterElseFi#1\else#2\fi{\fi#1}
\bsp{Text}
Yours sincerely
Heiko <oberdiek@ruf.uni-freiburg.de>