0

I found the code in the following page:

https://joerglenhard.wordpress.com/2011/11/29/labeled-item-with-custom-label-text/

In author's own words: "an item list where each \item is labeled, so I can reference it later on. Instead of a simple numeric label, I want some text to be displayed at the position of the label and the same text at each position where I reference the label".

In the following MWE the custom label text appears with red color since the linkcolor of the hyperref package is red. What I want is to modify the color of the custom label texts to green (to the whole document) without affecting the other settings.

\documentclass{article}

\usepackage[colorlinks=true,pagebackref,
    linkcolor=red,
    urlcolor=blue,
    pdftitle={Dossier de Candidature, MCF60},
    pdfauthor={Dimitrios S. Anagnostou}]{hyperref}

\newcounter{reqcount}
\newcommand{\descitem}[1]{%
  \item[R\ref*{#1}] \refstepcounter{reqcount}\label{#1}
}
\newcommand{\descref}[1]{%
  \hyperref[#1]{R\ref*{#1}}%
}

\begin{document}

\section{foo:section}\label{foo:section}

\begin{itemize}
 \descitem{item:xyz} foo
 \descitem{item:abc} bar
\end{itemize}

As defined in \descref{item:xyz} and opposed to \descref{item:abc} of Section \ref{foo:section}.

\end{document}

enter image description here

So in this example R1 and R2 should be green while 1 should stay red.

1
\documentclass{article}

\usepackage[colorlinks=true,pagebackref,
    linkcolor=red,
    urlcolor=blue,
    pdftitle={Dossier de Candidature, MCF60},
    pdfauthor={Dimitrios S. Anagnostou}]{hyperref}

\newcounter{reqcount}
\newcommand{\descitem}[1]{%
  \item[R\ref*{#1}] \refstepcounter{reqcount}\label{#1}
}
\makeatletter
\newcommand{\descref}[1]{%
  {\def\@linkcolor{green}\hyperref[#1]{R\ref*{#1}}}%
}
\makeatother
\begin{document}

\section{foo:section}\label{foo:section}

\begin{itemize}
 \descitem{item:xyz} foo
 \descitem{item:abc} bar
\end{itemize}

As defined in \descref{item:xyz} and opposed to \descref{item:abc} of Section \ref{foo:section}.

\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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