9

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?

JEuz
  • 97

2 Answers2

7

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

Marco Daniel
  • 95,681
  • 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 07:16
  • If someone needs this with only the underline, simply suppress the \bfseries from the name:bbold macro. – JEuz Mar 20 '17 at 07:21
  • 1
    Is there a way to make this work with style=apa? – Jasper Habicht Dec 04 '17 at 23:16
  • @JasperHabicht did you figure out how to use this with style=apa? – andreas-h May 17 '19 at 09: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 '19 at 20:41
0

To answer the question as to how to do this with style=apa: You just need to patch different bibmacros than in Marco Daniel’s great answer. The following setup should only underline a specific author's name if it is not at the first position:

\documentclass{article}

\usepackage{filecontents} \begin{filecontents}{\jobname.bib}

@inproceedings{ref01, AUTHOR = {Bloggs, Fred and Doe, John and Highlight, Shine}, TITLE = {First Marvellous Paper}, BOOKTITLE = {Amazing Book}, PAGES = {11--111}, YEAR = 2020}

@inproceedings{ref02, AUTHOR = {Highlight, Shine and Doe, John and Bloggs, Fred}, TITLE = {Second Marvellous Paper}, BOOKTITLE = {Amazing Book}, PAGES = {111--211}, YEAR = 2020}

\end{filecontents}

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

\usepackage{doi} \usepackage[backend=biber, style=apa, sortlocale=en_GB, sorting=ydnt, natbib=true, doi=true, bibencoding=latin1, defernumbers=true]{biblatex} \DeclareLanguageMapping{english}{english-apa}

\addbibresource{\jobname.bib}

\newbox\savenamebox

\newcount\emphcount \emphcount 0\relax

\newbibmacro*{name:bemph}[2]{% \ifnum\emphcount>0% \def\do##1{\iffieldequalstr{hash}{##1}{\setbox\savenamebox\hbox\bgroup \listbreak}{}}% \dolistloop{\emphnames}% \fi% }

\newbibmacro*{name:eemph}[2]{% \ifnum\emphcount>0% \ifthenelse{\value{listcount}=\value{listtotal}}% {\def\do##1{\iffieldequalstr{hash}{##1}{\egroup\uline{\usebox\savenamebox}\nopunct\listbreak}{}}% \dolistloop{\emphnames}\emphcount -1\relax}% {\def\do##1{\iffieldequalstr{hash}{##1}{\egroup\uline{\usebox\savenamebox}\listbreak}{}}% \dolistloop{\emphnames}}% \else% \ifthenelse{\value{listcount}=\value{listtotal}}% {\emphcount -1\relax}{}% \fi% \global\advance\emphcount 1\relax% }

\xpatchbibmacro{name:apa:family-given}{\usebibmacro{name:delim:apa:family-given}{#4#1}}{\usebibmacro{name:delim:apa:family-given}{#4#1}\begingroup\usebibmacro{name:bemph}{#1}{#2}}{}{} \xapptobibmacro{name:delim}{\begingroup\normalfont}{}{}

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

\newcommand*{\emphnames}{} \forcsvlist{\listadd\emphnames}{ {01b588ba4e4ad753feae6c81709fc04b}% }

\begin{document} \nocite{*}

\printbibliography

\end{document}

Output (compiled with LuaLaTeX and Biber):

enter image description here


Edit

The file apa.bbx has been changed over time. As of today (April 2023), the lines for patching in the above MWE need to be replaced by something like this:

\xpatchbibmacro{name:apa:family-given}{%
    \usebibmacro{name:hook}{#4#1}%
}{%
    \usebibmacro{name:hook}{#4#1}\begingroup\usebibmacro{name:bemph}{#1}{#2}%
}{}{}

\xpatchbibmacro{name:apa:family-given}{% \usebibmacro{name:hook}{#1}% }{% \usebibmacro{name:hook}{#1}\begingroup\usebibmacro{name:bemph}{#1}{#2}% }{}{}

\xpatchbibmacro{name:apa:family-given}{% \ifdefvoid{#5}{}{% \toggletrue{apablx@wantcomma}% \addcomma\bibnamedelimd\mkbibnamesuffix{#5}\isdot% }% }{% \ifdefvoid{#5}{}{% \toggletrue{apablx@wantcomma}% \addcomma\bibnamedelimd\mkbibnamesuffix{#5}\isdot% }% \usebibmacro{name:eemph}{#1}{#2}\endgroup% }{}{}