# Weird error when using amsart + tocdepth + paragraph

For the following MWE

\documentclass{amsart}
\setcounter{tocdepth}{3}
\title{Hi}
\begin{document}
\maketitle
\tableofcontents
\section{A}
\subsection{B}
\subsubsection{B}
\paragraph{D}
\end{document}


I'm getting the error

! Missing number, treated as zero.
\r@tocindent4
l.11 \end{document}

?


and I can't really figure out why. If I change amsart to article, or remove the \setcounter line, the error goes away.

• Welcome to TeX.SX! amsart doesn't support tocdepth=4. But also, having too deep sectioning level in the ToC looks weird. Are you sure you want that? – Phelype Oleinik Feb 6 '20 at 22:08
• I actually don't want that, but I would like to be able to want it in principle. the example also gives an error for tocdepth=3. But if the answer is that it can't be made to work with amsart then I'll accept that as an answer too. – Christine Feb 6 '20 at 22:12
• I'm editing the question to say tocdepth = 3. – Christine Feb 6 '20 at 22:16
• Hm... From what I can see, it should support 3... – Phelype Oleinik Feb 6 '20 at 22:18

First, amsart only supports tocdepth up to 3, because it only defines the variables \r@tocindentX for −1 ≤ X ≤ 3.

Even then, this looks like a bug in amsart, when you set tocdepth to 3.

The class defines:

\def\l@subsubsection{\@tocline{3}{0pt}{1pc}{7pc}{}}


and then also does:

\let\l@paragraph\l@subsubsection


The first line is OK, because it defines the ToC entry for a \subsubsection to be at level 3 (which is supported). However the second line also defines the ToC entry for \paragraph to be 3, which causes trouble, because \paragraph is level 4 (it does the same for \subparagraph.

The correct definition would be:

\def\l@paragraph{\@tocline{4}{0pt}{1pc}{7pc}{}}
\def\l@subparagraph{\@tocline{5}{0pt}{1pc}{7pc}{}}


\documentclass{amsart}
% bug fix:
\makeatletter
\def\l@paragraph{\@tocline{4}{0pt}{1pc}{7pc}{}}
\def\l@subparagraph{\@tocline{5}{0pt}{1pc}{7pc}{}}
\makeatother
%
\setcounter{tocdepth}{3}
\title{Hi}
\begin{document}
\maketitle
\tableofcontents
\section{A}
\subsection{B}
\subsubsection{B}
\paragraph{D}
\end{document}

• this did solve the orignal problem, but a quick follow-up question: if I would like to set tocdepth to 4, how can I make sure the value \r@tocindent4 is defined? – Christine Dec 5 '20 at 18:48
• Adding the following to your solution does the job : \@xp\gdef\csname r@tocindent4\endcsname{0pt} – Christine Dec 5 '20 at 18:59