Suppose I have an appendix in a beamer document, and I'd like to access it from various locations of the main part. Is there a way to make beamer remember where I came from?

To be more specific, consider the following snippet:

\documentclass{beamer}
\usepackage{lipsum}
\newcommand{\ReturnTo}{sec:2}
\begin{document}
\section{A section}\label{sec:1}
\begin{frame}
\frametitle{Some title}
\begin{overlayarea}{\textwidth}{\textheight}
\lipsum[1]\renewcommand{\ReturnTo}{sec:1}

\end{overlayarea}
\end{frame}
\section{Another section}\label{sec:2}
\begin{frame}
\frametitle{Another title}
\begin{overlayarea}{\textwidth}{\textheight}
\lipsum[2]\renewcommand{\ReturnTo}{sec:2}

\end{overlayarea}
\end{frame}
\section{And one more section}\label{sec:3}
\begin{frame}
\frametitle{And one more title}
\begin{overlayarea}{\textwidth}{\textheight}
\lipsum[3]\renewcommand{\ReturnTo}{sec:3}

\end{overlayarea}
\end{frame}
\appendix
\section{Some useful formulae}\label{sec:AppendixA}
\begin{frame}
\frametitle{Some useful formulae}
\begin{overlayarea}{\textwidth}{\textheight}
\begin{eqnarray*}
F_{\mu\nu}F^{\mu\nu}&=& E^2+B^2\\
E&=&m\,c^2\\
\end{eqnarray*}
\end{overlayarea}
\end{frame}
\end{document}


Here I want to be able to jump to the appendix from some of the sections, and go back to where I come from. Of course, the snippet does not achieve this, and I understand why. It would potentially work if I could teach beamer to redefine the \ReturnTo command upon clicking one of the \hyperlink{sec:AppendixA}{\beamergotobutton{details}} buttons.

It would be even nicer if I would not have to set the \ReturnTo by hand, but if it was set automatically to the current section. But I'd also like to keep the flexibility to set \ReturnTo by hand.

Notice that I am aware of the \againframe command. However, here I'd really like to enter an appendix, which is a separate section. And my presentation is so long that I cannot show all sections in the head line. Moreover, every section is long, and I may wish to really jump back to a specific slide/frame of a given section.

• some pdf viewer have the feature to go back to the slide the link came from – samcarter_is_at_topanswers.xyz Feb 1 '18 at 17:49
• Since you're fixing the hypertarget (the anchor) to sec:Appendix:A and jump from various positions to the same target, how should the hyperlink know to which other positions you want to jump back? Perhaps it is possible with some bare bone \pdf... and JavaScript wizardry – user31729 Feb 1 '18 at 17:49
• @ChristianHupfer Well, as I wrote, it would be great if the \ReturnTo macro would be changed upon clicks on the corresponding button. – user121799 Feb 1 '18 at 17:51
• @marmot: I don't think that macros can be redefined as soon as the pdf is shipped out – user31729 Feb 1 '18 at 17:55
• @marmot: I have no knowledge in JavaScript, but if your request should work the only way would be JavaScript (if possible at all), as far as I know. AlexG might have some clue for this – user31729 Feb 1 '18 at 18:37

The solution that follows makes use of JavaScript for Acrobat (Reader) and hence only works in PDF viewers with a JavaScript engine.

We define

\hLink{<destination>}{<link text>}


which is used exactly like the original \hyperlink command from package hyperref. It is used to create the "Details ..." buttons that take you to the corresponding slides in the appendix.

However, before taking you to the linked destination by clicking the button, the current view is saved in a JavaScript object and pushed onto a stack of saved views.

The "Back" button in the top-left corner of the slides allows you to browse backwards through the history of visited slides where the "Details ..." buttons were clicked. Thus, you may surf away from the current appendix slide you have just jumped to, you may even click another "Details ..." button. Clicking the "Back" button takes you right back to where you clicked "Details ..." before, in reverse order.

\documentclass{beamer}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
%  used like \hyperlink but saves the current view before jumping to
%  <destination>
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{pdfbase,atbegshi,amssymb,bm}
\ExplSyntaxOn
\leavevmode
/A <<
%first action: put current view on the stack of views
/S/JavaScript/JS (
if(typeof~viewStack==='undefined'){var~viewStack=new~Array();}
viewStack.push(this.viewState);
)
%next: actual GoTo action
/Next <</D (#1)/S/GoTo>>
>>
}{#2}
}
%backlink in the top-left slide corner
\AtBeginShipout{
\AtBeginShipoutUpperLeftForeground{
\fboxrule=0pt\fboxsep=1pt
\raisebox{-\height}{\fbox{
/A <<
/S/JavaScript/JS (
try{this.viewState=viewStack.pop();}catch(e){}
)
>>
}{\beamerbutton{$\bm\curvearrowleft$}}
}}
}
}
\ExplSyntaxOff
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\usepackage{kantlipsum}

\begin{document}

\part{My talk}
\frame{\partpage}

\begin{frame}{Some title}
\end{frame}

\begin{frame}{Another title}
\end{frame}

\begin{frame}{Yet another title}
\end{frame}

\begin{frame}{Something completely different}
\kant[4]
\end{frame}

\appendix
\frame{\partpage}

\begin{frame}{Appendix A}\label{frame:AppendixA}
$$\sqrt{16}=4$$
\end{frame}

\begin{frame}{Appendix B}\label{frame:AppendixB}
$$1+2=3$$
\end{frame}

\begin{frame}{Appendix C}\label{frame:AppendixC}
$$4<5$$
\end{frame}
\end{document}

• That's amazing! – user121799 Feb 2 '18 at 14:10

Many pdf-Viewers have an menu option (normally with the shortcut Alt + <) to go back. You can try to call this menu with \Acrobatmenu. This here works for me with the adobe reader (the \ref are there only for the tests):

\documentclass{article}
\usepackage{hyperref}
\begin{document}
\ref{xxx} page 1\newpage
\ref{xxx} page 2\newpage
\ref{xxx} page 3\newpage

\section{xxx}\label{xxx}