
The separate Toc
for the appendix entries can be achieved by letting an .app
(for example) file handle point to .toc
, i.e. at a certain point of document stopping to write to the .toc
file and everything meant for the .toc
enters the .app
file.
I have defined a \listofappendices
macro, that reuses \tableofcontents
by renaming \contentsname
and applying \@starttoc{app}
instead of \@starttoc{toc}
.
Please note, that any writting attempt to the .toc
will finally be placed in the .app
file, so if this is not desired, the file handle must be restored at the end of appendices
; this is not yet done.
\documentclass{article}
\usepackage{lipsum}
%\usepackage[utf8]{inputenc} % Not needed since TL 2018
\usepackage{hyperref}
\usepackage[page]{appendix}
% as per https://tex.stackexchange.com/questions/100479/label-appendix-as-appendix-i-ii-iii-rather-than-appendix-a-b-and-c
% use custom names for appendices
\renewcommand{\appendixtocname}{List of appendices}
\renewcommand{\appendixpagename}{Appendices}
\makeatletter
\let\oldappendix\appendices
\renewcommand{\appendices}{%
\clearpage
\renewcommand{\thesection}{\Roman{section}}
% From now, everything goes to the app - file and not to the toc
\let\tf@toc\tf@app
\addtocontents{app}{\protect\setcounter{tocdepth}{1}}
\immediate\write\@auxout{%
\string\let\string\tf@toc\string\tf@app^^J
}
\oldappendix
}%
\newcommand{\listofappendices}{%
\begingroup
\renewcommand{\contentsname}{\appendixtocname}
\let\@oldstarttoc\@starttoc
\def\@starttoc##1{\@oldstarttoc{app}}
\tableofcontents% Reusing the code for \tableofcontents with different \contentsname and different file handle app
\endgroup
}
\makeatother
\begin{document}
\tableofcontents
\listofappendices
\section{first section}
\lipsum
\section{second section}
\lipsum
\section{Third section}
\lipsum
\begin{appendices}
\section{My first appendix}
\lipsum
\section{My second appendix}
\lipsum
\section{My third appendix}
\lipsum
\end{appendices}
\end{document}
Update Version with restoring the possibility to write to the original ToC after the appendices:
\documentclass{article}
\usepackage{lipsum}
%\usepackage[utf8]{inputenc} % Not needed since TL 2018
\usepackage[page]{appendix}
\usepackage{etoolbox}
\usepackage{hyperref}
% as per https://tex.stackexchange.com/questions/100479/label-appendix-as-appendix-i-ii-iii-rather-than-appendix-a-b-and-c
% use custom names for appendices
\setcounter{tocdepth}{3}
\renewcommand{\appendixtocname}{List of appendices}
\renewcommand{\appendixpagename}{Appendices}
\makeatletter
\let\oldappendix\appendices
\g@addto@macro\tableofcontents{%
% Store the current toc file for later usage
\let\tf@toc@orig\tf@toc
}
\renewcommand{\appendices}{%
\clearpage
\renewcommand{\thesection}{\Roman{section}}
% From now, everything goes to the app - file and not to the toc
\let\tf@toc\tf@app
\addtocontents{app}{\protect\setcounter{tocdepth}{1}}
\immediate\write\@auxout{%
\string\let\string\tf@toc\string\tf@app
}
\oldappendix
}%
\g@addto@macro\endappendices{%
% Switch back to the old toc file handle
\let\tf@toc\tf@toc@orig
\immediate\write\@auxout{%
\string\let\string\tf@toc\string\tf@toc@orig
}%
}
\newcommand{\listofappendices}{%
\begingroup
\renewcommand{\contentsname}{\appendixtocname}
\let\@oldstarttoc\@starttoc
\def\@starttoc##1{\@oldstarttoc{app}}
\tableofcontents% Reusing the code for \tableofcontents with different \contentsname and different file handle app
\endgroup
}
\makeatother
\begin{document}
\tableofcontents
\listofappendices
\section{first section}
\lipsum
\section{second section}
\lipsum
\section{Third section}
\lipsum
\begin{appendices}
\section{My first appendix}
\lipsum
\section{My second appendix}
\lipsum
\section{My third appendix}
\lipsum
\end{appendices}
\section{A section after the appendices}
\end{document}

etoc
package. – albert Aug 25 '18 at 12:21