# Bibliography per chapter and a global bibliography in alphabetic order

I've been reading some other questions regarding this topic, I know they are a lot of them. Yet still, I haven't found a solution to my specific problem.

I have multiple chapters of my thesis, I would like a bibliography per chapter, which is easy using refsection. But I also want a global bibliography, which then users suggest the refsegment way.

The problem with the refsegment is that numbering now is not unique to each chapter, but is a set to a the global reference list as mentioned in the biblatex documentation.

Thus I also read on other questions the suggestion of using the defernumbers option to true which I did, and the reference numbering goes to hell, similar problem like (Biblatex: problem with defernumbers), even after compiling multiple times and deleting the aux, bbl, etc files.

My best effort has been to create a refsection per chapter and then another refsection for the global bibliography with the \nocite{*}, but then the backref is not working properly.

I also tried refsegments for each chapter nested into a overall refsection for the whole document which is a possibility in the biblatex documentation, but then the citations number are linked to the final bibliography and not the local subbibliographies.

Thus what I'm looking for is something like:

Chapter 1 Foo said [1] and blabla said [2] Bibliography [1] Foo (cited on page XXX). [2] Blabla (cited on page XXX).

Chapter 2 Foo said [1] and asd said [2] Bibliography [1] Foo (cited on page XXX) [2] Asd (cited on page XXX)

and then a Global bibliography in alphabetic order (nyt): Asd (cited on page XXX) Blabla (cited on page XXX) Foo (cited on page XXX)

So I've done two attemps, one with refsections that works well but the cited on XXX in the global bibliography does not work:

\documentclass[11pt, a4paper, showtrims]{memoir}

\usepackage[backend=biber, bibstyle=numeric-comp, citestyle=numeric-comp, backref=true]{biblatex}

\defbibenvironment{nolabelbib}
{\list
{}
{\setlength{\leftmargin}{\bibhang}%
\setlength{\itemindent}{-\leftmargin}%
\setlength{\itemsep}{\bibitemsep}%
\setlength{\parsep}{\bibparsep}}}
{\endlist}
{\item}

\usepackage{filecontents}

\begin{filecontents}{\jobname.bib}
@misc{A01,
keywords = {foo,bar},
author = {Author, A.},
year = {2001},
title = {Alpha},
}
@misc{B02x,
keywords = {foo},
author = {Buthor, B.},
year = {2002},
title = {Bravo},
}
@misc{B02y,
keywords = {bar},
author = {Buthor, B.},
year = {2002},
title = {Bravissimo},
}
\end{filecontents}

\begin{document}

\chapter{Chapter 1}
\begin{refsection}
This guy said blabla \autocite{A01}. And this other guy said blabla \autocite{B02x}.
\end{refsection}

\chapter{Chapter 2}
\begin{refsection}
This guy said blabla \autocite{A01}. And this other guy said blabla \autocite{B02y}.
\end{refsection}

\begin{refsection}
\nocite{*}
\newrefcontext[sorting=nyt]
\printbibliography[env=nolabelbib]
\end{refsection}

\end{document}


The other thing I've tried is with the refsegment nested into a refsection, please note I just copied from the \begin{document}:

\begin{document}
\begin{refsection}

\chapter{Chapter 1}
\begin{refsegment}
This guy said blabla \autocite{A01}. And this other guy said blabla \autocite{B02x}.
\end{refsegment}

\chapter{Chapter 2}
\begin{refsegment}
This guy said blabla \autocite{A01}. And this other guy said blabla \autocite{B02y}.
\end{refsegment}

\newrefcontext[sorting=nyt]
\printbibliography[env=nolabelbib]

\end{refsection}

\end{document}


In this last example, the cited on XXX works well, but the problem is that the numbering is linked to the global bibliography (that is arranged in alphabetic order) and not to the local chapter bibliographies. I also tried to turn on the defernumbers to true, and the numbering goes crazy. Also set the resetnumbers option to true in printbibliography and didn't fix the problem.

Im running MiKTeX-pdfTeX 2.9.6642 (1.40.19) (MiKTeX 2.9.6630 64-bit) Biber version 2.11, and according to MikTex Console I have the 3.12 of Biblatex

Thanks for all the help!

Here is a version of gusbrs' answer that adds extremely ugly low-level hackery to obtain a 'global' pageref/backref across refsections.

Normally refsections are completely separate from each other and there is no interface to combine the data of several refsections into one or to access data from one refsection in another (that's not exactly true: one can print the bibliography of one refsection in a different refsection, and with hacks it is possible to obtain all data from a different refsection). But since pageref is a special field that is populated from data in the .aux and not the .bbl we can actually obtain a global pageref.

\documentclass{book}

\usepackage[refsection=chapter, backref]{biblatex}

\DeclareBibliographyCategory{cited}

\makeatletter
\newcount\c@globalpageref

\defbibenvironment{globalbibliography}
{\list
{}
{\setlength{\leftmargin}{\bibhang}%
\setlength{\itemindent}{-\leftmargin}%
\setlength{\itemsep}{\bibitemsep}%
\setlength{\parsep}{\bibparsep}}}
{\endlist}
{\item
\iflistundef{globalpageref}
{}
{\savelist{globalpageref}{\tmpblx@pageref}%
\c@pageref\c@globalpageref
\restorelist{pageref}{\tmpblx@pageref}}}

\protected\def\blx@aux@backref#1#2#3#4#5{%
\ifcsundef{blx@pref@#3@\detokenize{#2}}
{\global\cslet{blx@pref@#3@\detokenize{#2}}\@empty
\expandafter\blx@onlypreamble\csname blx@pref@#3@\detokenize{#2}\endcsname}
{}%
\ifinlistcs{#4}{blx@pref@#3@\detokenize{#2}}
{}
\ifcsundef{blx@pref@global@\detokenize{#2}}
{\global\cslet{blx@pref@global@\detokenize{#2}}\@empty}
{}%
\ifinlistcs{#4}{blx@pref@global@\detokenize{#2}}
{}
\let\abx@aux@backref\blx@aux@backref

\AtDataInput{%
\ifcsundef{blx@pref@global@\abx@field@entrykey}
{}

\begingroup
\blx@tempcnta\z@
\let\blx@tempa\@empty
\def\do##1{%
\appto\blx@tempa{{##1}}%
\dolistcsloop{blx@pref@global@#1}%
\edef\blx@tempa{\endgroup\noexpand\blx@bbl@listdef
{globalpageref}{\the\blx@tempcnta}{\blx@tempa}}%
\blx@tempa
}
\makeatother

\begin{document}
\chapter{Chapter 1}
\autocite{sigfridsson}
\autocite{cotton}

\chapter{Chapter 2}
\autocite{sigfridsson}
\autocite{bertram}

\newrefsection
\nocite{*}
\newrefcontext[sorting=nyt]
\printbibliography[env=globalbibliography, title={Global Bibliography}, category=cited]
\end{document}


The more natural way to collect several partial bibliographies into one global bibliography would be via refsegments. But in this case refsegments are out because the entry data would be the same in all refsegments. Hence the label number cannot be restarted from 1 in each segment (or at least not in the way you want it to happen) since entries cited in several segments must keep their unique number across all segments.

• Ah! nice wizardry! (+1). I thought later about this, and I take the opportunity to vent a suggestion to the OP: If alphabetic labels could be considered as an alternative, instead of numeric ones, this set of requirements would fit way more naturally (then, with refsegments). – gusbrs Nov 9 '18 at 13:25
• Thanks a lot!! That is some wizardry and it works perfectly!!! I had a solution with python but this is way better because I only need 1 program and compile and that is it. Thanks a lot once again. and gusbrs too for his input. – AlbertoV Nov 10 '18 at 17:14

Mixing bibliography styles in the same document tends to be somewhat complicated and has some limitations. Particularly, mixing labeled (numeric/alpha) with non-labeled styles, as you request. But what you describe is doable, if you are not too picky on the details.

As you want to have independent numbering per chapter, you need refsection. refsegment wont do. A traditional way to collect cited works in other refsections is to add them to a category, lets say cited, and then print a global bibliography of this category only. The need to have numbered bibliographies per chapter and a non-numbered global one requires we define a proper bibenvironment which drops the entries' labels.

\documentclass{book}

\usepackage[refsection=chapter]{biblatex}

\DeclareBibliographyCategory{cited}
\defbibenvironment{globalbibliography}
{\list
{}
{\setlength{\leftmargin}{\bibhang}%
\setlength{\itemindent}{-\leftmargin}%
\setlength{\itemsep}{\bibitemsep}%
\setlength{\parsep}{\bibparsep}}}
{\endlist}
{\item}

\begin{document}

\chapter{Chapter 1}

\autocite{sigfridsson}

\autocite{cotton}

\printbibliography

\chapter{Chapter 2}

\autocite{sigfridsson}

\autocite{bertram}

\printbibliography

\chapter{Global Bibliography}

\nocite{*}
\newrefcontext[sorting=nyt]
\printbibliography[env=globalbibliography, title={Global Bibliography}, category=cited]

\end{document}

• Gusbrs, thanks for your quick answer. This result I managed it as well without the category, just by creating a new refsection and enviroment for the global bibliography. Thus my only complain with this solution, and I know I'm very picky haha, is that the backref no longer works on the global bibliography. But if no better solution comes up it was going to be my last resource to leave it like this. That is why I was thinking on leaning more towards refsegment, resetting the citation counter, nesting everything in a refsection so the backref could still work. Thanks once again – AlbertoV Nov 7 '18 at 18:14
• As far as I understand how it works, I don't think you will be able to get backrefs to work with different refsections, for those create sets which do not really communicate with each other. I'm also inclined to think that using refsegments and resetting the numbering will confuse the global backrefs (two different references with the same number), but I might be wrong. – gusbrs Nov 7 '18 at 19:28
• Btw, as to what's missing in my answer relative to your requirements, see how important it is to provide a MWE. If you had provided one, comprised of all (and only those) relevant elements, my guesswork would have been reduced, and I would've had a better chance of giving you a complete answer. – gusbrs Nov 7 '18 at 19:30
• You are right and I'm very sorry, I should've put more effort in a MWE so my example is clear and people don't use their time trying to understand my mess haha. Once again I'm sorry, first time in StackExchange. I've edited my post with two MWE, one with the case we discussed with the refsection, and one with the refsegments. – AlbertoV Nov 8 '18 at 8:19