0

I use both footnotes and endnotes with package endnotes (also with footnotes in the endnotes). I would like at the end of an endnote to add a link back to the link location wherever it was opened (there may be multiple references to an endnote in addition to where it is defined, also in other endnotes).

\documentclass{article}
\usepackage[usenames]{color}
\usepackage{hyperref} 
\hypersetup{
  colorlinks=true,  %RR colors links instead of ugly boxes
  linkcolor=red
}

%% \ref replacement to color the term also eg \rrref{figure}{fig:blabla} \def\rrref#1#2{\hyperref[#2]{#1,}\ref{#2}}

%% multi-par endnote with label: #1=topicname #2=reflabel #3=notetext \usepackage{endnotes} %RR normal number https://tex.stackexchange.com/questions/202542/ = egreg \renewcommand\enoteformat{%
\makebox[0pt][r]{\theenmark. \rule{0pt}{\dimexpr\ht\strutbox+\baselineskip}}} \usepackage{mfirstuc} \long\def\rrendnote#1#2#3{% \phantomsection\label{#2main}% %RR up front to jump back to start \stepcounter{endnote}% \hyperref[#2]{[{\color{red}{\bf {\em \theendnote\ #1/}}}]}% {\endnotetext{\phantomsection\label{#2}% %RR StExch trick to jump correctly \parindent=3ex {\bf {\em \nopagebreak\xmakefirstuc{#1}/}}\[0.5ex]% %RR first upper case {~,#3}% %RR note body ~~\hyperref[#2main]{[{\em Main call/}]}% }}}

%RR fatter footnote numbers https://tex.stackexchange.com/questions/68580/ \makeatletter \renewcommand{@makefnmark}{\hbox{\textsuperscript{\bf\scriptsize{@thefnmark}}}} \makeatother

%RR clicking footnotenumber jumps back to text location (not for endnotes) \usepackage{footnotebackref}

\begin{document}
\parindent=0ex \parskip=3ex %% to make jump-to location clear

Bla bla bla \rrendnote{first endnote}{note:1}{% This is the first endnote.}.

Bla bla bla \rrendnote{second endnote}{note:2}{% This is the second endnote. In here I refer to the first: see \rrref{endnote}{note:1}. Now in endnote 1 I would like to add a clicker [Back] at the end that jumps back to its link here, before the [Main call] clicker that jumps back to the call in the main text. There may be more such links to an endnote.}.

Bla bla bla.

%% endnotes \begingroup \def\enotesize{\normalsize} %RR normal readability \newpage \renewcommand{\enoteheading}{} %RR get rid of default Notes \section{Notes} \mbox{}\vspace*{-3ex} %RR fix white space, no idea why ~~\theendnotes %RR ~~ fix the first, no idea why \endgroup

\end{document}

Link to small examplecode endnotes

2 Answers2

1

As there can be more than one link which jumps to a destination, going back requires help from the pdf viewer. The easiest to go back is to use the GoBack which is normally accessed with Alt + left arrow.

You can add an action which does the same with the \Acrobatmenu command:

\documentclass{article}
\usepackage[usenames]{color}
\usepackage{hyperref}
\hypersetup{
  colorlinks=true, 
  linkcolor=red
}

\begin{document} \section{Test}\label{test}

\Acrobatmenu{GoBack}{Back} \newpage

Ref 1: \ref{test}

\newpage Ref 2: \ref{test} \end{document}

Ulrike Fischer
  • 327,261
  • This works the same without the \Acrobatmenu call (new to me). But I don't know the section label (or page label or phantomsection label) where I came from in the endnote (here Ref ). [Nice TUG interview! I started latex on Atari in 1988 - 2 hrs/run] – Rob Rutten May 23 '21 at 09:42
  • I added ~~[\Acrobatmenu{GoBack}{\em Back}]% into the \rrendnote definition. In acroread the resulting [back] in endnote 1 still jumps to page 1 just as [main call] also when called with the link in endnote 2. Worse: evince (my workhorse pdf reader) gives an error. – Rob Rutten May 23 '21 at 10:01
  • Does my code work in evince? – Ulrike Fischer May 23 '21 at 10:07
  • Your code works in evince. I was wrong above, in acroread the added line seems to work, will test in my big report. For evince https://gitlab.gnome.org/GNOME/evince/-/issues/43 says it is still an open problem. My colleagues are 90% Mac types (alas) so I need to check Preview. – Rob Rutten May 23 '21 at 20:28
0

The suggestion from Ulrike Fischer to use \Acrobatmenu{GoBack}{Back} is the answer: in the example above I added "~~[\Acrobatmenu{GoBack}{\em Back\/}]" underneath the line with "%RR note body". It adds a [Back] clicker at the end of each endnote and these do the job - but only partially: in Ubuntu they work in acroread, xpdf, firefox pdf viewer but not for evince and chrome pdf viewer. In macOS they work in Preview and Firefox pdf viewer but not in Safari pdf viewer. When they do not work nothing happens (in evince I get an ignorable error message in the terminal that started evince). I can live with this partial success because most of my target readers use macOS Preview.