我认为我不明白\DeclareSourcemap
其中的工作原理biblatex
。
我正在尝试定义 3 条规则:
- 移至
issue
数字; - 删除
number
以“Phys. Rev.”开头的期刊; - 删除
volume
“JHEP”期刊。
这是我现在所拥有的,但它似乎将所有转换应用于所有参考书目条目。
\DeclareSourcemap{
\maps[datatype=bibtex]{
\map{
\step[fieldsource=issue]
\step[fieldset=number, origfieldval]
\step[fieldset=issue, null]
%
\step[fieldsource=journal, fieldtarget=journaltitle]
\step[fieldsource=journaltitle, match=\regexp{\APhys\.\s+Rev\.}]
\step[fieldset=number, null]
%
\step[fieldsource=journal, fieldtarget=journaltitle]
\step[fieldsource=journaltitle, match=\regexp{\AJHEP\Z}]
\step[fieldset=volume, null]
}
}
}
理想情况下,我还希望能够issue
转移到number
除非 number
没有定义。
答案1
Biber 按顺序处理\step
a 中的所有 s,\map
除非其中一个\step
s 有final
选项,该选项告诉 Biber 如果不适用则在此步骤停止。
final
由于问题中显示的代码中没有s,因此所有\step
s 都会被执行,这意味着最后volume
和number
都会被删除。
您需要将想要做的不同的事情分成单独的\map
部分并使用final
。
\documentclass[british]{article}
\usepackage[T1]{fontenc}
\usepackage{babel}
\usepackage{csquotes}
\usepackage[backend=biber, style=authoryear]{biblatex}
\DeclareSourcemap{
\maps[datatype=bibtex]{
% remap fields for all entries, but nothing will be overwritten
\map{
\step[fieldsource=issue, fieldtarget=number]
\step[fieldsource=journal, fieldtarget=journaltitle]
}
% delete number only for Phys. Rev.
\map{
\step[fieldsource=journaltitle, match=\regexp{\APhys\.\s+Rev\.}, final]
\step[fieldset=number, null]
}
% delte volume only for JHEP
\map{
\step[fieldsource=journaltitle, match=\regexp{\AJHEP\Z}, final]
\step[fieldset=volume, null]
}
}
}
\begin{filecontents}{\jobname.bib}
@article{elk,
author = {Anne Elk},
title = {A Theory on Brontosauruses},
year = {1972},
journal = {Phys. Rev.},
volume = {131},
issue = {5},
}
@article{belk,
author = {Anne Belk},
title = {A Theory on Brontosauruses},
year = {1971},
journal = {JHEP},
volume = {132},
issue = {6},
}
@article{celk,
author = {Anne Celk},
title = {A Theory on Brontosauruses},
year = {1974},
journal = {Lorem},
volume = {133},
issue = {7},
}
@article{delk,
author = {Anne Delk},
title = {A Theory on Brontosauruses},
year = {1975},
journal = {Lorem},
volume = {134},
number = {8},
}
@article{felk,
author = {Anne Felk},
title = {A Theory on Brontosauruses},
year = {1977},
journal = {Lorem},
volume = {135},
number = {9},
issue = {Michaelmas term},
}
\end{filecontents}
\addbibresource{\jobname.bib}
\addbibresource{biblatex-examples.bib}
\begin{document}
Lorem \autocite{sigfridsson,elk,belk,celk,delk,felk}
\printbibliography
\end{document}