3

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.

1 Answers1

5

You are nearly there, you just need some resetnumbers in your \printbiliography commands:

\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]

Be aware that when using defernumbers, you have to be careful about how many runs of each tool you have. Start with a clean slate with no auxiliary files at all (most editors have a "clean" function to delete all .aux, .bcf etc. files). Then do latex->biber->latex->latex. It is imperative that you run latex twice after biber when using defernumbers (see docs). Most IDEs will tell you to do this as biblatex will warn you that using defernumbers requires this.

enter image description here

Technical note: All of the bibliography filtering systems like type and keyword options to \printbibliography plus more advanced filtering with \defbibfilter and \defbibcheck operate after biber has finished and so the .bbl datalists still contain all of the entries in the sorting order, with no filtering. So, when you filter things out, you basically leave "holes" in the ordering/numbering and so you have to use defernumbers to redo the numbering after the filtering has been applied, hence the extra latex run required.

PLK
  • 22,776