Question

If I have a document with multiple tables of contents, can I limit the scope of a toc sections are added and reset the toc?

Situation

I have a document made up of 10 languages. (using \input{en}, \input{de}, \input{da} etc.) There are 11 tables of contents:

• Language Directory (composed of each \input (probably going to have to just be a custom table containing hooks for each \input. I don't know how I will implement this yet.

Example Code

Example of Main .tex

\documentclass{article}
\usepackage{fontspec}
\begin{document}
\maketableofcontents % language directory (list of inputs with language names)
\input{en}
\input{de}
\input{da}
\end{document}


Example of en.tex

\maketableofcontents % local toc
\section{apple}
%\somecommand % TOC scope limit


Example of de.tex

\maketableofcontents % local toc
\section{apfel}
%\somecommand % TOC scope limit


Example of da.tex

\maketableofcontents % local toc
\section{æble}
%\somecommand % TOC scope limit

• if you place it the in the main file as: {\maketableocontents \input{en}} does this create the desired effect? – Rick de Groot Feb 19 '15 at 10:27
• The package tableof has dedicated commands for that – Denis Feb 19 '15 at 10:43
• etoc provides means for this – user31729 Feb 19 '15 at 12:02

Here's a solution using etoc. Note the limitations of the default filecontents environment

\begin{filecontents}{en.tex}
\localtableofcontents
\section{apple}
\end{filecontents}
\documentclass{article}
\usepackage{bookmark}
\usepackage{etoc}

% Use this version \newlang{<name>}{<file>}
% to use external files
\newcommand\newlangfile[2]{%
\newlang{#1}%
\input{#2}%
}
\newcommand\newlang[1]{%
\newpage\pdfbookmark{#1}{bkm#1}%
\renewcommand\contentsname{#1 Contents}%
\etoctoccontentsline{part}{#1}%
}

\begin{document}
\setcounter{tocdepth}{0}
\renewcommand\contentsname{Language directory}
\tableofcontents
\setcounter{tocdepth}{3}

%\newlang{english}
%\localtableofcontents
%\section{Apple}
% Or use
\newlangfile{english}{en.tex}
% if you prefer the second macro

\newlang{german}
\localtableofcontents
\section{Apfel}
\newlang{danish}
\localtableofcontents
\section{able}

\end{document}

• I am not sure I understand why \newlang{german} comes after \newlangfile{english}{en.tex}, but before \localtableofcontents. English should have a local TOC and so should German. – Jonathan Komar Feb 19 '15 at 13:55
• The macro \newlangfile{english}{en.tex} does the same as newlang, but additionally \inputs a file (provided by the second argument). This allows you to keep a main file similar to your example using \input. Furthermore, I've edited the macro definition to change the Title of every local toc to show that every language has its own toc. – Patrick Happel Feb 19 '15 at 14:05
• Awesome! Really, really cool stuff right there...Realistically the \contentsname will be set differently, but still, the other possibility of creating a language switch within \newlangfile is great. – Jonathan Komar Feb 19 '15 at 14:13
• I see you are creating toc parts that contain the language names. Is there a way to bring those parts together in a language directory? Also, it would be nice to have those parts show up in the PDF bookmarks. I am not sure at the moment whether that is a job for tocloft or etoc. – Jonathan Komar Feb 19 '15 at 14:17
• Ok, it was easy to get the language directory. I just had to temporarily do a \setcounter{tocdepth}{0}. It would be cool to get the parts into the bookmarks. I think this stuff is beyond the scope of the question, however. – Jonathan Komar Feb 19 '15 at 14:26