我必须使用多个书目,但其中一些应该共享相同的数字前缀。 Biblatex 允许设置前缀数字,但这会隐式强制重置数字。这会导致标签多次使用,因为每次调用 printbibliography 时都会重置编号。以下示例说明了这个问题:
\documentclass[a4paper,oneside]{article}
\usepackage{filecontents}
\begin{filecontents*}{bib.bib}
@Misc{A,
author = {A Author},
title = {Title},
year = 2013,
}
@Misc{B,
author = {B Buthor},
title = {Title},
year = 2013,
}
@Misc{C,
author = {C Cuthor},
title = {Title},
year = 2013,
}
\end{filecontents*}
\usepackage[english]{babel}
\usepackage[style=numeric-comp,defernumbers,backend=biber]{biblatex}
\addbibresource{bib.bib}
\DeclareBibliographyCategory{catA1}
\DeclareBibliographyCategory{catA2}
\DeclareBibliographyCategory{catB}
\addtocategory{catA1}{A}
\addtocategory{catA2}{B}
\addtocategory{catB}{C}
\begin{document}
\cite{A} supposed to be [A1]\\
\cite{B} supposed to be [A2]\\
\cite{C} supposed to be [B1]
\section{Part A1}
\printbibliography[category=catA1,prefixnumbers={A}]
\section{Part A2}
\printbibliography[category=catA2,prefixnumbers={A}]%resetnumbers=false does not work here
\section{Part B}
\printbibliography[category=catB,prefixnumbers={B}]
\end{document}
我如何告诉 Biblatex 在打印第二个参考书目时不要重置编号?
答案1
一种可能的,也是“黑客式的”方法是使用biblatex
(重新)定义不同bibliography
环境的能力。
因此,可以创建两个bibliography
环境:一个用于 A 前缀出版物,另一个用于 B 出版物(解决方案使用enumitem
包,即\usepackage{enumitem}
,帮助将bibliography
环境重新定义为enumerate
,以及其对不同 s 恢复计数的能力enumerate
)
\defbibenvironment{bibliography}
{\begin{enumerate}[series=bib,resume=bib,label=A\arabic*.,ref=A\arabic*]}
{\end{enumerate}}
{\item\label{\thefield{entrykey}}}
\defbibenvironment{bbiblio}
{\begin{enumerate}[label=B\arabic*.,ref=B\arabic*]}
{\end{enumerate}}
{\item\label{\thefield{entrykey}}}
请注意,我们必须定义枚举标签的显示方式以及参考文献的格式(ref
)。此解决方案还需要重新定义各种引用命令。\cite
可能的重新定义为
\DeclareCiteCommand{\cite}
[\mkbibbrackets]
{}
{\ref{\thefield{entrykey}}}
{\addcomma\addspace}
{\iffieldundef{postnote}{}{\addcomma\addspace\printfield{postnote}}}
其他 cite 命令也需要类似的定义。更好的方法是重新定义相应的bibmacro
s。
最后一步是使用选项调用具有所需书目环境的参考书目env
(这不是必需的bibliography
)。
\section{Part A1}
\printbibliography[category=catA1]
\section{Part A2}
\printbibliography[category=catA2]
\section{Part B}
\printbibliography[category=catB,env=bbiblio]
结果是
答案2
接受的答案破坏了几件事,例如,将连续数字转换为样式的范围numeric-comp
。自 biblatex 2.9a 版以来,该选项resetnumbers
接受数字。这允许使用每个部分的计数器来获得不太黑客的解决方案:
\newcounter{BibA}
\setcounter{BibA}{1}
\newcounter{BibB}
\setcounter{BibB}{1}
可以使用以下钩子获取书目中的条目数:
\newcounter{NumberOfBibEntries}
\AtBeginBibliography{\setcounter{NumberOfBibEntries}{0}}
\AtEveryBibitem{\stepcounter{NumberOfBibEntries}}
然后,每次调用之后都可以更新部分计数器,\printbibliography
并将其用作resetnumbers
以下参考书目的参数:
\section{Part A1}
\printbibliography[category=catA1,prefixnumbers={A}]
\addtocounter{BibA}{\value{NumberOfBibEntries}}
\section{Part A2}
\printbibliography[category=catA2,prefixnumbers={A}, resetnumbers=\number\value{BibA}]
\addtocounter{BibA}{\value{NumberOfBibEntries}}
\section{Part B}
\printbibliography[category=catB,prefixnumbers={B}]
\addtocounter{BibB}{\value{NumberOfBibEntries}}
最好将其包装在宏中,例如
\newcommand{\myprintbibliography}[2][]{%
\printbibliography[#1 ,prefixnumbers={#2}, resetnumbers=\number\value{Bib#2}]%
\addtocounter{Bib#2}{\value{NumberOfBibEntries}}%
}
完整文件:
\documentclass[a4paper,oneside]{article}
\usepackage{filecontents}
\begin{filecontents*}{bib.bib}
@Misc{A,
author = {A Author},
title = {Title},
year = 2013,
}
@Misc{B,
author = {B Buthor},
title = {Title},
year = 2013,
}
@Misc{C,
author = {C Cuthor},
title = {Title},
year = 2013,
}
@Misc{D,
author = {D Duthor},
title = {Title},
year = 2013,
}
\end{filecontents*}
\usepackage[english]{babel}
\usepackage{enumitem}
\usepackage[style=numeric-comp,defernumbers,backend=biber]{biblatex}
\addbibresource{bib.bib}
\DeclareBibliographyCategory{catA1}
\DeclareBibliographyCategory{catA2}
\DeclareBibliographyCategory{catB}
\addtocategory{catA1}{A,B}
\addtocategory{catA2}{C}
\addtocategory{catB}{D}
\newcounter{NumberOfBibEntries}
\AtBeginBibliography{\setcounter{NumberOfBibEntries}{0}}
\AtEveryBibitem{\stepcounter{NumberOfBibEntries}}
\newcounter{BibA}
\setcounter{BibA}{1}
\newcounter{BibB}
\setcounter{BibB}{1}
\newcommand{\myprintbibliography}[2][]{%
\printbibliography[#1 ,prefixnumbers={#2}, resetnumbers=\number\value{Bib#2}]
\addtocounter{Bib#2}{\value{NumberOfBibEntries}}
}
\parindent=0pt
\begin{document}
\cite{A, B, C} supposed to be [A1-A3]\\
\cite{D} supposed to be [B1]\\
\section{Part A1}
\myprintbibliography[category=catA1]{A}
\section{Part A2}
\myprintbibliography[category=catA2]{A}
\section{Part B}
\myprintbibliography[category=catB]{B}
\end{document}
我遇到的唯一问题与必要选项有关defernumbers
。正如手册所述,有时必须删除 .aux 文件才能获得正确的编号。
答案3
随着 biblatex 3.5+biber 2.6(目前均在 Sourceforge 的 DEV 中),此行为终于得到修复。现在可以resetnumbers
以正常方式覆盖隐式(示例已更新,其中更改prefixnumbers
移至 refcontext 机制,名称更改为labelprefix
biblatex 3.3 中):
\section{Part A1}
\newrefcontext[labelprefix=A]
\printbibliography[category=catA1]
\section{Part A2}
\printbibliography[category=catA2, resetnumbers=false]
\section{Part B}
\newrefcontext[labelprefix=B]
\printbibliography[category=catB]