-1

I would like to hide sections of Appendix from the table of contents, without losing the section number in the body of the document and section should be possible to reference.

I found a solution: hide an entry from Toc in latex

\newcommand{\toclesslab}[3]. 
{\bgroup\let\addcontentsline=\nocontentsline#1{#2\label{#3}}\egroup} 

Usage: \toclesslab\section{Motivation}{s:motivation}

but it is showing two errors first after the command:

Argument of \label has an extra }.
Missing $ inserted.

second after the row

LaTeX Error: Not in outer par mode.
Undefined control sequence.
Missing number, treated as zero.

and it's not possible to use \label

is there a way to hide a section without losing number and still be referencable?

I have tried this too Remove specific subsection from TOC in LaTeX [duplicate]

Minimal reproducible example: https://latexbase.com/d/498aec5c-d490-47d5-a469-9c6df79a2962

Thank you

FrankMa
  • 53
  • 1
  • 11

1 Answers1

4

It is possible by using toc depth, but it is important to reset the depth back to the previous value or it can break other lists.

\appendix
\section*{Appendix}
\addcontentsline{toc}{section}{Appendix}

%Here's the place to hide section from ToC 
\addtocontents{toc}{\protect\setcounter{tocdepth}{0}}

\section{Appendix section}
\label{appendixSection}
Text

%At the end of the appendix it has to be set to the previous value
\addtocontents{toc}{\protect\setcounter{tocdepth}{2}}
FrankMa
  • 53
  • 1
  • 11