我有一篇使用带标签的 multibib 版本的文档,即\usepackage[labeled]{multibib}
。但是,hyperref
在引用上不起作用,并且根据“为什么当激活多项选项“标记”时,超链接指向错误的页面?",看来应该使用 biblatex。
\usepackage[labeled]{multibib}
我怎样才能获得与使用相同的结果biblatex
并hyperref
正常工作?
具体来说,如何将下面的最小示例文档翻译成 biblatex?
\documentclass{article}
\usepackage[labeled]{multibib}
\usepackage{hyperref}
\begin{filecontents}{A.bbl}
\begin{thebibliography}{1}
\bibitem{slam2001}
Thomas Ball and Sriram~K. Rajamani.
\newblock Automatically validating temporal safety properties of interfaces.
\newblock In {\em Proceedings of the 8th International SPIN Workshop on Model
Checking of Software}, 2001.
\end{thebibliography}
\end{filecontents}
\begin{filecontents}{B.bbl}
\begin{thebibliography}{1}
\bibitem{blast2007}
Dirk Beyer, Thomas~A. Henzinger, Ranjit Jhala, and Rupak Majumdar.
\newblock The software model checker blast: Applications to software
engineering.
\newblock {\em International Journal on Software Tools for Technology
Transfer}, 2007.
\end{thebibliography}
\end{filecontents}
\newcites{A,B}{Primary,Secondary}
\begin{document}
CiteA~\citeA{slam2001}, CiteB~\citeB{blast2007}
\bibliographyA{refs}
\bibliographyB{refs}
\end{document}
该示例生成以下内容,但引用时无法正常工作pdflatex
:hyperref
答案1
您可以尝试以下操作。
我们假设有两个.bib
文件:\jobname-1.bib
和\jobname-2.bib
,这里通过以下方式创建filecontents*
\begin{filecontents*}{\jobname-1.bib}
@inproceedings{slam2001,
author = {Thomas Ball and Sriram K. Rajamani},
title = {Automatically Validating Temporal Safety Properties of Interfaces},
booktitle = {Proceedings of the 8th International SPIN Workshop on Model Checking of Software},
editor = {Matthew Dwyer},
date = {2001},
}
\end{filecontents*}
\begin{filecontents*}{\jobname-2.bib}
@article{blast2007,
author = {Dirk Beyer and Thomas A. Henzinger and Ranjit Jhala and Rupak Majumdar},
title = {The software model checker {BLAST}},
subtitle = {Applications to software engineering},
journal = {International Journal on Software Tools for Technology Transfer},
date = {2007},
volume = {9},
}
\end{filecontents*}
\addbibresource{\jobname-1.bib}
\addbibresource{\jobname-2.bib}
这两个文件将使用 Biber 的 sourcemapping 添加到不同的关键字
\DeclareSourcemap{
\maps[datatype=bibtex]{
\map{
\perdatasource{\jobname-1.bib}
\step[fieldset=keywords, fieldvalue={, primary}, append]
}
\map{
\perdatasource{\jobname-2.bib}
\step[fieldset=keywords, fieldvalue={, secondary}, append]
}
}
}
\jobname-1.bib
获取keyword
primary
,\jobname-2.bib
获取secondary
。(我在这里选择了primary
和secondary
,但你可以选择任何你喜欢的。只需确保这些关键词未用于文件.bib
或参考书目设置中的任何其他内容。)请注意,文件名.bib
在中是“硬编码”的\perdatasource
。如果你有不同的文件名,则需要相应地调整代码。
如果您坚持连续编号(即不希望第二个参考书目从 [B1] 开始),我们需要终止对以下情况biblatex
的自动检测:resetnumbers
labelprefix
\makeatletter
\providerobustcmd*{\blx@kv@defkey}{\define@key}
\blx@kv@defkey{blx@bib1}{noresetnumbersforlabelprefix}[true]{%
\ifstrequal{#1}{true}
{\let\blx@saved@refcontext@labelprefix\blx@refcontext@labelprefix
\let\blx@saved@refcontext@labelprefix\blx@refcontext@labelprefix@real
\let\blx@refcontext@labelprefix\@empty
\let\blx@refcontext@labelprefix@real\@empty}
{}}
\blx@kv@defkey{blx@bib2}{noresetnumbersforlabelprefix}[true]{%
\ifstrequal{#1}{true}
{\let\blx@refcontext@labelprefix\blx@saved@refcontext@labelprefix
\let\blx@refcontext@labelprefix@real\blx@saved@refcontext@labelprefix}
{}}
\makeatother
所有条目都可以通过 来引用\cite
(因此keyword
无关紧要,没有\citeA
或\citeB
)。
书目印有
\newrefcontext[labelprefix=A]
\printbibliography[keyword=primary, noresetnumbersforlabelprefix, title=Primary]
\newrefcontext[labelprefix=B]
\printbibliography[keyword=secondary, noresetnumbersforlabelprefix, title=Secondary]
也就是说,第一个参考书目仅包含带有 的条目keyword
primary
(实际上即来自 的条目\joabname-1.bib
),而第二个参考书目包含secondary
条目( )。我通过选项\jobname-2.bib
为标签添加了前缀(这更接近您的示例)。标题由 选项控制。labelprefix
\newrefcontext
title
平均能量损失
\documentclass{article}
\usepackage[style=numeric, defernumbers=true, backend=biber, maxnames=999]{biblatex}
\usepackage{hyperref}
\DeclareSourcemap{
\maps[datatype=bibtex]{
\map{
\perdatasource{\jobname-1.bib}
\step[fieldset=keywords, fieldvalue={, primary}, append]
}
\map{
\perdatasource{\jobname-2.bib}
\step[fieldset=keywords, fieldvalue={, secondary}, append]
}
}
}
\makeatletter
\providerobustcmd*{\blx@kv@defkey}{\define@key}
\blx@kv@defkey{blx@bib1}{noresetnumbersforlabelprefix}[true]{%
\ifstrequal{#1}{true}
{\let\blx@saved@refcontext@labelprefix\blx@refcontext@labelprefix
\let\blx@saved@refcontext@labelprefix\blx@refcontext@labelprefix@real
\let\blx@refcontext@labelprefix\@empty
\let\blx@refcontext@labelprefix@real\@empty}
{}}
\blx@kv@defkey{blx@bib2}{noresetnumbersforlabelprefix}[true]{%
\ifstrequal{#1}{true}
{\let\blx@refcontext@labelprefix\blx@saved@refcontext@labelprefix
\let\blx@refcontext@labelprefix@real\blx@saved@refcontext@labelprefix}
{}}
\makeatother
\begin{filecontents*}{\jobname-1.bib}
@inproceedings{slam2001,
author = {Thomas Ball and Sriram K. Rajamani},
title = {Automatically Validating Temporal Safety Properties of Interfaces},
booktitle = {Proceedings of the 8th International SPIN Workshop on Model Checking of Software},
editor = {Matthew Dwyer},
date = {2001},
}
@article{blast2008,
author = {Dirk Beyer and Thomas A. Henzinger and Ranjit Jhala and Rupak Majumdar},
title = {BLAST II},
journal = {International Journal on Software Tools for Technology Transfer},
date = {2008},
volume = {18},
}
\end{filecontents*}
\begin{filecontents*}{\jobname-2.bib}
@article{blast2007,
author = {Dirk Beyer and Thomas A. Henzinger and Ranjit Jhala and Rupak Majumdar},
title = {The software model checker {BLAST}},
subtitle = {Applications to software engineering},
journal = {International Journal on Software Tools for Technology Transfer},
date = {2007},
volume = {9},
}
@inproceedings{slam2002,
author = {Thomas Ball and Sriram K. Rajamani},
title = {Interfaces are Cool!},
booktitle = {Proceedings of the 8th International SPIN Workshop on Model Checking of Software},
date = {2002},
}
\end{filecontents*}
\addbibresource{\jobname-1.bib}
\addbibresource{\jobname-2.bib}
\begin{document}
CiteA~\cite{slam2001,slam2002}, CiteB~\cite{blast2007,blast2008}
\newrefcontext[labelprefix=A]
\printbibliography[keyword=primary, noresetnumbersforlabelprefix, title=Primary]
\newrefcontext[labelprefix=B]
\printbibliography[keyword=secondary, noresetnumbersforlabelprefix, title=Secondary]
\end{document}
超链接在这里似乎效果很好。
编辑答案已更新,可与较新版本的兼容biblatex
(已使用 v3.14 测试,但应从 v3.12 开始兼容)。如果您使用的是旧版本biblatex
(v3.3 或更低版本),请参阅编辑历史。