9

I am using the following code in my beamer document to make the frame title's appear in the table of contents:

\documentclass{beamer}
\usetheme{default}
\usepackage{bookmark}
\usepackage{etoolbox}
\usepackage{graphicx}

\makeatletter
\apptocmd{\beamer@@frametitle}{
  \addtocontents{toc}
{\protect\beamer@subsectionintoc{\the\c@section}{0}{#1}
    {\the\c@page}{\the\c@part}
    {\the\beamer@tocsectionnumber}}
    \bookmark[page=\the\c@page,level=3]{#1}}
  {\message{** patching of \string\beamer@@frametitle succeeded **}}%
  {\message{** patching of \string\beamer@@frametitle failed **}}%
\makeatother

\begin{document}
\begin{frame}[label=toc]{Table of Contents}
    \tableofcontents
    \end{frame}
\section{First Section}  
\begin{frame}{One} 
    content
\end{frame} 
\section{Second Section}
\begin{frame}{Two} 
    Content 
\end{frame} 
    \section{Third Section}
    \begin{frame}{Three} 
    Content 
    \end{frame}
\end{document}

What I am trying to do is understand what the solution does because I now want to add block titles to the table of contents as well as frame titles and I imagine that would be an easy function to add if I understood the code. Please help by re-writing the code (if possible) without the \makeatletter substitution command, using other latex commands.

Here are some related posts:

Make each frame (not slide) appear in the PDF bookmarks with beamer

What do \makeatletter and \makeatother do?

  • 1
    The \makeatletter command is needed because you want to modify the behavior of \beamer@@frametitle; it has no particular meaning; the second linked question explains why you need it. – egreg Mar 31 '13 at 10:12
  • In what way does the 2nd question you link to not answer your question? It would be helpful if you explain this a bit in your question. – Hendrik Vogt Mar 31 '13 at 10:34
8
\makeatletter

This is make at (@) a letter. That is: allow \c@page to be the command with name c@page with @ part of the name. In normal document code it would be parsed as the command \c the punctuation character @ and then the normal letters to be typeset page.

\apptocmd

this is a command from the etoolbox package that app(ends) extra code to a command.

 {\beamer@@frametitle}

This is the beamer command that is being modified.

  {
  \addtocontents{toc}
{\protect\beamer@subsectionintoc{\the\c@section}{0}{#1}
    {\the\c@page}{\the\c@part}
    {\the\beamer@tocsectionnumber}}
    \bookmark[page=\the\c@page,level=3]{#1}}

\addtocontents adds the specified line to the table of contents, by patching it to the beamer frame title command this will happen automatically every frame.

  {\message{** patching of \string\beamer@@frametitle succeeded **}}%
  {\message{** patching of \string\beamer@@frametitle failed **}}%

The etoolbox command lets you specify additional code to run in the case it found the command that is being modified or not. Here this is just used to give a suitable message.

\makeatother

Put @ back to being a punctuation character so internal commands can not be accessed.

3

There are a few nested completely different ball games here so I doubt anybody can satisfy your hunger. You really have a lot of homework to read before any of these truly makes sense.

Here is a conceptual strip-down of the code.

\makeatletter

\makeatother

This is explained in the linked question and it's the least problematic part to explain. The commands needs to be read as Make @ character a member of the category letter and Make @ character a member of the category other such that we can safely use @ in the macros. Seriously, read the linked question carefully to do justice

\apptocmd{which command}{what to append}{do if it looks like success}{do if it fails}

This append to command is a member of the monster etoolbox package and there is no simple explanation. You can check it's manual. It modifies, patches, appends etc. existing commands out of many other powerful tools. Here it searches for the command \beamer@@frametitle then adds the given code to the end of that commands definition.

\addtocontents{toc}
{\protect\beamer@subsectionintoc{\the\c@section}{0}{#1}
    {\the\c@page}{\the\c@part}
    {\the\beamer@tocsectionnumber}}

David is way faster (surprise) but here is some more juice.

\addtocontents{where to add}{what to add}

adds the given second argument to Table of Contents. And the added code is the modified subsection in toc template. See the beamer manual for the explanation. Then to make the table of contents item hyperlinked to jump to that slide, a bookmark is added to each item via

\bookmark[page=\the\c@page,level=3]{#1}}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.