以下是 mwe:
\begin{filecontents}[overwrite]{\jobname.bib}
@customa{a,
author = {Author},
eventdate = {1000-01-01},
title = {Title},
journaltitle = {Journaltitle},
date = {3000},
}
@customa{b,
author = {Author},
eventdate = {2000-01-01},
title = {Title},
journaltitle = {Journaltitle},
date = {1000},
}
@customa{c,
author = {Author},
eventdate = {3000-01-01},
title = {Title},
journaltitle = {Journaltitle},
date = {2000},
}
@article{article,
author = {Author},
title = {Title},
journaltitle = {Journaltitle},
date = {2000},
}
\end{filecontents}
\documentclass{article}
\usepackage[style=authortitle]{biblatex}
\addbibresource{\jobname.bib}
\DeclareStyleSourcemap{
\maps{
\map{
\pertype{customa}
\step[fieldsource=eventdate, match=\regexp{\A(\d+)}]
\step[fieldset=sortyear, fieldvalue={$1}]
}
}
}
\DeclareBibliographyDriver{customa}{%
\usebibmacro{bibindex}%
\usebibmacro{begentry}%
\printnames{author}%
\newunit
\printeventdate
\newunit
\usebibmacro{title}%
\newunit\newblock
\bibstring{in}%
\printunit{\intitlepunct}
\usebibmacro{journal+issuetitle}%
\usebibmacro{finentry}}
\begin{document}
\nocite{*}
\printbibliography
\end{document}
mwe 工作正常。
据我所知,如果<datetype>date
定义了,biber/biblatex 会自动生成<datetype>year
、<datetype>month
和<datetype>day
字段。
所以sourcemapping代码也应该可以按照下面的方式写。
\DeclareStyleSourcemap{
\maps{
\map{
\pertype{customa}
\step[fieldsource=eventyear]
\step[fieldset=sortyear, origfieldval]
}
}
}
但第二个解决方案不起作用。为什么?错误是什么?谢谢。
答案1
源映射步骤(Biber 将您对数据的更改应用于此步骤)在文件处理过程中的早期发生.bib
。具体而言,它发生在 Biber 将日期字段拆分为其组件的步骤之前。
因此,在\DeclareStyleSourcemap
执行时,日期字段仍然存在eventdate
(如文件中所给出的.bib
)并且eventyear
朋友尚不可用。