5

Is it possible with cleveref to customize on the fly the name in the clickable link? If you consider the basic example below, the idea would be to have "Condition (1)" active (as opposed to the current "Equation (1)".

\documentclass{article}
\usepackage[colorlinks=true,allcolors=red]{hyperref}
\usepackage[nameinlink,noabbrev]{cleveref}
\begin{document}
It is true that
\begin{equation}\label{eq:cos}
\cos\pi=-1
\end{equation}
However, Condition~\Cref{eq:cos} should be considered with care.
\end{document}

Partial answer [Posted after Mico's answer and including Circumscribe's comment]: this can be achieved manually with the \hyperref command:

\begin{equation} \label{eq:cos} 
\cos\pi=-1
\end{equation}
However, \hyperref[eq:cos]{Condition~\ref*{eq:cos}} should be considered with care.
pluton
  • 16,421
  • 1
    In your partial answer you may want to use \ref* instead of \ref since you've got a nested hyperlink now. – Circumscribe May 09 '20 at 17:23
  • @Circumscribe Good point. I am not sure what the difference is? – pluton May 10 '20 at 16:32
  • 1
    The difference is that \ref*{<label>} generates a reference that's not a hyperlink. It'll still say, for instance, “equation (1)”, but it won't be highlighted/boxed or clickable. – Circumscribe May 10 '20 at 16:44
  • Why not just the following? However, the condition in \Cref{eq:cos} – murray May 10 '20 at 18:47

2 Answers2

8

You asked,

Is it possible with cleveref to customize on the fly the name in the clickable link?

Short answer: Yes. Longer answer: Your typographic objective may be achieved using cleveref's aliasing capabilities. For more information, see section 6 of the package's user guide, entitled "Overriding the Cross-Reference Type".

enter image description here

\documentclass{article}
\usepackage[colorlinks=true,allcolors=red]{hyperref}
\usepackage[nameinlink,noabbrev]{cleveref}

% introduce an alias for 'equation'
\crefalias{condition}{equation}
\crefname{condition}{condition}{conditions}
\Crefname{condition}{Condition}{Conditions}
\creflabelformat{condition}{#2\textup{(#1)}#3} % same as 'equation'

\begin{document}
It is true that
\begin{equation} \label[condition]{eq:cos} % note the optional argument of '\label'
\cos\pi=-1
\end{equation}
However, \Cref{eq:cos} should be considered with care.
\end{document}
Mico
  • 506,678
  • Interesting thank you! However I can no longer refer to the proposed equation as "Equation (1)" in the text, right? It will always be "Condition (1)" now? Something like \Cref[condition]{eq:cos} (for condition) and \Cref{eq:cos} (for equation) would be great, to have both versions in the text! – pluton May 08 '20 at 20:01
  • @pluton - If you refer to some object as "Condition (1)" in some places and as "Equation (1)" in some others, you will most assuredly confuse your readers to no end. Don't do it. – Mico May 08 '20 at 21:07
  • @pluton - What you're asking for is a feature request. Feature requests are off-topic for this site. I suggest you direct it at the author/maintainer of the cleveref package. You may find his contact information on p. 1 of the user guide of the cleveref package. That said, I continue to think it'll confuse your readers needlessly if you use more than one noun to label a given object. – Mico May 08 '20 at 21:14
  • I did not know it was a feature request. I might contact the author. Yes, I do not disagree with you but sometimes what's within a \begin{equation}...\end{equation} is fairly obvious (like an inequality), and varying the terminology makes the text nicer. Saying "In Inequality (1)" is thus clear and equivalent to saying "In Equation (1)"... – pluton May 09 '20 at 01:09
  • In fact, it can be done manually with the \hyperlink command:\begin{equation} \label{eq:cos} \cos\pi=-1 \end{equation} However, \hyperlink{eq:cos}{Condition \ref{eq:cos}} should be considered with care – pluton May 09 '20 at 02:13
1

Mico's answer is of course interesting but it looks like new developments are needed. Instead a manual solution is possible:

However, \hyperref[eq:cos]{Condition~\eqref*{eq:cos}} should be considered with care.

It is thus possible to define a new command (here for equations) with two arguments (the term to be used and the label)

\newcommand*{\myrefeq}[2]{\hyperref[#2]{#1~(\ref*{#2})}}

We can then use it with the appropriate term, depending on the need: In \myrefeq{Equation}{eq:label}... or In \myrefeq{Condition}{eq:label}... where the hyperlink is on the full Equation (1) or Condition (1).

pluton
  • 16,421