# Adjusted reference of overlay numbers with names

I am trying to reference my beamer overlays by an identifier, much like in this question: reference overlay numbers with names.

Since I am using \visible<+->{} (where the beamerpauses counter is incremented after the execution of the command), I wanted to use the extensions mentioned in this comment and this comment in order to be able to define offsets.

When using the alternative \savepause definition, I get the error:

"You can't use \\unhbox' after \advance. \end{frame}"


When using the alternative \usepauseoffset, I get an error ...

"undefined control sequence".


Actually, it's a whole bunch of errors in both cases. I'm not yet experienced enough with LaTeX to program macros and understand such error messages.

Here is an MWE:

\documentclass{beamer}

% Save overlays by name
\makeatletter
\def\usepauseoffset[#1]#2{\number\numexpr\usepause{#2}+#1\re‌​lax}
\newcommand*{\pauseentry}[3]{\global\@namedef{pauses@#1@#2}{#3}}
\makeatother

\begin{document}

\begin{frame}
\visible<+->{Overlay 1 \savepause{first} (Counter: \usepause{first})}

\visible<+->{Overlay 2 \savepause{second} (Counter: \usepause{second})}

\visible<\usepause{first}->{Should be shown together with "Overlay 1".}

%\visible<\usepauseoffset[1]{second}->{Should be shown together with "Overlay 2".} % Does not compile.
\end{frame}

\end{document}


I'm sorry that I did not comment under the original question, but I do not yet have the privileges to comment.

In case anything is missing in my explanation, please let me know. I just joined Stackexchange.

Two different things need fixing.

First, there is some typo in \relax in the definition of \usepauseoffset. The peculiar highlighting of the code is a hint of this. Some invisible characters have got in between the e and the l. Removing these lets your code compile with the last line uncommented.

More fundamentally, the new proposed version of the \savepause definition does indeed have problems. Instead of stepping the counter, you can just save an adjusted value, e.g. by doing a \numexpr computation.

\DeclareRobustCommand*{\savepause}[2][0]{\only<1>{%
\immediate\write\@auxout{\string\pauseentry


Putting this together gives a first slide with

and the other slides behaving as requested.

\documentclass{beamer}

\makeatletter

\DeclareRobustCommand*{\savepause}[2][0]{\only<1>{%
\immediate\write\@auxout{\string\pauseentry

\newcommand*{\usepause}[1]{\@ifundefined{pauses@%

\def\usepauseoffset[#1]#2{\number\numexpr\usepause{#2}+#1\relax}

\newcommand*{\pauseentry}[3]{\global\@namedef{pauses@#1@#2}{#3}}

\makeatother

\begin{document}

\begin{frame}
\visible<+->{Overlay 1 \savepause[1]{first} (Counter:~\usepause{first})}

\visible<+->{Overlay 2 \savepause[1]{second} (Counter:~\usepause{second})}

\visible<\usepause{first}->{Should be shown together with Overlay 1''.}

\visible<\usepause{second}->{Should be shown together with Overlay 2''.}
\end{frame}

\begin{frame}
\visible<+->{Overlay 1 \savepause[1]{first}
(Counter:~\usepause{first})}

\visible<+->{Overlay 2 \savepause[1]{second}
(Counter:~\usepause{second})}

\visible<\usepauseoffset[1]{first}->{Should be shown together with
Overlay 2''.}

\visible<\usepause{second}->{Should be shown together with Overlay
2''.}
\end{frame}

\end{document}
`