I'm experiencing some weird behavior using \include instead of \input.
I create a custom table of contents with all frames which I fill by creation of the frametitle on every slide and with creation of every section automatically. In the minimal example I do that fully manual to keep the example simple.
Usually I have one .tex file per frame (maximum 2 or 3), so I can interchange frames between presentations easily. So in my main file you can find just the \sections and \include.
However the line
\addcontentsline{lbf}{section}{First Section\par}
seems to be executed after \include as you can see here:
with \include
In comparison \input works as desired and expected.
with \input
I can't see any logical reason for this behavior. What's wrong?
I'd like too keep using \include, mainly because of the \excludeonly functionality. Are there alternatives to switching to input?
\RequirePackage{filecontents}
\RequirePackage{excludeonly}
\documentclass{beamer}
\begin{filecontents}{frames.tex}
\begin{frame}
\frametitle{Test Frame One}
\addcontentsline{lbf}{subsection}{First Frame\par}%
test
\end{frame}
\begin{frame}
\frametitle{Test Frame Two}
\addcontentsline{lbf}{subsection}{Second Frame\par}%
test
\end{frame}
\begin{frame}
\frametitle{List of Frames}
\listofframes
\end{frame}
\end{filecontents}
\begin{filecontents}{exframes.tex}
\begin{frame}
\frametitle{Excluded Test Frame}
\addcontentsline{lbf}{subsection}{Excluded Frame\par}%
test
\end{frame}
\end{filecontents}
\makeatletter
\newcommand\listofframes{\@starttoc{lbf}}
\makeatother
\excludeonly{exframes}
\begin{document}
\section{Test section one}
\addcontentsline{lbf}{section}{First Section\par}%
%\input{frames.tex}\input{exframes.tex}
\include{frames}\include{exframes}
\end{document}
Further remarks
- Using or modifying the original ToC provided by beamer (which would work) is no option as I want to keep its complete functionality as it is.
- Of course I could put the
\addcontentslineinside the include command, but that wouldn't work for my workflow using interchangeable frames, so it's no option neither - In the worst case I'd use
\input, so if you think that's the only way it would be nice to have an explanation
Thank you!
The answer of the duplicate question, which did the job, is this one.


\addcontentslinewrite to the aux file when a page is shipped out a command "write something to the toc". Each \include has its own aux-file and writes to the main aux directly "include my aux-file". Your first section doesn't produce a frame or some output and so the output of the \addcontentsline is delayed. See also https://tex.stackexchange.com/questions/13914/toc-numbering-problem/13919#13919 – Ulrike Fischer Sep 20 '16 at 07:52