99

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.

7
  • 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, 2011 at 16:12
  • 2
    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. Nov 1, 2011 at 16:56
  • 2
    Do you use bibtex or biblatex?
    – Mico
    Nov 1, 2011 at 16:57
  • Mico: bibtex. Peter: I'll work on that.
    – keflavich
    Nov 1, 2011 at 17:11
  • 3
    cfr: to make it easier for readers to see where you are in the author list. In my field, at least, it makes a big difference if you're first or n'th author, and it can matter (though honestly, probably not...) whether n=2 or n=100
    – keflavich
    Apr 2, 2015 at 8:15

11 Answers 11

48

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}%
}
10
  • 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, 2011 at 22:57
  • 1
    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. Nov 2, 2011 at 10:09
  • 1
    Please see the two notes I've added to my post, since they would not have fitted into the comment field. Nov 2, 2011 at 16:03
  • 2
    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, 2011 at 19:39
  • 1
    @eelke: Add a % at the end of any line not ending with a macro, i.e. after {, } and the #1, or any line for good measure. Line endings will otherwise be turned into a space. I now edited the post to contain them. (I took the liberty to convert your post to a comment here) Dec 22, 2011 at 20:39
40
+100

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.

Update: For biblatex 3.3 and above use the answer by Lawrence Crosby below.

10
  • 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, 2014 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, 2014 at 12:13
  • \makeauthorbold works with non latin script, but \makeauthorsbold doesn't. Any idea why and how to fix it?
    – Theo
    Nov 20, 2015 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, 2015 at 13:40
  • 1
    Thanks for the downvote! I have added a comment to the answer. This is probably more useful for people than a downvote.
    – cgogolin
    Apr 2, 2017 at 17:42
35

As of biblatex 3.3 cgogolin's answer no longer works. This is due to changes in the \DeclareNameFormat macro (see https://github.com/plk/biblatex/issues/372 for a discussion). I was eventually able to modify cgogolin's macro to work, with the following as the solution:

\newcommand{\makeauthorbold}[1]{%
  \DeclareNameFormat{author}{%
    \ifthenelse{\value{listcount}=1}
    {%
      {\expandafter\ifstrequal\expandafter{\namepartfamily}{#1}{\mkbibbold{\namepartfamily\addcomma\addspace \namepartgiveni}}{\namepartfamily\addcomma\addspace \namepartgiveni}}
      %
    }{\ifnumless{\value{listcount}}{\value{liststop}}
        {\expandafter\ifstrequal\expandafter{\namepartfamily}{#1}{\mkbibbold{\addcomma\addspace \namepartfamily\addcomma\addspace \namepartgiveni}}{\addcomma\addspace \namepartfamily\addcomma\addspace \namepartgiveni}}
        {\expandafter\ifstrequal\expandafter{\namepartfamily}{#1}{\mkbibbold{\addcomma\addspace \namepartfamily\addcomma\addspace \namepartgiveni\addcomma\isdot}}{\addcomma\addspace \namepartfamily\addcomma\addspace \namepartgiveni\addcomma\isdot}}%
      }
    \ifthenelse{\value{listcount}<\value{liststop}}
    {\addcomma\space}{}
  }
}

This is my first attempt to write LaTeX macros, so I hope the code style doesn't deviate too far from convention. Hopefully this will help those who are using newer versions of the biblatex package.

(edit: added else block to last ifthenelse)

5
  • 1
    I did try your solution in a small document and everything was working fine. After putting it into a huge document with multiple \include{}-commands it did not work anymore and the error message was not useful for me at all. I suspected, the reason was because I use multiple bibliographies as explained here: tex.stackexchange.com/questions/35279/… . But this was not the case. As soon, as I had the \printbibliography-command in my main file, everything worked again. Does anybody have an idea, what the reason could be?
    – bene
    Apr 16, 2017 at 9:31
  • I tried this solution but it just removed the list of authors in the bibliography :-(. Oct 3, 2017 at 8:47
  • When I want the bibliography to stop listing names after the first 20, using [minbibnames=5, maxbibnames=20], this macro deletes the "et al" part. Nov 23, 2017 at 2:03
  • This macro deletes all the "et al" parts not with maxbibnames=20 but with maxnames=2 also and even without maxnames... It deletes this part anyway as far as I checked (but not sure)
    – koleygr
    Mar 18, 2019 at 18:14
  • 2
    Like cgogolin's answer this suggestion does not take prefixes and suffixes into account. It also drops "et al." handling and hard-codes things that are otherwise customisable. Furthermore the last \ifthenelse misses the <false> branch and produces a weird error in newer biblatex versions (similar in structure to github.com/plk/biblatex/issues/874). tex.stackexchange.com/q/73136/35864 has alternatives that keep underlying biblatex macros alive.
    – moewe
    Mar 19, 2019 at 16:08
26

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.

3
  • 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) Apr 15, 2013 at 11:40
  • 2
    Many fonts don't have bold small caps glyphs, so I guess that's why you can't combine the two styles. Jun 23, 2014 at 13:17
  • 1
    For those preparing a moderncv using IEEE bst files and don't use biblatex tis the way to go, and very EZ. I don't understand how it did but it even automatically accounts for LaTeX accents, for example if your name appears as Ötiker and Otiker differently in a number of documents within your bib fıle, if you just enter define cv.author as Otiker it finds them all! (note that it cannot find the UTF-8 Ötiker, you still have to use {\"O}tiker for tis to work). Brilliant solution!
    – nonKreon
    Dec 25, 2019 at 19:13
13

user2087764's multiauthor case needs to be updated, combining with Lawrence Crosby and Werner's correction:

\usepackage{xstring}
\usepackage{etoolbox}
\newboolean{bold}
\newcommand{\makeauthorsbold}[1]{%
  \DeclareNameFormat{author}{%
  \setboolean{bold}{false}%
    \renewcommand{\do}[1]{\expandafter\ifstrequal\expandafter{\namepartfamily}{####1}{\setboolean{bold}{true}}{}}%
    \docsvlist{#1}%
    \ifthenelse{\value{listcount}=1}
    {%
      {\expandafter\ifthenelse{\boolean{bold}}{\mkbibbold{\namepartfamily\addcomma\addspace \namepartgiveni}}{\namepartfamily\addcomma\addspace \namepartgiveni}}%
    }{\ifnumless{\value{listcount}}{\value{liststop}}
      {\expandafter\ifthenelse{\boolean{bold}}{\mkbibbold{\addcomma\addspace \namepartfamily\addcomma\addspace \namepartgiveni}}{\addcomma\addspace \namepartfamily\addcomma\addspace \namepartgiveni}}%
      {\expandafter\ifthenelse{\boolean{bold}}{\mkbibbold{\addcomma\addspace \namepartfamily\addcomma\addspace \namepartgiveni\addcomma\isdot}}{\addcomma\addspace \namepartfamily\addcomma\addspace \namepartgiveni\addcomma\isdot}}%
      }
    \ifthenelse{\value{listcount}<\value{liststop}}
    {\addcomma\space}{}
  }
}

\makeauthorsbold{Smith,Doe}
1
  • Like cgogolin's answer this suggestion does not take prefixes and suffixes into account. It also drops "et al." handling and hard-codes things that are otherwise customisable. Furthermore the last \ifthenelse misses the <false> branch and produces a weird error in newer biblatex versions (similar in structure to github.com/plk/biblatex/issues/874). tex.stackexchange.com/q/73136/35864 has alternatives that keep underlying biblatex macros alive.
    – moewe
    Mar 19, 2019 at 16:10
9

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)

2
  • In case you are using alpha-style or similar you may need to enclose the first letter a separe bold to theuse it show correly as {\bf L}{\bf astname}, {\bf Firstname.} and Name, Second Dec 12, 2017 at 13:48
  • Great! It seems to work with \bf and not with \textbf.
    – Karlo
    Nov 27, 2020 at 16:04
3

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.

6
  • 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, 2015 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, 2015 at 15:07
  • 3
    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, 2015 at 17:52
  • 2
    (+1) But I think that information would be more useful in your answer ;).
    – cfr
    Apr 3, 2015 at 18:24
  • 1
    Good idea! I've changed the answer to reflect your suggestion.
    – nzh
    Sep 4, 2015 at 15:09
3

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}
1
3

You can try a simple search and replace it as \textbf{A. Name} in your BibTeX file as below I have to bold the first author named Prateek Raj Gautam

in BibTeX entry, it is written as Gautam, Prateek Raj or some times as P. R. Gautam

and in the final output it is shown as P. R. Gautam so take this name and enclose it in \textbf{} as\textbf{P. R. Gautam}

original BibTeX entry

@article{Gautam2019,
author = {P. R. Gautam and Kumar, Sunil and Verma, Akshay and Rashid, Tarique and Kumar, Arvind},
    doi = {10.1109/TII.2019.2908437},
    journal = {IEEE Transactions on Industrial Informatics},
    number = {11},
    pages = {5827--5836},
    publisher = {IEEE},
    title = {Energy-Efficient Localization of Sensor Nodes in WSNs Using Beacons From Rotating},
    volume = {15},
    year = {2019}
    }

edited BibTeX entry

@article{Gautam2019,
    author = {\textbf{P. R. Gautam} and Kumar, Sunil and Verma, Akshay and Rashid, Tarique and Kumar, Arvind},
    doi = {10.1109/TII.2019.2908437},
    journal = {IEEE Transactions on Industrial Informatics},
    number = {11},
    pages = {5827--5836},
    publisher = {IEEE},
    title = {Energy-Efficient Localization of Sensor Nodes in WSNs Using Beacons From Rotating},
    volume = {15},
    year = {2019}
    }

for me, it works like charm no fuzz with bst file or complex macro needed

1
  • I was hoping something like this would work! This is by far easier than learning biblatex and/or hacking macros, .bst styles (which, e.g. on Overleaf, are not easy to supplant?). You're using your initials, but your friends can do this: (...) and \textbf{Kumar}, \textbf{Sunil} and (...). Aug 12, 2022 at 19:25
1

the following solution worked with biblatex while I automatically imported the references from Mendeley to the overleaf:

\usepackage{biblatex}
\addbibresource{References.bib} % your bibliography file


\DeclareSourcemap{
  \maps[datatype=bibtex]{
    \map{
      \step[fieldsource=author,
            match=\regexp{LastName,\sFirstName},
            replace=\regexp{\\textbf{FirstName} \\space \\textbf{LastName}}]
    }
  }
}
0

Modified Lawrence Crosby's answer, which matches names only based on the family name. And I also simplified the code to make it easier to modify and extend

\newcommand{\mynameformat}{\namepartfamily\addcomma\addspace \namepartgiveni}
\DeclareDelimFormat{andothersdelim}{et al.}
\newcommand{\makeauthorbold}[2]{
  \DeclareNameFormat{author}{
    \ifthenelse{\equal{\namepartfamily}{#1} \AND \equal{\namepartgiven}{#2}}
    {\mkbibbold{\mynameformat}}
    {\mynameformat}
    \ifthenelse{\value{listcount}<\value{liststop}}
    {\multinamedelim}
    {\ifmorenames{\andothersdelim}{}}
  }
}

To make author bold, add the following command

\makeauthorbold{Doe}{John}
1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .