1

I'm preparing a bibliography for a journal and the request is to have Book Title (Publisher) for book, incollection, etc. I have the following code (MWE):

\documentclass{article}

\usepackage[natbib,maxbibnames=99,uniquename=false,uniquelist=false,useprefix=true,style=ext-authoryear,innamebeforetitle=true]{biblatex}
\usepackage{xpatch}
%% FORMATTING OF THE REFERENCES SECTION
% This starts from "authoryear" style, makes changes
% Comma instead of period to separate fields
\renewcommand*{\newunitpunct}{\addcomma\space}
% Remove "pp."
\DeclareFieldFormat{pages}{#1} 
% Remove quotes around title
\DeclareFieldFormat[article,unpublished,inbook,incollection]{title}{#1}
% Remove parentheses around year
\DeclareFieldFormat{biblabeldate}{#1}
\DeclareDelimFormat[bib]{nameyeardelim}{\addcomma\space}
% Remove "In: " for articles; "in" without colon for inbook/incollection
\renewbibmacro*{in:}{%
  \ifentrytype{article}
    {}
    {\setunit{\space}%
       \printtext{%
       \addcomma\addspace\bibstring{in}\addspace}}}
% Only output volume, no number
\renewbibmacro*{volume+number+eid}{% 
  \ifentrytype{article}
    {\printfield{volume}%
    \setunit{\addcomma\space}%
    \printfield{eid}}
    {}}
% Put parentheses around publisher
\renewbibmacro*{publisher+location+date}{%
  \printtext[parens]{% ADDED
    \printlist{location}%
    \iflistundef{publisher}
      {\setunit*{\addcomma\space}}
      {\setunit*{\addcolon\space}}%
    \printlist{publisher}%
    \setunit*{\addcomma\space}%
    \usebibmacro{date}%
  }
  \newunit}
% Colon after editors
\DeclareFieldFormat{editortype}{#1:}
% Remove comma after booktitle

\begin{filecontents}{\jobname.bib}
@incollection{AuthorA,
  title     = {A paper that didn't get published in a real journal},
  publisher = {Publisher},
  year      = {2001},
  author    = {First Last},
  booktitle = {Book Title},
  editor   = {Albert Editor and Bob Editor}
}

@Article{AuthorB,
  author  = {Author One and Author Two and Author Three},
  title   = {A paper that did},
  journal = {Journal Name},
  year    = {2002},
  volume  = {99},
  number  = {9},
  pages   = {31--60},
}

@Unpublished{AuthorC,
  Title                    = {A paper that didn't get published at all},
  Author                   = {Author Three and Author One and Author Four and Author Five},
  Note                     = {Working paper},
  Year                     = {2003}
}
\end{filecontents}
\addbibresource{\jobname.bib}

\begin{document}
This is the story of \citet{AuthorA}, whose bibliography item had an extra comma after \emph{Book Title}, but also of \citet{AuthorB}, and of course of \citet{AuthorC}.

\printbibliography
\end{document}

This gives me the following result: Sample output

I would like to remove the comma between "Book Title" and "(Publisher)" in the first bibliography item. I've tried everything:

Please help!

2 Answers 2

2

If you add the parentheses with \printtext[parens]{<stuff>} you can easily force the preceding punctuation to be a space by inserting \setunit{\addspace}% directly in from of your \printtext. That's because the punctuation buffer only gets used and cleared once \printtext is encountered.

I have simplified a few other things in your code as well

  • We can retire the redefinition of the in: bibmacro in favour of biblatex-ext's articlein=false, option together with a redefinition of \intitlepunct.

  • To get rid of the number for journal articles we don't need to redefine the bibmacro volume+number+eid (which stops some of biblatex-ext's punctuation commands from working), we can get rid of the number with a sourcemap.

  • The colon after the editor names is better enforced with innametitledelim than with a colon in the editortype field format.

  • All in all there is no longer a need for xpatch with these modifications.

So we end up with

\documentclass{article}

\usepackage[
  style=ext-authoryear,
  maxbibnames=99, uniquename=false, uniquelist=false, useprefix=true,
  articlein=false,
  innamebeforetitle=true,
  natbib,
]{biblatex}


\renewcommand*{\newunitpunct}{\addcomma\space}
\DeclareFieldFormat{pages}{#1}
\DeclareFieldFormat[article,unpublished,inbook,incollection]{title}{#1}

\DeclareFieldFormat{biblabeldate}{#1}
\DeclareDelimFormat[bib]{nameyeardelim}{\addcomma\space}

\renewcommand*{\intitlepunct}{\addspace}

\DeclareDelimFormat[bib]{innametitledelim}{\addcolon\space}


\DeclareSourcemap{
  \maps[datatype = bibtex]{
    \map{
      \pertype{article}
      \step[fieldset=number, null]
    }
  }
}

\renewbibmacro*{publisher+location+date}{%
  \setunit{\addspace}%
  \printtext[parens]{% ADDED
    \printlist{location}%
    \iflistundef{publisher}
      {\setunit*{\addcomma\space}}
      {\setunit*{\addcolon\space}}%
    \printlist{publisher}%
    \setunit*{\addcomma\space}%
    \usebibmacro{date}}%
  \newunit}

\begin{filecontents}{\jobname.bib}
@incollection{AuthorA,
  title     = {A paper that didn't get published in a real journal},
  publisher = {Publisher},
  year      = {2001},
  author    = {First Last},
  booktitle = {Book Title},
  editor    = {Albert Editor and Bob Editor},
}
@Article{AuthorB,
  author  = {Author One and Author Two and Author Three},
  title   = {A paper that did},
  journal = {Journal Name},
  year    = {2002},
  volume  = {99},
  number  = {9},
  pages   = {31--60},
}
@Unpublished{AuthorC,
  Title  = {A paper that didn't get published at all},
  Author = {Author Three and Author One and Author Four and Author Five},
  Note   = {Working paper},
  Year   = {2003}
}
\end{filecontents}
\addbibresource{\jobname.bib}

\begin{document}
This is the story of \citet{AuthorA},
whose bibliography item had an extra comma after \emph{Book Title},
but also of \citet{AuthorB}, and of course of \citet{AuthorC}.

\printbibliography
\end{document}

Last, First, 2001, A paper that didn’t get published in a real journal, in Albert Editor and Bob Editor, eds.: Book Title (Publisher).

4
  • If you are interested in learning more about the punctuation buffer/tracker, have a look at tex.stackexchange.com/q/409148/35864, tex.stackexchange.com/q/430831/35864, tex.stackexchange.com/q/538920/35864.
    – moewe
    Commented Sep 20, 2022 at 16:51
  • Thank you, but I do not fully understand what the simplified version of my code does. Also I do not understand what is the use case of having anything other than \addspace inside the \newunitpunct macro. Sounds like it's only trouble.
    – Mattia
    Commented Sep 26, 2022 at 22:28
  • @MattiaLandoni I have added some explanations as to what changed and what things do (you can look up most of the commands in either the biblatex or biblatex-ext documentation if you still have any doubts - or ask in the comments). Unfortunately, I don't understand your comment about \addspace inside \newunitpunct. It is the default separator between "units of content" in the bibliography. As such it is almost always going to be either comma+space or period+space. But \newunitpunct does not apply in all places, sometimes more specific delimiters are available and used.
    – moewe
    Commented Sep 28, 2022 at 5:59
  • I will try to better explain my comment. It appears to me that to add a special separator before or after a bibliography element is quite easy, whereas to remove a separator is counterintuitive and requires a lot of code. If the default separator is "comma+space" or "period+space", there will be cases (like the above) in which we will have to struggle to remove a default-placed comma or period. On the other hand, if the default separator is just "space", it takes little work to add commas or periods where needed. Hope it makes sense now.
    – Mattia
    Commented Sep 30, 2022 at 23:52
1

You might see the following solution as either:

  1. an inelegant hack, or
  2. a brilliant, general solution to many punctuation problems together with a deep criticism of how BibLaTeX works.

The general way to control the punctuation in-between blocks and units is to change \newunitpunct. In the case of my journal, the Journal of Finance, all but one fields are comma-separated, so initially I thought it should be logical to set

\renewcommand*{\newunitpunct}{\addcomma\space}

and then to remove a comma.

However, removing commas turned out to be near-impossible for a mere academic scribbler like me (especially the one in question, which seems to be in between two "blocks"). Instead, it is much simpler to neutralize the \newunitpunct macro as follows:

\renewcommand*{\newunitpunct}{\addspace}

and then to add commas, parentheses, and whatever other punctuation might be needed on an item-by-item basis. For instance, in my case,

% Remove quotes around title and add comma after
\DeclareFieldFormat[article,unpublished,inbook,incollection]{title}{#1,}
% Remove parentheses around year and add comma before and after
\DeclareFieldFormat{biblabeldate}{#1,}
\DeclareDelimFormat[bib]{nameyeardelim}{\addcomma\space}

Here is the result:

Sample output - Fixed

You must log in to answer this question.

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