TransWikia.com

cleveref and customized refname

TeX - LaTeX Asked on December 31, 2021

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}
cospi=-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} 
cospi=-1
end{equation}
However, hyperref[eq:cos]{Condition~ref*{eq:cos}} should be considered with care.

2 Answers

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).

Answered by pluton on December 31, 2021

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}{#2textup{(#1)}#3} % same as 'equation'

begin{document}
It is true that
begin{equation} label[condition]{eq:cos} % note the optional argument of 'label'
cospi=-1
end{equation}
However, Cref{eq:cos} should be considered with care.
end{document}

Answered by Mico on December 31, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP