0

Taking heavy inspiration from the answer to:

Hide toc from toc, and shorttoc from shorttoc

I have made the following code:

\documentclass{memoir}

\newcommand{\shorttoc}{%
\renewcommand*{\contentsname}{Short Contents}
\begingroup%
\def\inshorttoc{}%
\tableofcontents*%
\addtocontents{toc}{\string\ifdefined\string\inshorttoc\string\else}%
\addcontentsline{toc}{chapter}{\contentsname}%
\addtocontents{toc}{\string\fi}%
\endgroup%
}

\newcommand{\toc}{%
\renewcommand*{\contentsname}{Contents}
\begingroup%
\def\intoc{}
\tableofcontents*
\addtocontents{toc}{\string\ifdefined\string\intoc\string\else}%
\addcontentsline{toc}{chapter}{\contentsname}%
\addtocontents{toc}{\string\fi}%
\endgroup%
}
\makeatother

\usepackage{mwe}

\begin{document}
\shorttoc

\cleardoublepage

\toc

\blinddocument
\end{document}

It should place the short contents entry into the long toc and vice versa. But after updating my TeX live distribution the code throws the errors:

Extra }, or forgotten \endgroup. \@writefile{toc}{\fi}
Extra }, or forgotten \endgroup. \@writefile{toc}{\fi}

But the code compiles without errors on older distributions.

  • Are you sure this has ever worked? – user31729 Jan 4 at 16:34
  • Yes it works if I compile it on Overleaf – M0erck Jan 4 at 16:35
  • Why not doing the test outside of the toc? Something like \newif\ifintoc \ifintoc \addcontentsline{toc}{chapter}{foo}\fi instead of writing tricky \if... stuff into the .aux and then to the .toc file? – user31729 Jan 4 at 16:54
  • I would be happy with another solution, but I cannot get your suggestion to work. Will "foo" not be added to both shorttoc and toc as along as intoc is true at some point in the document? – M0erck Jan 4 at 17:52
0

Looking into the newer releases of LaTeX I found out that the @\writefile command has been changed slightly (see pages 269--271 in the 2018-12-01 version of the LaTeX2e source documentation, a link is https://www.latex-project.org/help/documentation/source2e.pdf) to solve some problems with spurious spaces. Using the old definition of the @writefile command solved the problem, it is:

\long\def\@writefile#1#2{%
  \@ifundefined{tf@#1}\relax
    {\@temptokena{#2}%
     \immediate\write\csname tf@#1\endcsname{\the\@temptokena}%
    }%
}

A proper solution would avoid this redefinition of @writefile.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.