使用 biblatex 和 biber,我使用 重新剖析创建多个书目。此外,我还使用类别进一步细分参考书目。对于每个重新切取我使用不同的 bib 文件,该文件不受我的控制,密钥可能会在不同的 bib 文件中重复。
问题出现于,当一个条目被添加到第一个引用部分中的类别,而另一个具有相同键的条目被添加到下一个引用部分中的另一个类别时。在第二个引用部分中,该条目是错误的类别(如在第一个引用部分中分配的)。
这是一个运行示例
\documentclass{article}
\usepackage[backend=biber,defernums=true,doi=true]{biblatex}
\DeclareBibliographyCategory{own}
\DeclareBibliographyCategory{other}
\DeclareBibliographyCategory{important}
\defbibheading{first}{\section{First Bib}}
\defbibheading{second}{\section{Second Bib}}
\newcommand{\citex}[2][own]{%
\addtocategory{#1}{#2}%
\cite{#2}
}
\begin{filecontents}{aaa.bib}
@article{a,
author = {A Author},
title = {a from aaa.bib},
journal = {Journal of aaa.bib}}
\end{filecontents}
\begin{filecontents}{bbb.bib}
@article{a,
author = {A Author},
title = {a from bbb.bib},
journal = {Journal of bbb.bib}}
@article{b,
author = {B Author},
title = {b from bbb.bib},
journal = {Journal of bbb.bib}}
@article{c,
author = {C Author},
title = {c from bbb.bib},
journal = {Journal of bbb.bib}}
\end{filecontents}
\addbibresource[label=alabel]{aaa.bib}
\addbibresource[label=blabel]{bbb.bib}
\begin{document}
\begin{refsection}[alabel]
\section{First refsection}
First refsection with only contents of aaa.bib\citex[own]{a}
\printbibliography[section=\therefsection,heading=first, category=own]
Here comes the second Bibliography
\printbibliography[section=\therefsection,heading=second,notcategory=own]
\end{refsection}
\begin{refsection}[blabel]
\section{Second refsection}
Second refsection with only contents of bbb.bib\citex[own]{b}\citex[important]{a},\citex[other]{c}
\printbibliography[section=\therefsection,heading=first, category=own]
Here comes the second Bibliography
\printbibliography[section=\therefsection,heading=second,notcategory=own]
\end{refsection}
\end{document}
参考资料1“a from bbb.bib” 未添加到“自身”类别,而是添加到“重要”类别,该类别应打印在第二个参考书目(第 5 节)中,而不是第一个参考书目(第 4 节)中
biblatex 手册指出
\addtocategory{〈category〉}{〈key〉} 将〈key〉分配给〈category〉,用于与 \printbibliography 的分类和非分类过滤器结合使用。此命令可用于前言和文档正文中。〈key〉可以是单个条目键或以逗号分隔的键列表。该任务是全球性的。
有没有什么方法可以让类别保持局部于引用部分?
答案1
您可以尝试以下操作。它将所有内容添加到按 refsection 编号的类别中,然后您可以使用键进行过滤refcategory
:
\documentclass{article}
\usepackage[backend=biber,defernumbers=true,doi=true]{biblatex}
\DeclareBibliographyCategory{own}
\DeclareBibliographyCategory{other}
\DeclareBibliographyCategory{important}
\makeatletter
\def\blx@addtocategory#1#2{%
% If we are adding a set member to a category, make sure we also add the
% set parent if it is cited. If it is cited, we should be using the set
% parent in the category, not the set child member. blx@setc@... will
% only exist if the set parent is also cited as it is only defined when a
% member contains \inset which only happens when the set parent is cited.
\ifcsdef{blx@setc@\the\c@refsection @#2}
{\blx@auxwrite\@mainaux{}{\string\abx@aux@category{#1}{\csuse{blx@setc@\the\c@refsection @#2}}}%
\abx@aux@category{#1}{\csuse{blx@setc@\the\c@refsection @#2}}}
{}%
\blx@auxwrite\@mainaux{}{\string\abx@aux@category{#1}{#2}}%
\abx@aux@category{#1}{#2}%
%add ref categories
\blx@auxwrite\@mainaux{}{\string\abx@aux@category{\the\c@refsection-refsection-#1}{#2}}%
\abx@aux@category{\the\c@refsection-refsection-#1}{#2}%
}
\define@key{blx@bib1}{refcategory}{}
\define@key{blx@bib1}{notrefcategory}{}
\define@key{blx@biblist1}{refcategory}{}
\define@key{blx@biblist1}{notrefcategory}{}
\define@key{blx@bib2}{refcategory}{\expandafter\blx@key@category\expandafter{\the\c@refsection-refsection-#1}}
\define@key{blx@biblist2}{refcategory}{\expandafter\blx@key@category\expandafter{\the\c@refsection-refsection-#1}}
\define@key{blx@bib2}{notrefcategory}{\expandafter\blx@key@notcategory\expandafter{\the\c@refsection-refsection-#1}}
\define@key{blx@biblist2}{notrefcategory}{\expandafter\blx@key@notcategory\expandafter{\the\c@refsection-refsection-#1}}
\makeatother
\defbibheading{first}{\section{First Bib}}
\defbibheading{second}{\section{Second Bib}}
\newcommand{\citex}[2][own]{%
\addtocategory{#1}{#2}%
\cite{#2}
}
\begin{filecontents}{aaa.bib}
@article{a,
author = {A Author},
title = {a from aaa.bib},
journal = {Journal of aaa.bib}}
\end{filecontents}
\begin{filecontents}{bbb.bib}
@article{a,
author = {A Author},
title = {a from bbb.bib},
journal = {Journal of bbb.bib}}
@article{b,
author = {B Author},
title = {b from bbb.bib},
journal = {Journal of bbb.bib}}
@article{c,
author = {C Author},
title = {c from bbb.bib},
journal = {Journal of bbb.bib}}
\end{filecontents}
\addbibresource[label=alabel]{aaa.bib}
\addbibresource[label=blabel]{bbb.bib}
\begin{document}
\begin{refsection}[alabel]
\section{First refsection}
First refsection with only contents of aaa.bib\citex[own]{a}
\printbibliography[section=\therefsection,heading=first, refcategory=own]
Here comes the second Bibliography
\printbibliography[section=\therefsection,heading=second,notrefcategory=own]
\end{refsection}
\begin{refsection}[blabel]
\section{Second refsection}
Second refsection with only contents of bbb.bib\citex[own]{b}\citex[important]{a},\citex[other]{c}
\printbibliography[section=\therefsection,heading=first, refcategory=own]
Here comes the second Bibliography
\printbibliography[section=\therefsection,heading=second,notrefcategory=own]
\end{refsection}
\end{document}