5

I would like to colorise certain bibliography entries, e.g. "important" and "award" papers. What I have at the moment:

\documentclass{article}
\usepackage[utf8]{inputenc}

\usepackage[backend=biber,
        isbn=true,
        giveninits=true,
        style=numeric,
        maxnames=99,
        sorting=ydnt,
        defernumbers=true,
        autocite=superscript]{biblatex}
\defbibheading{bibliography}[\refname]{}
\addbibresource{references.bib}
\renewbibmacro{in:}{}

\usepackage[usenames,dvipsnames]{xcolor}

\DeclareBibliographyCategory{important}
\DeclareBibliographyCategory{award}

\addtocategory{important}{small}
\addtocategory{award}{big}

\AtEveryBibitem{
\ifcategory{award}%
    {\color{blue}}%
    {}%
\ifcategory{important}%
    {\color{orange}}%
    {}%
}

\begin{document}

\section{Main text}

\cite{small}

\cite{big}

\section{Bibliography}
\printbibliography

\end{document}

However, only the bibentry itself is orange (or blue, not shown below), not the reference number next to it. How can I achieve that?

enter image description here

  • Welcome to TeX.SX! Does https://tex.stackexchange.com/a/149753/124842 help you? Please add a minimal working example with bibliography(MWE). that illustrates your problem. Reproducing the problem and finding out what the issue is will be much easier when we see compilable code, starting with \documentclass and ending with \end{document}. – Bobyandbob Apr 28 '17 at 11:53
  • Thanks for your quick reply. No, that answer doesn't help since, still, only the entry itself but not the reference number in front are colorised. – andyknownasabu Apr 28 '17 at 11:57
  • Related to the problem is https://tex.stackexchange.com/a/366999/124842 . You can use\newcommand{\citeColored}[2]{\hypersetup{citecolor=#1}\cite{‌​#2}\hypersetup{citec‌​olor=blue}} and in text: \citeColored{yellow}{eg}. Please always add a MWE or MWEB. – Bobyandbob Apr 28 '17 at 12:01
  • yeah, but I would like the bibliography entry to be in a specific color (both reference and reference number), not the reference in the text. – andyknownasabu Apr 28 '17 at 14:23
  • 1
    Please add your code( as a minimal working example!!). You can edit your question. Can you also add a image , that illustrates what you are looking for? Only the bibliography should be colored like this: [1} Example Author , Thesis A, 2017 and not \cite{key2017} in the text(for example)? – Bobyandbob Apr 28 '17 at 14:48
  • I've added a MWE and picture of the (undesired) output – andyknownasabu Apr 29 '17 at 05:43
  • @UlrikeFischer . Can you help here? (Ref to: https://tex.stackexchange.com/a/327845/124842). Can \defbibenvironment{bibliography} and \printfield be helfpful here? – Bobyandbob Apr 29 '17 at 10:37

1 Answers1

6

You could simply use \AtBeginBibliography and \AtEveryBibitem to set the code for colorizing the bibliography entries only of the important category.

P.S. = Since you didn't add an example of your .bib file, I've used biblatex-examples.bib.

\documentclass{article}
\usepackage[utf8]{inputenc}

\usepackage[backend=biber,
isbn=true,
giveninits=true,
style=numeric,
maxnames=99,
sorting=ydnt,
defernumbers=true,
autocite=superscript]{biblatex}
\defbibheading{bibliography}[\refname]{}
\addbibresource{biblatex-examples.bib}
\renewbibmacro{in:}{}

\usepackage[usenames,dvipsnames]{xcolor}

\DeclareBibliographyCategory{important}
\addtocategory{important}{knuth:ct:a}
\addtocategory{important}{knuth:ct:c}

\AtBeginBibliography{%
    \DeclareFieldFormat{labelnumberwidth}{\ifcategory{important}%
        {\color{orange}\mkbibbrackets{#1}}%
        {\mkbibbrackets{#1}}%
    }}
\AtEveryBibitem{\ifcategory{important}
    {\color{orange}}
    {}}

\begin{document}

    \section{Main text}

    \cite{knuth:ct}
    \cite{knuth:ct:a}
    \cite{knuth:ct:b}       
    \cite{knuth:ct:c}       
    \cite{companion}

    \section{Bibliography}

    \printbibliography

\end{document}

enter image description here

Edit:

The \ifcategory command has this syntax:

\ifcategory{hcategoryi}{htruei}{hfalsei}

similar to may other \ifs commands, see biblatex manual para. 4.6.2 "Stand-alone Tests".

Within htruei or hfalsei you can nest as many \ifcategorys (or other \ifs) you want, you only have to pay attention matching all the braces.

Here is an example with three different colors for three different categories:

\documentclass{article}
\usepackage[utf8]{inputenc}

\usepackage[backend=biber,
isbn=true,
giveninits=true,
style=numeric,
maxnames=99,
sorting=ydnt,
defernumbers=true,
autocite=superscript]{biblatex}
\defbibheading{bibliography}[\refname]{}
\addbibresource{biblatex-examples.bib}
\renewbibmacro{in:}{}

\usepackage[usenames,dvipsnames]{xcolor}

\DeclareBibliographyCategory{important}
\addtocategory{important}{knuth:ct:a}
\addtocategory{important}{knuth:ct:c}
\DeclareBibliographyCategory{awards}
\addtocategory{awards}{knuth:ct:b}
\DeclareBibliographyCategory{ducks}
\addtocategory{ducks}{companion}

\AtBeginBibliography{%
    \DeclareFieldFormat{labelnumberwidth}%
        {\ifcategory{important}% if
            {\color{orange}\mkbibbrackets{#1}}% then
            {\ifcategory{awards}% else if
                {\color{blue}\mkbibbrackets{#1}}% then
                {\ifcategory{ducks}% else if
                    {\color{green}\mkbibbrackets{#1}}% then
                    {{\mkbibbrackets{#1}}%else
                }% end if
            }% end if
        }% end if
}}
\AtEveryBibitem%
    {\ifcategory{important}% if
        {\color{orange}}% then
        {\ifcategory{awards}% else if
            {\color{blue}}% then
            {\ifcategory{ducks}% else if
                {\color{green}}% then
                {}%else
            }% end if
        }% end if
    }% end if

\begin{document}

    \section{Main text}

    \cite{knuth:ct}
    \cite{knuth:ct:a}
    \cite{knuth:ct:b}       
    \cite{knuth:ct:c}       
    \cite{companion}

    \section{Bibliography}

    \printbibliography

\end{document}

enter image description here

CarLaTeX
  • 62,716
  • thanks a lot for your reply - that did the trick!

    One additional question: What do I have to do to make it work with different colors for multiple categories, e.g. "important" and "awards"?

    – andyknownasabu May 01 '17 at 05:55
  • @andyknownasabu You're welcome and thank you for accepting my answer! Making it work with multiple categories is very simple, see the edit to my answer. – CarLaTeX May 01 '17 at 07:21
  • Works like a charm, fantastic - thank you very much! – andyknownasabu May 01 '17 at 13:17
  • I have a "bonus question" - maybe you also have a solution ready for this: If I also want to colorise the corresponding reference in the text (also within a \cite{ref1,ref2,ref3}) - how could I achieve that? – andyknownasabu May 04 '17 at 13:52
  • @andyknownasabu It's feasible but it's better if you ask a follow-up question (that is a new question with this one linked), thank you! – CarLaTeX May 04 '17 at 13:57
  • done: https://tex.stackexchange.com/questions/368247/how-to-colorise-specific-entries-in-the-bibliography-and-corresponding-reference – andyknownasabu May 05 '17 at 08:01
  • @andyknownasabu You're welcome! – CarLaTeX May 05 '17 at 12:38