92

Let us consider the following example :

\documentclass[11pt,twoside,a4paper]{book}
\usepackage{hyperref}
\begin{document}
For more information about 'TikZ' click on the following link :
\href{url}{http://www.texample.net/tikz/resources/}
\end{document}

This gives :
enter image description here

When I click on the link on the PDF file it is not working. What is the way to go webpage clicking on the link ?

  • 4
    Looks like you have your parameters backwards. Try \href{http://www.texample.net/tikz/resources/}{url}. The second parameter is the text to display, the first is the url to link to. – Peter Grill Apr 10 '13 at 2:01
  • I am using 'Document viewer' on the system 'ubuntu 10.04' – Soumitra Sen Apr 10 '13 at 2:06
  • 2
    Please add the viewer info to the question, and try switching the order of the paramaters. – Peter Grill Apr 10 '13 at 2:08
  • It is do to the wrong order; I use Fedora with "Document Viewer" and I have no problems at all. – Svend Tveskæg Apr 10 '13 at 2:12
  • 2
    Since you have some responses below that seem to answer your question, please consider marking one of them as ‘Accepted’ by clicking on the tickmark below their vote count (see How do you accept an answer?). This shows which answer helped you most, and it assigns reputation points to the author of the answer (and to you!). It's part of this site's idea to identify good questions and answers through upvotes and acceptance of answers. – jub0bs May 9 '13 at 12:43
92

You have the two parameters backwards. The correct syntax is:

\href{<url>}{<text to display>}. 

The first parameter is the url to link to, the second is the text to display.

Also it should be noted that you need to ensure that your PDF viewer is capable of opening a link in a browser.

Code:

\documentclass[11pt,twoside,a4paper]{book} 
\usepackage{hyperref} 
\begin{document} 
    For more information about 'TikZ' click on the following link: 
    \href{http://www.texample.net/tikz/resources/}{Tex Example Site}
\end{document}

Although this question is only about linking to external URLs, one can use \href to open other types of files as well. So with the example below (assuming that there exists a foo.pdf, foo.tex, foo.png files in the current directory), and viewing with TeXShop's PDF viewer, all the files can be opened by clicking on the links.

However, with TeXWorks and Mac Preview only the web url link works. All the links also work with Acrobat once you accept the security warning.

enter image description here

Code:

\documentclass{article}
\usepackage{hyperref}

\begin{document}
\href{http://www.google.com}{Google}
\href{run:foo.pdf}{My PDF}
\href{run:foo.tex}{My TeX}
\href{run:foo.png}{My PNG}
\end{document}
  • Why do you say TeXworks doesn't open external links? On my computer it seems to work fine. – Ari Brodsky Apr 10 '13 at 2:23
  • @AriBrodsky: Hmmm... You are correct, at least on Windows. I will check further and update the answer shortly. Perhaps I am confusing opening URL links with opening other types of documents. – Peter Grill Apr 10 '13 at 2:27
  • I built a PDF using pdflatex. The links are not clickable although it is highlighted in green color. – Sudheer Apr 14 '15 at 7:15
  • @Sudheer: I suggest you post a separate question as I don't know how to help without more info. – Peter Grill Apr 14 '15 at 14:57
  • I was viewing the document in Okular. Apparently, it has a Browsing mode which I was not using when I posted my earlier comment. Links are good in PDF. – Sudheer Apr 15 '15 at 15:26

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