# Add section titles to list of frames - \insertsection does not work

By help of the answer Is there any way to produce List of frames with beamer? I succesfully created a list of frames. But I'd also like to include the section titles inbetween. This answer unfortunately does not work for me, as I need the original ToC untouched.

So I thought I could create a commamd \sectioninlbf which I call behind every \section (can be automated later...) and create a new content line in the lbf-file. However the \insertsection command seems to be ignored totally.

What am I doing wrong?

## MWE

\documentclass{beamer}

\usepackage{hyperref}

\makeatletter
\newcommand\listofframes{\@starttoc{lbf}}
\makeatother

\makeatletter
\mode<presentation>
{
\only<1>{
\hypertarget{\insertframetitle}{}%
\ifx\insertframesubtitle\@empty%
\else%
\fi%
\par}%
}
}
}
\makeatother

\newcommand{\sectioninlbf}{
\vspace{0.3\baselineskip}
\protect\footnotesize%
\protect\insertsection Here I want the section title.\par}%
}

\begin{document}

\begin{frame}
\frametitle{General outline}
\tableofcontents[hideallsubsections]
\end{frame}

\begin{frame}
\frametitle{List of Frames}
\listofframes
\end{frame}

\section{Test section one}\sectioninlbf

\begin{frame}
\frametitle{Test Frame One}
test
\end{frame}

\section{Test section two}\sectioninlbf
\begin{frame}
\frametitle{Test Frame Two}
\framesubtitle{Test Frame Two Subtitle}
test
\end{frame}
\begin{frame}
\frametitle{Test Frame Three}
\uncover<1->{test}
\uncover<2->{test}
\uncover<3->{test}
\end{frame}

\end{document}


## Update

As Sam Carter's answer changes my initial approach, I needed to extend the MWE to include some more requirements: If a framesubtitle exists, the framesubtitle should subsititute the frametitle in the ToC. Also the frame numbers are required. Also I use different frametitle templates, some of them add the frametitles and framesubtitles to the ToC, some of the don't. So I don't know if patching the base-command of frametitle is a good idea, unless an on/off switch exists.

• Would tex.stackexchange.com/a/17233/36296 be an alternative? – samcarter_is_at_topanswers.xyz Sep 13 '16 at 17:39
• \tableofcontents[hideallsubsections] will still give you the original toc – samcarter_is_at_topanswers.xyz Sep 13 '16 at 17:52
• @samcarter 2) yes I know, I asking about the next frame. But I don't want to "destroy" that first one, as I would with one of the linked answers. – thewaywewalk Sep 13 '16 at 18:42
• @samcarter 1) it highly depends. I heavily use uncover and so on, with my approach now I can handle it quite easy, that I just get an entry for the first occurence. Your linked solution doesn't seem to provide that functionality easily. – thewaywewalk Sep 13 '16 at 18:45

I see two requirements in your question:

1. "normal" toc should still be available: \tableofcontents[hideallsubsections]

2. should work with overlays: I modified the code a little bit so that only the first slide in a frame is added to the toc.

4. includes subtitle if available

\documentclass{beamer}

\makeatletter
\only<1>{%
\protect\beamer@subsectionintoc{\the\c@section}{0}{%
\ifx\insertframesubtitle\@empty%
\insertframetitle%
\else%
\insertframesubtitle%
\fi%
}{\the\c@page}{\the\c@part}{\the\beamer@tocsectionnumber}%
}%
}%
}%
\makeatother

\begin{document}

\begin{frame}
\tableofcontents[hideallsubsections]
\end{frame}

\begin{frame}
\tableofcontents
\end{frame}

\section{First Section}

\begin{frame}{First frame}
Text
\end{frame}

\begin{frame}{Second frame}
Text
\end{frame}

\section{Second Section}

\begin{frame}
\frametitle{Third frame}
\framesubtitle{mySubtitle}
Text
\end{frame}

\begin{frame}
\frametitle{Fourth frame}
Text
\pause
more text
\end{frame}

\end{document}


• \apptocmd{\beamer@@frametitle}{% \only<1>{ \addtocontents{toc}{\protect\beamer@subsectionintoc{\the\c@subsection}{0}{#1}{\the\c@page}{\the\c@part}% {\the\beamer@tocsectionnumber}}% }}{}{}% would be enough actually. However, as this answer completely changes the base code of my question I don't know how to proceed and my minimal example is too minimal now. I actually include a test whether a framesubtitle exists and if so, put the framsubtitle instead of the frametitle. Also I need the frame numbers. With my approach I would know how to do all that, now I don't... – thewaywewalk Sep 14 '16 at 7:05
• I'm very sorry, it's always so hard to tell how minimal a minimal example needs to be... – thewaywewalk Sep 14 '16 at 7:15
• @thewaywewalk I added the framenumbers. Will have a look later if the subtitles are possible as well. – samcarter_is_at_topanswers.xyz Sep 14 '16 at 13:32
• As your code stands now, you should be able to use the same if condition, as I did in my orginal question, uinder the assumption that the frametitle also exists (which is the case). But I can't try it now. – thewaywewalk Sep 14 '16 at 15:50

The answer finally was pretty simple:

Instead of \insertsection the undocumented (?) \secname should be used and everything works as desired.

\newcommand{\sectioninlbf}{