5

When I cite an entry in my bibliography (using style authoryear-comp) I would like the year typeset using old-style numbers. I have partially achieved what I want by redefining the bib macro cite:labeldate+extradate but it doesn't fully work (and makes me suspect I am fundamentally not going about this in the right way).

For example, below is a MWE:

\begin{filecontents}{\jobname.bib}
@article{Thor2009,
    author  = {Thor, Alice Ursula and Smith, John},
    journal = {Some Journal},
    number  = {8},
    pages   = {123--456},
    title   = {A Very Important Paper},
    volume  = {79},
    year    = {2009}
}

@article{Thor2009b,
    author  = {Thor, Alice Ursula and Smith, John},
    journal = {Some Different Journal},
    number  = {8},
    pages   = {123--456},
    title   = {Another Very Important Paper},
    volume  = {79},
    year    = {2009}
}
\end{filecontents}

\documentclass{article}
\usepackage[backend=biber,style=authoryear-comp]{biblatex}

\addbibresource{\jobname.bib}

% Style for years
\newcommand{\y}[1]{\oldstylenums{#1}}

\renewbibmacro*{cite:labeldate+extradate}{%
    \iffieldundef{labelyear}
    {}
    {\printtext[bibhyperref]{\y{\printlabeldateextra}}}}


\begin{document}
    Hello \textcite{Thor2009,Thor2009b}.

    \printbibliography
\end{document}

When the above is typeset the citation contains the string "(2009a,b)". The year is typeset using old-style numbers, however the "a" (I think) also is typeset in this way which makes it appear as if it were in italics, and finally the ",b" (correctly) is not affected. What I want is for the year (and nothing else) to be set in old-style numbers.

3 Answers 3

3

The code for date printing in biblatex is a bit ... unusual and scattered around many different places. It evolved quite a bit and the different requirements mean that it has grown quite complex.

The difficulty with the approach in the question is that the extradate label is also printed by the \printlabeldateextra command and so \oldstylenums would also apply to it.

Ultimately, the code that does the date typesetting lives in the .lbx file. If you want to change all years to old style numerals, you should probably attack there.

Unfortunately, the code is not exactly short and sweet.

The code below is taken from english.lbx (ll. 24-51). If you are using other languages, you need to apply a similar redefinition for each language you use.

\documentclass{article}
\usepackage[backend=biber,style=authoryear-comp]{biblatex}

\newcommand*{\bibyearformat}{\oldstylenums}

\DefineBibliographyExtras{english}{%
  \protected\def\mkbibdatelong#1#2#3{%
    \iffieldundef{#2}
      {}
      {\mkbibmonth{\thefield{#2}}%
       \iffieldundef{#3}
         {\iffieldundef{#1}{}{\space}}
         {\nobreakspace}}%
    \iffieldundef{#3}
      {}
      {\stripzeros{\thefield{#3}}%
       \iffieldundef{#1}{}{,\space}}%
     \iffieldbibstring{#1}
       {\bibstring{\thefield{#1}}}
       {\dateeraprintpre{#1}\bibyearformat{\stripzeros{\thefield{#1}}}}}%
  \protected\def\mkbibdateshort#1#2#3{%
    \iffieldundef{#2}
      {}
      {\mkmonthzeros{\thefield{#2}}%
       \iffieldundef{#3}
         {\iffieldundef{#1}{}{/}}
         {/}}%
    \iffieldundef{#3}
      {}
      {\mkdayzeros{\thefield{#3}}%
       \iffieldundef{#1}{}{/}}%
     \iffieldbibstring{#1}
       {\bibstring{\thefield{#1}}}
       {\dateeraprintpre{#1}\bibyearformat{\mkyearzeros{\thefield{#1}}}}}%
  \protected\def\mkbibseasondateshort#1#2{%
    \mkbibseason{\thefield{#2}}%
    \iffieldundef{#1}{}{\space}%
    \dateeraprintpre{#1}\bibyearformat{\mkyearzeros{\thefield{#1}}}}%
  \protected\def\mkbibseasondatelong#1#2{%
    \mkbibseason{\thefield{#2}}%
    \iffieldundef{#1}{}{\space}%
    \dateeraprintpre{#1}\bibyearformat{\mkyearzeros{\thefield{#1}}}}%
}

\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@article{Thor2009,
  author  = {Thor, Alice Ursula and Smith, John},
  journal = {Some Journal},
  number  = {8},
  pages   = {123--456},
  title   = {A Very Important Paper},
  volume  = {79},
  year    = {2009},
}
@article{Thor2009b,
  author  = {Thor, Alice Ursula and Smith, John},
  journal = {Some Different Journal},
  number  = {8},
  pages   = {123--456},
  title   = {Another Very Important Paper},
  volume  = {79},
  year    = {2009},
}
\end{filecontents}
\addbibresource{\jobname.bib}

\begin{document}
  Hello \textcite{Thor2009,Thor2009b}.

  \printbibliography
\end{document}

All years in old style numerals.

Currently, the code only applies old style nums for years. Months and days are left alone, one would probably change those to old style nums as well.

\newcommand*{\bibdatenumformat}{\oldstylenums}

\DefineBibliographyExtras{english}{%
  \protected\def\mkbibdatelong#1#2#3{%
    \iffieldundef{#2}
      {}
      {\mkbibmonth{\thefield{#2}}%
       \iffieldundef{#3}
         {\iffieldundef{#1}{}{\space}}
         {\nobreakspace}}%
    \iffieldundef{#3}
      {}
      {\bibdatenumformat{\stripzeros{\thefield{#3}}}%
       \iffieldundef{#1}{}{,\space}}%
     \iffieldbibstring{#1}
       {\bibstring{\thefield{#1}}}
       {\dateeraprintpre{#1}\bibdatenumformat{\stripzeros{\thefield{#1}}}}}%
  \protected\def\mkbibdateshort#1#2#3{%
    \iffieldundef{#2}
      {}
      {\bibdatenumformat{\mkmonthzeros{\thefield{#2}}}%
       \iffieldundef{#3}
         {\iffieldundef{#1}{}{/}}
         {/}}%
    \iffieldundef{#3}
      {}
      {\bibdatenumformat{\mkdayzeros{\thefield{#3}}}%
       \iffieldundef{#1}{}{/}}%
     \iffieldbibstring{#1}
       {\bibstring{\thefield{#1}}}
       {\dateeraprintpre{#1}\bibdatenumformat{\mkyearzeros{\thefield{#1}}}}}%
  \protected\def\mkbibseasondateshort#1#2{%
    \mkbibseason{\thefield{#2}}%
    \iffieldundef{#1}{}{\space}%
    \dateeraprintpre{#1}\bibdatenumformat{\mkyearzeros{\thefield{#1}}}}%
  \protected\def\mkbibseasondatelong#1#2{%
    \mkbibseason{\thefield{#2}}%
    \iffieldundef{#1}{}{\space}%
    \dateeraprintpre{#1}\bibdatenumformat{\mkyearzeros{\thefield{#1}}}}%
}
1
  • This works perfectly for me. Now I "just" need to understand the .lbx code!
    – banbh
    May 3, 2019 at 17:49
4
\DeclareFieldFormat{oldstyle}{\oldstylenums{#1}}

\renewbibmacro*{cite:labeldate+extradate}{%
    \iffieldundef{labelyear}
    {}
    {\printtext[oldstyle]{\printlabeldateextra}}}

or, if you need hyperref

\DeclareFieldFormat{oldstyle}{\bibhyperref{\oldstylenums{#1}}}

enter image description here

2
  • +1 But note that the b is not in the same style as the a May 3, 2019 at 15:33
  • While this is arguably more biblatex-y in its execution than the code in the question (use of \DeclareFieldFormat and \printtext over the naked macro) it produces the exact same result as the MWE from the question in this instance, so it can't really be the expected answer.
    – moewe
    May 3, 2019 at 15:45
2

You should adjust the field format for date etc. via e.g.

\DeclareFieldFormat{date}{\oldstylenums{#1}}

which is where the biblatex documentation says changes to fonts for individual fields belong. Unfortunately there are several fields to set to get this right. If have missed some please let me know.

Sample output

\begin{filecontents}{\jobname.bib}
@article{Thor2009,
    author  = {Thor, Alice Ursula and Smith, John},
    journal = {Some Journal},
    number  = {8},
    pages   = {123--456},
    title   = {A Very Important Paper},
    volume  = {79},
    year    = {2009}
}

@article{Thor2009b,
    author  = {Thor, Alice Ursula and Smith, John},
    journal = {Some Different Journal},
    number  = {8},
    pages   = {123--456},
    title   = {Another Very Important Paper},
    volume  = {79},
    year    = {2009}
}
\end{filecontents}

\documentclass{article}
\usepackage[backend=biber,style=authoryear-comp]{biblatex}

\addbibresource{\jobname.bib}

\DeclareFieldFormat{date}{\oldstylenums{#1}}
\DeclareFieldFormat{dateextra}{\oldstylenums{#1}}
\DeclareFieldFormat{extradate}{\oldstylenums{\mknumalph{#1}}}
\DeclareFieldFormat{labeldate}{\oldstylenums{#1}}
\DeclareFieldFormat{labeldateextra}{\oldstylenums{#1}}

\begin{document}

Hello \textcite{Thor2009,Thor2009b}.

\printbibliography

\end{document}
4
  • \DeclareFieldFormat{<datetype>date} won't do anything useful. The <datetype> in the documentation is supposed to be a variable that takes can take the various 'date type prefixes' like orig (for origdate) or url (for urldate) etc. (<datetype> is empty for date.)
    – moewe
    May 3, 2019 at 15:41
  • @moewe Ah, thank you for the clarification. I'll drop the line from my code, rather than trying to chase all possible instances. May 3, 2019 at 16:02
  • I think a problem with this approach is that it typesets the whole compound label using \oldstylenums. In some fonts (e.g., STIX; try adding \usepackage{stix2} to the preamble) only digits come out correctly (for example in STIX it looks like "(2009,)"). (Could this be fixed by writing a more sophisticated macro that typesets digits inside oldstylenums and leaves everything else unchanged?)
    – banbh
    May 3, 2019 at 17:43
  • \oldstylenums is core LaTeX and specifically sets letters in math style. stix2 should respect this; you can partially fix this by passing the notextcomp option to the package, but you should report this as a package bug. For near standard fonts you can use the cfr-lm package, cf. tex.stackexchange.com/q/13455/15925 fontspec with lualatex would provide other possibilities. May 4, 2019 at 8:35

You must log in to answer this question.

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