Make specific author bold using biblatex
You can patch the name:last
, name:first-last
and name:last-first
macros defined in biblatex.def
. These are used by all of the default name formatting directives and take four arguments:
{<last name>}{<first name>}{<name prefix>}{<name affix>}
or
{<last name>}{<first name (initials)>}{<name prefix>}{<name affix>}
In the following we match only on the first and last name parts.
\documentclass{article}
\usepackage{biblatex}
\usepackage{xpatch}% or use http://tex.stackexchange.com/a/40705
\makeatletter
\newbibmacro*{name:bold}[2]{%
\edef\blx@tmp@name{\expandonce#1, \expandonce#2}%
\def\do##1{\ifdefstring{\blx@tmp@name}{##1}{\bfseries\listbreak}{}}%
\dolistloop{\boldnames}}
\newcommand*{\boldnames}{}
\makeatother
\xpretobibmacro{name:family}{\begingroup\usebibmacro{name:bold}{#1}{#2}}{}{}
\xpretobibmacro{name:given-family}{\begingroup\usebibmacro{name:bold}{#1}{#2}}{}{}
\xpretobibmacro{name:family-given}{\begingroup\usebibmacro{name:bold}{#1}{#2}}{}{}
\xpretobibmacro{name:delim}{\begingroup\normalfont}{}{}
\xapptobibmacro{name:family}{\endgroup}{}{}
\xapptobibmacro{name:given-family}{\endgroup}{}{}
\xapptobibmacro{name:family-given}{\endgroup}{}{}
\xapptobibmacro{name:delim}{\endgroup}{}{}
% just for demonstration
\ExecuteBibliographyOptions{maxnames=99,giveninits}
\DeclareNameAlias{default}{family-given/given-family}
\addbibresource{biblatex-examples.bib}
\forcsvlist{\listadd\boldnames}
{{Herrmann, Wolfgang~A.}, {Herrmann, W.~A.}, {Herrmann, Wolfgang\bibnamedelima A.},
{Herrmann, W\bibinitperiod\bibinitdelim A\bibinitperiod}}
\setlength{\parindent}{0pt}
\setlength{\parskip}{\baselineskip}
\begin{document}
\fullcite{herrmann}
\forcsvlist{\listadd\boldnames}
{{{\"{O}}fele, Karl}, {{\"{O}}fele, K.}, {{\"{O}}fele, K\bibinitperiod}}
\fullcite{herrmann}
\renewcommand*{\boldnames}{}
\forcsvlist{\listadd\boldnames}
{{Hoffmann, Stephan~D.}, {Hoffmann, S.~D.}, {Hoffmann, Stephan\bibnamedelima D.},
{Hoffmann, S\bibinitperiod\bibinitdelim D\bibinitperiod}}
\fullcite{herrmann}
\end{document}
Note that the name parts in the \boldnames
etoolbox
internal list should follow the format of the bbl
file, which is backend-dependent. The example here covers both biber and BibTeX. With biber you can also perform matching using the hash
field:
\iffieldequalstr{hash}{<hash string>}
where <hash string>
can also be found in the bbl
file.
If your name is consistently formatted in the bib
file an alternative approach is to normalize name punctuation before matching. This example allows you to specify your name in BibTeX's format regardless of the backend.
\documentclass{article}
\usepackage{biblatex}
\usepackage{xpatch}% or use http://tex.stackexchange.com/a/40705
\def\makenamesetup{%
\def\bibnamedelima{~}%
\def\bibnamedelimb{ }%
\def\bibnamedelimc{ }%
\def\bibnamedelimd{ }%
\def\bibnamedelimi{ }%
\def\bibinitperiod{.}%
\def\bibinitdelim{~}%
\def\bibinithyphendelim{.-}}
\newcommand*{\makename}[3]{\begingroup\makenamesetup\xdef#1{#2, #3}\endgroup}
\newbibmacro*{name:bold}[2]{%
\makename{\currname}{#1}{#2}%
\makename{\findname}{\lastname}{\firstname}%
\makename{\findinit}{\lastname}{\firstinit}%
\ifboolexpr{ test {\ifdefequal{\currname}{\findname}}
or test {\ifdefequal{\currname}{\findinit}} }{\bfseries}{}}
\newcommand*{\boldname}[3]{%
\def\lastname{#1}%
\def\firstname{#2}%
\def\firstinit{#3}}
\boldname{}{}{}
\xpretobibmacro{name:family}{\begingroup\usebibmacro{name:bold}{#1}{#2}}{}{}
\xpretobibmacro{name:given-family}{\begingroup\usebibmacro{name:bold}{#1}{#2}}{}{}
\xpretobibmacro{name:family-given}{\begingroup\usebibmacro{name:bold}{#1}{#2}}{}{}
\xpretobibmacro{name:delim}{\begingroup\normalfont}{}{}
\xapptobibmacro{name:family}{\endgroup}{}{}
\xapptobibmacro{name:given-family}{\endgroup}{}{}
\xapptobibmacro{name:family-given}{\endgroup}{}{}
\xapptobibmacro{name:delim}{\endgroup}{}{}
% just for demonstration
\ExecuteBibliographyOptions{maxnames=99,giveninits}
\DeclareNameAlias{default}{family-given/given-family}
\addbibresource{biblatex-examples.bib}
\boldname{Herrmann}{Wolfgang~A.}{W.~A.}
\setlength{\parindent}{0pt}
\setlength{\parskip}{\baselineskip}
\begin{document}
\fullcite{herrmann}
\boldname{{\"O}fele}{Karl}{K.}
\fullcite{herrmann}
\boldname{Hoffmann}{Stephan~D.}{S.~D.}
\fullcite{herrmann}
\end{document}
This answer was updated to work with versions >= 3.3 of
biblatex
. See the edit history for older versions ofbiblatex
. -- moewe
Since biblatex
3.4/biber
2.5, there is a general "annotation" functionality to do things like this, for example:
\documentclass{article}
\usepackage{biblatex}
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@MISC{test,
AUTHOR = {Last1, First1 and Last2, First2 and Last3, First3},
AUTHOR+an = {2=highlight},
}
\end{filecontents}
\addbibresource{\jobname.bib}
\renewcommand*{\mkbibnamegiven}[1]{%
\ifitemannotation{highlight}
{\textbf{#1}}
{#1}}
\renewcommand*{\mkbibnamefamily}[1]{%
\ifitemannotation{highlight}
{\textbf{#1}}
{#1}}
\begin{document}
\nocite{*}
\printbibliography
\end{document}
You can also annotate at the name part level and the top-level field level. See the biblatex PDF manual for details.
As I couldn't use https://tex.stackexchange.com/a/73246/7561 as well, and in case others stumble into this looking for a solution, I'm updating the answers. As pointed by Adam Liter, in the comments of that answer, the options used in the previous answer are deprecated and doesn't work (at least for me).
Solution
Instead, I redefined the \mkbibnamegiven
and \mkbibnamefamily
, and used the same ideas as before.
Basically, you use the \boldname
to the define the name you want to mark as bold, like: \boldname{Lastname}{Givenname}{G.}
.
\newcommand*{\boldname}[3]{%
\def\lastname{#1}%
\def\firstname{#2}%
\def\firstinit{#3}}
\boldname{}{}{}
Then, we redefine the macros that generate the given and family names. The main idea is to search for the named defined above, and if it is found (including the given and family name) it makes it bold (using \mkbibbold
), if not it leaves it as is.
% Patch new definitions
\renewcommand{\mkbibnamegiven}[1]{%
\ifboolexpr{ ( test {\ifdefequal{\firstname}{\namepartgiven}} or test {\ifdefequal{\firstinit}{\namepartgiven}} ) and test {\ifdefequal{\lastname}{\namepartfamily}} }
{\mkbibbold{#1}}{#1}%
}
\renewcommand{\mkbibnamefamily}[1]{%
\ifboolexpr{ ( test {\ifdefequal{\firstname}{\namepartgiven}} or test {\ifdefequal{\firstinit}{\namepartgiven}} ) and test {\ifdefequal{\lastname}{\namepartfamily}} }
{\mkbibbold{#1}}{#1}%
}
Example
A full example:
% !BIB program = biber
\documentclass{article}
\usepackage[backend=biber,maxbibnames=99,defernumbers=true,sorting=ydnt,giveninits=true]{biblatex}
\begin{filecontents}{\jobname.bib}
@InProceedings{identifier1,
Title = {Some Awesome Title},
Author = {Some Author and Another Author},
Booktitle = {Some Book about the Future},
Year = {2042},
Pages = {1--42}
}
@InProceedings{identifier2,
Title = {Some So-So Title},
Author = {First Author and Second Author},
Booktitle = {An okay Booktitle},
Year = {2000},
Pages = {1--100}
}
@Book{test1,
author = {Goossens, Michel and Mittelbach, Frank
and Samarin, Alexander},
title = {The LaTeX Companion},
publisher = {Addison-Wesley},
location = {Reading, Mass.},
year = {1994},
}
@Book{test2,
author = {Mittelbach, F. and Goossens, Michel
and Samarin, Alexander},
title = {The LaTeX Companion},
publisher = {Addison-Wesley},
location = {Reading, Mass.},
year = {1994},
}
@Book{test3,
author = {Mittelbach, Frank and Samarin, Alexander
and Goossens, Michel},
title = {The LaTeX Companion},
publisher = {Addison-Wesley},
location = {Reading, Mass.},
year = {1994},
}
\end{filecontents}
\addbibresource{\jobname.bib}
\def\makenamesetup{%
\def\bibnamedelima{~}%
\def\bibnamedelimb{ }%
\def\bibnamedelimc{ }%
\def\bibnamedelimd{ }%
\def\bibnamedelimi{ }%
\def\bibinitperiod{.}%
\def\bibinitdelim{~}%
\def\bibinithyphendelim{.-}}
\newcommand*{\makename}[2]{\begingroup\makenamesetup\xdef#1{#2}\endgroup}
\newcommand*{\boldname}[3]{%
\def\lastname{#1}%
\def\firstname{#2}%
\def\firstinit{#3}}
\boldname{}{}{}
% Patch new definitions
\renewcommand{\mkbibnamegiven}[1]{%
\ifboolexpr{ ( test {\ifdefequal{\firstname}{\namepartgiven}} or test {\ifdefequal{\firstinit}{\namepartgiven}} ) and test {\ifdefequal{\lastname}{\namepartfamily}} }
{\mkbibbold{#1}}{#1}%
}
\renewcommand{\mkbibnamefamily}[1]{%
\ifboolexpr{ ( test {\ifdefequal{\firstname}{\namepartgiven}} or test {\ifdefequal{\firstinit}{\namepartgiven}} ) and test {\ifdefequal{\lastname}{\namepartfamily}} }
{\mkbibbold{#1}}{#1}%
}
\boldname{Author}{Some}{S.}
\begin{document}
\nocite{*}
\printbibliography
\boldname{Goossens}{Michel}{M.}
\printbibliography
\boldname{Mittelbach}{Frank}{F.}
\printbibliography
\end{document}
Update
Added support for checking given and family names before bolding the name.