2

I need this simple behaviour for citations key using biblatex. I need some references (the ones having a given keyword in the .bib file) to appear with a bold citation key in the text (and possibly also in the printed bibliography).

This question is similar to what was asked in Biblatex: How to automatically make in-text citations bold given a condition? but there, the numeric citation style was used, while I need it with the alpha style.

Raziel
  • 165

1 Answers1

3

The required modifications are very similar to the ones in Biblatex: How to automatically make in-text citations bold given a condition?, but the basis for the cite macro is the definition from alphabetic.cbx and not from numeric.cbx. Furthermore, we need to redefine labelalphawidth for the bibliography and not labelnumberwidth.

\documentclass[british]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{libertine}
\usepackage{babel}
\usepackage{csquotes}
\usepackage[style=alphabetic, backend=biber]{biblatex}
\usepackage{hyperref}

\DeclareFieldFormat{labelalphawidth}{\mkbibbrackets{\ifkeyword{important}{\mkbibbold{#1}}{#1}}}

\DeclareFieldFormat{boldimportant}{\ifkeyword{important}{\mkbibbold{#1}}{#1}}

\renewbibmacro*{cite}{%
  \printtext[bibhyperref]{%
    \printtext[boldimportant]{%
      \printfield{labelprefix}%
      \printfield{labelalpha}%
      \printfield{extraalpha}%
      \ifbool{bbx:subentry}
        {\printfield{entrysetcount}}
        {}}}}

\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@inproceedings{appleby,
  author    = {Humphrey Appleby},
  title     = {On the Importance of the Civil Service},
  booktitle = {Why We Matter},
  date      = {1980},
  keywords  = {important},
}
@book{hacker,
  author    = {James Hacker},
  title     = {The Government},
  date      = {1981},
}
\end{filecontents}
\addbibresource{\jobname.bib}

\begin{document}
\cite{appleby,hacker}
\printbibliography
\end{document}

[**App80**; Hac81], "App80" is in bold.

moewe
  • 175,683
  • Is there a way to do the same, but printing two different bibliographies and with different styles ? Namely, the first bibliography (the one in bold, shold be numeric, and the other one should be alpha). – Raziel Sep 29 '19 at 13:49
  • @Raziel That is a but trickier. In general biblatex does not allow you to mix two different styles in one document. But often there are acceptable workarounds. I suggest you ask a new question about this (ideally with a but of background info). – moewe Sep 29 '19 at 14:10
  • @Raziel Maybe https://tex.stackexchange.com/q/299064/35864 can help you enough already. – moewe Sep 29 '19 at 14:11