I am trying to generate a table of contents in beamer, but instead of displaying the page number on the right side, I would like to access/display the frame number. So my question is:

How do I create a table of contents that displays the frame number (and not the page number)?

Alternatively: How can I access the command that instructs the (standard latex) table of contents to use the page number (\thepage)? I have to assume that if I get access, then I can replace the page number with the frame number (\theframenumber)). Right?

I understand that this would not be an issue in a simple presentation, because the page number is identical to the frame number. However, I am creating presentations for lectures and I simultaneously develop intricate handouts using beamerarticle (in the same file). For example, some frames do not show up in the handout (e.g. A picture that helps me to make a point during the lecture, do not need to be included in the handout. Or some headline slides \AtBeginSection would only take up space in the handout without adding any important information). So I would like for my table of contents in the article version (handout) to be identical to the table of contents that I show on the wall (my beamer presentation) - though the included frames are different. In other words, I would need my beamerarticle to count the frames. Or maybe beamerarticle (or standard latex) has an option that allows me to implement \theframenumber in a regular doc.

I understand that it is possible that this is a difficult problem to solve, because one of the goals of the beamerarticle package is to ignore the \begin{frame}, \end{frame}, and other frame related commands. So I expect that it is not easy to count frames in article mode. But then again, that's why I am here to ask you. ... Maybe a new command can be created that I can globally place before/after each frame.

Here is a very much simplified MWE for a presentation:

%\documentclass{beamer} %uncomment to produce presentation

\documentclass{article} %comment out to produce presentation
\usepackage{beamerarticle} %comment out to produce presentation

\begin{document}

\begin{frame}
\frametitle{Title 1}
\tableofcontents % Works well in beamer, but does not show correct frame numbers in article mode

In article mode, I would like this list to read as follows:

1 Sec One .... Frame 2

2 Sec Two .... Frame 4

3 Sec Three .... Frame 6
\end{frame}

\section{Sec One}
\begin{frame}
\frametitle{Title 2}
\end{frame}

\begin{frame}
\frametitle{Title 3}
\end{frame}

\section{Sec Two}
\begin{frame}
\frametitle{Title 4}
\end{frame}

\section{Sec Three}
\mode<presentation>{ % Only shows up in presentation, so list of frames must make a jump here
\begin{frame}
\frametitle{Title 5}
\end{frame}
}

\begin{frame}
\frametitle{Title 6}
\end{frame}

\end{document}


I really appreciate any input or pointers in the right directions. Anything that can help me solve this issue would be great. Thanks.

## Update:

Based on SimonDispa's post, I was able to make some tweaks, but it still did not get me to the full solution. I believe that either the refcount or the zref package can get me over the finish line.

First, because I have so many presentations/handouts in which I will use this type of approach, I would like the solution to be more automated (or more global). Based on this post (diabonas' answer), it is possible to make \atBeginSection work when I compile the beamerarticle

% Make atBeginSection work in article mode
\mode<article>
\makeatletter
\expandafter\let\expandafter\originalsection\expandafter=\csname @orig\string\section\endcsname
\def\sectionwithhook{\@ifstar\@sectionwithhook\@@sectionwithhook}
\newcommand{\@sectionwithhook}[1]{\originalsection*{#1}}
\newcommand{\@@sectionwithhook}[2][]{\beamer@ifempty{#1}{\originalsection{#2}}{\originalsection[#1]{#2}}\beamer@atbeginsection}
\renewcommand<>{\section}{\alt#1{\sectionwithhook}{\beamer@secgobble}}
\makeatother
\mode<all>


This allows me to set a counter (MyFrameNumber) to the current frame number plus 1, at the beginning of each section,

\AtBeginSection[]
{
}


Thanks to the tocloft package, I can manipulate the appearance of the toc and I would like to do so as follows:

\mode<article>{
\usepackage{tocloft}
% How to make \theMyFrameNumber work and update properly in toc?
% It currently produces a 0
% Can it be done with the refcount package ?
% Can it be done with the zref package ?
}}


But it leaves an issue with \theMyFrameNumber{}. I have to speculate a little bit, but there are a few potential issues prevent this from working properly:

• The toc is generated before the rest of the document (but proper handling of the aux file could probably fix this issue).
• The counter MyFrameNumber is not written to the aux file, and the toc cannot access the information. Hence, it prints a zero for all instances.
• Even if the counter MyFrameNumber would be written to the aux file as it is, it would currently only have a single value (the last/highest one)

Accordingly, I believe that I could make this work, if I had a method that allows me to cross reference \theMyFrameNumber{}. In other words, I would need a method that writes the current number (or label) of \theMyFrameNumber{} to the aux file and a method to read that number or label back into my table of contents.

I have tried the refcount and the zref package, as I believe that those package could hold the solution. However, I am not familiar enough with those commands and I seem unable to piece it together. Am I wrong? Can it be done with the tools provided in those packages? Or would a different approach be better?

Here is the updated full MWE, it feels so close:

%\documentclass{beamer} %uncomment to produce presentation

\documentclass{article} %comment out to produce presentation
\usepackage{beamerarticle} %comment out to produce presentation

\usepackage{calc}
%\usepackage{refcount}
%\usepackage{zref}

\mode<article>{
\usepackage{tocloft}
% How to make \theMyFrameNumber work properly in toc?
% It currently produces a 0
% Can it be done with the refcount package ?
% Can it be done with the zref package ?
}}

% Make atBeginSection work in article mode
\mode<article>
\makeatletter
\expandafter\let\expandafter\originalsection\expandafter=\csname @orig\string\section\endcsname
\def\sectionwithhook{\@ifstar\@sectionwithhook\@@sectionwithhook}
\newcommand{\@sectionwithhook}[1]{\originalsection*{#1}}
\newcommand{\@@sectionwithhook}[2][]{\beamer@ifempty{#1}{\originalsection{#2}}{\originalsection[#1]{#2}}\beamer@atbeginsection}
\renewcommand<>{\section}{\alt#1{\sectionwithhook}{\beamer@secgobble}}
\makeatother
\mode<all>

\AtBeginSection[]
{
%
%\begin{frame}
%\tableofcontents[currentsection]
%\end{frame}
}

\begin{document}

\begin{frame}
\frametitle{Title 1}
\pagenumbering{gobble} % suppress page numbering in TOC
\tableofcontents % Works well in beamer, but does not show correct frame number in article

\bigskip
In article mode, I would like this list to read as follows:

\bigskip
1 Sec One \dotfill{} Starts at Frame 2\\

2 Sec Two \dotfill{} Starts at Frame 4\\

3 Sec Two \dotfill{} Starts at Frame 5\\

\end{frame}

\section{Sec One}

\begin{frame}
\frametitle{Title 2}
% Check correctness
\end{frame}

\begin{frame}
\frametitle{Title 3}
% Here \theMyFrameNumber does not work
% because it only incremented/updated atBeginSection
% Check correctness
\end{frame}

\section{Sec Two}

\begin{frame}
\frametitle{Title 4}
% Check correctness
\end{frame}

\section{Sec Three}
\begin{frame}
\frametitle{Title 5}
% Check correctness
\end{frame}

\end{document}


## Only needed for resolution. Everything below will be deleted after fix.

The solution provide by @SimonDispa is great, and the final outcome looks exactly like what I am looking for. However, when I compile the code on my computer, it looks like this:

As you can see, the blue table of contents does not compile correctly. I have tried to manipulate the code (in beamerarticleETOC.tex, which I copied directly into the main document), but without any success.

• (1) The only problem you found with your approach is when there are more than one frame per section, as Title 3? (2) In you new MWE there are no frames in \mode<presentation>. You drop this requirement? (3) with you new MWE all frame number in TOC are zero. May 3, 2021 at 23:06
• @SimonDispa 1) I do not consider that a real problem. I included that scenario to show the difference between my self created \theMyFrameNumber{} and the default \theframenumber. II believe that can be fixed through assigning a different/new "helper counter". 2) I believe once I understand point 3), I can handle presentation and article mode. 3) That is exactly the remaining issue. That is what I would like to fix, but I do not know how. It appears challenging (to me) because it requires writing a counter to the aux file and reading it back into the tocloft command. May 4, 2021 at 5:50
• I reloaded the same code in case any lines were missing. Please download the two files to an empty directory and try again. May 7, 2021 at 20:12

Updated according to the follow up exchange.

All the extra code is included in beamerarticleETOC.tex, to be loaded in the article mode.

The proposed solution is based on the etoc package.

Frames declare a \paragraph that is selected by etoc from the table of contents to list the first frames in the sections, except if the first frame is in presentation mode like the fifth (Title 5).

In this case, the second (Title 6) is chosen as "first".

Article mode Note that in beamer mode the title of the fifth frame is Title 5

Beamer mode (the default style does not include the section number in the list)

This is the main code, set in article mode

% !TeX TS-program = pdflatex

%% article mode
%\documentclass{beamer}  % beamer mode only
%\newcommand{\listofframesinsection}{\tableofcontents} % beamer mode only

\documentclass{article}%  for article mode only
\usepackage{beamerarticle}%  for article mode only
\input{beamerarticleETOC}%  for article mode with etoc only

\renewcommand{\contentsname}{}

\begin{document}

\begin{frame}   % << without title!
\listofframesinsection      % \tableofcontents in beamer mode
\bigskip

\color{red} In article mode, I would like this list to read as follows: \par
\bigskip
1 Sec One \dotfill{} Starts at Frame 2\par
2 Sec Two \dotfill{} Starts at Frame 4\par
3 Sec Three \dotfill{} Starts at Frame 5\par
\end{frame}

\section{Sec One F2 \& F3}
\begin{frame}
\frametitle{Title 2}
\end{frame}

\begin{frame}
\frametitle{Title 3}
\end{frame}

\section{Sec Two F4}
\begin{frame}
\frametitle{Title 4}
\end{frame}

\section{Sec Three F5 \& F6}
\mode<presentation>{ % % Only shows up in presentation,
\begin{frame}
\frametitle{Title 5}
\end{frame}
}
\begin{frame}
\frametitle{Title 6}
\end{frame}

\end{document}


This is the file beamerarticleETOC.tex

%%%% beamerarticleETOC.tex starts %%%%%%%%%%%%%%%%%%%%%

\usepackage{etoc}
\etocsettocdepth{all}

\setbeamertemplate{frametitle}{% rename frame for etoc
\paragraph{\renameframe}
\noindent\mbox{}\par
}

\newcommand{\renameframe}{% Frame + frame number
(\insertframetitle)
}

\newcommand{\formatlist}{\color{blue}\normalsize\rmfamily\bfseries} %format list of first frames
\newcommand{\listframes}{} % optional title

\newcommand{\listofframesinsection}{%
\begingroup
\etocsetlevel {section}{1}%  sections
\etocsetlevel {paragraph}{2}%  frames as paragraphs
\etoctoclines % package default styles for sections
\etocsettocstyle {\formatlist\noindent \listframes\par}{}%
\etocsetnexttocdepth {paragraph}%
\etocsetstyle {paragraph}
{}
{\leavevmode\leftskip 0em\relax} % left indent
{\etociffirst{Starts at \,\etocname \par}}
{}
\etocsetstyle {section}
{}{}
{\formatlist    \etocnumber. \etocname \dotfill}
{\parfillskip 10pt plus 1fil\relax }
\tableofcontents
\endgroup
}
\etocsetnexttocdepth{section}
%%%% beamerarticleETOC.tex ends %%%%%%%%%%%%%%%%%%%%%%%%%%

• Thank you very much! This got me closer, but does not solve all my problems because the entire template is more intricate. For example, in my beamer theme, I use the short section name [] in the navigation bar and it would not make sense to place Frame XY in the navigation. In addition, I would like to have a more automated method. But it got me thinking and I believe I am closer to the solution. I will post my updated approach (as "answer"). May 3, 2021 at 21:27
• I just posted the update. Does the question still fall into your realm of expertise? May 3, 2021 at 22:15
• Thanks a bunch! This is great and exactly what I am looking for. However, the new (blue) table of contents doe not come out correctly and my attempts to fix it did not make it any better (as I am not familiar with the etoc package. I added a temp addendum to my original post to show you how the pdf looks on my end. Do you have any idea why it comes out differently for me? May 7, 2021 at 19:05
• @Raphael I reloaded the same code in case any lines were missing. Please download the two files to an empty directory and try again. May 7, 2021 at 20:12