[Tex/LaTex] Different style/color for some specific references using natbib

citingcolorfontsnatbib

I need to differentiate some specific references from the others, for both the text and the reference list at the end of the document. Let's say I want the "regular" ones in blue and the specific (i.e. mine actually) in orange. There is way with BibTeX see here: Different style/color for some specific references using Bibtex

But I'd like to do similar things with natbib.

(Following is similar to the previous post but it now concerns natbib instead of BibTeX)

I have something quite standard like this:

in the .tex file:

\usepackage[authoryear,colon,square]{natbib}
\bibliographystyle{dcu}
\begin{document}

Something to say \citep{one_regular_ref01,another_regular_ref02,my_specific01}.

My .bib is normal as I parsed the entries from journal's website.

This gives me something like this:

Something to say [RegRef et al, 2001; aRegRef et al, 2002; My_paper, 2010].

Everything has the same color. But I'd like my own ref in a different one.

Ok I can edit the .bib file but it seems odd to me as I can potentially use the same .bib for another document without this very specific need.

I was thinking that adding * (for instance) to the end of the citation call (i.e. \citep{my_specific01*}) could be a way to discriminate the specific citations but now how can I tell natbib to change the way these references are displayed (again in the text and the reference list) to a different color or potentially any font style.

I did not find anything on the web that treat and solve this very specific task using natbib but any ideas would be more than appreciated.

thanks

Best Answer

EDITED to totally replace my earlier attempt, which did not meet the OP's specifications. EDITED to provide 2nd TRIAL VERSION.

SAFE VERSION:

With the 1st (safer) version, I was unable to make the year in the cite colored, because apparently it uses a sorting pattern on that field (the #3 argument to \harvarditem), and therefore must remain alphabetic. I accomplished what I did by redefining \harvarditem to call on \[ref]color where [ref] is the cite key. These colors are defined by \refcolor{A01}{green} which, for example, defines a macro \A01color as {green}.

\documentclass{article}
\usepackage{xcolor,ifthen,filecontents}
\usepackage[authoryear,colon,square]{natbib}
\bibliographystyle{dcu}
\def\refcolor#1#2{\expandafter\xdef\csname#1color\endcsname{#2}}

\refcolor{A01}{green}
\refcolor{A01b}{cyan}
\refcolor{C03}{red}

\def\setbibcolor#1{%
  \expandafter\ifx\csname#1color\endcsname\relax%
    \color{black}%
  \else%
    \color{\csname#1color\endcsname}%
  \fi%
}
\makeatletter
\renewcommand\harvarditem[4][]{%
 \if\relax#1\relax
   \setbibcolor{#4}\bibitem[\setbibcolor{#4}#2(#3)]{#4}%
 \else
   \bibitem[#1(#3)#2]{#4}%
 \fi
}%
\makeatother
\begin{filecontents}{mybib.bib}
@misc{A01,
  author = {Author, A.},
  year = {2001},
  title = {Alpha}
}
@misc{A01b,
  author = {Author, A.},
  year = {2001},
  title = {Alpha TWO}
}
@misc{B02,
  author = {Buthor, B.},
  year = {2002},
  title = {Bravo}
}
@misc{C03,
  author = {Cuthor, C.},
  year = {2003},
  title = {Charlie}
}
@misc{D04,
  author = {Duthor, D.},
  year = {2004},
  title = {Delta}
}
\end{filecontents}
\begin{document}
cite \cite{A01, A01b, B02, C03, D04}
\bibliography{mybib}
\end{document}

enter image description here


TRIAL UPDATE:

By redefining

\renewcommand\harvarditem[4][]{%
 \if\relax#1\relax
   \setbibcolor{#4}\bibitem[\setbibcolor{#4}#2\ {[}#3{]}()]{#4}%
 \else
   \bibitem[#1(#3)#2]{#4}%
 \fi
}%

as such, I get the desired result for this MWE. However, I am not sure what I may have broken in the process... year-based sorting, I presume. Clearly I fixed the year delimiters as [] but there may be other things, too. But here it is, if it suits.

enter image description here

Related Question