0

I am sure that I overlooked something very obvious. Still, why does the example in this nice answer work, but if I remove the loop, I get an error about a grouping mismatch?

Consider the following minimal non-working example:

\documentclass{article}

\begin{filecontents}{\jobname.bib} @article{testref, author = {Miller, Alice and Highlight, Shine and Smith, Bob}, title = {The title}, journal = {The journal}, 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

% does not work \newbibmacro*{name:bbold}[2]{% \iffieldequalstr{hash}{01b588ba4e4ad753feae6c81709fc04b}% {\bfseries\setbox\savenamebox\hbox\bgroup\listbreak}{}% }

\newbibmacro*{name:ebold}[2]{% \iffieldequalstr{hash}{01b588ba4e4ad753feae6c81709fc04b}% {\egroup\uline{\usebox\savenamebox}\listbreak}{}% } % ===

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

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

\begin{document} \nocite{*}

\printbibliography

\end{document}

The original code has instead

\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}% }

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

This works well. But why is this? Does the loop somehow delay expansion so that the grouping mismatch is irrelevant? How could I get a working example without a loop?

  • 1
    You have \listbreak left-overs from the original code. Try without them. – user691586 Apr 13 '23 at 07:05
  • @user691586 I see, so \listbreak is actually needed to go through the list generated by \forcsvlist, right? Then it makes a lot of sense that this macro should not be part of the macros without the loop! Thank you! – Jasper Habicht Apr 13 '23 at 08:56
  • latexdef -p etoolbox listbreak returns \listbreak: \long macro:#1&-> so it looks like a clean-up thing, I did not check the catcode of the & though. I guess it does what its name indicates, breaking out of a loop and for whatever reason that was needed in the original code you started with. – user691586 Apr 13 '23 at 09:48

1 Answers1

0

The problem, as pointed out in the comments (thanks to user691586), is that I forgot to remove the \listbreak macros from the original code which are somehow used for processing the CSV list and which are not needed here any more. Without these, the code works fine:

\documentclass{article}

\begin{filecontents}{\jobname.bib} @article{testref, author = {Miller, Alice and Highlight, Shine and Smith, Bob}, title = {The title}, journal = {The journal}, 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]{% \iffieldequalstr{hash}{01b588ba4e4ad753feae6c81709fc04b}% {\bfseries\setbox\savenamebox\hbox\bgroup}{}% }

\newbibmacro*{name:ebold}[2]{% \iffieldequalstr{hash}{01b588ba4e4ad753feae6c81709fc04b}% {\egroup\uline{\usebox\savenamebox}}{}% }

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

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

\begin{document} \nocite{*}

\printbibliography

\end{document}

enter image description here