2

I have a minor issue with biblatex and punctuation, when a field, say author, may be empty. I would like to insert a comma instead that a period, when author is defined, but I fail to do so without to insert a comma even when author is empty.

So I have

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}  
\usepackage[american,italian]{babel}
\usepackage[italian]{babel}
\usepackage[babel,italian=guillemets]{csquotes}

\usepackage[style=mario-standard,defernumbers=true,sorting=ynt,maxbibnames=99]{biblatex}
\addbibresource{min.bib}

\begin{document}
\noindent 
\cite{*}

\defbibnote{A}{Group A}
\defbibnote{B}{Group B}

\newrefcontext[labelprefix={A-}]
\printbibliography[prenote={A}, keyword=A] 
\newrefcontext[labelprefix={B-}]
\printbibliography[prenote={B}, keyword=B] 
\end{document}

min.bib file is

@Book{AAA,
%author = {NO Author},
label = {MM},
title = {aaa},
publisher = {book pub},
location = {myTown},
year = {2020},
 keywords = {A}
}

@Book{BBB,
author = {mario myself},
title = {bbb},
publisher = {book pub},
location = {myTown},
year = {2020},
 keywords = {B}
}

I use a custom .bbx file, where \DeclareBibliographyDriver{book} is defined as:

\DeclareBibliographyDriver{book}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{author/editor+others/translator+others}%
  \setunit{\labelnamepunct}\newblock
  \usebibmacro{maintitle+title}%
  \iffieldundef{note}{
    \newunit\newblock}{
    \printfield{note}
    }
  \newunit
  \printlist{language}
  \newunit\newblock
  \usebibmacro{byauthor}
  \newunit\newblock
  \usebibmacro{byeditor+others}
  \newunit\newblock
  \printfield{howpublished}%
  \setunit{\bibpagerefpunct}\subtitlepunct\newblock
  \printfield{edition}%
  \newunit
  \iffieldundef{maintitle}
    {\printfield{volume}%
     \printfield{part}}
    {}%
  \newunit
  \printfield{volumes}%
  \newunit\newblock
  \usebibmacro{series+number}%
  \newunit\newblock
  \usebibmacro{publisher+location+date}%
  \newunit\newblock
  \usebibmacro{chapter+pages}%
  \newunit
  \printfield{pagetotal}%
  \newunit\newblock
  \iftoggle{bbx:isbn}
    {\printfield{isbn}}
    {}%
  \newunit\newblock
  \usebibmacro{doi+eprint+url}%
  \newunit\newblock
  \usebibmacro{addendum+pubstate}%
  \setunit{\bibpagerefpunct}\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \iftoggle{bbx:related}
    {\usebibmacro{related:init}%
     \usebibmacro{related}}
    {}
  \usebibmacro{finentry}}

The question is: how to hack \DeclareBibliographyDriver{book} to get a comma after the author just in case author is defined. Thks.

enter image description here

  • 2
    \renewcommand*{\labelnamepunct}{\addcomma\space} should be enough. – moewe Dec 8 '17 at 11:44
  • It seems it works. Thanks. How/where do I renew the command just for the Book case? – mario Dec 8 '17 at 14:41
  • Do you really want that? That would make things a tad inconsistent. Two possible solutions: \renewcommand*{\labelnamepunct}{\ifentrytype{book}{\addcomma\space}{\newunitpunct}}. Or you change the \setunit{\labelnamepunct} in the @book driver to \setunit{\addcomma\space} – moewe Dec 8 '17 at 14:43
3

biblatex has its punctuation tracker to make sure not to print punctuation when it is not needed (for example, if a field is missing/empty). You can read up on the punctuation tracker in §4.11.7 Using the Punctuation Tracker and §4.7 Punctuation and Spacing of the biblatex documentation

For this specific issue the punctuation lives in a dedicated macro, so

\renewcommand*{\labelnamepunct}{\addcomma\space}

Should be enough.

You can restrict this change to @book only with

\renewcommand*{\labelnamepunct}{%
  \ifentrytype{book}
    {\addcomma‌​\space}
    {\newunitpunc‌​t}}

or by changing the line \setunit{\labelnamepunct}\newblock in \DeclareBibliographyDriver{book} to

\setunit{\addcomma‌​\space}\newblock
  • Can you explain why you chose \space and not \addspace? – StrongBad Dec 8 '17 at 18:17
  • Ok, I am a old newbie: where do I learn about the punctuation tracker? Anyway, I got what I needed. Thks – mario Dec 8 '17 at 20:19
  • 1
    @StrongBad Good question! \addcomma‌​\space is a common biblatex idiom. Essentially \add<punct or space> removes preceding space, does some bookkeeping and prints <punct or space>. If we use \add<punct> that already removes preceding space and does bookkeeping so that an \addspace after that would not add anything useful (since it comes after \add<punct> we can be sure no unwanted space was introduced), so we can resort to the simpler \addcomma\space. If it appears alone \addspace is preferred over \space, but in combination with other \add<punct> it might not be needed. – moewe Dec 9 '17 at 10:40
  • @mario I updated the answer with two references. – moewe Dec 9 '17 at 10:41

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.