0

I would like to have a bibliography entry which has rounds brackets around multiple items. I somewhat succeeded, but need to fine-tune the format.

First of all, here is the MWE:

% xelatex - biber - xelatex - xelatex
\documentclass{article}
\usepackage[style=nature,maxbibnames=99]{biblatex}
\usepackage{hyperref}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % to create a file when first processed % \begin{filecontents}[<options>]{<filename>} % possible options: overwrite, nosearch, noheader \begin{filecontents}{bib_2ndtry.bib} @misc{A2020, author = {Author, A. and Author, B. and Author C.}, title = {Title of some conference talk}, eventtitle = {Conference title}, date = {2011}, venue = {Conference location}, } @misc{B2021, author = {Buthor, A.}, year = {2021}, title = {Bravo}, } \end{filecontents} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\addbibresource{bib_2ndtry.bib}

\DeclareBibliographyDriver{misc}{% \usebibmacro{title}% \newunit \printfield{eventtitle}% \newunit \mkbibparens{% \printfield{venue}% \newunit \usebibmacro{date}% }% \usebibmacro{finentry}% }

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

This results in the following document:

enter image description here

I need to

  1. add an additional space in-front of the opening bracket
  2. remove the dot after the opening bracket
  3. remove the space after the opening bracket
  4. replace the dot after the Conference location by a comma

I am somewhat lost how to achieve that and would greatly appreciate any hint.

Alf
  • 467

2 Answers2

1

You may want to familiarise yourself with biblatex's punctuation buffer/tracking features. They are discussed extensively in the manual (§4.7 Punctuation and Spacing and §4.11.7 Using the Punctuation Tracker) and there are a few examples on this site (What do \setunit and \newunit do?, biblatex: \DeclareCiteCommand adds semicolon between \printfield and \printnames, but only sometimes, If Statements in Biblatex, Is there any difference between \setunit*{<punct>} and \setunit{\add<punct>}).

It is usually bad to place punctuation and formatting commands like \mkbibparens directly in drivers and bibmacros. Punctuation is best handled with the punctuation buffer. Formatting commands are best handled with \DeclareFieldFormat and friends.

Usually all you need is a few \newunits/\setunits and you are good to go. If you want to print several fields within the same parentheses, some more work is needed as you need to check for the presence of those fields at the same time. In your example we might do this as follows

\documentclass{article}
\usepackage[style=nature,maxbibnames=99]{biblatex}
\usepackage{hyperref}

\DeclareBibliographyDriver{misc}{% \usebibmacro{bibindex}% \usebibmacro{begentry}% \usebibmacro{title}% \newunit \ifboolexpr{ test {\iffieldundef{venue}} and test {\iffieldundef{year}} } {} {\printtext[parens]{% \printfield{venue}% \setunit*{\addcomma\space}% \printdate}}% \usebibmacro{finentry}% }

\begin{filecontents}{\jobname.bib} @misc{A2020, author = {Author, A. and Author, B. and Author C.}, title = {Title of some conference talk}, eventtitle = {Conference title}, date = {2011}, venue = {Conference location}, } @misc{B2021, author = {Buthor, A.}, year = {2021}, title = {Bravo}, } \end{filecontents} \addbibresource{\jobname.bib}

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

1. Title of some conference talk (Conference location, 2011).
2. Bravo (2021).

Note that standard biblatex has a macro called event+venue+date defined as (standard.bbx, ll. 828-843 in v3.18)

\newbibmacro*{event+venue+date}{%
  \printfield{eventtitle}%
  \newunit
  \printfield{eventtitleaddon}%
  \ifboolexpr{
    test {\iffieldundef{venue}}
    and
    test {\iffieldundef{eventyear}}
  }
    {}
    {\setunit{\addspace}%
     \printtext[parens]{%
       \printfield{venue}%
       \setunit*{\addcomma\space}%
       \printeventdate}}%
  \newunit}

that would print almost the same information that we're printing, except that it uses eventdate instead of date. This macro, however, loses the parentheses in biblatex-nature (nature.bbx, ll. 152-166 in v1.3d).

moewe
  • 175,683
0

Okay, I almost succeeded, using the following approach:

\DeclareBibliographyDriver{misc}{%
  \usebibmacro{title}%
  \printfield{eventtitle}%
  \setunit{\space}
  \mkbibparens{%
      \setunit{}%
      \printfield{venue}%
      \printunit{\addcomma\addspace}%
      \usebibmacro{date}%
  }%
  \usebibmacro{finentry}%
}

This results in the following bibliography:

enter image description here

As you can see, it is fine for the first item. The second item, however, has some problem: if venue is empty, there is an unwanted whitespace which I need to remove somehow... any ideas?


Update:

After some reading, I realized that there is a method to check if an item is present. So I changed the above listed code as follows:

\DeclareBibliographyDriver{misc}{%
  \usebibmacro{title}%
  \printfield{eventtitle}%
  \setunit{\space}
  \mkbibparens{%
    \setunit{}%
    \iffieldundef{venue}{%
      \usebibmacro{date}%
    }{%
      \printfield{venue}%
      \printunit{\addcomma\addspace}%
      \usebibmacro{date}%
    }%
  }%
  \usebibmacro{finentry}%
}

Now the unwanted whitespace is gone. I am, however, not sure how good my approach/solution is...

Alf
  • 467