0

Below a mwe:

\begin{filecontents}[overwrite]{\jobname.bib}
@customa{a,
  author = {Author},
  eventdate = {1000-01-01},
  title = {Title},
  journaltitle = {Journaltitle},
  date = {3000},
}
@customa{b,
  author = {Author},
  eventdate = {2000-01-01},
  title = {Title},
  journaltitle = {Journaltitle},
  date = {1000},
}
@customa{c,
  author = {Author},
  eventdate = {3000-01-01},
  title = {Title},
  journaltitle = {Journaltitle},
  date = {2000},
}
@article{article,
  author = {Author},
  title = {Title},
  journaltitle = {Journaltitle},
  date = {2000},
}
\end{filecontents}

\documentclass{article}
\usepackage[style=authortitle]{biblatex}
\addbibresource{\jobname.bib}

\DeclareStyleSourcemap{
  \maps{
    \map{
      \pertype{customa}
      \step[fieldsource=eventdate, match=\regexp{\A(\d+)}]
      \step[fieldset=sortyear, fieldvalue={$1}]
    }
  }
}

\DeclareBibliographyDriver{customa}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \printnames{author}%
  \newunit
  \printeventdate
  \newunit
  \usebibmacro{title}%
  \newunit\newblock
  \bibstring{in}%
  \printunit{\intitlepunct}
  \usebibmacro{journal+issuetitle}%
  \usebibmacro{finentry}}

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

The mwe works fine.

From what I understand, if <datetype>date is defined, biber/biblatex automatically generates the <datetype>year, <datetype>month and <datetype>day fields.

So the sourcemapping code should also be able to be written in the following way.

\DeclareStyleSourcemap{
  \maps{
    \map{
      \pertype{customa}
      \step[fieldsource=eventyear]
      \step[fieldset=sortyear, origfieldval]
    }
  }
}

But this second solution does not work. Why? What is the error? Thanks.

1 Answer 1

1

The sourcemapping step, in which Biber applies your changes to the data, happens very early on during processing of the .bib file. In particular it happens before the step in which Biber splits up date fields into their components.

So when \DeclareStyleSourcemap is executed, the date field is still eventdate (as given in the .bib file) and eventyear and friends are not yet available.

2
  • very interesting. Do you think it is useful to open an issue to ask to change the order of execution of these internal operations in biber?
    – matteofg
    Commented Apr 19 at 9:21
  • @matteo339 You can always open an issue to discuss things. In this case both possible options have their pros and cons (though I would say it is slightly more natural for the sourcemap to operate before all other data processing steps Biber does, because the assumption is that a sourcemap lets you manipulate the source data so that you can still control what Biber makes of it - if you come in later, when Biber has already processed stuff it seems messier to change things), but there appears to be a simple workaround for your use case.
    – moewe
    Commented Apr 19 at 23:58

You must log in to answer this question.

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