我想要以下形式的书目标签:
文件 X:
[A-302] publication A
[A-801] publication B
...
其中 为A-
,labelprefix
数字是.bib
文件本身中定义的值(即未生成的值)。
我需要这个,因为在不同的文档中(或\newrefcontext
在同一文档中),我想保证相同的编号用于来自的相同文档.bib
,但前缀不同:
文件Y:
[B-302] publication A
[B-801] publication B
...
所以这些标签编号是不是由 BibTeX 生成,但由不同的独立应用程序维护。
这大致就是我目前所拥有的。
文件十:
\documentclass[twoside,a4paper,11pt]{report}
\usepackage[%
backend=biber,
defernumbers=true, % NOTE: not sure about this one
labelnumber=true,
style=numeric,
]{biblatex}
\addbibresource{references.bib}
\begin{document}
This is the first document, where references made to \cite{KEY_A} and \cite{KEY_C}.
\newrefcontext[labelprefix=A]
\printbibliography[heading=none]
\end{document}
文件Y:
\documentclass[twoside,a4paper,11pt]{report}
\usepackage[%
backend=biber,
defernumbers=true, % NOTE: not sure about this one
labelnumber=true,
style=numeric,
]{biblatex}
\addbibresource{references.bib}
\begin{document}
This is the second document, where references made to \cite{KEY_B} and \cite{KEY_C}.
\newrefcontext[labelprefix=B]
\printbibliography[heading=none]
\end{document}
references.bib
:
@Article{KEY_A,
shorthand = 0302,
author = "Albert Einstein",
title = "On the molecular-kinetic theory of the
movement by heat of particles suspended in liquids at
rest",
year = "1905"
}
@book{KEY_B,
shorthand = 0815,
author = {Mr. Egghead},
year = "2001",
title = "My superawesome book about how to be superawesome",
}
@book{KEY_C,
shorthand = 1033,
author = {Ms. Egghead},
year = "2002",
title = "My normal book about how to live with someone who's convinced he's superawesome",
}
在这种情况下,结果仅使用shorthand
,而labelprefix
完全忽略:
我尝试了该shorthand
选项的几种变体(如上所示)。我还尝试过自定义labelnumber
,
\DeclareFieldFormat{labelnumber}{\thefield{key}}
试图使用字段key
而不是shorthand
字段。这行不通,因为我最终得到了仅有的(labelprefix
暗示\thefield{key}
并不像我预期的那样起作用)。
我已经尝试了很多类似的方法,但似乎无法将我的自定义标签编号与本地定义的前缀结合起来......我该如何做到这一点?
答案1
shorthand
您可以使用 sorcemap直接将前缀添加到您的。
\documentclass[twoside,a4paper,11pt]{report}
\usepackage[%
% backend=biber, % this is already the default
% defernumbers=true, % I don't see why you'd need it here
% labelnumber=true, % it is the default of numeric style
% style=numeric, % it is the default of biblatex
]{biblatex}
\addbibresource{references.bib}
\DeclareSourcemap{
\maps[datatype=bibtex]{
\map[overwrite]{
\step[fieldsource=shorthand]
\step[fieldset=shorthand, fieldvalue={A-}]
\step[fieldset=shorthand, origfieldval, append]
}
}
}
\begin{document}
This is the first document, where references made to \cite{KEY_A}, \cite{KEY_B} and \cite{KEY_C}.
\printbibliography[heading=none]
\end{document}
当然,您可以直接将源映射中的值更改为“文档 Y”上的“B-”。