# Add short toc entry to toc entry and vice versa

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*%
\endgroup%
}

\newcommand{\toc}{%
\renewcommand*{\contentsname}{Contents}
\begingroup%
\def\intoc{}
\tableofcontents*
\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

\long\def\@writefile#1#2{%