1

I want to be able to define a list of authors in a command and highlight them in the bibliography or citations. I am using biblatex with my latex document (I have not been able to update my OS lately and I am using Package: biblatex 2013/11/25 v2.8a programmable bibliographies (PK/JW/AB)).

So far I have been able to create a new macro that is called each time the names of the authors are printed. However, when I compare the author last name and first name with the values that I defined using \newcommand, I always get the evaluation to false in the if statement. Here is what I got so far (inspired by a combination of [1], [2] and [3]) :

\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{color}
\usepackage[backend=biber,bibencoding=utf8,style=numeric-comp,maxbibnames=99,firstinits=true]{biblatex}

\addbibresource{\jobname.bib}


\newcommand{\authorgivenname}{t. P.} 
\newcommand{\authorfamilyname}{InBold} 
\newcommand{\authorbibname}{\authorfamilyname, \authorgivenname} 

\newbibmacro*{name:emph}[2]{%
    First arugment: #1 =? \authorfamilyname \\
    Second argument: #2 =? \authorgivenname \\
    \ifstrequal{#2}{\authorgivenname}
    {
        \textcolor{green}{Evaluated to true: #1, #2} \\
    }
    {
        \textcolor{red}{Evaluated to false: #1, #2} \\
    }
}

\xpretobibmacro{name:last}{\begingroup\usebibmacro{name:emph}{#1}{#2}}{}{}
\xpretobibmacro{name:first-last}{\begingroup\usebibmacro{name:emph}{#1}{#2}}{}{}
\xpretobibmacro{name:last-first}{\begingroup\usebibmacro{name:emph}{#1}{#2}}{}{}    
\xpretobibmacro{name:delim}{\begingroup\normalfont}{}{}    

\xapptobibmacro{name:last}{\endgroup}{}{}
\xapptobibmacro{name:first-last}{\endgroup}{}{}
\xapptobibmacro{name:last-first}{\endgroup}{}{}    
\xapptobibmacro{name:delim}{\endgroup}{}{} 


\begin{document}
\nocite{*}

\noindent\fullcite{boldref}

\end{document}

If I get this code to work, the idea is that I will change \textcolor{green}{Evaluated to true: #1, #2} to \bfseries and the author name will be in bold font. I suspect that this has to do with when each element is expanded. Am I right? How can I fix it? Moreover, how can I extend it to compare with a list of elements rather than just one author?

I also noted that the variables #1 and #2 are already processed by some other macro when the macro name:emph is called and give the abbreviated name (if it is requested in the configuration of biblatex). This means that I would have to declare different authors names depending on the configuration of firstinits option in biblatex.

Thank you very much.

P.S.: I have read other options that add elements to the bibliography entries ([1] or [4]) but I do not want that as I automatically generate my bibliography files (.bib) with programs that do not support adding fields. I have also tried to build on top of [5] but I cannot even get to compile that example.

0
2

There are several problems here. The first is that your code uses the old name format with first and last, biblatex has been using given and family instead for two years now Biblatex 3.3 name formatting.

So you need

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

\xapptobibmacro{name:family}{\endgroup}{}{}
\xapptobibmacro{name:given-family}{\endgroup}{}{}
\xapptobibmacro{name:family-given}{\endgroup}{}{}    
\xapptobibmacro{name:delim}{\endgroup}{}{} 

The second problem is with \ifstrequal{#2}{\authorgivenname} in name:emph. What you actually need is \ifdefstrequal. \ifstrequal compares its two arguments as strings directly and does not expand anything. So \ifstrequal{hallo}{hallo} is true, but \def\hallo{hallo} \ifstrequal{\hallo}{hallo} is not true. \authorgivenname is already a macro and #2 will ultimately be the macro \namepartgiven, so what we compare two macros here. This is done with \ifdefstrequal.

Your third problem is that the first name initials of InBold, to Put are not actually t. P., they are t\bibinitperiod\bibinitdelim P\bibinitperiod. So

\newcommand{\authorgivenname}{t\bibinitperiod\bibinitdelim P\bibinitperiod} 

works. Alternatively, you would have to 'normalise' these commands for the name comparison as shown in Audrey's answer to Make specific author bold using biblatex.

In full

\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{color}
\usepackage[backend=biber,bibencoding=utf8,style=numeric-comp,maxbibnames=99,firstinits=true]{biblatex}

\addbibresource{\jobname.bib}

\newcommand{\authorgivenname}{t\bibinitperiod\bibinitdelim P\bibinitperiod} 
\newcommand{\authorfamilyname}{InBold} 
\newcommand{\authorbibname}{\authorfamilyname, \authorgivenname} 

\newbibmacro*{name:emph}[2]{%
    First arugment: #1 =? \authorfamilyname \\
    Second argument: #2 =? \authorgivenname \\
    \ifdefstrequal{\authorgivenname}{#2}
    {
        \textcolor{green}{Evaluated to true: #1, #2} \\
    }
    {
        \textcolor{red}{Evaluated to false: #1, #2} \\
    }
}

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

\xapptobibmacro{name:family}{\endgroup}{}{}
\xapptobibmacro{name:given-family}{\endgroup}{}{}
\xapptobibmacro{name:family-given}{\endgroup}{}{}    
\xapptobibmacro{name:delim}{\endgroup}{}{} 


\begin{document}
\def\hallo{hallo}
\ifstrequal{\hallo}{hallo}{a}{b}

\nocite{*}
\noindent\fullcite{boldref}
\end{document}

As it turns out your biblatex is more than four years old now. You don't need to worry about the new name format in that case and can stick with

\xpretobibmacro{name:last}{\begingroup\usebibmacro{name:emph}{#1}{#2}}{}{}
\xpretobibmacro{name:first-last}{\begingroup\usebibmacro{name:emph}{#1}{#2}}{}{}
\xpretobibmacro{name:last-first}{\begingroup\usebibmacro{name:emph}{#1}{#2}}{}{}    
\xpretobibmacro{name:delim}{\begingroup\normalfont}{}{}    

\xapptobibmacro{name:last}{\endgroup}{}{}
\xapptobibmacro{name:first-last}{\endgroup}{}{}
\xapptobibmacro{name:last-first}{\endgroup}{}{}    
\xapptobibmacro{name:delim}{\endgroup}{}{} 

In that old version the #2 in \ifstrequal{#2}{\authorgivenname} was not a macro but a string, \authorgivenname is still a macro, though, so you should try

\ifdefstring{\authorgivenname}{#2}

for the comparison.


Instead of this solution I would recommend you try my answer to Make specific author bold using biblatex instead. The advantage is that you can input a name as you would in the .bib file and that the answer responds to giveninits automatically.

4
  • Thank you for such a detailed explanation. I will have a look at all this information to see if I solve this. If I do you'll get upvote and accepted. However, I want to point out that I might be using an old version of biblatex as the commands you pointe out that changed (given-family instead of first-last) do no work for me. – apalomer Apr 14 '18 at 15:35
  • I confirm that I am using a quite old version: Package: biblatex 2013/11/25 v2.8a programmable bibliographies (PK/JW/AB) – apalomer Apr 14 '18 at 15:39
  • @apalomer Ah, well that is an ancient version. Things are different there. Try tex.stackexchange.com/a/416416/35864 – moewe Apr 14 '18 at 15:43
  • Thank you very much. The \ifdefstring{\authorgivenname}{#2} was the solution!! Moreover, I think this answer is a very good answer as it gives a lot of options and references to other good answers. I keep this for when I update the biblatex (as I assume it will stop working). – apalomer Apr 14 '18 at 16:13

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.