2

I'd like to print all \cite{} of a given author in bold in my document. For now, I do shorthand = {\textbf{Foo23}} in my .bib, but it is not really practical, and, it not only has the issue of handling poorly duplicated entries having the same shorthand, more importantly, the alphabetical order is broken:

enter image description here

\documentclass{article}

\usepackage[ style=alphabetic,% also minalphanames=3,maxalphanames=4, % [Foo+99] -> [FBB+99]. maxnames=99, % Do not put "et al". Sets maxbibnames, maxcitenames and maxsortnames. sortcites=true, sortcites=false, % \cite{B,A,C}: [A,B,C] --> [B,A,C] ]{biblatex}

\usepackage{filecontents}

\begin{filecontents}[overwrite]{\jobname.bib} @article{a1, author={John Smith and Mary Stuart and Peter Pan}, year = 2020, shorthand = {\textbf{SSP20}}, journal = {I should should have a Awesome Journal}, volume = 3 } @article{a2, author={John Smith and Mary Stuart and Peter Pan}, year = 2020, journal = {Another Journal}, volume = 3 } @article{a3, author={Abc Abc and Def Ahi}, year = 2020, journal = {I should appear first in the list as it is sorted alphabetically}, volume = 3 } \end{filecontents}

\addbibresource{\jobname.bib}

\begin{document}

\cite{a1,a2,a3}

\printbibliography

\end{document}

tobiasBora
  • 8,684

1 Answers1

2

Usually it is best to avoid formatting commands as much as possible in .bib input. As you noticed, the commands will be treated more or less like normal text and can mess up sorting and uniqueness calculations.

Instead it is better to set a semantic marker in the data and act upon that on the biblatex side. One option would be to set a keyword.

Surprisingly there is no simple way on the biblatex side to highlight the whole citation label, so we need to build that into the cite bibmacro.

\documentclass{article}

\usepackage[ style=alphabetic,% also minalphanames=3,maxalphanames=4, % [Foo+99] -> [FBB+99]. maxnames=99, % Do not put "et al". Sets maxbibnames, maxcitenames and maxsortnames. sortcites=true, sortcites=false, % \cite{B,A,C}: [A,B,C] --> [B,A,C] ]{biblatex}

\DeclareFieldFormat{citelabel}{% \ifkeyword{importantauthor} {\mkbibbold{#1}} {#1}}

\DeclareFieldFormat{labelalphawidth}{% \mkbibbrackets{% \ifkeyword{importantauthor} {\mkbibbold{#1}} {#1}}}

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

\begin{filecontents}{\jobname.bib} @article{a1, author = {John Smith and Mary Stuart and Peter Pan}, year = 2020, journal = {I should should have a Awesome Journal}, volume = 3, keywords = {importantauthor}, } @article{a2, author = {John Smith and Mary Stuart and Peter Pan}, year = 2020, journal = {Another Journal}, volume = 3, } @article{a3, author = {Abc Abc and Def Ahi}, year = 2020, journal = {I should appear first in the list as it is sorted alphabetically}, volume = 3, } \end{filecontents} \addbibresource{\jobname.bib}

\begin{document}

\cite{a1,a2,a3}

\printbibliography

\end{document}

"[SSP20a; SSP20b; AA20]" with "SSP20a" in bold

moewe
  • 175,683
  • Thanks a lot! By curiosity, I also tried to do it automatically if, say, the word Smith is contained in the list of authors, but I can't find how to do. Do you know if it is possible? – tobiasBora Feb 03 '24 at 08:19
  • 1
    @tobiasBora You can try something like https://tex.stackexchange.com/q/65114/35864, but generally that can be a bit fickly, because .bib files allow "Last, First" and "First Last" input (so you'd have to look for both forms) and RegExp does not always play particularly nice with TeX commands, because it doesn't do nesting well (though that would be less of a concern here, I guess). – moewe Feb 03 '24 at 08:42