3

I've been trying to figure out a way to automatically highlight my name in the bibliography. I thought that I could just compare first name and \namepartgiven and last name with \namepartfamily, but nothing was highlighted. The stem of the issue seems to be namepartgiven not being the same as the first name that I specified. Originally I thought it was due to \bibnamedelima, but that doesn't seem to be the case. A minimal working example is below.

\begin{filecontents*}{test.bib}
@inproceedings{hattimare2022maruna,
    title        = {Maruna Bot: An Extensible Retrieval-Focused Framework for Task-Oriented Dialogues},
    author       = {Hattimare, Amit and Dharawat, Arkin and Khan, Yelman and Lien, Yen-Chieh and Samarinas, Chris and Wei, George Z. and Yang, Yulin and Zamani, Hamed},
    author+an    = {6=highlight;},
    year         = 2022,
    booktitle    = {Alexa Prize TaskBot Challenge Proceedings},
    url          = {https://www.amazon.science/alexa-prize/proceedings/maruna-bot-an-extensible-retrieval-focused-framework-for-task-oriented-dialogues}
}
\end{filecontents*}

\documentclass{article}

\usepackage[ % BibLaTeX sorting=ydnt, % Sorts entries by year (descending order), name, title style=verbose, doi=false, isbn=true, url=false, eprint=false, backref = false, % include back references in bibliography maxcitenames=3, % affects only the citations in the document body maxbibnames=99, % affects only the bibliography, pass 99 to print all hyperref=true, block=none, backend=biber % {Options: bibtex, biber} ]{biblatex} \usepackage{etoolbox}

\def\bibnamedelima{ }

\makeatletter \newcommand{\name}[2]{\def@firstname{#1}\def@lastname{#2}} \newcommand{\firstname}[1]{\def@firstname{#1}} \newcommand*{\lastname}[1]{\def@lastname{#1}}

\renewcommand*{\mkbibnamefamily}[1]{% \ifboolexpr{ test {\ifdefstrequal{\namepartgiven}{@firstname}} and test {\ifdefstrequal{\namepartfamily}{@lastname}}} {\textbf{#1}}% {#1}% }

\renewcommand*{\mkbibnamegiven}[1]{% \ifboolexpr{ test {\ifdefstrequal{\namepartgiven}{@firstname}} and test {\ifdefstrequal{\namepartfamily}{@lastname}}} {\textbf{#1}}% {#1}% } \makeatother \name{George Z.}{Wei}. % My name should be highlighted, but it isn't???? % I narrowed it down to the first name (\namepartgiven), but not sure why it doesn't work

\addbibresource{test.bib}

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

Could anyone explain to me why this isn't highlighting my name and how to fix it?

  • A cleaner way to do this is by using the annotation feature - see: https://tex.stackexchange.com/questions/73136/make-specific-author-bold-using-biblatex – PLK Aug 23 '22 at 14:55

2 Answers2

2

If you want to do string comparisons on name parts you need to take into account that the backend might apply some post-processing to the name so that it comes out slightly different than expected.

In this case the problem is indeed \bibnamedelima. The solution, however, is not to redefine \bibnamedelima. The solution is to anticipate that it is there and change the comparison string accordingly. This is all discussed in Marijn's answer.

I would like to suggest a slightly more convenient way, though. The approach is discussed in more detail in my answer to Make specific author bold using biblatex. The idea is to have Biber deal with all these name normalisations and input the name on the LaTeX level in the usual format.

\documentclass{article}

\usepackage[ backend=biber, style=verbose, sorting=ydnt, maxcitenames=3, maxbibnames=99, doi=false, isbn=true, url=false, eprint=false, backref = false, block=none, ]{biblatex}

\makeatletter \def\nhblx@bibfile@name{\jobname -nhblx.bib} \newwrite\nhblx@bibfile \immediate\openout\nhblx@bibfile=\nhblx@bibfile@name

\immediate\write\nhblx@bibfile{% @comment{Auto-generated file}\blx@nl}

\newcounter{nhblx@name} \setcounter{nhblx@name}{0}

\newcommand*{\nhblx@writenametobib}[1]{% \stepcounter{nhblx@name}% \edef\nhblx@tmp@nocite{% \noexpand\AfterPreamble{% \noexpand\setbox0\noexpand\vbox{% \noexpand\nhblx@getmethehash{nhblx@name@\the\value{nhblx@name}}}}% }% \nhblx@tmp@nocite \immediate\write\nhblx@bibfile{% @misc{nhblx@name@\the\value{nhblx@name}, author = {\unexpanded{#1}}, % options = {dataonly=true},}% }% }

\AtEndDocument{% \closeout\nhblx@bibfile}

\addbibresource{\nhblx@bibfile@name}

\newcommand*{\nhblx@boldhashes}{} \DeclareNameFormat{nhblx@hashextract}{% \xifinlist{\thefield{hash}}{\nhblx@boldhashes} {} {\listxadd{\nhblx@boldhashes}{\thefield{hash}}}}

\DeclareCiteCommand{\nhblx@getmethehash} {} {\printnames[nhblx@hashextract][1-999]{author}} {} {}

\newcommand{\addboldnames}{\forcsvlist\nhblx@writenametobib} \newcommand{\resetboldnames}{\def\nhblx@boldhashes{}}

\newcommand*{\mkboldifhashinlist}[1]{% \xifinlist{\thefield{hash}}{\nhblx@boldhashes} {\mkbibbold{#1}} {#1}} \makeatother

\DeclareNameWrapperFormat{boldifhashinlist}{% \renewcommand*{\mkbibcompletename}{\mkboldifhashinlist}% #1}

\DeclareNameWrapperAlias{sortname}{default} \DeclareNameWrapperAlias{default}{boldifhashinlist}

\addboldnames{George Z. Wei}

\begin{filecontents}{\jobname.bib} @inproceedings{hattimare2022maruna, title = {Maruna Bot: An Extensible Retrieval-Focused Framework for Task-Oriented Dialogues}, author = {Hattimare, Amit and Dharawat, Arkin and Khan, Yelman and Lien, Yen-Chieh and Samarinas, Chris and Wei, George Z. and Yang, Yulin and Zamani, Hamed}, year = 2022, booktitle = {Alexa Prize TaskBot Challenge Proceedings}, url = {https://www.amazon.science/alexa-prize/proceedings/maruna-bot-an-extensible-retrieval-focused-framework-for-task-oriented-dialogues} } \end{filecontents} \addbibresource{\jobname.bib}

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

"Hattimare, Amit, Arkin Dharawat, Yelman Khan, Yen-Chieh Lien, Chris Samarinas, George Z. Wei, Yulin Yang, and Hamed Zamani. “Maruna Bot: An Extensible Retrieval-Focused Framework for Task-Oriented Dialogues”. In: Alexa Prize TaskBot Challenge Proceedings. 2022." "George Z. Wei" is highlighted in bold.


Note that the solution presented here as well as the solution in Marijn's answer do not use the name annotation author+an = {6=highlight;}, from the original MWE.

If you have already added name annotations to all relevant fields, you can use them as follows without the need for any further name or hash comparisons.

\documentclass{article}

\usepackage[ backend=biber, style=verbose, sorting=ydnt, maxcitenames=3, maxbibnames=99, doi=false, isbn=true, url=false, eprint=false, backref = false, block=none, ]{biblatex}

\newcommand*{\mkboldifhighlight}[1]{% \ifitemannotation{highlight} {\mkbibbold{#1}} {#1}}

\DeclareNameWrapperFormat{boldifhighlight}{% \renewcommand*{\mkbibcompletename}{\mkboldifhighlight}% #1}

\DeclareNameWrapperAlias{sortname}{default} \DeclareNameWrapperAlias{default}{boldifhighlight}

\begin{filecontents}{\jobname.bib} @inproceedings{hattimare2022maruna, title = {Maruna Bot: An Extensible Retrieval-Focused Framework for Task-Oriented Dialogues}, author = {Hattimare, Amit and Dharawat, Arkin and Khan, Yelman and Lien, Yen-Chieh and Samarinas, Chris and Wei, George Z. and Yang, Yulin and Zamani, Hamed}, author+an = {6=highlight;}, year = 2022, booktitle = {Alexa Prize TaskBot Challenge Proceedings}, url = {https://www.amazon.science/alexa-prize/proceedings/maruna-bot-an-extensible-retrieval-focused-framework-for-task-oriented-dialogues} } \end{filecontents} \addbibresource{\jobname.bib}

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

moewe
  • 175,683
  • Thank you for the detailed explanation, however I was looking for something a bit simpler as I already use \name(and consequently \@firstname and \@lastname) in my CV, so @Marijn answer is more suitable in my case. – George Wei Aug 23 '22 at 13:49
1

Biblatex preprocesses the name before assigning it to \namepartgiven. If the name consists of multiple elements (here the first name and an initial) then various formatting commands to handle spaces, periods, hyphens etc. are inserted (see page 122 of the Biblatex manual, section 3.12.1 Generic commands and hooks). Here the name is stored as George\bibnamedelima Z.. The \bibnamedelima macro is defined by default as a space with a high penalty, which means LaTeX will try not to insert a line break at that position.

The easiest solution is therefore to compare directly with this preprocessed string, i.e., keep your MWE as it is and change only

\name{George\bibnamedelima Z.}{Wei}

Result:

enter image description here

To check what happens during preprocessing you can add a debugging line to either of the \mkbibname macro definitions, for example:

\renewcommand*{\mkbibnamegiven}[1]{%
  \typeout{\meaning\namepartgiven}
  \ifboolexpr{ test {\ifdefstrequal{\namepartgiven}{\@firstname}}
               and
               test {\ifdefstrequal{\namepartfamily}{\@lastname}}}
    {\textbf{#1}}%
    {#1}%
}

The added line \typeout{\meaning\namepartgiven} prints (for each name separately) the definition of \namepartgiven to the terminal and log file.

Marijn
  • 37,699