2

I'm trying to create a DeclareSourcemap to append a string ("Modern publication date ") and a source field value (the value from date) to a target field (addendum). In my biblatex source I have some entries where addendum doesn't exist; and some entries where addendum does exist, with existing text that I don't want to overwrite.

I want to prefix a space to the result appended to addendum, if addendum already contains text. E.g. To end up with something like:

addendum={Existing addendum text. Modern publication date 2015-02-23}

But I don't want to prefix a space to the result appended to 'addendum', if addendum doesn't exist. E.g. To end up with something like:

addendum={Modern publication date 1975-06-15}

I can successfully prefix a space to the string to be appended. But I can't work out how to do this conditionally, depending on whether addendum exists or not (or has a non-zero length string value, or not).

Just to share the deeper motivation: I'm trying to set up a source mapping so that I can readily switch between styles that don't support origdate (e.g. a biblatex native style like authoryear) and those that do (e.g. biblatex-chicago) without having to change my biblatex source file (of bibliographic entries). Also with my in-text citations and bibliographic entries I'm wanting to give prominence to the original date rather than modern date. My Minimum Working Example (MWE) below does all this (the data source mapping is used with biblatex's native style authoryear), except for the conditional prefixing of spaces to appended text ...

\documentclass{article}

\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
  % Entry doesn't have an addendum
  @book{plato_2004_republic,
    author = {{Plato}},
    date = {2004-09-15},
    origdate = {-0379~},
    title = {Republic},
    translator = {Reeve, C. D. C.},
    publisher = {{Hackett Publishing Company, Inc.}},
  }

  % Entry has an addendum with existing text.
  @incollection{hume_1975_enquiry,
    author = {Hume, David},
    date = {1975-06-12},
    origdate = {1751},
    title = {An {{Enquiry Concerning}} the {{Principles}} of
       {{Morals}}},
    addendum = {Previously existing addendum text.},
    editor = {Selby-Bigge, L. A. and Nidditch, P. H.},
    publisher = {{Oxford University Press}},
    booktitle = {Enquiries {{Concerning Human Understanding}}
       and {{Concerning}} the {{Principles}} of {{Morals}}},
  }
\end{filecontents}

\usepackage[
%  style=debug,
  style=authoryear,
  alldates=ymd,
  dateera=secular,
  datecirca=true,
  datezeros=true,
  dateuncertain=true,
  backend=biber,
  backref=true,
  sorting=none
]{biblatex}

\DeclareSourcemap{
  \maps[datatype=bibtex]{
    \map[overwrite]{
      %%% addendum to "Modern publication date [datevalue]"
      %%% e.g. addendum={
      %%% [Optional existing text.] Modern publication date 
      %%%  2004-09-15
      %%% }
      % Append some text to the addendum field:
      % - With a leading space of there is text already in 
      %the addendum field (currently works); but
      % - Without a leading space if the addendum field 
      % doesn't exist (currently doesn't work).
      % XXXXXXXXXXXXX Problem line next XXXXXXXXXXXXX
      \step[fieldset=addendum, fieldvalue={\ Modern 
      publication 
      date{ }}, append]
      % The addendum field must exist with at least "Modern 
      % publication date ".
      % Append the date.
      \step[fieldsource=date]
      \step[fieldset=addendum, origfieldval, append]
      %%% origdate: origdatevalue to date: origdatevalue 
      %%% e.g. origdate = {1751} to date = {1751}
      \step[fieldsource=origdate]
      \step[fieldset=date, origfieldval]
    }
  }
}

\addbibresource{\jobname.bib}

\begin{document}
  %\autocite{plato_2004_republic}\\
  %\autocite{hume_1975_enquiry}\\
  \nocite{*}
  \printbibliography
\end{document}

This give a result of ...

BiblatexDeclareSourcemapConditionalSpacePrefixProblem01

... the Plato entry has two spaces before "Modern publication date ..." (where one space is desired), Hume's entry has one space (as desired) before "Modern publication date ...". Using style=debug makes this more obvious.

I'm not sure if the solution entails one or more of:

  • A better understanding of latex space handling; or
  • Some regexp (which DeclareSourcemap supports);
  • A better understanding of DeclareSourcemap handling;
  • Changes to biblatex source code, of data source mapping, to offer a more powerful append functionality.

One option is to ignore the double space. It is hardly noticeable. But, of course, we coders like to be able to get things exactly as we want them.

I'm using the dev versions of biber (sourceforge link) and biblatex (3.7, sourceforge link). The production versions have been choking for me against the above MWE. I'm using Xelatex.

Edit: Commented out MWE in-text citations so result will appear exactly as posted in image (without backreferences).

Edit: Fixed title capitalisation. "How" to "how".

3

You don't have to put everything into one \map - that makes some things impossible. Try this:

\DeclareSourcemap{
  \maps[datatype=bibtex]{
    \map[overwrite]{
      \step[fieldsource=addendum, final]
      \step[fieldset=addendum, fieldvalue={~}, append]
    }
    \map[overwrite]{
      % Only suffix "Modern publication date ..." where there is an origdate
      \step[fieldsource=origdate, final] 
      \step[fieldset=addendum, fieldvalue={Modern publication  date{ }}, append]
      \step[fieldsource=date]
      \step[fieldset=addendum, origfieldval, append]
      \step[fieldsource=origdate]
      \step[fieldset=date, origfieldval]
    }
  }
}

This first puts a space at the end of addendum if it exists and then does the actual field modifications. This could be further conditionalised with final \maps to be safer. The point is that you can force \maps to only apply to some entries with final. This is generally how to conditionalise maps.

Edit by John Bentley:

To the above solution, to make it further safer (as PLK suggests), I've added

  % Only suffix "Modern publication date ..." where there is an origdate
  \step[fieldsource=origdate, final] 

... one could also test for this by adding to the MWE ...

  @article{chalmers_1995_facinga,
    author = {Chalmers, David J.},
    date = {1995},
    title = {Facing up to the Problem of Consciousness},
    pages = {200--19},
    journaltitle = {Journal of Consciousness Studies},
    number = {3},
    timestamp = {2016-06-05T20:09:34Z},
    url = {http://consc.net/papers/facing.html},
    volume = {2},
    addendum={This entry only has a date, not origdate, so no ``Modern publication date" should be output}
  }
  • That works, thanks PLK! Apart from your explanation on using multiple \maps and final for conditionalising, the other key part of your solution seems to be the use of the non-breaking space ~. Other space types don't appear to work, e.g. with fieldvalue={{ }} or fieldvalue={\space}. – John Bentley Oct 16 '16 at 18:15
  • What about fieldvalue={\\ } – PLK Oct 16 '16 at 18:44
  • Yes that works at my end and so counts as a another possibility, to force a newline and thereby make "Modern publication date ..." more prominent. In this case it'd be better to not make the appending conditional, by removing step[fieldsource=addendum, final]. However, I think your ~ suggestion results in something more in keeping with the style guides. – John Bentley Oct 17 '16 at 4:49

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.