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 ...
... 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".