In one refsection of my document the references are grouped into categories by their keywords. Now I want to print the bibliography for every section based on the category of the citation, e.g. one bibliography for articles with keyword in
and one bibliography with keyword out
. For aesthetic I want the bibliographies to be numbered continuously, like in this textual mockup
**In**
[1-1] a. “a”. In: a (a).
[1-2] c. “c”. In: c (c).
[1-3] e. “e”. In: e (e).
**Out**
[1-4] b. “b”. In: b (b).
[1-5] d. “d”. In: d (d).
Hence, I use the defernumbers
of biblatex
to number the entries continuously. The problem is, that this leads to the numbering starting with 1 again for every \printbibliography
.
I'd like to enable defernumbers
across \printbibliography
per \refsection
.
MWE
\documentclass{article}
\pagestyle{empty}
\usepackage{filecontents}
\begin{filecontents*}{test.bib}
@article{a,
title = {a},
author = {a},
journal = {a},
year = {a},
keywords = {in}
}
@article{b,
title = {b},
author = {b},
journal = {b},
year = {b},
keywords = {out}
}
@article{c,
title = {c},
author = {c},
journal = {c},
year = {c},
keywords = {in}
}
@article{d,
title = {d},
author = {d},
journal = {d},
year = {d},
keywords = {out}
}
@article{e,
title = {e},
author = {e},
journal = {e},
year = {e},
keywords = {in}
}
\end{filecontents*}
\usepackage[
defernumbers=true,
citestyle=numeric,
]{biblatex}
\defbibheading{subbibliography}[\bibname]{%
\subsubsection*{#1}
}
\addbibresource{test.bib}
\begin{document}
\section{Testing biblatex}
\refsection
\cite{a,b,c,d,e}
\printbibliography[
title={In},
prefixnumbers={\thesection-},
heading=subbibliography,
keyword=in
]
\printbibliography[
title={Out},
prefixnumbers={\thesection-},
heading=subbibliography,
keyword=out
]
\endrefsection
\section{Testing biblatex}
\refsection
\cite{a,b,c,d,e}
\printbibliography[
title={In},
prefixnumbers={\thesection-},
heading=subbibliography,
keyword=in
]
\printbibliography[
title={Out},
prefixnumbers={\thesection-},
heading=subbibliography,
keyword=out
]
\endrefsection
\end{document}
Output
Of course, bounty will be offered!
Best Answer
This problem arises from an inherent functionality of
biblatex
. As seen from other questions,biblatex
has an implicitresetnumbers=true
that is applied when you useprefixnumbers
to add a prefix to the label. This can be addressed in different ways, but only through hacks that really either change the problem slightly or alter the way the prefix is handled/applied.Since the intent of this question is to subdivide each bibliography by section (or chapter, etc), it is possible to apply the
prefixnumber
setting globally in a different fashion, eliminating the implicitresetnumbers=true
that is applied at each\printbibliography
. To do so, we redefine the way the label is printed, incorporating\thesection
into the format:Each label is stored as 1, 2, 3... but is formatted with the section number that it appears in when it is printed. (Note*: because we are adding the prefix in this way, the
\printbibliography
command must appear in the samesection
/refsection
as the citations. In particular this means that you cannot use this method to print a cumulative bibliography at the end with multiplerefsection
s subdivided out with\printbibliography[section=1...]
).At this point, all that remains is to reset the numbering at the proper point (the first bibliography of each
refsection
) with\printbibliography[...resetnumbers=true]
.Result
The result appears as:
MWE
I have made a few changes to make the solution more efficient than in the original MWE.
refsection=section
(could also be...=part
,...=chapter
, etc) is passed globally tobiblatex
to collect references only in each section. This can be replaced with\newrefsection
/\endrefsection
as appropriate to manually partition the bibliography items.defernumbers=true
is retained to sort each subbibliography sequentially.I also commented out a few of the citations to accentuate the effect of the numbering and
refsection
s.The modified MWE demonstrating this solution:
*@Guido's solution redefines the entire bibliography environment and uses the enumerate series counter to continue counting for certain labels but not others. This might work for this problem (and would fix the issue of the cumulative bibliography), but I was unable to get the code to compile with section numbering the way the OP asked.