3

I'm having a problem with related entries in biblatex when they are started within parentheses.

\begrelateddelim is inserted after the first field in the related entry, since it isn't included at the beginning of the related entry in this case.

So the following MWE places a semi-colon after the author in the related entry. i.e.,

[1] Author1. Title1. 2017 (Author2; Title2. 2018).

The desired output is:

[1] Author1. Title1. 2017 (Author2. Title2. 2018).

MWE

\documentclass{article}
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@book{book1,
  author = {Author1},
  title = {Title1},
  volume = {2},
  date = {2017},
  related = {book2}
}
@book{book2,
  author = {Author2},
  title = {Title2},
  date = {2018}
}
\end{filecontents}
\usepackage{biblatex}
\addbibresource{\jobname.bib}
\renewcommand*{\begrelateddelim}{\addsemicolon\space}
\DeclareBibliographyDriver{book}{%
  \usebibmacro{begentry}%
  \printnames{author}%
  \newunit
  \printfield{title}%
  \newunit
  \printdate
  \setunit{\addspace}%
  \iftoggle{bbx:related}
    {\togglefalse{bbx:related}%
     \printtext[parens]{%
       \usebibmacro{related:init}%
       \usebibmacro{related}}}
    {}%
  \usebibmacro{finentry}}
\begin{document}
\nocite{book1}
\printbibliography
\end{document}
3
  • 1
    Indeed, the related macro makes use of \printunit{\begrelateddelim}. The "first level" approach would be to patch the macro and substitute it for \setunit, but there's probably a reason for \printunit there...
    – gusbrs
    Commented May 18, 2018 at 1:33
  • Yup, short of the above (untested, and likely unwise) idea, I also cannot untie the knot.
    – gusbrs
    Commented May 18, 2018 at 2:02
  • @gusbrs, thanks. I'll wait and see what moewe has to say before patching the related macro. Commented May 18, 2018 at 2:46

1 Answer 1

2

I suggest you use the field format related or related:<relatedtype>. Additionally I redefined \begrelateddelim to be \addspace because I could not see where the semicolon should enter the equation here.

\documentclass{article}
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@book{book1,
  author = {Author1},
  title = {Title1},
  volume = {2},
  date = {2017},
  related = {book2}
}
@book{book2,
  author = {Author2},
  title = {Title2},
  date = {2018}
}
\end{filecontents}
\usepackage{biblatex}
\addbibresource{\jobname.bib}
\renewcommand*{\begrelateddelim}{\addspace}
\DeclareFieldFormat{related}{\mkbibparens{#1}}

\DeclareBibliographyDriver{book}{%
  \usebibmacro{begentry}%
  \printnames{author}%
  \newunit
  \printfield{title}%
  \newunit
  \printdate
  \newunit\newblock
  \iftoggle{bbx:related}
    {\usebibmacro{related:init}%
     \usebibmacro{related}}
    {}%
  \usebibmacro{finentry}}

\begin{document}
\nocite{book1}
\printbibliography
\end{document}

enter image description here

You'll find that the related block has exactly the same form as in the standard drivers and that the \togglefalse{bbx:related} is not needed any more.


So what was the problem about?

It is mainly caused by

 \printtext[parens]{%
   \usebibmacro{related:init}%
   \usebibmacro{related}}

Internally \usebibmacro{related} also calls a \printtext (the one whose format we define with \DeclareFieldFormat{related}{\mkbibparens{#1}} or \DeclareFieldFormat{related:<relatedtype>}{\mkbibparens{#1}}). Additionally, \usebibmacro{related} also sets the \begrelateddelim in a printunit before it starts the \printtext. So we end up with

\printtext[parens]{%
  \printunit{\begrelateddelim}%
  \printtext[related]{%
    ...
  }%
}%

Because nothing is printed in between the two \printtext statements, the punctuation buffer survives into the second \printtext. You can see the same effect with

\printtext[parens]{%
  \printunit{\addperiod\space}%
  \printtext[related]{%
    \printtext{foo}%
    \setunit{\addcomma\space}%
    \printtext{goo}}}%

The first \printtext[parens] prints and flushes the punctuation tracker before it. Then \addperiod\space is added to the tracker with \printunit. Now \printtext[related] prints, but for the punctuation tracker nothing was printed before it. Hence, \addperiod\space survives and even overrides the \addcomma\space later on.


Note that

 \printtext[parens]{%
   \usebibmacro{related:init}%
   \usebibmacro{related}}

has another problem: It doesn't check if there is a related entry at all. So it will print empty parentheses in that case (cite book2 to see the problem). The \togglefalse{bbx:related} could only remedy this if book2 was printed as a related entry of book2, but not if it is printed in its own right. \usebibmacro{related} has the checks necessary to avoid this built in already.

7
  • That all said, I'm not sure if we really need a \printunit here anyway, a \setunit could be enough (if no one issued a \printunit before)....
    – moewe
    Commented May 18, 2018 at 8:38
  • You make it look simple. :) +1 It actually still took me quite some time to understand, even after you explained, that \printtext[\bbx@tempa]{% was doing \printtext[related]{%...
    – gusbrs
    Commented May 18, 2018 at 9:53
  • Useful. But sadly my MWE is too simple :(. I actually have more than just the related entry within the parentheses. I use it for particularly complex reference types in biblatex-sbl. The semicolon was simply something other than \newunitpunct in this MWE. I'll close this off and make a more complex MWE in a new question. Commented May 18, 2018 at 10:14
  • @DavidPurton In this case, wouldn't the begrelatedloop and endrelatedloop macros be useful? They are defined empty by default, but may provide the hooks you need.
    – gusbrs
    Commented May 18, 2018 at 11:35
  • 1
    @DavidPurton Ah, great to hear that! But that's just testimony of how carefully crafted biblatex is. ;) The hook is there, even though it is not used, but because it "might be needed". Someone has thought of you!
    – gusbrs
    Commented May 19, 2018 at 1:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .