3

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.

Janosh
  • 4,042

1 Answers1

7

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.

moewe
  • 175,683
  • 1
    Very good, thanks. @pacificorion I have one non-TeXnical question. Would a more recent modified date imply that the site was visted that day as well? If not, if a change of contents is known, why is there no check for updates or corrections, making the last visited field match up once again. If the last modified information is known, doesn't that mean any date later than that will have the exact same information available on page, making the visited field redundant? Just my two cents on the topic. – Johannes_B May 10 '15 at 16:55