biblatex - 如何在块末尾将日期(始终以 YYYY-MM 形式提供)作为字符串打印出来?

biblatex - 如何在块末尾将日期(始终以 YYYY-MM 形式提供)作为字符串打印出来?

在 的条目末尾standardisodin,我希望将Date-field 中的内容打印出来,如下所示:

[...] 内容,版本:2011 年 5 月。

我认为月份稍后会更改为我的语言,但添加字符串版本,我到现在还没一点成功。

平均能量损失

\documentclass[
a4paper,
12pt,
]{scrartcl}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}

\usepackage[
language=auto,
style=authoryear-ibid,
backend=biber,
hyperref=true,
dashed=false,
isbn=false,
doi=false,
maxcitenames=2,
maxbibnames=99,
sorting=nyt,
firstinits=true,
uniquename=init,
uniquelist=false,
autocite=footnote,
ibidtracker=true,
date=comp,
mincrossrefs=1,
]{biblatex}
\usepackage{xpatch}

%definition of new source type: Standard (ISO, DIN, or other guidelines)
\DeclareDatamodelEntrytypes{standardisodin}
\DeclareDatamodelEntryfields[standardisodin]{type,number}
\DeclareBibliographyDriver{standardisodin}{%
\usebibmacro{bibindex}%
\usebibmacro{begentry}%
%\usebibmacro{author}%
%\setunit{\labelnamepunct}\newblock
\printfield{type}\addspace%
\printfield{number}\addcolon\addspace%
\usebibmacro{title}\addspace%
%\newunit\newblock
%\usebibmacro{location+date}%
\newunit\newblock
\printfield{date}
\newunit\newblock
\iftoggle{bbx:url}
{\usebibmacro{url+urldate}}
{}%
\newunit\newblock
\usebibmacro{addendum+pubstate}%
\setunit{\bibpagerefpunct}\newblock
\usebibmacro{pageref}%
\newunit\newblock
\usebibmacro{related}%
\usebibmacro{finentry}}

\DeclareCiteCommand{\citetitle}
{\boolfalse{citetracker}%
    \boolfalse{pagetracker}%
    \usebibmacro{prenote}}
{\ifciteindex
    {\indexfield{indextitle}}
    {}%
    \ifentrytype{standardisodin} 
    {\printfield{type}%
        \setunit{\addspace}%
        \printfield{number}%
        \setunit{\addcolon\space}}
    {}
    \printfield[citetitle]{labeltitle}}
{\multicitedelim}
{\usebibmacro{postnote}}

\renewbibmacro*{cite}{%
    \global\boolfalse{cbx:loccit}%
    \iffieldundef{shorthand}
    {\ifthenelse{\ifciteibid\AND\NOT\iffirstonpage}
        {\usebibmacro{cite:ibid}}
        {\ifentrytype{standardisodin}
            {\printfield{type}%
                \setunit{\addspace}%
                \printfield{number}}
            {\ifthenelse{\ifnameundef{labelname}\OR\iffieldundef{labelyear}}
                {\usebibmacro{cite:label}%
                    \setunit{\addspace}}
                {\printnames{labelname}%
                    \setunit{\nameyeardelim}}%
                \usebibmacro{cite:labelyear+extrayear}}}}
    {\usebibmacro{cite:shorthand}}}

\begin{filecontents}{\jobname.bib}
@Standardisodin{abc,
Title                    = {Stuff},
Author                   = {{DIN Deutsches Institut für Normung e.~V.}},
Date                     = {2011-05},
Location                 = {Berlin},
Number                   = {333444},
Type                     = {DIN},
Year                     = {2011},
}
\end{filecontents}

\addbibresource{\jobname.bib}
\nocite{*}

\listfiles

\begin{document}
\begin{flushleft}
\citetitle{abc}
\end{flushleft}

Words.

\printbibliography
\end{document}

答案1

要打印日期,最简单的方法是使用\printdate,如果您对提供的格式不满意\printdate,我们将不得不付出更大的努力才能获得良好的输出。

我们要添加的代码是

\iffieldundef{year}
  {}
  {\printtext{Version:} \printdate}%

仅当存在日期时,它才会打印日期和前缀“版本”(请注意,biblatex/Biber 会自动将该date字段分解为yearmonth和 等部分date)。

在驱动程序中

\DeclareBibliographyDriver{standardisodin}{%
\usebibmacro{bibindex}%
\usebibmacro{begentry}%
%\usebibmacro{author}%
%\setunit{\labelnamepunct}\newblock
\printfield{type}
\setunit{\addspace}%
\printfield{number}
\setunit{\addcolon\space}%
\usebibmacro{title}
\setunit{\addcomma\space}%
%\usebibmacro{location+date}%
\iffieldundef{year}
  {}
  {\printtext{Version:} \printdate}%
\newunit\newblock
\iftoggle{bbx:url}
{\usebibmacro{url+urldate}}
{}%
\newunit\newblock
\usebibmacro{addendum+pubstate}%
\setunit{\bibpagerefpunct}\newblock
\usebibmacro{pageref}%
\newunit\newblock
\usebibmacro{related}%
\usebibmacro{finentry}}

平均能量损失

\documentclass[
a4paper,
12pt,
]{scrartcl}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}

\usepackage[
language=auto,
style=authoryear-ibid,
backend=biber,
hyperref=true,
dashed=false,
isbn=false,
doi=false,
maxcitenames=2,
maxbibnames=99,
sorting=nyt,
firstinits=true,
uniquename=init,
uniquelist=false,
autocite=footnote,
ibidtracker=true,
date=comp,
mincrossrefs=1,
]{biblatex}
\usepackage{filecontents}

%definition of new source type: Standard (ISO, DIN, or other guidelines)
\DeclareDatamodelEntrytypes{standardisodin}
\DeclareDatamodelEntryfields[standardisodin]{type,number}
\DeclareBibliographyDriver{standardisodin}{%
\usebibmacro{bibindex}%
\usebibmacro{begentry}%
%\usebibmacro{author}%
%\setunit{\labelnamepunct}\newblock
\printfield{type}
\setunit{\addspace}%
\printfield{number}
\setunit{\addcolon\space}%
\usebibmacro{title}
\setunit{\addcomma\space}%
%\usebibmacro{location+date}%
\iffieldundef{year}
  {}
  {\printtext{Version:} \printdate}%
\newunit\newblock
\iftoggle{bbx:url}
{\usebibmacro{url+urldate}}
{}%
\newunit\newblock
\usebibmacro{addendum+pubstate}%
\setunit{\bibpagerefpunct}\newblock
\usebibmacro{pageref}%
\newunit\newblock
\usebibmacro{related}%
\usebibmacro{finentry}}

\DeclareCiteCommand{\citetitle}
{\boolfalse{citetracker}%
    \boolfalse{pagetracker}%
    \usebibmacro{prenote}}
{\ifciteindex
    {\indexfield{indextitle}}
    {}%
    \ifentrytype{standardisodin} 
    {\printfield{type}%
        \setunit{\addspace}%
        \printfield{number}%
        \setunit{\addcolon\space}}
    {}
    \printfield[citetitle]{labeltitle}}
{\multicitedelim}
{\usebibmacro{postnote}}

\renewbibmacro*{cite}{%
    \global\boolfalse{cbx:loccit}%
    \iffieldundef{shorthand}
    {\ifthenelse{\ifciteibid\AND\NOT\iffirstonpage}
        {\usebibmacro{cite:ibid}}
        {\ifentrytype{standardisodin}
            {\printfield{type}%
                \setunit{\addspace}%
                \printfield{number}}
            {\ifthenelse{\ifnameundef{labelname}\OR\iffieldundef{labelyear}}
                {\usebibmacro{cite:label}%
                    \setunit{\addspace}}
                {\printnames{labelname}%
                    \setunit{\nameyeardelim}}%
                \usebibmacro{cite:labelyear+extrayear}}}}
    {\usebibmacro{cite:shorthand}}}

\begin{filecontents*}{\jobname.bib}
@Standardisodin{abc,
Title                    = {Stuff},
Author                   = {{DIN Deutsches Institut für Normung e.~V.}},
Date                     = {2011-05},
Location                 = {Berlin},
Number                   = {333444},
Type                     = {DIN},
}

@Standardisodin{def,
Title                    = {No Date},
Author                   = {{DIN Deutsches Institut für Normung e.~V.}},
Location                 = {Berlin},
Number                   = {333444},
Type                     = {DIN},
addendum = {hi},
}
\end{filecontents*}

\addbibresource{\jobname.bib}
\nocite{*}

\listfiles

\begin{document}
\begin{flushleft}
\citetitle{abc}
\end{flushleft}

Words.

\printbibliography
\end{document}

在此处输入图片描述

相关内容