Is there any way, using biblatex, to get citations for certain bib-keys / bib-entries, and only them, to be differently coloured?
In the MWE below, I've made a custom command (inspired by this answer) for differently coloured citations. However, what I am looking for is a way of having biblatex/biber automatically colour citations referencing certain entries, and only them, without using any custom commands. In the text, the same command would be used (e.g. \parencite
) but for specified entries (e.g. articlecoloured
) the output would be coloured; for other entries, it would not.
In other words, using the citation commands as in section "No custom commands" in the MWE but getting the same output as in section "Using custom commands".
The example includes a bib-content with two entries, articlenormal
and articlecoloured
.
I'd like to be able to use the normal citation commands (\parencite
, \citeyear
, \textcite
etc.) but for some bib-keys (articlecoloured
) output would be coloured; for all others (e.g. articlenormal
) it would not. (In my working document, I have custom commands for the various citation commands I use, which all colour output as in the MWE. In the MWE, I've only included \parencite
.)
Is it possible to get articlecoloured
, and only articlecoloured
, to have a custom colour without using a custom citation command?
Perhaps which bibentries to colour could be based either on a list of keys (i.e. articlecoloured
), or to have a relevant keyword in the bibentry?
(Bonus points if specified entry to be coloured is also coloured in the bibliography.)
\documentclass{article}
\usepackage{xcolor}
\definecolor{citecolor}{RGB}{12,127,172}
\begin{filecontents*}{mybib.bib}
@ARTICLE{articlenormal,
author = {Normal, Article},
title = {Normal},
year = {2020}
}
@ARTICLE{articlecoloured,
author = {Coloured, Article},
title = {Coloured},
year = {2020}
}
\end{filecontents*}
\usepackage[style=apa,backend=biber]{biblatex}
\DeclareLanguageMapping{english}{british-apa}
\bibliography{mybib}
% Using custom command
\newcommand{\mkbibparenscoloured}[1]{\textcolor{citecolor}{\mkbibparens{#1}}}
\DeclareDelimFormat[parencite]{finalnamedelim}
{\ifnum\value{liststop}>2 \finalandcomma\fi\addspace\&\space}
\DeclareCiteCommand{\colparencite}[\mkbibparenscoloured]
{\usebibmacro{cite:init}%
\usebibmacro{prenote}%
\toggletrue{apa:inpcite}}
{\usebibmacro{citeindex}%
\usebibmacro{cite}%
\usebibmacro{cite:post}}
{}
{\usebibmacro{postnote}%
\togglefalse{apa:inpcite}}
\begin{document}
\section*{No custom commands}
Citation, should be normal colour \parencite{articlenormal}.
Citation, should be differently coloured \parencite{articlecoloured}.
\section*{Using custom commands}
Citation, should be normal colour \parencite{articlenormal}.
Citation, should be differently coloured \colparencite{articlecoloured}.
\printbibliography{}
\end{document}
\parencite{articlenormal,articlecoloured}
.\textcite
is going to be tricky, I'll see what can be done. (Of coursebiblatex-apa
is quite a complex style, so things are going to be more tricky than with your averageauthoryear
. Can you please check the version ofbiblatex-apa
that you have installed? You can add\listfiles
to the beginning of your file and then read off the version in the.log
file output.)biblatex.def 2019/12/01 v3.14 biblatex compatibility (PK/MW)
standard.bbx 2019/12/01 v3.14 biblatex bibliography style (PK/MW)
apa.bbx 2017/01/06 v7.4 APA biblatex references style
Hmm. Thatapa.bbx
looks old. I think it's an old remnant in my local-texmf. I'll remove that and re-run with texmf-dist biblatex-apa.biblatex-apa
so old, but yourbiblatex
is current? Note that your version ofbiblatex-apa
produces the (now outdated) 6th-edition APA style. A current versions ofbiblatex-apa
(v9.6) will produce 7th-edition APA style. If you want 6th-edition APA style on an up-to-date system, you would be usingbiblatex-apa6
'sstyle=apa6,
.