# Make one author's name bold every time it shows up in the bibliography

I'm working on a CV. I'd like to highlight my name in every entry in the bibliography. I've tried simply replacing {myname} with {\bf myname} or {{\bf myname}}, but they fail with various errors, particularly when sorting.

This post gives a solution that's nearly what I'm looking for. The solution in the linked post is to use:

\newcommand{\myname}[1]{\textbf{#1}}


to wrap all instances of the name in question.

EDIT: Removed error example because it was caused by an unassociated error in a .bst file. The answer selected below now directly answers the only question posed above.

-
Maybe you can simply modify the .bib database to change your name to be a macro and use \providecommand to provide a default value for the macro. – Leo Liu Nov 1 '11 at 16:12
It is always best to compose a MWE that illustrates the problem including the \documentclass so that those trying to help don't have to recreate it. – Peter Grill Nov 1 '11 at 16:56
Do you use bibtex or biblatex? – Mico Nov 1 '11 at 16:57
Mico: bibtex. Peter: I'll work on that. – keflavich Nov 1 '11 at 17:11
You might also want to consider using amsrefs and this simple (though requiring some manual work) solution: mbork.pl/2009-04-14_List_of_publications_of_a_person_%28en%29 – mbork Mar 11 '12 at 22:04

## 6 Answers

In the solution I found, you need to modify your bibtex style file for this and implement a new TeX macro. Suppose you use the plain bibliography style. Locate plain.bst (you can use the command kpsewhich plain.bst for that) and copy it to your local tex directory as, say, myplain.bst. In myplain.bst locate the function format.names. In this function replace the line

{ s nameptr "{ff~}{vv~}{ll}{, jj}" format.name$'t :=  by { "\FormatName{" s nameptr "{ff~}{vv~}{ll}{, jj}" format.name$ * "}" * 't :=


Now in your tex file, first change the style to myplain.bst and insert the following macro definitions:

\def\FormatName#1{%
\def\myname{Elmar Zander}%
\edef\name{#1}%
\ifx\name\myname
\textbf{#1}%
\else
#1%
\fi
}


This should work now. (And, of course, don't forget do replace my name by yours ;-)

Note1: format.name$ is a builtin function that takes the preceding three arguments, which are: a string with the author names (s), the number of the name to be formatted (nameptr) and a formatting string ("{ff~...") and formats the author name according to this format string. As bibtex is stack oriented the arguments need to be pushed first on the stack, then format.name$ pops them off the stack, computes the result and pushes it back onto the stack. The "ff,ll,vv,jj" in the format string stand for first name(s), last name, stuff like "von" or "de", and stuff like "jr./junior" respectively (see btxhak.pdf included in the bibtex distribution). The single letter versions "f", "l" etc. would give you abbreviated forms. The * operator in bibtex concatenates two strings. Again, the strings need to be on the stack first, and the result is pushed back on the top of the stack.

Note2: You can have the FormatName macro in your bst file: modify the begin.bib function in myplain.bst in the following way

FUNCTION {begin.bib}
{
"\def\FormatName#1{%" write$" \edef\name{#1}%" write$
"  \ifx\name\myname" write$" \textbf{#1}%" write$
"  \else%" write$" #1%" write$
"  \fi" write$"}" write$
preamble$empty$
'skip${ preamble$ write$newline$ }
if$"\begin{thebibliography}{" longest.label * "}" * write$ newline$}  Just keep the \def\myname{...} macro in your tex file. So that you can change the name to be highlighted (if any) easily. Note3: the FormatName command can have problems with the spaces between a first name and last name, and it will also not find both 'Elmar Zander' and 'E. Zander'. If the above does not work for you, you can use the xstring package and then define FormatName as follows: \def\FormatName#1{% \IfSubStr{#1}{Zander}{\textbf{#1}}{#1}% }  - That may be an alternate solution, but I like the simpler one I've seen that simply requires replacing elements in the .bib file; since I am more fluent in .bib and .tex than .bst, I trust editing those files more. Still, I like the example... it helps me understand what the bst file does. – keflavich Nov 1 '11 at 22:57 Well, I prefer separating the formatting from the content and this solution does. I wouldn't want to put formatting commands into one of my bib files. If you ever decide e.g. you want another name emphasized with this solution it will be easy. I agree that fiddling with bst files ist not to everyones liking (in fact they're really horrible), but you don't need to understand the bibtex style file language in order to apply the patch given. Whatever, its yours to decide and what you're more comfortable with. – Elmar Zander Nov 2 '11 at 10:09 That's a fair point - with any other language, I'd go the route you suggested. Can you explain what that line is, though? i.e., what does nameptr, format.name$, {ff~}, etc. mean? Also, is it possible to put the \FormatName command into the .bst file or does it have to be in the .tex file? – keflavich Nov 2 '11 at 15:08
Please see the two notes I've added to my post, since they would not have fitted into the comment field. – Elmar Zander Nov 2 '11 at 16:03
the first solution seems to insert a lot of whitespace. Is there a way to trim it? There's a trimspaces package but I can't get it to work with the provided macro. – user10226 Dec 22 '11 at 19:39

You can do this with BibLaTeX without much hackery by putting the following in your preamble:

\newcommand{\makeauthorbold}[1]{%
\DeclareNameFormat{author}{%
\ifnumequal{\value{listcount}}{1}
{\ifnumequal{\value{liststop}}{1}
{\expandafter\ifstrequal{##1}{#1}{\textbf{##1\addcomma\addspace ##4\addcomma\isdot}}{##1\addcomma\addspace ##4\addcomma\isdot}}
{\expandafter\ifstrequal{##1}{#1}{\textbf{##1\addcomma\addspace ##4}}{##1\addcomma\addspace ##4}}}
{\ifnumless{\value{listcount}}{\value{liststop}}
{\expandafter\ifstrequal{##1}{#1}{\textbf{\addcomma\addspace ##1\addcomma\addspace ##4}}{\addcomma\addspace ##1\addcomma\addspace ##4}}
{\expandafter\ifstrequal{##1}{#1}{\textbf{\addcomma\addspace ##1\addcomma\addspace ##4\addcomma\isdot}}{\addcomma\addspace ##1\addcomma\addspace ##4\addcomma\isdot}}%
}%
}%
}
\makeauthorbold{Smith}


By using \IfSubStr from the xstring package in place of \ifstrequal one can also make multiple names bold with something like the following:

\usepackage{xstring}
\newcommand{\makeauthorsbold}[1]{%
\DeclareNameFormat{author}{%
\ifnumequal{\value{listcount}}{1}
{\ifnumequal{\value{liststop}}{1}
{\expandafter\IfSubStr{#1}{##1}{\textbf{##1\addcomma\addspace ##4\addcomma\isdot}}{##1\addcomma\addspace ##4\addcomma\isdot}}
{\expandafter\IfSubStr{#1}{##1}{\textbf{##1\addcomma\addspace ##4}}{##1\addcomma\addspace ##4}}}
{\ifnumless{\value{listcount}}{\value{liststop}}
{\expandafter\IfSubStr{#1}{##1}{\textbf{\addcomma\addspace ##1\addcomma\addspace ##4}}{\addcomma\addspace ##1\addcomma\addspace ##4}}
{\expandafter\IfSubStr{#1}{##1}{\textbf{\addcomma\addspace ##1\addcomma\addspace ##4\addcomma\isdot}}{\addcomma\addspace ##1\addcomma\addspace ##4\addcomma\isdot}}%
}%
}%
}
\makeauthorsbold{Smith,Doe}


The only caveat is that this will also make authors bold whose name is a sub string of one of the given names. For example "Do" will also end up being bold.

-
Could you 'wrap' this in a macro, so it is possible to add \makeauthorbold{Smith} and \makeauthorbold{Williams} in the preamble? I am not sure how that works, since it already uses #1 and such. – Andy Nov 12 '14 at 12:33
You can use ##1 in nested \newcommand like constructs. Aparently this also works with \DeclareNameFormat. See also tex.stackexchange.com/questions/39339/… – cgogolin Nov 19 '14 at 12:13
\makeauthorbold works with non latin script, but \makeauthorsbold doesn't. Any idea why and how to fix it? – Theo Nov 20 '15 at 20:41
This seems to mess up (in the bibliography) the detection of the last author in the list, whose name should be preceded by "and" and not followed by a comma. So instead of "Smith and Doe (1990)" I get "Smith, Doe, (1990)", even when the author printed in bold is Darwin. I use style=authoryear-comp,natbib=true in biblatex... maybe I should open a new question? – Jos Dec 14 '15 at 13:40
Without having tested anything I suspect that either the authoryear-comp style or the option natbib=true also sets the format for printing names by calling \DeclareNameFormat. This is then overwritten when the above macro is called. I guess the only solution is to look into how this combination affects the name format and replicate this behavior in the macro defined above. – cgogolin Dec 15 '15 at 11:18

I think a simpler method contained within the .bst file works as follows (i.e., take your favorite .bst, create a duplicate, and add this code to that as in the previous answer).

1. Create a function that returns your name:

FUNCTION {cv.author}
{ "Doe, J." }

2. Create a function that highlights stuff (here, bold and small caps)

FUNCTION {highlight}
{ duplicate$empty$
{ pop$"" } { "\textbf{\textsc{" swap$ * "}}" * }
if$}  3. Create a function that highlights your name FUNCTION {highlight.if.cv.author} { duplicate$ purify$cv.author purify$ =
{ highlight }
'skip$if$
}

4. Finally, in the function FUNCTION {format.names}, add a call to this new function after the line format.name$, i.e.  FUNCTION {format.names} ... format.name$
highlight.if.cv.author
remove.dots
...


Run bibtex as normal and your name should be highlighted in any way you want.

-
Works great, thanks! (although bold fonts seem to be ignored when using \textsc or \sc, but that might be related to something else I do in my bst) – Anthony Labarre Apr 15 '13 at 11:40
Many fonts don't have bold small caps glyphs, so I guess that's why you can't combine the two styles. – Supernormal Jun 23 '14 at 13:17

For reference, another approach to doing this is with Bibulous in place of BibTeX or Biblatex, and is worth noting because the implementation is straightforward. In order make a given author bold, all that is needed is to apply a "substring replace" operator into the author list variable. For example, to replace the author "J. W. Tukey" with its bold version "\textbf{J. W. Tukey}" we can change the <au> variable in the Bibulous templates. Thus, in the "SPECIAL TEMPLATES" section of the *.bst file, we can change the <au> and <ed> variable definitions from their defaults of

au = <authorlist.format_authorlist()>
ed = <editorlist.format_editorlist()>


to their new forms of

au_orig = <authorlist.format_authorlist()>
au = <au_orig.replace(J. W. Tukey,\textbf{J. W. Tukey})>
ed_orig = <editorlist.format_editorlist()>
ed = <ed_orig.replace(J. W. Tukey,\textbf{J. W. Tukey})>


Note that this approach closely follows that of the answer posted here, where the OP aims to underline an author name rather than use boldface.

-
But this needs to be done for every type of bibliography entry as opposed to only once for the biblatex solution. So it is not really straightforward, and will be fragile if additional kinds of entries are used in the future. – cfr Apr 1 '15 at 23:51
@cfr: The above change is to the style template and not to any database entries, and so it only needs the one change shown to make the author's name in bold everywhere it occurs in the output reference list. – nzh Apr 2 '15 at 15:07
Yes, the example shown above is specific to article-type entries. And, although this is easy to copy into all of the entrytype templates, it will make them hard to read. So that's a good point. An alternative is to override the default definition of the au variable, so that the same applies to all entry types. For example, in the SPECIAL-TEMPLATES section of the template file, one can define au_orig = <authorname.0>, ..., <authorname.9> and then <au> = <au_orig.replace(J. W. Tukey,\textbf{J. W. Tukey})>. This applies the change to every instance of <au> in every entrytype template. – nzh Apr 3 '15 at 17:52
(+1) But I think that information would be more useful in your answer ;). – cfr Apr 3 '15 at 18:24
Good idea! I've changed the answer to reflect your suggestion. – nzh Sep 4 '15 at 15:09

It is possible to do this without introducing any special commands and just changing how the name is entered in the bibtex file.

You can simply use ... and {\bf first name} {\bf last name} in the author list in the bibtex file or ... and {\bf last name}, {\bf first name}.

You mentioned errors occurring during sorting. I suspect this is because you did {\bf first name last name}, in which case it treats this as if it's just your last name. In my experience (at least using natbib) I don't see any errors.

If you do have error in sorting, then use \noopsort: at the very beginning of your bibtex file, put

@PREAMBLE{"\providecommand{\noopsort}[1]{}"}


then do something like this in the author name:

author =     {{\noopsort{Hofstad}}{\bf van der Hofstad}, {\bf R.}}


This would cause the name to be alphabetized by "Hofstad" and then put the name in bold

I have to use \noopsort often because many Dutch authors write in my field, and by Dutch convention, "van der Hofstad" is alphabetized with "H". See for example https://www.nas.ewi.tudelft.nl/people/Piet/Eigennamen.html (note - there are exceptions to this rule, particularly if the name is actually Belgian)

-

Iterating on the great answer by cgogolin, here is a macro to put in bold multiple authors. I solved the caveat of "Do" ending bold if "Doe" is in the author list by using the package etoolbox that allows to loop over items in a comma separated list.

\usepackage{xstring}
\usepackage{etoolbox}
\newboolean{bold}
\newcommand{\makeauthorsbold}[1]{%
\DeclareNameFormat{author}{%
\setboolean{bold}{false}%
\renewcommand{\do}[1]{\ifstrequal{##1}{####1}{\setboolean{bold}{true}}{}}%
\docsvlist{#1}%
\ifnumequal{\value{listcount}}{1}%
{\ifnumequal{\value{liststop}}{1}%Single author
{\expandafter\ifthenelse{\boolean{bold}}{\textbf{##1\addcomma\addspace ##4\addcomma\isdot}}{##1\addcomma\addspace ##4\addcomma\isdot}}
%first author
{\expandafter\ifthenelse{\boolean{bold}}{\textbf{##1\addcomma\addspace ##4}}{##1\addcomma\addspace ##4}}}
%last author
{\ifnumless{\value{listcount}}{\value{liststop}}
{\expandafter\ifthenelse{\boolean{bold}}{\addcomma\addspace \textbf{##1\addcomma\addspace ##4}}{\addcomma\addspace ##1\addcomma\addspace ##4}}
%middle author
{\expandafter\ifthenelse{\boolean{bold}}{\addcomma\addspace \textbf{##1\addcomma\addspace ##4\addcomma\isdot}}{\addcomma\addspace ##1\addcomma\addspace ##4\addcomma\isdot}}%
}%
}%
}
\makeauthorsbold{Smith,Doe}

-