55

This question led to a new package:
footnotebackref

I'm using hyperref to have footnote marks link to the footnote proper and I'd like to have some sort of "backreferences" from the footnote proper back to where they're called (à la Wikipedia). For example:

This[1] is the text[2] that serves[3] as an example[1] to
the footnote[2] backrefence thing[4].
-------
[1] The first footnote. [a, d]
[2] The second footnote. [b, e]
[3] The third footnote. [c]
[4] The fourth footnote. [f]

Where a, b, c, d, e and f are links to the first, second, third, fourth, fifth and sixth places where footnotemarks are respectively.

I hope I managed to communicate what I'd like, I'm not that good at it :P

A MWE follows.

\documentclass{book}
\usepackage{hyperref}
\begin{document}
  This\footnote{The first footnote. [a, d]} is the text\footnote{The second footnote. [b, e]}
  that serves\footnote{The third footnote. [c]} as an example\footnotemark[1] to
  the footnote\footnotemark[2] backrefence thing\footnote{The fourth footnote. [f]}.
\end{document}
lockstep
  • 250,273
mpr
  • 3,646
  • 4
    I think you have communicated it very well. But, even though it may seem trivial it would be better to compose a MWE that illustrates the problem including the \documentclass so that those trying to help don't have to recreate it. – Peter Grill Oct 23 '11 at 01:15
  • 1
    In your real application, are these going to be "free-text footnotes", i.e. do you specify the content of the footnote explicitly, or are they bibliographic footnotes generated using something like biblatex? – Jake Oct 23 '11 at 02:05
  • For the foreseeable future at least, these are supposed to be normal footnotes. – mpr Oct 23 '11 at 02:20
  • The mechanism will probably involve \hypertarget{linkname}{link text} and \hyperlink{linkname}{a or b or c etc}. This is quite a tricky problem to automate, it's almost like you're creating a little toc in the footnote. – cmhughes Oct 23 '11 at 15:49
  • 1
    It's quite easy to get working if there is at most one footnote mark per footnote... I got stuck when I typeset the first double mark one :S – mpr Oct 23 '11 at 17:53
  • I never understood this question. Therefore, I cannot understand the answer either. :( – Sony Jan 06 '12 at 18:12

1 Answers1

51

Edit: Using the new package footnotebackref

Just include the package in the preamble and use the \footnote-command as usual. There are two options which are described in the package documentation.

\documentclass{article}
\usepackage{footnotebackref}
%\usepackage[symbol=$\wedge$]{footnotebackref}
%\usepackage[numberlinked=false]{footnotebackref}

\textheight=3cm
\begin{document}\noindent
Text\footnote{The first footnote.} Text\\
Text\footnote[4]{The second footnote.} Text\\
Text\footnote{The third footnote.} Text
\end{document}

footnotebackref


The original answer:

Here is a non tricky approach for the backreferences. I used the hyperref[target]{text} command from the hyperref package and created an new footnote to expand the standard footnote command. Before I set the standard footnote I place a label with an unambiguous(!) tag (myFootnoteTag) for the label-ref-mechanism using an independent counter. To reference the label from the footnote the hyperref[]{} command is used. This is set to the footnotetext and create a clickable reference in it. Here one can choose between different styles for the clickable item.

\documentclass{article}
\usepackage{hyperref}

\newcounter{myHyperFootnoteCounter}

\newcommand{\myHyperFootnote}[1]{%
    \refstepcounter{myHyperFootnoteCounter}%
    \def\myFootnoteTag{hfn:\themyHyperFootnoteCounter}%
    \label{\myFootnoteTag}%
    %\footnote{\hyperref[\myFootnoteTag]{#1}}% clickable footnotetext
    \footnote{\hyperref[\myFootnoteTag]{$\wedge$}#1}% Wikipedia style
}

\makeatletter
%clickable footnote number
\renewcommand\@makefntext[1]{%
    \noindent\makebox[1.8em][r]{%
    \mbox{\textsuperscript{\normalfont\hyperref[\myFootnoteTag]{\@thefnmark}}}\,}#1%
}

\makeatother

\begin{document}
Text\myHyperFootnote{The first footnote.} Text\\
Text\myHyperFootnote{The second footnote.} Text\\
Text\myHyperFootnote{The third footnote.} Text\\
Text\myHyperFootnote{The fourth footnote.} Text\\
Text\myHyperFootnote{The fifth footnote.} Text\\
Text\myHyperFootnote{The sixth footnote.} Text
\end{document}

Edit: After the question of Stephen I give an extended version. I use the TeX-command \@ifnextchar to branch between the footnotes with or without optional argument. If the next char after \myHyperFootnote is [ the macro \my@OptHyperFootnote will be executed. If there is no [ the macro \my@HyperFootnote will be executed. Keep in mind that all macros are in the \makeatletter environment now because I used the @ in the 'submacros'.

\documentclass{article}
\usepackage{hyperref}

%a new counter to create an unambiguous label-tag
\newcounter{myHyperFootnoteCounter}

\makeatletter

% branch between the footnote with/without opt. argument
\def\myHyperFootnote{\@ifnextchar[\my@OptHyperFootnote\my@HyperFootnote}

%define an new footnote without optional argument
\def\my@HyperFootnote#1{%
    \refstepcounter{myHyperFootnoteCounter}%
    \def\myFootnoteTag{hfn:\themyHyperFootnoteCounter}%
    \label{\myFootnoteTag}%
    \footnote{\hyperref[\myFootnoteTag]{$\wedge$}#1}%
}

%define an new footnote with optional argument
\def\my@OptHyperFootnote[#1]#2{%
    \refstepcounter{myHyperFootnoteCounter}%
    \def\myFootnoteTag{hfn:\themyHyperFootnoteCounter}%
    \label{\myFootnoteTag}%
    % put the optional argument to the original `footnote`
    \footnote[#1]{\hyperref[\myFootnoteTag]{$\wedge$}#2}% 
}

%if the footnote number should be the reference than redefine the footnote macro
\renewcommand\@makefntext[1]{%
    \noindent\makebox[1.8em][r]{%
    \mbox{\textsuperscript{\normalfont\hyperref[\myFootnoteTag]{\@thefnmark}}}\,}#1%
}
\makeatother


\begin{document}
Text\myHyperFootnote{The first footnote.} Text\\
Text\myHyperFootnote[4]{The second footnote.} Text\\
Text\myHyperFootnote{The third footnote.} Text\\
Text\myHyperFootnote{The fourth footnote.} Text\\
Text\myHyperFootnote[8]{The fifth footnote.} Text\\
Text\myHyperFootnote{The sixth footnote.} Text
\end{document}
David Carlisle
  • 757,742
Holle
  • 5,344
  • That is really nice. Do you have an idea how to handle conditional footnote-numbers, i.e. \footnote[7]{The third footnote.}? – Stephen May 02 '12 at 15:22
  • @Stephen: I extend the hyperFootnote with an optional argument. – Holle May 02 '12 at 17:43
  • 1
    That is great!!! If I had not upvoted it before, I would have done so now. Thanks! (I just removed an empty line, which introduced a line-break in the text whenever an optional argument was used with \footnote.) – Stephen May 03 '12 at 15:16
  • Please see my comment, given as "answer" because of the limited length of comments. Thanks! – Stephen Jun 08 '12 at 17:14
  • @Holle I use your package with numberlinked=true. At a higher zoom level after clicking on the footnote number inside the text I jump to the footnote. Then I am not able to see the footnote number in the footer since the link points directly to the text. When I want to go back to the main text, I have to go the left of the footnote to see the footnote number and click on it. This scrolling is a bit annoying though. May be you can change this, so that the link from the main text points to number in the footer and not the text in the footer. – maetra Jul 04 '12 at 16:40
  • @maetra Thank you for the info. But this behavior is not caused by my code. Keep in mind that my code is responsible for the backreference (jumping back from the 'lower' footnote number to the footnote number in the main text). Jumping from the main text to the footnote at the bottom is coded in the 'hyperref'-package. You can test it by comment out my package and include only the 'hyperref'-package. You will see the same behavior if you 'jumping down'. Maybe you can open a new question about this topic!? – Holle Jul 04 '12 at 21:41
  • @Holle I knew that hyperref is responsible for that, I just thought you may be have a quick solution. I posted a question here: http://tex.stackexchange.com/questions/62259/change-reference-position-for-footnote-link – maetra Jul 05 '12 at 08:53
  • @Holle: I updated the tablefootnote package (version 1.0h) to be compatible with your footnotebackref package. – Stephen Aug 01 '12 at 18:02
  • 1
    I'm a bit disappointed there is no option in the package to select the text to be footnoted (~ \footnote{read this footnote}{this is the footnote}), in a way the backref takes you to its beginning and not to its end, where the footnote call symbol is usually placed! If there is no option, how would I do it? – Andrestand Apr 08 '16 at 09:06