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}

Here's a link to \href{http://twitter.com/home}{Twitter}.

\end{document}

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

Tagged with: ,
Posted in Uncategorized
22 comments on “How to link to web pages from LaTeX-generated PDF
  1. Carlos Hidalgo says:

    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 says:

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

  3. Jensse says:

    Manuel… and others… you have probably forgotten to add the:

    usepackage{hyperref}

    Just place it below the documentclass statement

  4. cagatay says:

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

  5. cagatay says:

    not just Jensse; John i meant, infact :)

  6. anonymous says:

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

  7. 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. John says:

    Rafael: Yes, that would be fine. Thanks.

  9. Greg says:

    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?

    Thanks in advance!
    greg

  10. Greg2 says:

    Actually I found the solution myself:

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

    url{http://www.thereallyreallyverylonglink.com/pointing/to/some/interesting/stuff/in/the/web}

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

    HTH
    g

  11. billy bob says:

    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. Anomalie says:

    An address like http://googlesystem.blogspot.com/2009/09/google-docs-has-equation-editor-oh-i-am-so-excited-this-has-been-a-long-time-coming-goodness-gracious-me-blah-blah-blah-someobody-shoot-me.html is not going to be solved even with all of these in effect

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

    because it’s not allowed to break at a hyphen, at least I couldn’t get it to. Help, please?

  13. John says:

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

  14. Anomalie says:

    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?

  15. Raz Ofek says:

    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?

  16. pal2 says:

    it’s too good …simple …..

  17. Ed Feng says:

    John,

    Thanks, made my life easy. You showed up in my Twitter feed last week. How about a follow as thanks? :)

    Ed

  18. Alex says:

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

    usepackage[hyphens]{url}
    usepackage[breaklinks,pdftex]{hyperref}

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

  19. Muhammad says:

    THANKS!

  20. 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}

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

  22. Chris Meaney says:

    Dear John,

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

    I am trying to link to certain Wikipedia pages…for example:
    http://en.wikipedia.org/wiki/Mann%E2%80%93Whitney_U

    I use the following command:
    \href{http://en.wikipedia.org/wiki/Mann%E2%80%93Whitney_U}{\textcolor{blue}{Wikipedia}}.

    I can’t seem to get it to work…I think because Latex assumes % to be a comment symbol. But Wikipedia uses % in the URL name. So the URL seems to be confusing Latex.

    Any thoughts on a work around to this problem. I’m very new to latex so I greatly appreciate any help you could provide.

    Chris

1 Pings/Trackbacks for "How to link to web pages from LaTeX-generated PDF"
  1. [...] This post was mentioned on Twitter by hikmat farhat, TeX tips. TeX tips said: How to link to web pages from a LaTeX-generated PDF file http://bit.ly/9Cqkh7 [...]