I am trying to get a summary out of toc. The summary should only show chapters and sections. I used the following code:

\makeatletter
\newcommand*{\tableofcontentssummary}{%
\begingroup
\value{tocdepth}=1\relax% usually show part, chapter and section only
\@fileswfalse
\renewcommand*{\contentsname}{Summary}%
\tableofcontents
\endgroup
}
\makeatother

\section*{Summary}
\markboth{}{SUMMARY}
\label{sec:summary}

\tableofcontentssummary


This should work but I am getting issues with the functions I previously added to the toc. They also apply themselves to the summary. I want to remove >\renewcommand and and >\addtocontents{toc}.

Here is what I get.

• Please provide a complete (compilable) code that includes documentclass and the relevant packages. This is called MWE, see tex.meta.stackexchange.com/questions/228. Otherwise, there is a big risk that there are misunderstandings and wrong assumptions. Jun 8, 2021 at 1:30
• If you can use any class, memoir could be a good choice for you. Take a look at section 9.2.5 of the manual. In fact its table of contents is an example of what I believe you want Jun 8, 2021 at 2:17
• \documentclass[12pt,a4paper]{report}
– pyaj
Jun 8, 2021 at 8:33
• The rest of my includes is pretty long (150 lines). It does not fit in the comment
– pyaj
Jun 8, 2021 at 8:49
• For future reference, don't post code or updates in comments. edit it into the post itself. And a MWE is almost never 150 lines. Jun 8, 2021 at 12:26

Assuming package tocbasic is already in use (\listoftoc is a tocbasic macro):

\documentclass{book}
\usepackage{blindtext}% only for dummy text

\usepackage{tocbasic}
\newcommand*{\originaltableofcontents}{\listoftoc[\contentsname]{toc}}
\renewcommand*{\listoffigures}{\listoftoc[\listfigurename]{lof}}
\renewcommand*{\listoftables}{\listoftoc[\listtablename]{lot}}
\setuptoc{lof}{leveldown,totoc}
\setuptoc{lot}{leveldown,totoc}

\makeatletter
\newcommand*{\tableofcontentssummary}{%
\begingroup
\value{tocdepth}=1\relax% usually show part, chapter and section only
\@fileswfalse
\renewcommand*{\contentsname}{Summary}%
\setuptoc{toc}{leveldown,totoc}%
\originaltableofcontents
\endgroup
}
\makeatother

\renewcommand*{\tableofcontents}{%
\setuptoc{toc}{totoc}%
\originaltableofcontents
}
\newcommand*\maintocsetup[1]{%
\thispagestyle{empty}\clearpage\markboth{}{\MakeUppercase{\contentsname}}%
}
\setcounter{tocdepth}{5}

\begin{document}
\frontmatter
\tableofcontentssummary
\listoffigures
\listoftables

\mainmatter
\Blinddocument
\begin{table}
\caption{A table}
\end{table}
\begin{figure}%
\caption{A figure}%
\end{figure}
\Blinddocument\Blinddocument\Blinddocument

\tableofcontents
\end{document}


A dirty trick: First compile twice the document with the usual \tableofcontents, then remove it and use the .toc file directly as many times as you want.

\documentclass{book}
\usepackage{blindtext}
\begin{document}
\frontmatter
% \tableofcontents
\section*{Default ToC}
\input{\jobname.toc}
\setcounter{tocdepth}{1}
\section*{ToC Summary}
\input{\jobname.toc}
\setcounter{tocdepth}{4}
\section*{Full ToC}
\input{\jobname.toc}
\mainmatter
\Blinddocument
\end{document}


If manually comment one line after first compilation is too much work, you can do also automatically:

\documentclass{book}
\usepackage{blindtext}
\begin{document}
\frontmatter
\IfFileExists{\jobname.toc}{%
\chapter{Contents}%
\input{\jobname.toc}%
\setcounter{tocdepth}{1}%
\chapter{ToC Summary}
\input{\jobname.toc}}%
{\tableofcontents%
\marginpar{\huge Compile\\ again!}}
\mainmatter
\Blinddocument
\end{document}


Again you have not provided an MWE that shows the \documentclass. The answers to yourprevious question Set list of tables and list of figures as section in table of contents showed two MWEs but you seem to have taken no notice of what they looked like. --- GOM

If you use the memoir class (a superset of book and report classes) then this simply provides for multiple ToCs. The following is an MWE of 30 lines showing this.

% shorttocprob.tex SE 600373
\documentclass{memoir}

\begin{document}
\frontmatter

% The short ToC
\setcounter{tocdepth}{1} % chapters and sections
\renewcommand{\contentsname}{Short ToC}
\tableofcontents* % this does not add Contents to the ToC

% The regular ToC
\renewcommand{\contentsname}{Contents}
\setcounter{tocdepth}{2} % chapters to subsections
%\tableofcontents  % this adds Contents to the ToC
\tableofcontents* % this does not add Contents to the ToC

\mainmatter
\setsecnumdepth{subsection}  % number subsections

\chapter{A chapter}
Text.
\section{A section}
Text.
\subsection{A subsection}
Text.
\subsubsection{A subsubsection}
Text.

\end{document}