My document has several \href
that I would like to be shown on the footnote. How can I do it?
[Tex/LaTex] How display the href link in the footnote
footnoteslinks
Related Solutions
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}
%\PassOptionsToPackage{numberlinked=false}{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
}
\@ifpackageloaded{footnotebackref}{%
\ifFootnoteBackref@numberlinked
\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}%
}{%
\Hy@raisedlink{%
\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}
This is nothing to do with the footnote. The \href
macro takes two arguments. The first is the link destination, and the second is what's displayed.
\documentclass[10pt,a4paper]{article}
\usepackage{hyperref}
\usepackage{xcolor}
\definecolor{medium-blue}{rgb}{0,0,1}
\hypersetup{colorlinks, urlcolor={medium-blue}}
\begin{document}
Text\footnote{Click \href{http://google.co.in}{here}.}
\end{document}
Best Answer
I usually write something like this, so the entry is hyperlinked for onscreen reading but there's also a footnote to the URL for paper output.