[Tex/LaTex] field for ‘last modified’ in Biblatex

biblatexonline

I am writing a report in which I cite several webpages. I would like to supply the dates on which these websites were last revised. Is there a field called last modified (or something similar) for the online entry or any other entry type for that matter? A quick search of the Biblatex documentation turned nothing up but perhaps I was searching for the wrong terms.

Best Answer

I would argue that a "last modified" field for websites is not really necessary. The date field will contain this information. If you cite a book you always use the year of your print version for the year field, not the year of some other edition (be it the first or just one you like, if you insist on giving information like this there is origdate).

You can add information like "last modified" in the note or addendum fields, which are designed to hold miscellaneous information.

There is also the urldate for last visited (which is not exactly what you seem to want, but deserves a mention anyway).


But who am I to deny you the joy of having a lastmodifieddate field. It won't come for free though. We will follow the more complex example in How can I create entirely new data types with BibLaTeX/Biber?.

We will need a new data model for this. Save the following in a file called lastmod.dbx (in the MWE below this file is automatically created via filecontents).

\DeclareDatamodelFields[type=field, datatype=datepart]{
  lastmodifiedyear,
  lastmodifiedmonth,
  lastmodifiedday,
  lastmodifiedhour,
  lastmodifiedminute,
  lastmodifiedsecond,
  lastmodifiedtimezone,
  lastmodifiedseason,
}
\DeclareDatamodelFields[type=field, datatype=date, skipout]{
  lastmodifieddate}
\DeclareDatamodelEntryfields{
  lastmodifieddate}

Note that we will later load biblatex with the option datamodel=lastmod.

Now Biber knows lastmodifieddate.

We can even have localisation features (save this in english-lastmod.lbx)

\ProvidesFile{english-lastmod.lbx}[2015/05/10 english with edditions for last modified]
\InheritBibliographyExtras{english}
\NewBibliographyString{lastmodified}
\DeclareBibliographyStrings{%
  inherit   = {english},
  lastmodified = {{last modified}{last mod\adddot}},
}

Finally, we enable printing the new date via

\DeclareFieldFormat{lastmodifieddate}{\bibstring{lastmodified}\space#1}
\newbibmacro*{lastmodifieddate}{\printlastmodifieddate}

\renewbibmacro*{url+urldate}{%
  \usebibmacro{url}%
  \iffieldundef{lastmodifiedyear}
    {}
    {\setunit*{\addcomma\space}%
     \usebibmacro{lastmodifieddate}}
  \iffieldundef{urlyear}
    {}
    {\setunit*{\addspace}%
     \usebibmacro{urldate}}}

The MWE

\RequirePackage{filecontents}
\begin{filecontents*}{\jobname.bib}
@online{webs,
  author       = {Anne Uthor},
  title        = {A Website from the Future},
  url          = {https://example.com},
  urldate      = {2014-12-12},
  lastmodifieddate = {2015-06-06},
}
\end{filecontents*}
\begin{filecontents}{lastmod.dbx}
\DeclareDatamodelFields[type=field, datatype=datepart]{
  lastmodifiedyear,
  lastmodifiedmonth,
  lastmodifiedday,
  lastmodifiedhour,
  lastmodifiedminute,
  lastmodifiedsecond,
  lastmodifiedtimezone,
  lastmodifiedseason,
}
\DeclareDatamodelFields[type=field, datatype=date, skipout]{
  lastmodifieddate}
\DeclareDatamodelEntryfields{
  lastmodifieddate}
\end{filecontents}
\documentclass[english]{article}
\usepackage{babel}
\usepackage{csquotes}
\usepackage[datamodel=lastmod,backend=biber]{biblatex}
\usepackage{hyperref}
\addbibresource{\jobname.bib}

\begin{filecontents*}{english-lastmod.lbx}
\ProvidesFile{english-lastmod.lbx}[2015/05/10 english with edditions for last modified]
\InheritBibliographyExtras{english}
\NewBibliographyString{lastmodified}
\DeclareBibliographyStrings{%
  inherit   = {english},
  lastmodified = {{last modified}{last mod\adddot}},
}
\end{filecontents*}
\DeclareLanguageMapping{english}{english-lastmod}

\ExecuteBibliographyOptions{lastmodifieddate=short}
\DeclareFieldFormat{lastmodifieddate}{\bibstring{lastmodified}\space#1}
\newbibmacro*{lastmodifieddate}{\printlastmodifieddate}

\renewbibmacro*{url+urldate}{%
  \usebibmacro{url}%
  \iffieldundef{lastmodifiedyear}
    {}
    {\setunit*{\addcomma\space}%
     \usebibmacro{lastmodifieddate}}
  \iffieldundef{urlyear}
    {}
    {\setunit*{\addspace}%
     \usebibmacro{urldate}}}

\begin{document}
\cite{webs}

\printbibliography
\end{document}

gives

enter image description here

The answer was updated to reflect changes in biblatex's internals that make defining date fields easier. If you are using a very old version of biblatex you may have to check the edit history.

Related Question