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?
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?
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.
Smith by \textit{Smith} and Harrison by \textit{Harrison}.
– alfC
Feb 20 '19 at 11:08
StrSubstitute after the other or nest and didn't work (didn't replace anything).
– alfC
Feb 20 '19 at 12:35
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}}}
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 04 '16 at 09:43
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}}
\newcommand{\myname}[1]{\uline{#1}} would be the more general option.
– e9t
Dec 12 '15 at 07:17
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:
This is with BibTeX, Version 0.99d (TeX Live 2017)
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}
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.
Another option is to add this functionality to the .bst file. I define one simple function with the surnames of those whom I want to bold, and another function to check if a name is in the surname list. Here is the code.
FUNCTION{ boldees }{ "Jones and Smith" }
INTEGERS { boldptr np }
% determine if a name should be bolded
% simply modify the boldees string to change the names
%
% pops: <author last name>
% pushes: 1 iff name is to be bolded, 0 o.w.
FUNCTION { bold.names }
{
#1 'boldptr :=
{ boldees num.names$ #1 + boldptr > } %do while boldptr <= #boldees
{ duplicate$ %duplicate name to check since it gets popped
boldees boldptr "{ll}" format.name$ %extract and format the name of a boldee
= %author match boldee name?
{ boldees num.names$ #2 + 'boldptr := } %true->exit with counter set > #bolded names
{ boldptr #1 + 'boldptr := } %false->increment boldee name to extract
if$ %is this a name to bold?
}
while$ %loop through bolded name list
pop$ %get rid of the extra instance of the name to check
boldptr #1 - boldees num.names$ = %check counter value of exit condition
{ #0 }
{ #1 }
if$
}
and then in format.names
bold.names
{s nameptr "{{\bf\bgroup}f. {\egroup}}{vv~}{{\bf\bgroup}ll{}{\egroup}}" format.name$ 't := }
{s nameptr "{f. }{vv~}{ll}{, jj}" format.name$ 't := }
if$