Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am trying to create a clickable hyperlink using hyperref for a list of urls. One url is giving me trouble:

http://en.wikipedia.org/wiki/Function_(mathematics)

The relevant line of latex is:

\hyperref[ref6]{http://en.wikipedia.org/wiki/Function\_(mathematics)}

The line is clickable in the resultant PDF, but it only links to:

http://en.wikipedia.org/wiki/Function

with the _(mathematics) part ignored.

I expect that this calls for some special escaping, but have tried several different approaches to no avail (backslashes and the like) and would appreciate some assistance.

Here's a minimal working example:

\documentclass{article}
\usepackage{hyperref}

\begin{document}
Here's what's broke:

\hyperref[ref6]{http://en.wikipedia.org/wiki/Function\_(mathematics)}

\end{document}

Thanks!

share|improve this question
    
Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. BTW thanks for providing a MWE. :) –  Harish Kumar Aug 31 at 0:49

1 Answer 1

up vote 3 down vote accepted

You need to use \href for this:

\href[options]{URL}{text}

The text is made a hyperlink to the URL; this must be a full URL (relative to the base URL, if that is defined). The special characters # and ˜ do not need to be escaped in any way (from hyperref manual, page 15).

Or use \url.

\documentclass{article}
\usepackage{hyperref}

\begin{document}
Here's what's broke:

\url{http://en.wikipedia.org/wiki/Function_(mathematics)}

\href{http://en.wikipedia.org/wiki/Function_(mathematics)}{ref6}

\end{document}

enter image description here

Please note that you can use _ and no need of \_.

By default, \url uses type writer fonts. To get url in roman font add \urlstyle{rm} in the preamble:

\documentclass{article}
\usepackage{hyperref}
\urlstyle{rm}     %% <--------- default is \urlstyle{tt}
\begin{document}
'
'
'
share|improve this answer
    
\url worked, but it's not in the same font as \hyperref or \href, is there a way to get the full url displayed in roman font? –  Will Senn Aug 31 at 1:51
    
@decuser Add \urlstyle{rm} in your preamble (say before \begin{document}). –  Harish Kumar Aug 31 at 2:04
    
Is there a way to ensure that \urlstyle is honored? When I also use \usepackage{apacite}, the urlstyle doesn't seem to hold and it is printed in the default typewriter font. –  Will Senn Aug 31 at 3:36
    
@WillSenn Try putting \urlstyle after \usepackage{apacite}. Just a guess, in the absence of your code for this. May be you can ask a new question with the code. –  Harish Kumar Aug 31 at 3:39

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.