[Tex/LaTex] Second table of contents only for annexes

appendicestable of contents

I'd like to have in my report a table of contents from introduction to conclusion and another between the conclusion and the first annexe. This latter only for annexes :

- Table of contents
    - 1. Intro
    - 2. Chapter 1
    - ...
    - 20. Conclusion
- 1. Intro
- 2. Chapter 1
- ...
- 20. Conclusion
- SECOND TABLE OF CONTENTS
    - Annexe 1
    - Annexe n
- Annexe 1
- Annexe n

I know we can add annexes to the table of contents using :

\addcontentsline{toc}{chapter}{Annexes}

but is there a way to name a TOC like :

\tableofcontents{TOC1}

and use it to specify which one we want to add contents line :

\addcontentsline{toc}{chapter}{Annexes}{TOC1}

Thank you for your help.

Best Answer

yes article defines

\newcommand\tableofcontents{%
    \section*{\contentsname
        \@mkboth{%
           \MakeUppercase\contentsname}{\MakeUppercase\contentsname}}%
    \@starttoc{toc}%
    }

so you could define

\newcommand\tableofcontentsA{%
    \section*{\contentsname
        \@mkboth{%
           \MakeUppercase\contentsname}{\MakeUppercase\contentsname}}%
    \@starttoc{toca}%
    }

then use

\addcontentsline{toca}{chapter}{Annexes}

instead of

\addcontentsline{toc}{chapter}{Annexes}

This will store the headings in a filename with extension .tocA and input that file at the point where you use \tableofcontentsA. Note as there are @ in the command names the definition needs to be in a package file or between \makeatletter \makeatother

If your annexes are using sectioning commands that are internally writing to the .toc file so that you can not easily just write to toca you can redefine the internal writing command to write to toca if passed toc as argument like so:

\let\oldaddtocontents\addtocontents

\def\addtocontents#1{%
   \def\tmpa{#1}%
   \def\tmpb{toc}%
   \ifx\tmpa\tmpb
      \def\tmpa{toca}%
   \fi
   \expandafter\oldaddtocontents\expandafter{\tmpa}}

In the standard classes (and most none standard ones) this will make all the sectioning commands write to .toca from the point of redefinition.

so a complete document

\documentclass{book}

\makeatletter
    \newcommand\tableofcontentsA{%
        \chapter*{\contentsname
            \@mkboth{%
               \MakeUppercase\contentsname}{\MakeUppercase\contentsname}}%
        \@starttoc{toca}%
        }
\makeatother
\begin{document}
\tableofcontents

\chapter{aa}
\chapter{aaa}

\appendix
\let\oldaddtocontents\addtocontents
\def\addtocontents#1{%
   \def\tmpa{#1}%
   \def\tmpb{toc}%
   \ifx\tmpa\tmpb
      \def\tmpa{toca}%
   \fi
   \expandafter\oldaddtocontents\expandafter{\tmpa}}
\tableofcontentsA

\chapter{bbaa}
\chapter{bbaa}

\end{document}
Related Question