2

I would like to colorize some of the references in the bibliography similarly to this question, this one, and this one.

However, these techniques use an additional category. This other one uses keywords. Rather, I would like to use annotations on authors, which I already use for highlighting author names.

Here is an example in which the author highlighting works, but not reference and citation. The objective is to have the names of annotated authors in bold, and all the references for which at least one author annotated in red (both the reference and the citations).

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

\usepackage[usenames,dvipsnames]{xcolor}

\begin{filecontents}{test-example.bib} @article{a, author = {Name, A and Name, B}, author+an = {1=highlight}, title = {Title A}, journal = {Journal A} } @inproceedings{b, author = {Name, E and Name, F}, title = {Title B}, booktitle = {Conference B} } @article{c, author = {Name, C and Name, D}, title = {Title C}, journal = {Journal C} } @inproceedings{d, author = {Name, E and Name, F}, author+an = {2=highlight}, title = {Title D}, booktitle = {Conference D} } \end{filecontents}

\usepackage[style=numeric]{biblatex} \addbibresource{test-example.bib}

% Highlighting annotated authors \renewcommand{\mkbibnamegiven}[1]{% \ifitemannotation[author]{highlight} {\textbf{#1}} {#1}} \renewcommand{\mkbibnamefamily}[1]{% \ifitemannotation[author]{highlight} {\textbf{#1}} {#1}}

% Expected result: citations and references with at least % one annotated author should be red \DeclareFieldFormat{labelprefix}{% \iffieldannotation[author]{highlight} {\textcolor{red}{#1}} {#1}}

\DeclareFieldFormat{labelnumber}{% \iffieldannotation[author]{highlight} {\textcolor{red}{#1}} {#1}}

\DeclareFieldFormat{labelnumberwidth}{% \iffieldannotation[author]{highlight} {\textcolor{red}{\mkbibbrackets{#1}}} {\mkbibbrackets{#1}}}

\AtEveryBibitem{% \iffieldannotation[author]{highlight} {\color{red}} {}}

\begin{document}

\cite{a,b,c,d}

\cite{a}\cite{b}\cite{c}\cite{d}

\printbibliography \end{document}

Tom
  • 337

1 Answers1

3

In order to find out if an entry should be highlighted we need to loop through all of its authors to see if any one of them has the required annotation. Since it would be pretty wasteful to rerun the loop whenever we need to decide whether or not an entry should be highlighted, we use the trick shown in biblatex: filter out publications from a specific author in the references dynamically to loop through the names once in \AtDataInput and assign an entry to the bibliography category highlight if it should be highlighted. We can then check if an entry should be red with \ifcategory{highlight}{<true>}{<false>}.

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

\usepackage[usenames,dvipsnames]{xcolor} \usepackage[style=numeric]{biblatex}

\DeclareBibliographyCategory{highlight}

\DeclareIndexNameFormat{IsHighlighted}{% \ifitemannotation[author]{highlight} {\addtocategory{highlight}{\thefield{entrykey}}} {}}

\AtDataInput{% \indexnames[IsHighlighted][1-999]{author}}

% Highlighting annotated authors \renewcommand{\mkbibnamegiven}[1]{% \ifitemannotation[author]{highlight} {\textbf{#1}} {#1}} \renewcommand{\mkbibnamefamily}[1]{% \ifitemannotation[author]{highlight} {\textbf{#1}} {#1}}

% Expected result: citations and references with at least % one annotated author should be red \DeclareFieldFormat{labelprefix}{% \ifcategory{highlight} {\textcolor{red}{#1}} {#1}}

\DeclareFieldFormat{labelnumber}{% \ifcategory{highlight} {\textcolor{red}{#1}} {#1}}

\DeclareFieldFormat{labelnumberwidth}{% \ifcategory{highlight} {\textcolor{red}{\mkbibbrackets{#1}}} {\mkbibbrackets{#1}}}

\AtEveryBibitem{% \ifcategory{highlight} {\color{red}} {}}

\begin{filecontents}{\jobname.bib} @article{a, author = {Name, A and Name, B}, author+an = {1=highlight}, title = {Title A}, journal = {Journal A} } @inproceedings{b, author = {Name, E and Name, F}, title = {Title B}, booktitle = {Conference B} } @article{c, author = {Name, C and Name, D}, title = {Title C}, journal = {Journal C} } @inproceedings{d, author = {Name, E and Name, F}, author+an = {2=highlight}, title = {Title D}, booktitle = {Conference D} } \end{filecontents} \addbibresource{\jobname.bib}

\begin{document} \cite{a,b,c,d}

\cite{a}\cite{b}\cite{c}\cite{d}

\printbibliography \end{document}

[1, 3, 2, 4]
[1][3][2][4]
[1] A Name and B Name. “Title A”. In: Journal A ().
[2] C Name and D Name. “Title C”. In: Journal C ().
[3] E Name and F Name. “Title B”. In: Conference B.
[4] E Name and F Name. “Title D”. In: Conference D.
The entries "1" and "4" are always highlighted in red

moewe
  • 175,683