Erratic behavior from beamer goto and return buttons

The code below is generating erratic behavior in two respects: 1) The line \returnFrom{fourthGoto}{fourthReturn} creates a beamerreturnbutton that says Frame #2. All of the other buttons correctly return a button saying Frame #1. 2) The only difference between the returnFrom and altReturnFrom macros is that the latter does not include the word Frame inside the beamerreturnbutton. It's hard to imagine why this difference should matter. Yet the last button predictably behaves unpredictably. Clicking back and forth on the buttons labeled -> #6 and <-#6, sometimes it works, but eventually,click on the button on Frame #6 takes me back to the first line of the first frame, rather than the sixth line of that frame. I haven't been able to generate this error from the return button labeled #5 on frame #5.

\documentclass{beamer}
\usepackage{ifthen}
\makeatletter
\@ifundefined{c@insideAList}{\newcounter{insideAList}}{}
\let\beamer@cramped\relax% just because
\let\c@insideAList\@listdepth % make a latex counter version
\makeatother
\def\condHyperTarget#1{
\ifthenelse{\theinsideAList=0}
{\hypertarget<.(1)>{#1}{} }
{\hypertarget<.>{#1}{} }}
\def\pointTo#1#2{
\label{pointToLoc#1}
\condHyperTarget{#1}
\def\returnFrom#1#2{
\label{returnFromLoc#1}
\def\altReturnFrom#1#2{
\label{returnFromLoc#1}
\begin{document}
\begin{frame}[<+->]
First line   \\
\pause
Second line \\
\pause
Third line
\pointTo{firstReturn}{firstGoto}
\pause
\begin{itemize}[<+->]
\item First item OUTER
\item Second item OUTER
\pointTo{secondReturn}{secondGoto}
\begin{enumerate}[<+->]
\item First item INNER
\item Second item INNER
\pointTo{thirdReturn}{thirdGoto}
\pause
\end{enumerate}
\end{itemize}
Fourth line   \\
\pause
Fifth line
\pointTo{fourthReturn}{fourthGoto} \\
\pause
Sixth Line
\pointTo{fifthReturn}{fifthGoto}
\end{frame}
\begin{frame}[<+->]
Frame 2\\
\returnFrom{firstGoto}{firstReturn}
$\empty$\\%
\end{frame} \begin{frame}[<+->]
Frame 3\\
\returnFrom{secondGoto}{secondReturn}
$\empty$\\%
\end{frame} \begin{frame}[<+->]
Frame 4\\
\returnFrom{thirdGoto}{thirdReturn}
$\empty$\\%
\end{frame} \begin{frame}[<+->]
Frame 5\\
\returnFrom{fourthGoto}{fourthReturn}
\end{frame} \begin{frame}[<+->]
Frame 6\\
\altReturnFrom{fifthGoto}{fifthReturn}
\end{frame}
\end{document}

• Do you really need frame number in the text of your buttons? – Mike Sep 25 '17 at 23:46
• I include the frame numbers because I (and others) sometimes work off hard-copies of my slide deck. Without the numbers, really the only way to navigate the deck is on screen. – Leo Simon Sep 26 '17 at 10:52

Problem 2

The second problem is easy to solve. You are using \ref in your macros, which will produce a link, but just for the number. With a viwer which show the target of a link, if the mouse hovers over it, this can be seen (Gehe zu Seite = Goto Page):

This applies to both, \returnFrom and \altReturnFrom. But with the latter you're less likely to hit the number.

Solution: just repalce \ref with \ref*.
The latter only gives out the number without making it a link.

Problem 1

The first problem is caused by using \label, which refers to the number of the last structure element (frame, equation, numbered item, ...). In your case it's item 2 of the enumerate environmet. To test this, you can replace enumerate with itemize.

Unfortuneately, to my knowlegde, there is no way build into beamer to reference the frame number. It can be done, but requires quite some programming.

Edit:

Since you have a good reason for having the frame number in the buttons, here is a solution for this. It produces an additional auxiliary file \jobname.fno.

You need to run LaTeX twice for this to work. But you don't need to change the source after \begin{document} (with the exception of \altReturnFrom, which I didn't implement here).

\documentclass{beamer}

\makeatletter
\let\beamer@cramped\relax% just because

\csname #1\endcsname
}
\protected@write\@auxout{}%
}

\def\condHyperTarget#1{%
\ifnum\@listdepth=0\relax
\hypertarget<.(1)>{#1}{}%
\else
\hypertarget<.>{#1}{}%
\fi
}%
\def\pointTo#1#2{%
\condHyperTarget{#1}%
\def\returnFrom#1#2{%
\condHyperTarget{#1}%

% read .fno file
\AtBeginDocument{%
\InputIfFileExists{\jobname.fno}{}{}%
}

% open .fno file for LaTeX to write
\AtEndDocument{%
\if@filesw\newwrite\tf@fno
\immediate\openout\tf@fno\jobname.fno\fi
}
\makeatother

\begin{document}
\begin{frame}[<+->]
First line   \\
\pause
Second line \\
\pause
Third line
\pointTo{firstReturn}{firstGoto}
\pause
\begin{itemize}[<+->]
\item First item OUTER
\item Second item OUTER
\pointTo{secondReturn}{secondGoto}
\begin{enumerate}[<+->]
\item First item INNER
\item Second item INNER
\pointTo{thirdReturn}{thirdGoto}
\pause
\end{enumerate}
\end{itemize}
Fourth line   \\
\pause
Fifth line
\pointTo{fourthReturn}{fourthGoto} \\
\pause
Sixth Line
\pointTo{fifthReturn}{fifthGoto}
\end{frame}

\begin{frame}[<+->]
Frame 2\\
\returnFrom{firstGoto}{firstReturn}
$\empty$\\%
\end{frame}

\begin{frame}[<+->]
Frame 3\\
\returnFrom{secondGoto}{secondReturn}
$\empty$\\%
\end{frame}

\begin{frame}[<+->]
Frame 4\\
\returnFrom{thirdGoto}{thirdReturn}
$\empty$\\%
\end{frame}

\begin{frame}[<+->]
Frame 5\\
\returnFrom{fourthGoto}{fourthReturn}
\end{frame}

\begin{frame}[<+->]
Frame 6\\
\returnFrom{fifthGoto}{fifthReturn}
\end{frame}
\end{document}

• Thanks very much @Mike. No longer mystifying. I guess I'll have to work around problem #1 by using itemize instead of enumerate when I need to add a button, and then manually insert numbers. – Leo Simon Sep 26 '17 at 10:42
• @LeoSimon I added an example for referencing frame numbers, see edit in my answer. – Mike Sep 26 '17 at 11:45
• Thanks very much indeed, @Mike for all that work. It's very daunting. One question: you're not using the \ref* format here, yet it seems to be the case that whereever I put the cursor in the button it works. Is the construction you are using an alternative to \ref*. Thanks! – Leo Simon Sep 26 '17 at 22:36
• @LeoSimon \labelframenumber and \refframenumber are pimitive compared to \label and \ref. They don't produce links (this is done with \hypertarget and \hyperlink in your macros), they just store/retrieve the frame number. – Mike Sep 27 '17 at 9:41