
我正在嘗試調整解決方案這裡和這裡。我的目標如下:我想要將參考書目分為兩部分。第一個部分本身應該按引用類型分為多個小節,並且第一部分的引用應該有一個額外的前綴AO
並帶有顏色。第二部分的引文沒有前綴,沒有特定的分割,也沒有著色。
我幾乎可以透過以下程式碼達到令人滿意的效果:
\documentclass{article}
\usepackage{filecontents}
\begin{filecontents}{file1.bib}
@article{article1,
author = {Onymous, Anne},
title = {First Bibliography: An Journal Article},
date = {2000},
}
@inproceedings{inproc1,
author = {Onymous, Anne},
title = {First Bibliography: A Conference Article},
date = {1899},
}
\end{filecontents}
\begin{filecontents}{file2.bib}
@article{article2,
author = {Writer, William},
title = {Second Bibliography: A First Reference},
date = {2010},
}
@article{article2bis,
author = {Poetaster, Paula},
title = {Second Bibliography: A Second Reference},
date = {1767},
}
\end{filecontents}
\usepackage[
backend=biber,
hyperref=true,
backref=true,
giveninits=true,
citestyle=numeric-comp,
bibstyle=numeric,
sortcites=false,
maxbibnames=99,
maxcitenames=2,
sorting=none,
defernumbers=true,
]{biblatex}
\addbibresource{file1.bib}
\addbibresource{file2.bib}
\usepackage[dvipsnames]{xcolor}
% https://tex.stackexchange.com/questions/470852/different-colors-for-each-bib-file-and-custom-prefix
\DeclareSourcemap{
\maps[datatype=bibtex,overwrite]{
\map{
\perdatasource{file1.bib}
\step[fieldset=keywords, fieldvalue={,mypapers}, append]
}
}
\maps[datatype=bibtex,overwrite]{
\map{
\perdatasource{file2.bib}
\step[fieldset=keywords, fieldvalue={,otherpapers}, append]
}
}
}
% https://tex.stackexchange.com/questions/368247/how-to-colorise-specific-entries-in-the-bibliography-and-corresponding-reference
\renewbibmacro{in:}{}
\DeclareFieldFormat{labelprefix}{%
\ifkeyword{mypapers}
{\textcolor{red}{#1}}
{#1}}
\DeclareFieldFormat{labelnumber}{%
\ifkeyword{mypapers}
{\textcolor{red}{#1}}
{#1}}
\begin{document}
\title{Citation Test}
\author{Ann Onymous}
\maketitle
\cite{inproc1} \cite{article1} \cite{article2} \cite{article2bis}
\section*{Publications}
\newrefcontext[labelprefix=AO]
\printbibliography[type=inproceedings,keyword=mypapers,heading=subbibliography,title={Publications in Conference Post-Proceedings}]
\printbibliography[type=article,keyword=mypapers,heading=subbibliography,title={Journal Articles}]
\newrefcontext
\printbibliography[keyword=otherpapers]
\end{document}
但標註錯誤,引文分別標註為AO1
、AO1
、2
、3
。理想情況下,我希望第一部分中的所有引文共享一個唯一的計數器,即標記為AO1
、AO2
等,第二部分中的引文重新從 1 開始,即標記為1
、2
等。我會對它們從第一個完成的地方開始感到滿意,即3
在這個例子中。但是具有相同標籤的兩個不同引用是不可能的...
如果我刪除newrefcontext
,我會得到預期的著色和唯一的編號,但我會丟失前綴,這是不幸的。
我已經找到了resetnumbers
關鍵\printbibliography
,但還沒有找到如何正確使用它。
答案1
你已經快到了,你只需要resetnumbers
在你的\printbiliography
命令中執行一些操作:
\newrefcontext[labelprefix=AO]
\printbibliography[type=inproceedings,keyword=mypapers,heading=subbibliography,title={Publications in Conference Post-Proceedings}]
\printbibliography[resetnumbers=false,type=article,keyword=mypapers,heading=subbibliography,title={Journal Articles}]
\newrefcontext
\printbibliography[resetnumbers=true,keyword=otherpapers]
請注意,使用時defernumbers
,您必須注意每種工具的運行次數。從一個乾淨的石板開始,根本沒有任何輔助文件(大多數編輯器都有一個“乾淨”功能來刪除所有.aux
等.bcf
文件)。然後做latex->biber->latex->latex
。使用後必須執行latex
兩次(請參閱文件)。大多數 IDE 會告訴您這樣做,並且會警告您使用需要這樣做。biber
defernumbers
biblatex
defernumbers
技術說明:所有參考書目過濾系統(如type
和keyword
選項)都可以在完成後\printbibliography
添加更高級的過濾\defbibfilter
和\defbibcheck
操作,因此資料列表仍然包含排序順序中的所有條目,沒有過濾。因此,當您過濾掉內容時,基本上會在排序/編號中留下“漏洞”,因此您必須在應用過濾後重新進行編號,因此需要額外的運行。biber
.bbl
defernumbers
latex