0

Q: Why does this cause an infinite loop? (Full code below.) Does let not do what I thought?

\let \oldchapter \chapter
\renewcommand \chapter [2] {\oldchapter{#2}}

Using report as the base class, I want some listoffigures-type lists (e.g. \listoftables, \listoftheorems) as numbered appendices; e.g. "Appendix A: List of theorems" To do this, I have an environment, TocLikeListInternal, that temporarily redefines \chapter. (This seemed the most reliable and straightforward option to support various packages' listings.)

Full context:

\ExplSyntaxOn
\cs_new:Npn \desert__listof_fix:nn #1#2
{
    \let \oldchapter \chapter
    \renewcommand \addcontentsline [3] {}
    \bool_if:nTF {#1}  % want numbered?
        { \renewcommand \chapter [2] {\oldchapter{#2}}   }  % always number
        { \renewcommand \chapter [2] {\oldchapter*{#2}}  }  % never number
    \bool_if:nF {#2}   % want in TOC?
        { \renewcommand \addcontentsline [3] {} }
}

\ProvideDocumentEnvironment {TocLikeListInternal} { m m } { \desert__listof_fix:nn{#1}{#2} } {}

\NewDocumentCommand \ShowListOfTheorems { s t! m } { \begin{TocLikeListInternal}{#1}{#2} \listoftheorems[#3] \end{TocLikeListInternal} }

0 Answers0