16

I want the a particular reference in the bibliography list to take on a different color, say, blue. These are some minimum working examples.

This is my latex file:

\documentclass{article}
\usepackage{color}
\usepackage{cite}
\begin{document} 
This is my document \cite{fuente} and we have another \cite{nature}
\bibliographystyle{ieeetr}
\bibliography{myreference} 
\end{document}

This is the bibtex file:

//myReference.bib file

@article{fuente, 
author = {D. de la Fuente and J.G. Castaño and M. Morcillo}, 
title = {Long-term atmospheric corrosion of zinc}, 
journal = {Corrosion Science}, 
volume = {49}, 
year = {2007}, 
pages = {1420–1436},
}
@article{nature, 
author = {\color{blue}Rosa Rademakers and Manuela Neumann and Ian R. Mackenzie}}, 
title = {\color{blue}Advances in understanding the molecular basis of frontotemporal dementia - elongated title}}, 
journal = {\color{blue} {Nature Reviews Neurology}}, 
volume = {\color{blue}{8}}, 
year = {\color{blue}{2012}}, 
pages = {\color{blue}{423-434}}, 
doi = {\color{blue}{10.1038/nrneurol.2012.117}},
} 

PDF Output

I want just the first reference to be blue. How to achieve this?

Find below updated tex file:

\documentclass{article}
\usepackage{color}
\usepackage{cite}
\usepackage{etoolbox}

\renewcommand{\bibitem}[1]{%
\ifstrequal{#1}{nature}
{\color{blue}\mybibitem{#1}}
{\color{black}\mybibitem{#1}}%
}
\begin{document} 
This is my document \cite{fuente} and we have another \cite{nature}
\bibliographystyle{ieeetr}
\bibliography{myReference} 
\let\mybibitem\bibitem

\end{document}
arrchana
  • 193

3 Answers3

10

I found a simple - and totally hackish - way to color specific items.

Just find in the resulting file the last thing written in the reference you want to color and put a \color{black} after it, so everything after the reference will not be painted by a different color.

There are two versions of this trick:

  1. Put \color{blue} after the first subitem of your reference and \color{black} after the last one. In your case, the first subitem is the author and the last is the year, so your bibfile will looks like this (P.s.: I added another reference to test the effect):

    @article{fuente, 
      author = {D. de la Fuente and J.G. Castaño and M. Morcillo}, 
      title = {Long-term atmospheric corrosion of zinc}, 
      journal = {Corrosion Science}, 
      volume = {49}, 
      year = {2007}, 
      pages = {1420–1436},
    }
    @article{test2, 
      author = {Zhu Zimmermann}, 
      title = {The glory of the letter Z}, 
      journal = {Alphanumeric Characters}, 
      volume = {99}, 
      year = {1999}, 
      pages = {199-299},
    }
    @article{nature, 
      author = {\color{blue}Rosa Rademakers and Manuela Neumann and Ian R. Mackenzie}, 
      title = {Advances in understanding the molecular basis of frontotemporal dementia - elongated title}, 
      journal = {Nature Reviews Neurology}, 
      volume = {8}, 
      year = {2012\color{black}}, 
      pages = {423-434}, 
      doi = {10.1038/nrneurol.2012.117},
    }
    

    And your result will be this:

enter image description here

  • Advantages: you don't need to test for the string content, so you can easily apply in many unrelated items.
  • Drawbacks: the numbering will NOT be painted along with the reference

If you need the number to have the same color, you can try this:

  1. Don't put the \color{blue} in the first subitem of the reference you want to color, but instead in the last subitem of the reference immediately above your reference - in the resulting file, NOT in the bib file. This way, the number will be painted together with the text. This will be your bibfile:

    @article{fuente, 
      author = {D. de la Fuente and J.G. Castaño and M. Morcillo}, 
      title = {Long-term atmospheric corrosion of zinc}, 
      journal = {Corrosion Science}, 
      volume = {49}, 
      year = {2007\color{blue}}, 
      pages = {1420–1436},
    }
    @article{test2, 
      author = {Zhu Zimmermann}, 
      title = {The glory of the letter Z}, 
      journal = {Alphanumeric Characters}, 
      volume = {99}, 
      year = {1999}, 
      pages = {199-299},
    }
    @article{nature, 
      author = {Rosa Rademakers and Manuela Neumann and Ian R. Mackenzie}, 
      title = {Advances in understanding the molecular basis of frontotemporal dementia - elongated title}, 
      journal = {Nature Reviews Neurology}, 
      volume = {8}, 
      year = {2012\color{black}}, 
      pages = {423-434}, 
      doi = {10.1038/nrneurol.2012.117},
    }
    

    And here is the result:

enter image description here

  • Advantages: the numbering will be painted along with the reference
  • Drawbacks: items are not independent of the others, so if you add another item you may need to change where you put the \color{blue}.
7

\color{xxx} is a switch that change the color of the text, and it applies to the text following it (in a group). However, \bibitem does not set a group. This is way the color is propagated to the item following the entry where the color is set.

Here is a simple hack to that achieve the result of the OP (it uses the toolbox package, i.e., \usepackage{etoolbox})

\let\mybibitem\bibitem
\renewcommand{\bibitem}[1]{%
  \ifstrequal{#1}{nature}
    {\color{blue}\mybibitem{#1}}
    {\color{black}\mybibitem{#1}}%
}

enter image description here

Guido
  • 30,740
0

Output:

enter image description here

I am trying to combine the original answers here:

  1. https://tex.stackexchange.com/a/242055/285518
  2. https://tex.stackexchange.com/a/26873

In the main.tex:

\documentclass{article}
% ====================
% show blue for the specific references whose marker has a substring "RefBlue"
% This section should be put together with other "\usepackage", and xcolor, xparse, etoolbox are needed
% Note: for all the markers of used references, only use the letter or number: \cite{36_942} would cause some errors
% usage: \cite{RefBlueMyRef1} or \cite{MyRef2RefBlue}
\usepackage{xparse}
\usepackage{etoolbox}
\usepackage{xcolor}
\ExplSyntaxOn
\NewDocumentCommand{\instringTF}{mmmm}
{\oleks_instring:nnnn { #1 } { #2 } { #3 } { #4 }}
\tl_new:N \l__oleks_instring_test_tl
\cs_new_protected:Nn \oleks_instring:nnnn
{
    \tl_set:Nn \l__oleks_instring_test_tl { #1 }
    \regex_match:nnTF { \u{l__oleks_instring_test_tl} } { #2 } { #3 } { #4 }
}
\ExplSyntaxOff
\let\mybibitem\bibitem
\renewcommand{\bibitem}[1]{%
    \instringTF{RefBlue}{#1}
    {\color{blue}\mybibitem{#1}}
    {\color{black}\mybibitem{#1}}%
}
% ====================

\begin{document}

first ref for blue \cite{myRef1RefBlue}, second ref for black \cite{myRef2} \bibliography{mybib} \bibliographystyle{plain}

\end{document}

Then in the mybib.bib:

@article{myRef1RefBlue,
    author = {myRef1RefBlue},
    title = {test for blue},
    journal = {Test},
    volume = {74},
    pages = {17-29},
    year = {2018},
}

@article{myRef2, author = {myRef2}, title = {test for black}, journal = {Test}, volume = {74}, pages = {17-29}, year = {2018}, }

wzFelix
  • 33