17

I would like to have a beamer presentation in which every frame appears in the PDF table of contents (i.e. has a bookmark). My specific presentation only has sections, so all of the frames can appear as a "subsection" on the PDF. Note that I don't want to make a subsection for each frame.

One way to do that is make up a command that patches frametitle by calling the appropriate bookmark command of hyperref. Is there any better way?

2
  • Just to clarify, you want them to show up on the frame containing the table of contents or do you want to see them in your PDF viewer's sidebar/listing? Commented May 3, 2011 at 8:16
  • I want them to show up only on the PDF viewer's sidebar. Commented May 4, 2011 at 13:15

1 Answer 1

22

Here is a solution that patches an auxiliary macro in \frametitle, adding code that adds a bookmark and table-of-contents line as if it were a subsection (you can just comment this out if not wanted):

\documentclass{beamer}

\AtBeginSection{\frame{\tableofcontents[currentsection]}}

\usepackage{bookmark}
\usepackage{etoolbox}
\makeatletter
% save the current definition of \beamer@@frametitle
\let\nobookmarkbeamer@@frametitle\beamer@@frametitle
% then patch it to do the bookmarks and/or TOC entries
\apptocmd{\beamer@@frametitle}{%
  % keep this to add the frame title to the TOC at the "subsection level"
  \addtocontents{toc}{\protect\beamer@subsectionintoc{\the\c@section}{0}{#1}{\the\c@page}{\the\c@part}%
        {\the\beamer@tocsectionnumber}}%
  % keep this line to add a bookmark that shows up in the PDF TOC at the subsection level
  \bookmark[page=\the\c@page,level=3]{#1}%
  }%
  {\message{** patching of \string\beamer@@frametitle succeeded **}}%
  {\errmessage{** patching of \string\beamer@@frametitle failed **}}%

\pretocmd{\beamer@checknoslide}{%
  % ensure the bookmark is not created if the slide is filtered out
  \let\beamer@@frametitle\nobookmarkbeamer@@frametitle
  }%
  {\message{** patching of \string\beamer@checknoslide succeeded **}}%
  {\errmessage{** patching of \string\beamer@checknoslide failed **}}%

\makeatother



\begin{document}



\section{First Section}

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

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



\section{Second Section}

\begin{frame}{Third frame}Text\end{frame}

\begin{frame}\frametitle{Fourth frame}Text\end{frame}

\begin{frame}<handout>\frametitle{Fifth frame}Text\end{frame}


\end{document}

I had to dig around in beamerbasesection.sty to figure that out. But it seems to work.

Output

EDIT. (by cyberSingularity): Now prevents unwanted bookmarks when the slide is not shown by also patching \beamer@checknoslide, and provided an additional frame to test.

Note: if there are frames with multiple slides (e.g. due to \pauses), you may also be interested in this follow up question.

3
  • @cyberSingularity: Very useful addon, thanks for sharing it!
    – Daniel
    Commented Oct 5, 2013 at 21:52
  • Am I the only one to have issues with this patch when printing the bibliography? ERROR: Missing } inserted. --- TeX said --- <inserted text> } l.6 \beamer@sectionintoc {1}and my first section
    – Francesco
    Commented May 4, 2014 at 13:35
  • This adds duplicate entries to TOC when a single slide uses \framebreak Commented Nov 16, 2015 at 23:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .