1

I'm trying to compare the content of \partnamefamily of an author's name in biblatex against a manual definition that is stored in another macro, lets call it \family, using \ifdefequal.

So, I have

  • Lastname is found without problem in the comparison
  • Compound~Lastname creates a problem as the ~ is converted to a \bibnamedelima macro that is stored inside. So the name is Compound\bibnamedelima Lastname instead. And that is not the same when doing the definition comparison.

The issue, that I think is happening, is related to the protected macro \bibnamedelima that appears when the name has a non-breaking space (~). If the name has no special delimiter that is handled by biblatex the comparison works fine. However, I can't compare it when that happens. My solutions were

  • Try to expand it, and then compare strings or macros with the expanded \partnamefamily on it. But didn't work. I guess it is due to the protected macro \bibnamedelima.
  • Try to compare the macros by doing a substitution, but that didn't work either.

I searched for a way of expanding macros with protected macros on it (like On unprotecting (expanding) \protected macros (or, "the space after command name") and Expanding arguments before macro call) but didn't help. Also, tried to convert it to string without success.

Is there a way to compare these two macros directly?

Here is an example to show my problem

% !BIB program = biber
\documentclass{article}
\usepackage[backend=biber, giveninits=true]{biblatex}
\begin{filecontents}{\jobname.bib}
@InProceedings{identifier1,
  Title                    = {Some Awesome Title},
  Author                   = {One~Two, Author and Three, Author},
  Booktitle                = {Some Book about the Future},
  Year                     = {2042},
  Pages                    = {1--42}
}
\end{filecontents}
\addbibresource{\jobname.bib}
\newcommand*{\name}[1]{%
  \def\lastname{#1}}
\name{}
\renewcommand{\mkbibnamefamily}[1]{%
  % I have a complex expression here, so I was using the \ifboolexpr
  \ifboolexpr{ test {\ifdefequal{\lastname}{\namepartfamily}} }
  {(F)\mkbibbold{#1}}{(NF)#1}%
}
\begin{document}
\nocite{*}
\name{One~Two}% not found due to ~, as biblatex convert ~ to \bibnamedelima
\printbibliography
\name{One\bibnamedelima Two}% found due to \bibnamedelima instead of ~
\printbibliography
% found as it is not using any delim
\name{Three}
\printbibliography
\end{document}
  • You probably don't want to hear that, but the nicest way to compare names in biblatex (in my opinion) is to use hashes as hinted at by Audrey here and explained in one of my answers here. – moewe Nov 23 '16 at 20:13
  • I saw the hashes, but wanted to have something more readable and easy to use on the text. Is there a way to produce the hash of a given name on the fly? Didn't find info on this. So, I was looking for some trick of expanding the name all the way through the \bibnamedelima and putting it back into a macro, or something in that lines. – adn Nov 23 '16 at 20:23
  • Since Biber produces the hashes I'm not aware of a solution where it is calculated on the fly from within the document. If you insist on comparing namer parts, maybe you need to temporarily redefine all \bibnamedelim...s and do the comparison on expanded macros... But I'm really not sure. – moewe Nov 24 '16 at 6:43
1

You can temporarily redefine \bibnamedelima and ~ to a simple space.

\makeatletter
\renewcommand{\mkbibnamefamily}[1]{%
  \begingroup
    \def\bibnamedelima{ }%
    \def~{ }%
    \edef\adn@tmp@lastname{\lastname}%
    \edef\adn@tmp@namepartfamily{\namepartfamily}%
    % I have a complex expression here, so I was using the \ifboolexpr
    \ifboolexpr{ test {\ifcsequal{adn@tmp@lastname}{adn@tmp@namepartfamily}} }
      {(F)\mkbibbold{#1}}
      {(NF)#1}%
  \endgroup
}
\makeatother

In particular you can now use the easier to digest

\name{One Two}

This is similar to Audrey's answer to Make specific author bold using biblatex, the answer there takes care of more of biblatex's delimiters, but the general idea is the same.

MWE

\documentclass{article}
\usepackage[backend=biber, giveninits=true]{biblatex}
\begin{filecontents}{\jobname.bib}
@InProceedings{identifier1,
  Title                    = {Some Awesome Title},
  Author                   = {One~Two, Author and Three, Author},
  Booktitle                = {Some Book about the Future},
  Year                     = {2042},
  Pages                    = {1--42}
}
\end{filecontents}
\addbibresource{\jobname.bib}
\newcommand*{\name}[1]{%
  \def\lastname{#1}}
\name{}

\makeatletter
\renewcommand{\mkbibnamefamily}[1]{%
  \begingroup
    \def\bibnamedelima{ }%
    \def~{ }%
    \edef\adn@tmp@lastname{\lastname}%
    \edef\adn@tmp@namepartfamily{\namepartfamily}%
    % I have a complex expression here, so I was using the \ifboolexpr
    \ifboolexpr{ test {\ifcsequal{adn@tmp@lastname}{adn@tmp@namepartfamily}} }
      {(F)\mkbibbold{#1}}
      {(NF)#1}%
  \endgroup
}
\makeatother

\begin{document}
\nocite{*}

\name{One~Two}
\printbibliography

\name{One\bibnamedelima Two}
\printbibliography

\name{One Two}
\printbibliography

\name{Three}
\printbibliography
\end{document}

enter image description here

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.