[Tex/LaTex] How to underline name of specific authors in biblatex

biberbiblatexcitingulemxpatch

My goal is to underline the name of specific authors in a bibliography processed by biber/biblatex.

I can make them in bold following https://tex.stackexchange.com/a/73246/127979 and https://tex.stackexchange.com/a/274571/127979

Here is a MWE:

\documentclass{article}

\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@inproceedings{boldref, 
  AUTHOR = {InBold, to Put and Author, Non bold  and Highlight, Shine and  Ano, therOne},
  TITLE = {The title},
  BOOKTITLE = {The conference},
  PAGES = {65--78},
  YEAR = 2014}
\end{filecontents}

\usepackage{xpatch}
\usepackage[normalem]{ulem}

\usepackage[backend=biber,bibencoding=utf8,style=numeric-comp,maxbibnames=99]{biblatex}

\addbibresource{\jobname.bib}

\newbibmacro*{name:bbold}[2]{%
  \def\do##1{\iffieldequalstr{hash}{##1}{\bfseries\bgroup \listbreak}{}}%
  \dolistloop{\boldnames}%
}

\newbibmacro*{name:ebold}[2]{%
  \def\do##1{\iffieldequalstr{hash}{##1}{\egroup \listbreak}{}}%
  \dolistloop{\boldnames}%
}

\xpretobibmacro{name:given-family}{\begingroup\usebibmacro{name:bbold}{#1}{#2}}{}{}
\xpretobibmacro{name:delim}{\begingroup\normalfont}{}{}

\xapptobibmacro{name:given-family}{\usebibmacro{name:ebold}{#1}{#2}\endgroup}{}{}
\xapptobibmacro{name:delim}{\endgroup}{}{}

\newcommand*{\boldnames}{}
\forcsvlist{\listadd\boldnames}{
  {4fcd4bca11ef811f3aef17c792b6ef3e}, % InBold
  {01b588ba4e4ad753feae6c81709fc04b}} % Highlight

\begin{document}
\nocite{*}

\printbibliography

\end{document}

But, if I try to underline them, either

  • by replacing the \bfseries by \uline, I get the error:

    ./MWE.tex:47: Extra }, or forgotten \endgroup.
    \UL@stop ... \UL@putbox \fi \else \egroup \egroup 
                                                  \UL@putbox \fi \ifnum   \UL@...l.47 
    
    ./MWE.tex:47: Undefined control sequence.
    \UL@leaders ...L@skip \tw@ \UL@pixel \UL@leadtype 
                                                  \LA@hskip \UL@skip    \LA@hsk...l.47 
    
    ./MWE.tex:47: Missing } inserted. 
    <inserted text> 
                    } 
    
  • by adding \useunder{\uline}{\bfseries}{} before \printbibliography, this results in an error:

    Runaway argument?
    {{\@hangfrom {\hskip \z@ }\interlinepenalty \@M \refname \@@par }\endgroup \ETC.
    ! File ended while scanning use of \UL@on.
    <inserted text> 
                    \par 
    <*> \input MWE.tex
    
    ! Emergency stop.
    <*> \input MWE.tex
    
    !  ==> Fatal error occurred, no output PDF file produced!
    

I suspect that this is related to the need of a \uline{} while {\bf } is sufficient for bold, but I may be missing something.

Is there any way to achieve this? Do I have to patch a style-specific macro like in https://tex.stackexchange.com/a/31202/127979?

Best Answer

Using uline is very difficult. The following solution provides a method which doesn't allow a linebreak at the highlighted author.

Using this you have to remove the following line

\xpretobibmacro{name:given-family}{\begingroup\usebibmacro{name:bbold}{#1}{#2}}{}{}

Therefor your need an other patch which only holds the name.

\xpatchbibmacro{name:given-family}{\usebibmacro{name:delim}{#2#3#1}}{\usebibmacro{name:delim}{#2#3#1}\begingroup\usebibmacro{name:bbold}{#1}{#2}}{}{}

After this you have to save the highlighted name inside a savebox to use \uline later:

\newbox\savenamebox

\newbibmacro*{name:bbold}[2]{%
  \def\do##1{\iffieldequalstr{hash}{##1}{\bfseries\setbox\savenamebox\hbox\bgroup \listbreak}{}}%
  \dolistloop{\boldnames}%
}

\newbibmacro*{name:ebold}[2]{%
  \def\do##1{\iffieldequalstr{hash}{##1}{\egroup\uline{\usebox\savenamebox}\listbreak}{}}%
  \dolistloop{\boldnames}%
}

The complete example is here:

\documentclass{article}

\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@inproceedings{boldref, 
  AUTHOR = {InBold, to Put and Author, Non bold  and Highlight, Shine and  Ano, therOne},
  TITLE = {The title},
  BOOKTITLE = {The conference},
  PAGES = {65--78},
  YEAR = 2014}
\end{filecontents}

\usepackage{xpatch}
\usepackage[normalem]{ulem}

\usepackage[backend=biber,bibencoding=utf8,style=numeric-comp,maxbibnames=99]{biblatex}

\addbibresource{\jobname.bib}

\newbox\savenamebox

\newbibmacro*{name:bbold}[2]{%
  \def\do##1{\iffieldequalstr{hash}{##1}{\bfseries\setbox\savenamebox\hbox\bgroup \listbreak}{}}%
  \dolistloop{\boldnames}%
}

\newbibmacro*{name:ebold}[2]{%
  \def\do##1{\iffieldequalstr{hash}{##1}{\egroup\uline{\usebox\savenamebox}\listbreak}{}}%
  \dolistloop{\boldnames}%
}

\xpatchbibmacro{name:given-family}{\usebibmacro{name:delim}{#2#3#1}}{\usebibmacro{name:delim}{#2#3#1}\begingroup\usebibmacro{name:bbold}{#1}{#2}}{}{}

%\xpretobibmacro{name:given-family}{\begingroup\usebibmacro{name:bbold}{#1}{#2}}{}{}
\xapptobibmacro{name:delim}{\begingroup\normalfont}{}{}

\xapptobibmacro{name:given-family}{\usebibmacro{name:ebold}{#1}{#2}\endgroup}{}{}
\xapptobibmacro{name:delim}{\endgroup}{}{}

\newcommand*{\boldnames}{}
\forcsvlist{\listadd\boldnames}{
  {4fcd4bca11ef811f3aef17c792b6ef3e}, % InBold
  {01b588ba4e4ad753feae6c81709fc04b}} % Highlight

\begin{document}
\nocite{*}

\printbibliography

\end{document}

enter image description here

Related Question