[Tex/LaTex] Hide details of a chapter from TOC and list of tables, figures and algorithms

floatssectioningtable of contents

I have the simple following document:

\documentclass[10pt,a4paper]{report}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\setcounter{secnumdepth}{4}
\setcounter{tocdepth}{4}
\usepackage{algorithm,algcompatible}
\begin{document}
    \tableofcontents
    \listoffigures
    \listoftables
    \listofalgorithms

\chapter{Chapter First}
This is my chapter first.

\chapter{Chapter Two}   
This is my chapter two.

\section{sec 1}

\begin{table}
    \centering
    \caption{my table}
    \label{tab1}
    \begin{tabular}{|c|c|}
        \hline 1 & 2 \\ 
        \hline 3 & 4 \\ 
        \hline 
    \end{tabular} 
\end{table}

\subsection{subsec 1}

\begin{algorithm}
    \caption{(\textit{The EGl-FOM})}
    \label{myalg}
    \begin{algorithmic}[1]
        \STATE Choose 
        \STATE Use the 
        \STATE Compute $\alpha_m$
        \STATE Compute $\lVert R_m\rVert_F=h_{m, m+1}|e_m^T\alpha_m|$.
    \end{algorithmic}
\end{algorithm}

\subsubsection{subsubsec 1}

\end{document}

I am going to hide chapter, section, subsection and subsubsection titles about chapter two from table of contents. Furthermore, I want to hide tables, figures and algorithms titles about chapter two from list of tables, figures and algorithms. Is there a proper way to do these things?

Best Answer

You can set a trigger before chapter two to stop writing content to the ToC/LoF/LoT/LoA and then restore this writing after chapter two (just before chapter three).

The two macros \hidefromtoc and \writetotoc are the triggers that stop/restore writing to the tables:

\documentclass{report}
\setcounter{secnumdepth}{4}
\setcounter{tocdepth}{4}
\usepackage{algorithm,algcompatible}

\let\oldaddcontentsline\addcontentsline
\newcommand{\hidefromtoc}{\renewcommand{\addcontentsline}[3]{}}
\newcommand{\writetotoc}{\let\addcontentsline\oldaddcontentsline}

\begin{document}

\tableofcontents
\listoffigures
\listoftables
\listofalgorithms

\chapter{First chapter}
\section{First section}
\subsection{First subsection}
\begin{figure}
  \caption{A figure}
\end{figure}
\begin{table}
  \caption{A table}
\end{table}
\begin{algorithm}
  \caption{An algorithm}
\end{algorithm}

\hidefromtoc% <------------ Stop writing content to ToC/LoF/LoT/LoA

\chapter{Second chapter}
\section{Second section}
\subsection{Second subsection}
\begin{figure}
  \caption{A figure}
\end{figure}
\begin{table}
  \caption{A table}
\end{table}
\begin{algorithm}
  \caption{An algorithm}
\end{algorithm}

\writetotoc% <------------ Restore writing content to ToC/LoF/LoT/LoA

\chapter{Third chapter}
\section{Third section}
\subsection{Third subsection}
\begin{figure}
  \caption{A figure}
\end{figure}
\begin{table}
  \caption{A table}
\end{table}
\begin{algorithm}
  \caption{An algorithm}
\end{algorithm}

\end{document}