119

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 ?

Peter Grill
  • 223,288
Soumitra Sen
  • 2,995

1 Answers1

122

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}

Peter Grill
  • 223,288
  • Why do you say TeXworks doesn't open external links? On my computer it seems to work fine. – Ari Brodsky Apr 10 '13 at 02: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 02:27
  • I built a PDF using pdflatex. The links are not clickable although it is highlighted in green color. – Sudheer Apr 14 '15 at 07: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