# Customizing citations depending on the author with BibLaTeX style “authoryear” or “authoryear-comp”

Say I use BibLaTeX with standard style authoryear or authoryear-comp.

Then given a citation command such as \parencite{A, B, C} (or any other standard Biblatex citation command), I'd like the resulting citations to be typeset differently depending on whether a given field (e.g. the author field) in the corresponding bibliography entry contains a given string (e.g. someone's lastname).

MWE:

\documentclass{article}
\usepackage{filecontents}
\usepackage[backend=biber,style = authoryear-comp]{biblatex}
\DeclareSourcemap{%
\maps[datatype=bibtex]{%
\map{%
\step[fieldsource=author, match=Doe, final]%
\step[fieldset=keywords, fieldvalue=doe]%
}%
}%
}
\begin{filecontents}{\jobname.bib}
@Book{p1,
author =       "A. U. Thor and John Doe",
title =        "A Scientific Article 1",
year =         "1975"
}
@Book{p2,
author =       "John Doe",
title =        "A Scientific Article 2",
year =         "1985"
}
@Book{p3,
author =       "Joe Bar",
title =        "A Scientific Article 3",
year =         "1995"
}
@Book{p4,
author =       "Jane Baz",
title =        "A Scientific Article 4",
year =         "2005"
}
@Book{p5,
author =       "A. U. Thor and John Doe",
title =        "A Scientific Article 5",
year =         "2010"
}
@Book{p6,
author =       "Jane Baz",
title =        "A Scientific Article 6",
year =         "2015"
}
\end{filecontents}

\nocite{*}
\begin{document}
In: \parencite{p4, p1, p2, p3, p5, p6}, Thor and Doe 1975, 2010'' and Doe
1985'' should be \emph{emphasized} (but the corresponding entries in the
References section should remain typeset as the others).

\printbibliography
\end{document}


Note: I asked a similar question here but the proposed solution does not work with standard styles authoryear or authoryear-comp.

If you want this to be applicable to multiple styles, we can modify the cite bibmacro as follows

\DeclareFieldFormat{keywordcite}{\ifkeyword{doe}{\mkbibemph{#1}}{#1}}
\csletcs{old:cite}{abx@macro@cite}
\renewbibmacro{cite}{\printtext[keywordcite]{\csuse{old:cite}}}


MWE

\documentclass{article}
\usepackage{filecontents}
\usepackage[backend=biber,style = authoryear-comp]{biblatex}
\DeclareSourcemap{%
\maps[datatype=bibtex]{%
\map{%
\step[fieldsource=author, match=Doe, final]%
\step[fieldset=keywords, fieldvalue=doe]%
}%
}%
}
\begin{filecontents}{\jobname.bib}
@Book{p1,
author =       "A. U. Thor and John Doe",
title =        "A Scientific Article 1",
year =         "1975"
}
@Book{p2,
author =       "John Doe",
title =        "A Scientific Article 2",
year =         "1985"
}
@Book{p3,
author =       "Joe Bar",
title =        "A Scientific Article 3",
year =         "1995"
}
@Book{p4,
author =       "Jane Baz",
title =        "A Scientific Article 4",
year =         "2005"
}
@Book{p5,
author =       "A. U. Thor and John Doe",
title =        "A Scientific Article 5",
year =         "2010"
}
@Book{p6,
author =       "Jane Baz",
title =        "A Scientific Article 6",
year =         "2015"
}
\end{filecontents}

\DeclareFieldFormat{keywordcite}{\ifkeyword{doe}{\mkbibemph{#1}}{#1}}
\csletcs{old:cite}{abx@macro@cite}
\renewbibmacro{cite}{\printtext[keywordcite]{\csuse{old:cite}}}

\nocite{*}
\begin{document}
In: \parencite{p4, p1, p2, p3, p5, p6}, Thor and Doe 1975, 2010'' and Doe
1985'' should be \emph{emphasized} (but the corresponding entries in the
References section should remain typeset as the others).

\printbibliography
\end{document}


• It works, thank you for your help. EDIT: actually it des not work with the \textcite command. – Grayswandyr Jul 28 '16 at 8:29
• @Grayswandyr For \textcite you need \csletcs{old:textcite}{abx@macro@textcite} \renewbibmacro{textcite}{\printtext[keywordcite]{\csuse{old:textcite}}} as well. – moewe Jul 28 '16 at 8:39