5

I'm using the hyperref package to write an unusual document. It has clickable URL links in the section titles. Unfortunately, when clicking on the section title in the table of contents, one is not brought to that part of the document where the section starts but instead to the linked website.

Is it possible to turn off URL links within a group environment? Here's an MWE:

\documentclass{article} \usepackage[% unicode, colorlinks=true, linkcolor=blue, urlcolor=blue, citecolor=blue]% {hyperref} \begin{document} \begingroup % Turn off URL links here \tableofcontents \endgroup \section{\href{www.google.com}{Google}} \end{document} 

2 Answers 2

6

Even if the urls are turned off at TOC, they may appear in other places like the headers. Hence it is better to use the optional argument of \section

\documentclass{article} \usepackage[% unicode, colorlinks=true, linkcolor=blue, urlcolor=blue, citecolor=blue]% {hyperref} \begin{document} \tableofcontents \section[Google]{\href{www.google.com}{Google}} \end{document} 
1
  • Don't have any headers in my document. Still, now that you mention it, using the optional toc entry seems like the cleanest solution. Commented Sep 2, 2015 at 15:05
6

\href can be redefined locally:

\begingroup \renewcommand*{\href}[2]{#2} \tableofcontents \endgroup 
2
  • Works great. Thanks a lot. So all you're doing is making \href ignore the first argument passed to it, i.e. the url? Commented Sep 2, 2015 at 14:58
  • @PacificOrion Yes. Because you want to have the second argument without the link, \href is redefined to just return the second argument. Commented Sep 2, 2015 at 16:03

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.