Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm writing a document which includes a list of URLs that I want to be clickable, so I'm using hyperref to achieve this. This has the awkward side effect that my equation numbers, some of which I don't want to be clickable links, to also be clickable. I've hidden this by giving hypersetup the options colorlinks, linkcolor={black}

But this is suboptimal, in that the link is still clickable. I tried the following MWE, but it didn't work (the * just displays above the environment.)

\documentclass{article}
\usepackage{xcolor}
\usepackage{hyperref}
\hypersetup{colorlinks, linkcolor={black}}
\title{This is the title}
\begin{document}
\let\oldref\ref
\let\ref\ref*
\begin{equation}
  \label{eq:one}
  e^{i\pi} + 1 = 0
\end{equation}
This is a link to the equation \ref{eq:one}, when it shouldn't be...
\let\ref\oldref %% Changing it back to normal behaviour
\end{document}

I also tried using renewcommand, but that failed too.

It's got something to do with the *, since \let\ref\autoref works fine.

I can't just find and replace the ones I want unlinked, because they are inside LTXexample environments, and I want the code to display as \ref not as \ref*

So I have two questions:

  1. How do I get this temporary redefinition of \ref to work?
  2. Or, how do I turn off equation links globally, but still have URL links work? (And if possible, is there a way to then have some equations linky with a different command)
share|improve this question
2  
Just to explain why \let\ref\ref* can't work: * is not letter, so the command is not \ref* but \ref, and this takes an optional argument *. So what you did was \let\ref\ref (not helpful :-)) and then typset *. –  Hendrik Vogt Nov 29 '10 at 14:27
    
Would it be that bad to have clickable links all over if they didn't have any special colors or boxes around them in the PDF? –  MSC Apr 4 at 17:49

1 Answer 1

up vote 16 down vote accepted

Instead of \ref* use \@refstar:

\makeatletter
\let\ref\@refstar
\makeatother

Why? hyperref redefines \ref this way.

\DeclareRobustCommand\ref{\@ifstar\@refstar\T@ref}%

\@ifstar is a LaTeX command which tests if the next character is a *. In this case the * would be gobbled and the first of the following commands will be executed (\@refstar), otherwise the second (\T@ref).

Thus, \ref* is essentially the same as \@refstar und you could use that instead.

If one would like to go deeper: the source code documentation of hyperref (or hyperref.dtx on CTAN or on your local TeX system) tells that \HyRef@StarSetRef belongs to \ref* and would not be linked, and \@refstar is defined this way:

\def\@refstar#1{%
  \HyRef@StarSetRef{#1}\@firstoffive
}
share|improve this answer
    
thanks for the explanation! –  Seamus Nov 29 '10 at 14:45

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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