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. [Update: looks like these links went away.]
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.
It is not working now(2010) ¿what is happening?
Manuel… and others… you have probably forgotten to add the:
usepackage{hyperref}
Just place it below the
documentclass
statementThank you for this information Jensse :) It has really helped me.
not just Jensse; John i meant, infact :)
thank you.
very nice post.
clean, simple AND effective
:)
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!
Rafael: Yes, that would be fine. Thanks.
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
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
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!
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?
One way around the problem is to shrink the URL first through a service like bit.ly or goo.gl.
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?
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?
it’s too good …simple …..
John,
Thanks, made my life easy. You showed up in my Twitter feed last week. How about a follow as thanks? :)
Ed
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.
THANKS!
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}
href works perfectly fine for me, after tweaking the settings a bit,
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