8

I am still working on formatting my references according to my department’s standard. I am currently trying to alter a date format but failing.

I need:

30. Sept. 2003.

Yet anything I do doesn’t seem to have any influence. Find attached a MWE:

\documentclass[a4paper,12pt]{article}
\usepackage{xpatch}
\usepackage{polyglossia}
\setmainlanguage[variant=british]{english}
\usepackage{fontspec,xltxtra,xunicode}
\usepackage{csquotes}
\usepackage{url}
\usepackage[style=authoryear-ibid,backend=biber,doi=false,isbn=false,url=false,autolang=hyphen]{biblatex}
     \addbibresource{Merkliste.bib}
     \renewcommand*{\postnotedelim}{\addcolon\space}
     \renewbibmacro{in:}{\ifentrytype{article}{}{\printtext{\bibstring{in}\intitlepunct}}}
    \renewcommand*{\intitlepunct}{\addspace}
     \renewcommand{\bibpagespunct}{\ifentrytype{incollection}{\addperiod\addspace}{\addcolon\addspace}}

\DeclareFieldFormat
  [online]
  {url}{{#1}}
\DeclareFieldFormat
  [online]
  {title}{\mkbibquote{#1\isdot}}
\xpatchbibmacro{title}{\printfield[titlecase]{subtitle}}%
{\printfield[titlecase]{subtitle}\ifentrytype{online}{\addperiod}{}}%
{}{}%
\DeclareFieldFormat{urldate}{#1}
\DeclareFieldFormat{postnote}{#1}
\DeclareFieldFormat{multipostnote}{#1}
\DeclareFieldFormat{pages}{#1}
%% Here are my tries.
\xpatchbibmacro{url+urldate}{\printfield{urlyear}\mkbibmonth{\thefield{urlmonth}}{\thefield{urlday}}}{}{}
    \xpatchbibmacro{date+extrayear}{%
  \printtext[parens]%
}{%
  \setunit*{\addperiod\space}%
  \printtext%
}{}{}

\xpatchbibmacro{title}{\printfield[titlecase]{subtitle}}%
{\printfield[titlecase]{subtitle}\ifentrytype{article}{\addperiod}{}}%
{}{}%

\AtEveryBibitem{\clearlist{language}} % clears language
\AtEveryBibitem{\clearfield{note}}    % clears notes
\AtEveryBibitem{\clearfield{series}}   % clears Series
\AtEveryBibitem{\ifentrytype{book}{\clearfield{number}}{}}
\AtEveryBibitem{\ifentrytype{book}{\clearfield{pages}}{}}

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

and a .bib-extract:

![@online{secretariat_a_la_politique_linguistique_quebec_dynamique_2014,
    Author = {{Secr{\'e}tariat {\`a} la politique linguistique Qu{\'e}bec}},
    Date-Modified = {2014-08-03 17:01:54 +0000},
    File = {Dynamique des langues en quelques chiffres \: Tableaux - Secr{\'e}tariat {\`a} la politique linguistique.pdf:/Users/Moritz/Desktop/Dynamique des langues en quelques chiffres \: Tableaux - Secr{\'e}tariat {\`a} la politique linguistique.pdf:application/pdf},
    Month = jul,
    Title = {La dynamique des langues en quelques chiffres : Tableaux},
    Urldate = {2014-07-28},
    Year = {2014}}][1]

Here’s my not-perfect output

4
  • 1
    Is there really a dot after 30? – Bernard Aug 3 '14 at 17:11
  • Yes, I just double-checked. – Moritz Aug 3 '14 at 17:15
  • 1
    Strange… Never seen that. Btw, do you know that if you use biber, your .bib file can be utf8-encoded, i.e. you can type Québec, for instance (comment aside, I suppose it's du Québec). – Bernard Aug 3 '14 at 17:19
  • Is the urldate field supposed to be printed in long French format, with mainlanguage=british? – Bernard Aug 3 '14 at 18:19
8

Biblatex offers different options to format a date. If the format is not a predefined one, it is possible to use \DeclareFieldFormat to provide a now format, in this case we can provide a format for urldate

\DeclareFieldFormat{urldate}{%
  \thefield{urlday}\adddot\addspace%
  \mkbibmonth{\thefield{urlmonth}}\adddot\addspace%
  \thefield{urlyear}\isdot}

To use the abbreviated version for the month one can use the dateabbrev option of biblatex.

enter image description here

5
  • I'm not sure the braces are correctly placed. – egreg Aug 3 '14 at 20:03
  • 1
    There can’t be much that can’t be changed in LaTeX with tex.sx’s help:) – Moritz Aug 4 '14 at 12:15
  • 1
    This disables the urldate= option and all other date features of biblatex. A different solution, while longer, is definitely preferable in general (and also in this particular case). – moewe Feb 23 '18 at 11:45
  • @moewe what is the preferred solution here ? – baxx Sep 26 '18 at 1:02
  • @baxx Depends on the details of the case. It would probably look like Paul Langeslag's answer. – moewe Sep 26 '18 at 5:40
5

biblatex uses more than one date field. We'll want to reformat the output of the date field as well as urldate, for instance. Fortunately, biblatex calls all these date fields through \mkbibdatelong or \mkbibdateshort, so that's what we'll want to look at. We'll also need to count with the possibility that a date field contains only a year, say, or a date range like 1986/1990, so we need to make use of if-then constructions.

Since the document language is set to British English, we'll want to base ourselves on british.lbx. It contains the following definition:

  \protected\def\mkbibdatelong#1#2#3{%
    \iffieldundef{#3}
      {}
      {\mkbibordinal{\thefield{#3}}%
       \iffieldundef{#2}{}{\nobreakspace}}%
    \iffieldundef{#2}
      {}
      {\mkbibmonth{\thefield{#2}}%
       \iffieldundef{#1}{}{\space}}%
    \stripzeros{\thefield{#1}}}%

We need to copy this into our preamble, containing it in the argument of \DefineBibliographyExtras{british} and:

  1. Tell biblatex that we want to use a longer date format using the option alldates=long;
  2. Tell biblatex to abbreviate month names using the option dateabbrev=true;
  3. Remove the alphabetical ordinal in the day field (\mkbibordinal);
  4. Restore the \stripzeros that was previously triggered by the command \mkbibordinal;
  5. Insert our punctuated ordinal with \adddot.

MWE:

\documentclass[a4paper,12pt]{article}
\usepackage{polyglossia}
\setmainlanguage[variant=british]{english}
\usepackage{fontspec}
\usepackage{csquotes}
\usepackage[style=authoryear-ibid,doi=false,isbn=false,url=false,autolang=hyphen,alldates=long,dateabbrev=true]{biblatex}
 \addbibresource{Merkliste.bib}

\DefineBibliographyExtras{english}{%
    \protected\def\mkbibdatelong#1#2#3{%
    \iffieldundef{#3}
      {}
      {\stripzeros{\thefield{#3}}\adddot%
       \iffieldundef{#2}{}{\nobreakspace}}%
    \iffieldundef{#2}
      {}
      {\mkbibmonth{\thefield{#2}}%
       \iffieldundef{#1}{}{\space}}%
    \stripzeros{\thefield{#1}}}%
}

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

You'll find that "July" in your sample bibliography is not abbreviated because four-letter months are conventionally not abbreviated.

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.