4

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?

3

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

  • Great! This works out-of-the-box. Thanks for explaining in detail. I was worrying about the newline restriction (I was also expecting this), but my actual use case is in F. LastName format and out of all the bibliography, there is not one problem. – JEuz Mar 20 '17 at 7:16
  • If someone needs this with only the underline, simply suppress the \bfseries from the name:bbold macro. – JEuz Mar 20 '17 at 7:21
  • 1
    Is there a way to make this work with style=apa? – Jasper Habicht Dec 4 '17 at 23:16
  • @JasperHabicht did you figure out how to use this with style=apa? – andreas-h May 17 at 9:16
  • @andreas-h Yes, I somehow managed to solve the problem. But I don’t really remember where the problem was at the time I asked my question … My current code looks very similar to the above. So, I cannot recall what I did in order to solve the problem. Maybe you just open a new question with your concrete problem and we can look into your problem? – Jasper Habicht May 27 at 20:41

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.