The url
package (used by hyperref
) gives you the \Url@HyperHook
hook, which is also used in \urldef
(see Getting percent sign into an URL in a footnote).
The original URL string is located in \Url@String
(expandable) and the already formatted string in \Url@FormatString
(not expandable).
This can be used to implement your own \url
like macros. The code below then creates the wanted \footnote
with an \href
. A second macro is required to read the second argument of \href
after the URL. This is a little tricky because the rest of the internal code of \url
most be jumped over first and then reinserted.
\documentclass{article}
\usepackage{hyperref}
\makeatletter
\def\hreffootnote{%
%\unskip % maybe required
\begingroup
\def\Url@HyperHook ##1\endgroup{%
\let\Url@HyperHook\relax
\href@footnote
}%
\url
}
\let\realhref\href
\def\href@footnote#1\endgroup#2{%
\footnote{\expandafter\realhref\expandafter{\Url@String}{#2}}%
\endgroup\endgroup#1\endgroup% #1 is some internal `\url` code
}
\begin{document}
Text\hreffootnote{http://foobar.com/~test/%^&*$_##/test}{there} after
Text \href{http://foobar.com/~test/%^&*$_##/test}{there} after
\let\href\hreffootnote
Text \href{http://foobar.com/~test/%^&*$_##/test}{there} after
Hello\hreffootnote{http://www.google.com/#sclient=psy&hl=en&site=&source=hp&q=numbers&aq=f&aqi=&aql=&oq=&pbx=1&fp=d5033c56880e0199}{b} world.
\end{document}
Alternatively a home made solution which reads the first argument verbatim (except { }
characters):
\documentclass{article}
\usepackage{hyperref}
\makeatletter
\def\hreffootnote{%
%\unskip
\begingroup
\let\do\@makeother
\dospecials
\catcode`\{=1\relax
\catcode`\}=2\relax
\href@footnote
}
\def\href@footnote#1{%
\endgroup
\href@@footnote{#1}%
}
\let\realhref\href
\def\href@@footnote#1#2{%
\footnote{\realhref{#1}{#2}}%
}
\begin{document}
Text\hreffootnote{http://foobar.com/~test/%^&*$_##/test}{there} after
Text \href{http://foobar.com/~test/%^&*$_##/test}{there} after
\let\href\hreffootnote
Text \href{http://foobar.com/~test/%^&*$_##/test}{there} after
Hello\hreffootnote{http://www.google.com/#sclient=psy&hl=en&site=&source=hp&q=numbers&aq=f&aqi=&aql=&oq=&pbx=1&fp=d5033c56880e0199}{b} world.
\end{document}
Update 2011-07-27:
I now published a new version of newverbs
which provides \collectverb
and \Collectverb
to collect verbatim arguments easily. For the sake of completeness here again the full solution based on this package. (It is also an answer to Changing href's to footnotes).
\documentclass{article}
\usepackage{hyperref}
\usepackage{newverbs}[2011/07/24]
\let\orighref\href
\renewcommand{\href}{\Collectverb{\hrefii}}
\newcommand\hrefii[2]{\footnote{\orighref{#1}{#2}}}
\usepackage{lipsum}% Dummy text
\begin{document}
\lipsum*[1]\href{http://test.com/%$^£$%^_@~}{Test URL}
% With other argument separators as { }:
\lipsum*[2]\href|http://test.com/%$^£$}{%^_@~|{Test URL}
% If a real \href is wanted (also used for comparison here)
\lipsum*[3]\orighref{http://test.com/%$^£$%^_@~}{Test URL}
\end{document}
The color of hyperlinks produced using \href
is controlled by the filecolor
key, so you can say
\usepackage[
pdftitle={Mongolia games paper},
pdfauthor={Daniel Rubenson, Peter Loewen \& Richard Sawyer},
colorlinks=true,
urlcolor=green,
linkcolor=green,
citecolor=green,
filecolor=green,
raiselinks=false,
hyperfootnotes=true]{hyperref}
but apparently you want all the hyperlinks to be the same color; in this case, it is better to use allcolors
:
\usepackage[
pdftitle={Mongolia games paper},
pdfauthor={Daniel Rubenson, Peter Loewen \& Richard Sawyer},
colorlinks=true,
allcolors=green,
raiselinks=false,
hyperfootnotes=true]{hyperref}
A complete example incorporating some of your code (i changed the value of paperheight
just for the example):
\documentclass[11pt]{article}
\usepackage{setspace}
\usepackage{amssymb, natbib}
\usepackage[tbtags]{amsmath}
\usepackage{rotating}
\usepackage{ctable}
\usepackage{sectsty}
\usepackage{fancyhdr}
\usepackage{caption}
\usepackage{comment}
\usepackage{appendix}
\usepackage{verbatim}
\usepackage[margin=1.1in,
paperheight=8cm% just for the example
]{geometry}
\usepackage[
pdftitle={Mongolia games paper},
pdfauthor={Daniel Rubenson, Peter Loewen \& Richard Sawyer},
colorlinks=true,
urlcolor=green,
linkcolor=green,
citecolor=green,
filecolor=green,
raiselinks=false,
hyperfootnotes=true]{hyperref}
\usepackage{hypernat}
\newcommand{\revertstretch}{\setstretch{1.3}}
\revertstretch
\begin{document}
\href{a_link}{a link}
An example.\footnote{An example.}
\end{document}
Regarding the issue with footnote hyperlink, it is a well known fact that hyperref
might not cooperate well with footnotes; here's a little note about the hyperfootnotes
option, taken from hyperref
's documentation:
Best Answer
The
linkbordercolor
option is used for internal links, e.g. for the TOC, equation numbers etc.For a 'true' hyperlink to a web site use the
urlbordercolor
option, either withurlbordercolor=red
combined with a colour nameurlbordercolor=[1 0 0]
with some RGB colour specification (values from 0 to 1 allowed)If all link borders should appear in red colour use the option
allborders=red
instead