There are at least two questions, that ask for this without mentioning it explicitly, so there we go.
Neither this nor actually answer the questions, how to make \href
style the same way as \url
- without additional commands in the second argument of \href
. I've seen Heiko's comment in another related question, that \href
is much more complicated, since it supports images and whatnot. But wouldn't patching \href
to additionally include a \texttt
be rather benign?
However, \href
looks rather complicated; how would one patch it the least invasive way to sneak in an enforced monospaced fontstyle?
My naive solution/MWE simply redefines \href
and inserts a \texttt
, which works fine in the trivial test case(s), but I have no idea about consequences in more complex usages of hyperref.
\documentclass{article}
\usepackage[hidelinks]{hyperref}
\usepackage{letltxmacro}
\begin{document}
\bigskip
url: \url{www.yahoo.com}
original href: \href{http://www.yahoo.com/}{www.yahoo.com}
\bigskip
url: \url{www.yahoo.com}
nolink-url href: \href{http://www.yahoo.com/}{\nolinkurl{www.yahoo.com}}
% patch it - usually in the preamble of course...
\LetLtxMacro\oldhref\href
\renewcommand{\href}[3][]{%
\oldhref[#1]{#2}{\texttt{#3}}
}
\bigskip
url: \url{www.yahoo.com}
patched href: \href{http://www.yahoo.com/}{www.yahoo.com}
\medskip
yay!
\end{document}
What are possible consequences of this (test cases that would break it) and how to do it better?
#
or%
.