title: Hide sections from ToC in Latex
body: <p>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.</p>
  
  <p>I found a solution: <a href="https://stackoverflow.com/questions/2785260/hide-an-entry-from-toc-in-latex">hide an entry from Toc in latex</a></p>
  
  <pre><code>\newcommand{\toclesslab}[3]. 
  {\bgroup\let\addcontentsline=\nocontentsline#1{#2\label{#3}}\egroup} 
  </code></pre>
  
  <p>Usage: \toclesslab\section{Motivation}{s:motivation}</p>
  
  <p>but it is showing two errors first after the command:</p>
  
  <pre><code>Argument of \label has an extra }.
  Missing $ inserted.
  </code></pre>
  
  <p>second after the row</p>
  
  <pre><code>LaTeX Error: Not in outer par mode.
  Undefined control sequence.
  Missing number, treated as zero.
  </code></pre>
  
  <p>and it's not possible to use \label</p>
  
  <p>is there a way to hide a section without losing number and still be referencable?</p>
  
  <p>I have tried this too <a href="https://stackoverflow.com/questions/3791950/remove-specific-subsection-from-toc-in-latex">Remove specific subsection from TOC in LaTeX [duplicate]</a></p>
  
  <p>Minimal reproducible example: <a href="https://latexbase.com/d/498aec5c-d490-47d5-a469-9c6df79a2962" rel="nofollow noreferrer">https://latexbase.com/d/498aec5c-d490-47d5-a469-9c6df79a2962</a></p>
  
  <p>Thank you</p>