# Remove entries from short ToC but not from long ToC

Please find a minimal example illustrating this question below.

The problem is this:

• There is only one appendix chapter, which is divided into several paragraphs. These paragraphs should appear in the detailed ToC (made possible using the shorttoc package) but not in the short ToC.
• In the detailed ToC appendix paragraphs (but only appendix(!!) paragraphs) should appear as sections meaning they are intended to be aligned on the same level as sections in the rest of the ToC.

The solution shown in the minimal example arised from the answers to two related questions I posted here. However, one problem is still unsolved:

How can I achieve in the code given below that the appendix sections(=paragraphs) do not figure in the short ToC (which currently they do since paragraphs actually are sections modified so that they look like paragraphs)?

I found several related problems on the web but in the end they amount to removing certain sections from ToC (see the parts of my code commented out). This of course has the consequence that they do not appear in the detailed ToC either since the detailed ToC gets its data from the .toc file ...

I hope I made clear what the problem is!? Seems to me a quite tricky issue!

\documentclass[10pt, a4paper]{report}

\usepackage[titletoc]{appendix}
\usepackage{titlesec}
\usepackage{titletoc}
\usepackage{shorttoc}
\usepackage{hyperref}

%\newcommand{\nocontentsline}[3]{}

\begin{document}

\setcounter{secnumdepth}{3}

\renewcommand*\contentsname{Contents (detailed)}

\pdfbookmark[1]{Contents}{toc}
\shorttoc{Contents}{1}

\cleardoublepage

\setcounter{tocdepth}{4}
\renewcommand*\contentsname{Contents (detailed)}
\pdfbookmark[1]{Contents (detailed)}{toc (detailed)}
\tableofcontents

\chapter{Test Chapter}
\section{Test Section}
\subsection{Test Subsection}
\subsubsection{Test Subsubsection}
\paragraph{Test Paragraph}

\begin{appendices}

\renewcommand\thechapter{}

\chapter{Test Appendix}

\titleformat{\section}[runin]
{\normalfont\normalsize\bfseries}{}{1em}{}
\titlespacing*{\section}
{0pt}{3.25ex plus 1ex minus .2ex}{1em}
\titlecontents{section}[1.5em]
{}{}{}{\titlerule*[7.5pt]{.}\contentspage}

%\tocless\section{Test Section One}
\section{First section looking like a paragraph}
%\tocless\section{Test Section Two}
\section{Second section looking like a paragraph}

\end{appendices}

\end{document}

-

Possibly not the most elegant way:

• Create a new boolean switch shorttoc,

• Use the etoolbox package to patch the \@startshorttoc macro so that the shorttoc switch is set to true (inside a group),

• At the start of the appendix, add a line to the .toc file setting the tocdepth counter to 0 if the shorttoc switch is true.

\documentclass[10pt, a4paper]{report}

\usepackage[titletoc]{appendix}
\usepackage{titlesec}
\usepackage{titletoc}
\usepackage{shorttoc}
\usepackage{hyperref}

%\newcommand{\nocontentsline}[3]{}

\usepackage{etoolbox}

\newbool{shorttoc}

\makeatletter
\patchcmd{\@startshorttoc}{\bgroup}{\bgroup\booltrue{shorttoc}}{}{}
\makeatother

\begin{document}

\setcounter{secnumdepth}{3}

\renewcommand*\contentsname{Contents (detailed)}

\pdfbookmark[1]{Contents}{toc}
\shorttoc{Contents}{1}

\cleardoublepage

\setcounter{tocdepth}{4}
\renewcommand*\contentsname{Contents (detailed)}
\pdfbookmark[1]{Contents (detailed)}{toc (detailed)}
\tableofcontents

\chapter{Test Chapter}
\section{Test Section}
\subsection{Test Subsection}
\subsubsection{Test Subsubsection}
\paragraph{Test Paragraph}

\begin{appendices}

\renewcommand\thechapter{}

\chapter{Test Appendix}

\titleformat{\section}[runin]
{\normalfont\normalsize\bfseries}{}{1em}{}
\titlespacing*{\section}
{0pt}{3.25ex plus 1ex minus .2ex}{1em}
\titlecontents{section}[1.5em]
{}{}{}{\titlerule*[7.5pt]{.}\contentspage}

%\tocless\section{Test Section One}
\section{First section looking like a paragraph}
%\tocless\section{Test Section Two}
\section{Second section looking like a paragraph}

\end{appendices}

\end{document}


-
Yes, that works. etoolbox is comewhat beyond my possibilities, but after checking the manual I now have a vague idea why your code does what it does. What I still do not understand is for example why your code does not result in the sections being removed from the detailed ToC too!? (Of course that's exactly what is intended -- what I don't understand is WHY it does what it should do!) –  lpdbw Jul 28 '12 at 13:00
PROBLEM: Your solution only works in the minimal example! In my main file however I get the following error though I copied the code exactly!? I cannot reproduce the erro in my minimal example! Here is the error message: [242]) ! Undefined control sequence. \@calc@post@scan ...st@scan \else \def \calc@next {\calc@error #1}\fi \fi \f... l.94 ...ool{shorttoc}{\setcounter{tocdepth}{0}}{}} ? X –  lpdbw Jul 28 '12 at 13:28
I could reproduce the error now in a minimal example! There seems to be an incompatibility of your solution with the mathtools package! Could you please try and add the mathtools package and see whether your solution still works!? –  lpdbw Jul 28 '12 at 13:44
Problem with mathtools is solved here tex.stackexchange.com/questions/65029/… –  lpdbw Jul 28 '12 at 14:56