2

Is there an easy way to get LaTeX with bibtex (not biblatex) to print references that are not cited in the text in a different color/format than references that are cited?

So in the MWE below I want the `exciting' paper listed in a different color in the reference list (automatically).

Thanks!

LaTex:

\documentclass{article}
\usepackage{natbib}
\bibliographystyle{apalike}
\begin{document}    
\nocite{*}
\citet{boring} is boring.  
\bibliography{simple}
\end{document}

simple.bib:

@article{boring,
 title={Some idiotic paper},
 author={A. Boring Author},
 year={2014},
 journal={Dumb and Dumber}
}

@article{exciting,
 title={An exciting paper},
 author={Smart Person},
 year={2014},
 journal={Excitement}
}
  • 1
    Please help us to help you and add a minimal working example (MWE) that illustrates your setup. I am not sure whether this can be done with bibtex but your chances that somebody will help will be much greater if you make it easy by providing compilable code people can copy/paste/compile. – cfr Nov 16 '14 at 20:39
  • I've done just that. – JPi Nov 16 '14 at 21:33
  • If your audience includes people with poor colour vision, it might be better to separate your bibliography into (eg) References and Further Reading, as in (this question)[tex.stackexchange.com/questions/6967/… – Brent.Longborough Aug 7 '16 at 11:03
5

enter image description here

\documentclass{article}
\usepackage{natbib}
\usepackage{color}
\bibliographystyle{apalike}
\makeatletter
\let\oldcitation\citation
\def\citation#1{%
\global\@namedef{ZZ#1}{}%
\oldcitation{#1}}
\let\oldbibitem\bibitem
\let\bibcolor\relax
\renewcommand\bibitem[2][]{%
\expandafter\ifx\csname ZZ#2\endcsname\relax
\color{red}%
\else
\color{black}%
\fi
\oldbibitem[#1]{#2}}%
\makeatother

\begin{document}    
\nocite{*}
\citet{boring} is boring.  
\bibliography{simple}
\end{document}
  • This seems to fail in my 100+ page document. It seems to mark items cited in \cite{ref1,ref2}- commands as uncited. (using memoir, natbib, hyperref, and cleverref) – rubenvb May 21 '15 at 8:29
  • @rubenvb not sure why that should be, the \cite{ref1,ref2} form should produce two \citation commands in the aux file, the same as cite{ref1}cite{ref2} If you can make an example that isn't 100 pages ask a new question, referencing this one... – David Carlisle May 21 '15 at 8:36
1

As noted in the comments, David's answer doesn't work with multi-citations like \cite{boring,exciting}. Here is a tweak to make it work:

\makeatletter
\let\oldcitation\citation
\def\citation#1{%
\@for\tmp:=#1\do{%
\global\@namedef{ZZ\tmp}{}%
\oldcitation{\tmp}}}
\let\oldbibitem\bibitem
\let\bibcolor\relax
\renewcommand\bibitem[2][]{%
\expandafter\ifx\csname ZZ#2\endcsname\relax
\color{red}%
\else
\color{black}%
\fi
\oldbibitem[#1]{#2}}%
\makeatother

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.