5

I use \url to make an URL clickable. When the line breaks, the part of the URL after the line break is not clickable. Why, and how to fix it?

Demo:

\documentclass[11pt,letterpaper]{article}

\usepackage{url}
 \begin{document}
\url{http://google.com}

blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah 
blah blah blah blah blah blah blah blah blah blah blah \url{http://google.com}
\end{document}

enter image description here

I observed this behavior with the built-in Google Chrome PDF Viewer and Sumatra PDF on Windows 7 SP1 x64 Ultimate.

6

hyperref does a better job at managing line-breaks in URLs:

enter image description here

\documentclass[11pt,letterpaper]{article}

\usepackage{hyperref}
\hypersetup{
  hidelinks, % Remove visible links altogether
  %urlbordercolor = 1 1 1% Make URL link border white
}

\begin{document}

\url{http://google.com}

blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah 
blah blah blah blah blah blah blah blah blah blah blah \url{http://google.com}
\end{document}

\end{document}

You can remove the borders using the hidelinks option, or set the border colour for URLs specifically to white (1 1 1).

  • It works great, thanks! As a positive side effect, it also made the URL clickable in Adobe Reader. Just a small typo: there should be no , after hidelinks (I cannot edit due to SE bitching about edit size) – Franck Dernoncourt Jan 4 '16 at 22:12
  • @FranckDernoncourt: There is no real harm in leaving the , there, as a key-value setting allows for empty items in a list. – Werner Jan 4 '16 at 22:14
  • Just to clarify, the url package does not make the link clickable, it only formats it and allow it to break in a sensible place. However, some pdf readers will parse the text and if a url is detected will allow the user to click on the link, but that link is not part of the pdf. hyperref on the other hand, does create clickable links and not only for urls but also for internal links such as references, toc, labels, etc... Additionally, hyperref will only allow to break links by default if the pdftex engine is used, if you are using latex>dvipdfm then you need the breaklinks option. – ArTourter Jan 5 '16 at 0:30
  • @ArTourter: Great remark. Yes, the fact that .com is not seen as part of the URL is a misinterpretation of the reader. hyperref corrects this. – Werner Jan 5 '16 at 0:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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