使用 biblatex 以旧式数字排版年份

使用 biblatex 以旧式数字排版年份

当我引用参考书目中的条目(使用 style authoryear-comp)时,我希望使用旧式数字排版年份。我通过重新定义 bib 宏部分实现了我想要的功能,cite:labeldate+extradate但它并没有完全起作用(这让我怀疑我根本没有以正确的方式处理这个问题)。

例如,下面是一个 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}

当上面的内容排版时,引文包含字符串“(2009a,b)”。年份使用旧式数字排版,但是“a”(我认为)也以这种方式排版,使其看起来像是斜体,最后“,b”(正确)不受影响。我想要的是将年份(而不是其他内容)设置为旧式数字。

答案1

日期打印的代码biblatex有点……不寻常,分散在许多不同的地方。它发展了很多,不同的要求意味着它变得相当复杂。

问题中的方法的难点在于extradate标签也是由命令打印的\printlabeldateextra,因此\oldstylenums也适用于它。

最终,进行日期排版的代码存在于.lbx文件中。如果你想将所有年份改为旧式数字,你应该从那里下手。

不幸的是,该代码并不简短。

下面的代码取自english.lbx第24-51行)。如果您正在使用其他语言,则需要对所使用的每种语言应用类似的重新定义。

\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}

所有年份均采用旧式数字。

目前,代码只对年份应用旧式数字。月份和日期保持不变,人们可能也会将它们更改为旧式数字。

\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}}}}%
}

答案2

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

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

或者,如果你需要hyperref

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

在此处输入图片描述

答案3

date您应该通过例如调整字段格式等

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

文档中说,对各个字段的字体进行更改属于此处biblatex。不幸的是,要正确设置多个字段。如果遗漏了一些,请告诉我。

示例输出

\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}

相关内容