# How to prevent \settocdepth{chapter} lead to an empty list of listings

Why does uncommenting the (IMHO innocent) call to \settocdepth{chapter} in the following MWE make the list of listings become blank? Or rather: what can I do to both preserve a chapter-only TOC for the appendix and keep the list of listings "alive"?

\documentclass{memoir}
\usepackage{listings}

\begin{document}
\tableofcontents
\lstlistoflistings
\newpage

\chapter{A chapter}
\begin{lstlisting}[float,caption={Foo},label={lst:foo}]
Foo code
\end{lstlisting}
\newpage

%\settocdepth{chapter} % uncomment --> list of listings empty
\appendix
\chapter{Foo}
Bar
\end{document}


The command \settocdepth{chapter} causes

\changetocdepth{0}


to be written in the .toc file, so this setting continues when the list of listings is read in for typesetting.

Just reset it:

\documentclass{memoir}
\usepackage{listings}

\begin{document}
\tableofcontents

\settocdepth{subsection}
\lstlistoflistings
\newpage

\chapter{A chapter}
\section{A section}
\begin{lstlisting}[float,caption={Foo},label={lst:foo}]
Foo code
\end{lstlisting}
\newpage

\settocdepth{chapter}
\appendix
\chapter{Foo}
\section{A section}
Bar
\end{document}


• Thanks, that worked! I don't exactly understand why this is happening to a list of listings, but not an identically placed list of figures/tables.
– ojdo
Sep 23, 2015 at 14:57
• @ojdo \lstlistoflistings uses the same framework as \tableofcontents, only changing the heading. Sep 23, 2015 at 15:06