我想使用文献管理工具中的组作为关键字来BibLaTeX
为某些章节创建特定的书目。如果条目包含这两个字段,我设法将组字段重新映射为关键字字段,但这似乎不起作用。我必须如何调整命令\DeclareSourcemap
才能使其工作?提前致谢!
梅威瑟:
\documentclass[a4paper,12pt]{scrartcl}
\usepackage{filecontents}
\usepackage[
backend=biber,
style=authoryear-comp,
]{biblatex}
\DeclareSourcemap{
\maps[datatype=bibtex]{
\map{
\step[fieldsource=groups, fieldtarget=keywords]
}
}
}
\begin{filecontents}{sample.bib}
@article{greenwade93,
author = "George D. Greenwade",
title = "The {C}omprehensive {T}ex {A}rchive {N}etwork ({CTAN})",
year = "1993",
journal = "TUGBoat",
volume = "14",
number = "3",
pages = "342--351",
keywords = {bar},
groups = {foo}
}
@article{redwade93,
author = "George D. Redwade",
title = "The {C}omprehensive {T}ex {A}rchive {N}etwork ({CTAN})",
year = "1993",
journal = "TUGBoat",
volume = "14",
number = "3",
pages = "342--351",
groups = {foo}
}
@article{bluewade93,
author = "George D. Bluewade",
title = "The {C}omprehensive {T}ex {A}rchive {N}etwork ({CTAN})",
year = "1993",
journal = "TUGBoat",
volume = "14",
number = "3",
pages = "342--351",
keywords = {bar}
}
\end{filecontents}
\addbibresource{sample.bib}
\begin{document}
This document contains citations of \cite{greenwade93}, \cite{redwade93} and \cite{bluewade93}---but \cite{greenwade93} doesn't appear in the first bibliography.
\printbibliography[keyword=foo,title={Bibliography One}]
\printbibliography[keyword=bar,title={Bibliography Two}]
\end{document}
答案1
默认情况下,biblatex
非常不愿意更改或覆盖现有字段。您必须用 来鼓励它overwrite=true
。
然而,在 Biber 2.7 版及以上版本中,fieldtarget
即使启用了该方法,该方法似乎也难以处理现有字段overwrite=true
。您可以使用
\DeclareSourcemap{
\maps[datatype=bibtex]{
\map[overwrite=true]{
\step[fieldsource=groups]
\step[fieldset=keywords, origfieldval]
}
}
}
这只会keywords
用 的内容覆盖groups
。
该问题已在 2.8 版(DEV 版本,尚未发布)中修复,因此我们可以使用
\DeclareSourcemap{
\maps[datatype=bibtex]{
\map[overwrite=true]{
\step[fieldsource=groups, fieldtarget=keywords]
}
}
}
如果你想收集这两个字段并加以keywords
使用
\DeclareSourcemap{
\maps[datatype=bibtex]{
\map[overwrite=true]{
\step[fieldsource=keywords, final]
\step[fieldsource=groups]
\step[fieldset=keywords, fieldvalue={,}, append]
\step[fieldset=keywords, origfieldval, append]
}
\map{
\step[fieldsource=groups]
\step[fieldset=keywords, origfieldval]
}
}
}
如果后者不存在,则将其groups
复制到;如果已经存在一些关键字,则将的内容附加到(请注意,我们需要插入逗号,因此我们不能一次性完成两个步骤)。keywords
groups
keywords