# Different colors for each bib file and custom prefix

I have multiple bib files. I would like to use different text colors for all the references mentioned in different bib files. Secondly, i would like a custom prefix for each bib file.

Please let me know how can I do it?

The result should be similar to as follows:

[R1] uses [O1] and [R2] is based on [O2].

References

[R1] .....

[R2] .....

Other References

[O1] ....

[O2] ....

Color of references mentioned in section "References" will be black, where as color of references mentioned in section "Other references" will be blue.

• You have tagged the question with both biblatex and multibib. Those two packages are incompatible (biblatex being a complete re-implementation of BibTeX's bibliography/citation approach and multibib being a BibTeX-based solution). Do you want to use biblatex (see tex.stackexchange.com/q/5091/35864, you would not be able to keep using your current .bst bibliography style) or multibib? – moewe Jan 19 at 12:51
• Any solution can work for me....if it is biblatex, it will be preferable... – Muhammad Hammad Jan 19 at 13:40
• Please do not change the question significantly after you have already gotten an answer. Please ask a new question making it clear that you insist on a solution with elsarticle, but leave this question in its original state. See tex.meta.stackexchange.com/q/7678/35864 – moewe Jan 19 at 19:26
• Ok....I will post another question specifically for elsarticle – Muhammad Hammad Jan 19 at 19:30
• Thank you very much for rolling back the elsarticle edit. – moewe Jan 19 at 19:30

We can split the bibliography by .bib file (something that is not necessarily very semantic) following biblatex: multiple bibliographies categorised by different .bib files and separating bibliography items based on resource file (the second link shows how to deal with existing keywords).

Adding the additional letter into the label is then as simple as issuing \newrefcontext[labelprefix=<prefix>] before the \printbibliography. See Biblatex entry renumbering and prefixing, Custom citation label, Biblatex with sections, prefix, and reversed order, Separate bibliographies for phdthesis and mastersthesis in biblatex.

\documentclass{article}

\usepackage{xcolor}
\usepackage[backend=biber, style=numeric, defernumbers]{biblatex}

\DeclareSourcemap{
\maps[datatype=bibtex,overwrite]{
\map{
\perdatasource{\jobname-1.bib}
\step[fieldset=keywords, fieldvalue={,file1}, append]
}
\map{
\perdatasource{\jobname-2.bib}
\step[fieldset=keywords, fieldvalue={,file2}, append]
}
}
}

\newcommand*{\mkbibcolourcite}[1]{%
\ifkeyword{file2}
{\textcolor{blue}{#1}}
{#1}}
\DeclareFieldFormat{labelnumberwidth}{\mkbibbrackets{\mkbibcolourcite{#1}}}
\DeclareFieldFormat{colourcite}{\mkbibcolourcite{#1}}

\renewbibmacro*{cite}{%
\printtext[bibhyperref]{%
\printtext[colourcite]{%
\printfield{labelprefix}%
\printfield{labelnumber}%
\ifbool{bbx:subentry}
{\printfield{entrysetcount}}
{}}}}

\usepackage{filecontents}
\begin{filecontents}{\jobname-1.bib}
@book{book1,
author = {Onymous, Anne},
title  = {First Bibliography: Category 1},
date   = {2000},
}
@book{book3,
author   = {Scribbler, Sarah},
title    = {First Bibliography Again: Category A and B},
date     = {1899},
keywords = {cata},
}
\end{filecontents}
\begin{filecontents}{\jobname-2.bib}
@book{book2,
author = {Writer, William},
title  = {Second Bibliography: Category 2},
date   = {2010},
}
@book{book4,
author = {Poetaster, Paula},
title  = {Second Bibliography Again: Category B},
date   = {1767},
}
\end{filecontents}

\begin{document}
\cite{book1,book2,book3,book4}
\newrefcontext[labelprefix=R]
\printbibliography[keyword=file1]
\newrefcontext[labelprefix=O]
\printbibliography[keyword=file2, title=Other references]
\end{document}


edit How embarassing! I completely forgot to colour the citations according to their file/keyword. That is fixed now. Sorry!

• Thanks a lot...but, when I would like to merge the example with my Elsevier article, by using \documentclass[5p,preprint,10pt,authoryear]{elsarticle} \usepackage{ecrc}. It is giving me an error of "! Package biblatex Error: Incompatible package 'natbib'." Please guide me how can I resolve it? – Muhammad Hammad Jan 19 at 18:54
• @MuhammadHammad Sorry, elsarticle is completely incompatible with biblatex, see tex.stackexchange.com/q/468152/35864. There are theoretically ways to hack around that (see tex.stackexchange.com/q/321989/35864), but I'm pretty sure Elsevier will not like that. – moewe Jan 19 at 19:01