# Change reference position for footnote link

With the recent package footnotebackref it is possible to backrefence footnotes, one can then jump directly from the main text to the footnote and back. The link in the footnote that points back to the main text can be set to symbols inside the footnote text or, like I prefer it, directly to the footnote number in the footnote. The hyperref package links the footnote number in the main text to the text and not the number of the footnote.

When the document is viewed at a higher zoom level, so that the page width does not fit in the window of pdf viewer anymore, this causes an unwanted result. After clicking on the footnote number inside the main text the footnote number and therefore backreference is hardly or not at all displayed. So I would like know if it is possible to change the position for the hyperref reference for footnotes directly to the footnote number.

## Visual Example

Here you can see what I mean, in case I was unable to explain right or anybody does want to read my description.

## MWE

\documentclass{article}
\usepackage{footnotebackref}

\textheight=3cm
\begin{document}
Text\footnote{The first footnote.} Text\\
\end{document}

• It might be a problem with Sumatra? I cannot verify this behaviour for Okular (v0.13.2) or Adobe Reader (v9.5.1). – clemens Jul 5 '12 at 15:41
• @cgnieder I can confirm this issue for Adobe Reader (10.1.3), Adobe Acrobat (9.5.1) and Foxit Reader (5.0.1.0523). As I mentioned the zoom settings have to be high enough so that page does not fully fit into the window. Might that be the reason? I wonder why Acrobat (9.5.1) and Reader (9.5.1) would differ. – maetra Jul 6 '12 at 7:27
• Curious... maybe the linux version (that I have) and the windows version of the Adobe programs differ? (I just tested your MWE again to make sure I wasn't mistaken: with both my pdf readers the hyperlink jumps in a way that the “1” is perfectly visible in the upper left corner (document zoomed to 400%). – clemens Jul 6 '12 at 10:28
• I can confirm the issue for Adobe Reader 10.1.3 and Windows XP. – Stephen Aug 1 '12 at 18:06

The trick is to move code used by hyperref for setting the footnote anchor/target as part of the footnote text (so after the footnote mark has been 'drawn') into the code for defining the 'footnote' part of the footnote mark! (The footnote mark is used twice for every footnote, once in the text and once in the footnote itself; I am referring to the latter here.)

Default LaTeX makes no distinction between the two footnote marks, which may be why hyperref originally does things this way around. footnotebackref does make the distinction in some sense, but not in a way we can cleanly patch, so we undo their changes and patch them back in using our method (I copied the code for this from the current version of footnotebackref, so this may get out of sync).

The following code should work whether or not footnotebackref is used (but if it is used, it must be loaded before this patch). hyperref must also be loaded before this patch. Original definitions of \@makefnmark are preserved except when footnotebackref is used, which clobbers them anyway.

\documentclass{article}
% comment/uncomment various combinations of these for testing
%\PassOptionsToPackage{symbol=$\wedge$}{footnotebackref}
\usepackage{footnotebackref}

\usepackage{hyperref}

\makeatletter

% distinguish between footnote marks in the text and in the footnotes themselves!
\let\hyperfoot@oldmakefntext\@makefntext
\renewcommand*{\@makefntext}{%
\let\hyperfoot@base@makefnmark\@makefnmark
\let\@makefnmark\hyperfoot@infootnote@makefnmark
\hyperfoot@oldmakefntext}

% set the hypertarget (through \hyper@@anchor) before placing \@thefnmark
\newcommand*{\hyperfoot@infootnote@makefnmark}{%
\fn@settarget
\hyperfoot@base@makefnmark
}

\let\hyperfoot@oldmakefntext\BHFN@OldMakefntext% undo their patch
\renewcommand\hyperfoot@infootnote@makefnmark{%... and merge with ours
\fn@settarget
\mbox{\textsuperscript{\normalfont%
\hyperref[\BackrefFootnoteTag]{\@thefnmark}}}\,}%
\fi
}{}

% reset hyperref's overriding of \@footnotetext, which basically just adds the \hyper@@anchor as part of the footnote text
\long\def\@footnotetext#1{%
\H@@footnotetext{#1}}
% and put the hyperref magic into \fn@settarget instead
% note that we set the anchor text to be \relax. previously, it was sometimes (=when allowing links to be nested) the footnote text. I don't actually know what the effect is of having anchor text... but apparently no drivers support nesting at the moment anyway.
\newcommand\fn@settarget{% a form of this was previously part of hyperref's \@footnotetext
%\message{^^J^^J**setting target!**^^J^^J}% we should only see as many 'setting target' messages in the log as there are footnotes!
\ifHy@nesting
\expandafter\ltx@firstoftwo
\else
\expandafter\ltx@secondoftwo
\fi
{%
\expandafter\hyper@@anchor\expandafter{%
\Hy@footnote@currentHref
}{\relax}%
}{%
\expandafter\hyper@@anchor\expandafter{%
\Hy@footnote@currentHref
}{\relax}%
}%
\let\@currentHref\Hy@footnote@currentHref
\let\@currentlabelname\@empty
}%
}

% following makes testing slightly easier on my monitor
\hypersetup{pdfstartview={XYZ null null 4}}
\textheight=3cm

\begin{document}
Text\footnote{The first footnote.} Text.

Let's have more than one footnote!\footnote{For better testing!}
\end{document}

• 2018 4Q TexShop (MacTeX) TexLive 2016. Back-referenced footnote scenario. cyberSingularity code (still) works like a champ. Original link to footnote scrolled one text-line too low. The "fix" arrived via compiling with xelatex (at least twice). See Amphipolis and Kotthoff. – Saphar Koshet Oct 13 '18 at 14:57