29

For several documents I'm preparing, I need to highlight (or underline) occurences of my name within the bibliography.

Is there an easy way of doing this?

  • 2
    The title is not consistent with the body of the question: do you want to highlight, or to underline? – Clément Oct 4 '17 at 2:05
25

It depends on how you prepare the bibliography. If you are preparing it with BibTeX, you can use a trick I mentioned earlier today, which requires you change the .bib files; this definition should go in the .tex file

\newcommand{\myname}[1]{\textit{Wurm, Y.}}

and an entry in the .bib file will have

author={{\myname{wurm}} and Zauthor, X.}

However this depends also on how you want the names displayed in the bibliography.

If you don't want to act on the bib files, a different approach might work:

\usepackage{xstring}

\let\originalbibitem\bibitem
\def\bibitem#1#2\par{%
  \noexpandarg
  \originalbibitem{#1}
  \StrSubstitute{#2}{Wurm}{\textit{Wurm}}\par}

This exploits the fact that BibTeX separates each \bibitem entry with empty lines. A different redefinition of \bibitem must be done if you use the abbrv bibstyle instead of plain.

For biblatex the situation is more involved; I got something with

\usepackage{xstring}
\noexpandarg\exploregroups
\makeatletter
\let\orig@blx@bbl@entry\blx@bbl@entry
\def\blx@bbl@entry#1\endentry{%
  \StrSubstitute{#1}{Wurm}{\textit{Wurm}}[\Result]%
  \expandafter\orig@blx@bbl@entry\Result\endentry}
\makeatother

for the standard style; but I don't know if there are side effects. Probably acting as Alan Munn suggested in a comment is best.

  • 1
    thanks for the quick reply greg. However, I was hoping to be able to only change something in my .tex file. Messing with .bib file (which may require having multiple copies) is something I would like to avoid... – Yannick Wurm May 20 '11 at 11:30
  • @Yannick: see the edit – egreg May 20 '11 at 11:58
  • 1
    Is there a biber/biblatex solution? – Raphael May 20 '11 at 12:07
  • 7
    The accepted answer to this question: Pass variable from LaTeX to bibtex (for easy anonymization)? gives you another way take on the multiple bibfile: you make your name a variable in the bib file and then alias it to a command. So you don't really have multiple bib files, just one line for the special formatting, and the other for not. – Alan Munn May 20 '11 at 12:42
  • Thanks for all the replies. Problem with having a different bib file with different formatting is that the formatting will be applied in the main text as well, not only in the bibliography. (I want my name to be highlighted only in the list of references)... – Yannick Wurm May 21 '11 at 13:39
12

If you are using biblatex you can override the formatting of the list of authors:

\usepackage[normalem]{ulem} %for \uline

\DeclareNameFormat{author}{%
\ifthenelse{\equal{#1}{YourLastName}}%
    {\uline{\ifblank{#4}{}{#4\space}#1}}%
    {\ifblank{#4}{}{#4\space}#1}%
\ifthenelse{\value{listcount}<\value{liststop}}%
    {\addcomma\space}
    {}}

This of course means you have to reproduce formatting of the backend you are using but it allows you to e.g. underline your initials and last name together[1]. The example above is fairly basic (for example it doesn't care about inserting "et al." or "and" as required by some guidelines).

[1] I might be wrong here (I couldn't make the attached example to work) but it seems to me that egreg's solution works at .bbl file level, where initials, first and last names are still kept separately.


(edit)

Below is a redefined default name formatting macro (based on definition of a name:first-last macro from a biblatex.def file). I'm sorry for my poor coding style. If someone could show me how to properly restructure this macro (to avoid repetition) that would be great.

\usepackage[normalem]{ulem} %for \uline

\renewbibmacro*{name:first-last}[4]{%
  \usebibmacro{name:delim}{#2#3#1}%
  \usebibmacro{name:hook}{#2#3#1}%
  \ifthenelse{\equal{#1}{YourLastName}}% matches last name against YourLastName
    {
      \uline{% wrapped with \uline
      \ifblank{#2}{}{\mkbibnamefirst{#2}\isdot\bibnamedelimd}%
      \ifblank{#3}{}{%
        \mkbibnameprefix{#3}\isdot%
        \ifpunctmark{'}%
          {}%
          {\ifuseprefix{\bibnamedelimc}{\bibnamedelimd}}}%
      \mkbibnamelast{#1}\isdot%
      \ifblank{#4}{}{\bibnamedelimd\mkbibnameaffix{#4}\isdot}}}%
    {% original
      \ifblank{#2}{}{\mkbibnamefirst{#2}\isdot\bibnamedelimd}%
      \ifblank{#3}{}{%
        \mkbibnameprefix{#3}\isdot%
        \ifpunctmark{'}%
          {}%
          {\ifuseprefix{\bibnamedelimc}{\bibnamedelimd}}}%
      \mkbibnamelast{#1}\isdot%
      \ifblank{#4}{}{\bibnamedelimd\mkbibnameaffix{#4}\isdot}}}
  • 2
    While this is an old post, I have recently noticed that the format in biblatex (see the release notes for version 3.3). In particular, when using DeclareNameFormat, one should add \nameparts{#1} at the beginning of its definition and use \namepartXXXX instead of the numbered arguments #2 and so on as detailed in the release notes. – Egon Apr 4 '16 at 9:43
3

I am using Mendeley to manage my references. It can output a bibtex file but LaTeX has problems with lines that are too long (abstracts). I use a simple shell script to strip abstracts in a new .bib file, and following egreg's advice, included the {\myname{wurm}} change to the .bib file. I am also using the bibliography style ieeetr and my name is underlined as expected.

For me, the shell script contains:

sed "/^abstract/d" library.bib | sed "s|Hurvitz, P. M.|{\\\myname{hurvitz}}|" > library_noabstract.bib

and in my .tex file:

\usepackage[normalem]{ulem}
\newcommand{\myname}[1]{\uline{P. M. Hurvitz}}
2

I was using the answer by @Andrzej until recently; I think the problem developed when moving from TeX Live 2016 to 2017. As @Egon has pointed out, this may no longer be valid in newer versions of biblatex.

Following a look at biblatex.def I have modified \DeclcareNameFormat as below. This works well enough for my purposes, but I'm sure could be improved further:

\documentclass{article}
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
 @article{boldref, 
  AUTHOR = {Adam myLastName and Ben Bravo and Charlie Charlie and David Delta},
  TITLE = {The title},
  JOURNAL = {Journal of Examples},
  PAGES = {65--78},
  YEAR = 2017}
\end{filecontents}
\usepackage[backend=bibtex, bibstyle=numeric-verb, maxnames=99,
           block=space, firstinits=true, terseinits=true]{biblatex}
\addbibresource{\jobname.bib}
\usepackage[normalem]{ulem} %for \uline{}
\DeclareNameFormat{given-family}{
  \ifgiveninits
  {\ifthenelse{\equal{\namepartfamily}{myLastName}}
    {\uline{\namepartfamily\addspace\namepartgiveni\namepartsuffix}}
    {\namepartfamily\addspace\namepartgiveni\namepartsuffix}
    \ifthenelse{\value{listcount} < \value{liststop}}
    {\addcomma}
    {\ifthenelse{\ifmorenames}{~et \,al \adddot}}
    {}
  }
}

\begin{document}
\nocite{*}
\printbibliography
\end{document}

giving:

enter image description here

This is with BibTeX, Version 0.99d (TeX Live 2017)

1

An arguably simple answer is to use strings and mkbibbold (or, alternatively, \mkbibemph or \mkbibitalic)

\documentclass{article}
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
    @string{myself={\mkbibbold{MyLastName}, \mkbibbold{MyFirstName}}}
    @article{boldref, 
        author = {Bravo, Ben and Charlie, Charlie and }#myself,
        TITLE = {The title},
        JOURNAL = {Journal of Examples},
        PAGES = {65--78},
        YEAR = 2017}
\end{filecontents}
\usepackage[backend=bibtex]{biblatex}
\addbibresource{\jobname.bib}
\begin{document}
    \nocite{*}
    \printbibliography
\end{document}

enter image description here

On top of being a concise way to achieve what you want, it is also very portable: just redefine the string myself to come back to a normal behaviour, i.e., use

@string{myself={MyLastName, MyFirstName}}

And your name will be printed normally.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.