I am trying to adapt the solutions here and here. My goal is the following: I want a bibliography split in two sections. The first should be itself split in multiple subsections, by citation type, and citations in this first section should have an extra prefix AO and be colored. Citations in in the second section have no prefix, no particular splitting, and no coloring.
I can almost reach something satisfactory, with the following code:
\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}
However, labeling is wrong, citations are respectively labeled AO1, AO1 again, 2 and 3. Ideally, I would like all citations in the first section to share a unique counter, ie be labelled AO1, AO2, etc. and citations in the second section to start again from 1, ie be labelled 1, 2, and so on. I would be content with them starting where the first ones finish, ie at 3 in this example. But having two different citations with the same label is just not possible…
If I remove the newrefcontext, I get coloration as expected and unique numbering, but I lose the prefix, which is unfortunate.
I have found the resetnumbers key to \printbibliography, but have not found how to use it properly.
