# How to link to web pages from LaTeX-generated PDF

This has been on my to-do list for a while, but I finally found out how to embed hyperlinks in a PDF file generated from LaTeX.

Short answer: put \usepackage{hyperref} in your header, and when you want to link to a page, use the command \href{URL}{anchor text}. For example,

\documentclass{article}
\usepackage{hyperref}
\begin{document}

\end{document}

For much more detail on links in LaTeX documents, see Patrick Jöckel’s LaTeX-PDF page and the hyperref package documentation.

* * *

## 22 thoughts on “How to link to web pages from LaTeX-generated PDF”

1. Carlos Hidalgo

Thanks a lot. This is the simple statement about how to use href I was looking for!
Much clearer than the ‘short’ documentation of the hyperref package.

2. Manuel

It is not working now(2010) ¿what is happening?

3. Jensse

Manuel… and others… you have probably forgotten to add the:
 usepackage{hyperref}
Just place it below the documentclass statement

4. cagatay

Thank you for this information Jensse :) It has really helped me.

5. cagatay

not just Jensse; John i meant, infact :)

6. anonymous

thank you.
very nice post.
clean, simple AND effective
:)

7. Rafael Beraldo

John,

Can I translate some of your posts on LaTeX to Portuguese and post them in my own blog, of course referring to the original post? They’re quite straightforward.

Thanks!

8. Rafael: Yes, that would be fine. Thanks.

9. hi,

I managed to use href to add a weblink to my pdf. however i want the anchor text to be equal to the url (in order to also enable someone who printed the doc get to that web page). so I do:
href{}{}

The problem is that the URL is much longer than the textwidth. how can i make the link use multiple lines?

greg

10. Actually I found the solution myself:

usepackage{url}
usepackage{hyperref}
usepackage{breakurl}

it seems to be important to import the packages in this order!

HTH
g

11. billy bob

If you use dvipdfm to make your pdf, you’ll need to use the following command:
usepackage[dvipdfm]{hyperref}
in place of
usepackage{hyperref}

Best!

12. One way around the problem is to shrink the URL first through a service like bit.ly or goo.gl.

13. Anomalie

Thanks for that suggestion. I still feel that it should be possible to address the url wrapping problem within latex. I mean I suspect some of the above packages deliberately avoid breaking at hyphens because it creates ambiguity as to whether the hyphen is meant as a breaking hyphen or is actually a non-breaking hyphen that is part of the original URL.

The conflicts and overrides generated by successively calling on multiple packages really means you have to rack your brain to figure out the right order to call packages. Ultimately it may not be possible to manipulate the order so all commands provided by these packages work as they are intended to.

I’m using all of

usepackage{url}
usepackage{hyperref}
usepackage{breakurl}

Can John or somebody else suggest a Latex solution, for a long URL with many hyphens?

14. Raz Ofek

I want to have the effect of an hyperref but I don’t really want to link it to a web site. What I want is to have a box, with the text I provide, open whenever the cursor is on the supposed link. Nothing more. Any idea how I can do that?

15. it’s too good …simple …..

16. John,

Ed

17. In order to allow breaking a url at hyphens, one can load the following packages:

usepackage[hyphens]{url}

As you can probably tell, this works with pdflatex. Haven’t tried it with “regular” latex, though.

THANKS!

19. The default colours are not incredibly pretty; instead of just including hyperref without options, something like this might help:

 usepackage[usenames,dvipsnames]{xcolor} usepackage[hidelinks,colorlinks,citecolor=Fuchsia,urlcolor=blue,linkcolor=Cerulean]{hyperref}

20. Annamae Michl

href works perfectly fine for me, after tweaking the settings a bit,

21. Chris Meaney

Dear John,

Thank you for the useful pointers on hyper-linking your latex generated PDF’s.