我正在使用 bilatex 构建 bibdriver,并用它\entrydata*
来从另一个条目中检索信息,但同时,我需要封闭条目的信息。Biblatex 确实提供了一种机制,正是带星号的版本\entrydata
“将使用以字符串‘saved’为前缀的字段、计数器和其他资源名称克隆封闭条目的所有字段。”
这对于大多数字段都适用,但我似乎找不到访问封闭条目的日期字段的方法。日期当然是特殊字段(感谢 moewe),并使用 打印\print<datetype>date
。但似乎没有“已保存”的日期类型。那么,我如何使用 访问“已保存日期” \entrydata*
?
\documentclass{article}
\usepackage[style=authortitle]{biblatex}
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@book{mybook,
author = {Author},
title = {Book Title},
date = {2018},
}
@customa{myentry,
author = {Buthor},
title = {My entry's title},
date = {2017},
xref = {book},
}
\end{filecontents}
\addbibresource{\jobname.bib}
\DeclareBibliographyDriver{customa}{%
\usebibmacro{bibindex}%
\usebibmacro{begentry}%
\printnames{author}%
\setunit{\addcomma\space}%
\printfield{title}%
\newunit\newblock
\usebibmacro{in:}%
\entrydata*{mybook}{%
\printnames{author}%
\setunit{\addcomma\space}%
\printfield{title}%
\newunit\newblock
\printtext{Which contains:\space}%
\printnames{savedauthor}%
\setunit{\addcomma\space}%
\printfield{savedtitle}%
\setunit{\addcomma\space}%
\printdate%
%\printsaveddate % <- this doesn't work
\setunit{\addcomma\space}%
\printtext{\thefield{entrykey}}%
\setunit{\addcomma\space}%
\printtext{\thefield{clonesourcekey}}% <- this prints nothing
\setunit{\addcomma\space}%
\entrydata{\thefield{clonesourcekey}}{\printdate}% this doesn't work either
\setunit{\addcomma\space}%
\printtext{\mkbibdateshort{savedyear}{savedmonth}{savedday}}% following David's suggestion in the comments: adds unwanted bce string
}%
\setunit{\addcomma\space}%
\printtext{\mkbibdateshort{year}{month}{day}}% no bce string here
\usebibmacro{finentry}%
}
\begin{document}
\nocite{*}
\fullcite{myentry}
\end{document}
更新:我尝试使用嵌套的 entrydata 来实现这一点。我想到访问savedentrykey
。结果发现它有一个特殊名称clonesourcekey
。因此,我想到使用\entrydata{\thefield{clonesourcekey}}{\printdate}
。但不知何故,我也无法让它工作。\thefield{clonesourcekey}
那里什么都不打印。我更新了代码以包含此尝试。
更新 2:按照 David 在评论中的建议(或大致如此),我尝试使用\mkbibdateshort{savedyear}{savedmonth}{savedday}
。但不知何故,这样生成的日期会得到一个不需要的(和不必要的)bce 字符串。
答案1
这是一个在 3.11 版中已修复的错误
biblatex
。如果您遇到类似的问题,请更新您的 TeX 发行版以确保您拥有最新版本的
biblatex
Biber。其余答案留待历史兴趣来解答。
biblatex
目前确实不支持正确保存日期字段。请测试https://github.com/plk/biblatex/pull/684。
经过更改后,可以使用
\printsaveddate
就像您期望的那样简单地打印保存的日期。
根据 David 的想法提出的临时解决方法
\printtext{\mkbibdateshort{savedyear}{savedmonth}{savedday}}
也是可能的。
我们只需要提供一些未自动保存的额外宏。
\documentclass[ngerman]{article}
\usepackage{babel}
\usepackage[style=authortitle]{biblatex}
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@book{mybook,
author = {Author},
title = {Book Title},
date = {2018},
}
@customa{myentry,
author = {Buthor},
title = {My entry's title},
date = {2017},
xref = {book},
}
\end{filecontents}
\addbibresource{\jobname.bib}
\makeatletter
\def\gusbrs@datemeta#1{%
\csdef{ifsaved#1dateera}##1{\ifcsstring{abx@field@saved#1dateera}{##1}}%
\csdef{ifsaved#1enddateera}##1{\ifcsstring{abx@field@saved#1enddateera}{##1}}%
}
\DeclareBibliographyDriver{customa}{%
\usebibmacro{bibindex}%
\usebibmacro{begentry}%
\printnames{author}%
\setunit{\addcomma\space}%
\printfield{title}%
\newunit\newblock
\usebibmacro{in:}%
\entrydata*{mybook}{%
\printnames{author}%
\setunit{\addcomma\space}%
\printfield{title}%
\newunit\newblock
\printtext{Which contains:\space}%
\printnames{savedauthor}%
\setunit{\addcomma\space}%
\printfield{savedtitle}%
\setunit{\addcomma\space}%
\printdate
\setunit{\addcomma\space}%
\gusbrs@datemeta{}%
\printtext{\mkbibdateshort{savedyear}{savedmonth}{savedday}}%
}%
}
\makeatother
\begin{document}
\nocite{*}
\fullcite{myentry}
\end{document}