2

I would like to be able to change the name and colour of the things I reference within my own document.

Example

\documentclass[a4paper,12pt,oneside]{article}
\usepackage{hyperref}

\hypersetup{
colorlinks,
citecolor=blue,
filecolor=green,
linkcolor=magenta,
urlcolor=blue}
\begin{document}
\begin{equation}\label{map}
f:A\rightarrow B
\end{equation}
We see that a \ref{map} is a ...
\end{document}

Currently the output is like

"We see that a 1 is "

with clicking the 1 bringing me to the equation. I would like to make the following changes - instead of the visible reference being 1 I would like to change it to actually saying map, i.e. I would like the display to read

"We see that a map is"

1
  • 1
    Welcome to TeX.SX. What if you have a second 'equation'? Should that be called map too?
    – user31729
    Commented Sep 5, 2016 at 8:41

1 Answer 1

3

This naming and referring scheme may be confusing, but it is possible to change the content that is set as reference value.

\label uses 'whatever' is stored in the \@currentlabel macro and writes this content to the .aux file.

Here, I used \otherref{labelname}{labelcontent} to change the reference content.

Please note that a proper usage of cleveref might be much more convenient.

\documentclass[a4paper,12pt,oneside]{article}
\usepackage{hyperref}

\hypersetup{
colorlinks,
citecolor=blue,
filecolor=green,
linkcolor=magenta,
urlcolor=blue}

\makeatletter
\newcommand{\otherlabel}[2]{\protected@edef\@currentlabel{#2}\label{#1}}
\makeatother

\begin{document}
\begin{equation}\otherlabel{map}{map}%
f:A\rightarrow B
\end{equation}

\begin{equation}\otherlabel{einstein}{Einstein}%
E = mc^2
\end{equation}

We see that \ref{map} is a ... and the equation from \ref{einstein}

\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .