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.
\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 '19 at 16:54