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,
urlcolor=blue,
citecolor=blue]%
{hyperref}

\begin{document}

\begingroup
% Turn off URL links here
\tableofcontents
\endgroup

\end{document}


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,
urlcolor=blue,
citecolor=blue]%
{hyperref}

\begin{document}
\tableofcontents

\end{document}

• Don't have any headers in my document. Still, now that you mention it, using the optional toc entry seems like the cleanest solution. Sep 2 '15 at 15:05

\href can be redefined locally:

\begingroup
\renewcommand*{\href}[2]{#2}
\tableofcontents
\endgroup

• Works great. Thanks a lot. So all you're doing is making \href ignore the first argument passed to it, i.e. the url? Sep 2 '15 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. Sep 2 '15 at 16:03