# Double bibliography with biblatex: at the end of each chapter, and at the end of the document

I'm facing so many troubles to get my bibliographies properly, so maybe one of you guys can help me to find out the way. The idea is to have a separate bibliography at the end of each chapter with the following requisites:

• Entries numbered and begining with [1].
• Entries sorted according to their order of appearance.
• Same entry may appear in different chapters; in that case, each instance of the same entry must have a different numbering according to its order of appearance.

Also, at the end of the document there must be another bibliography with some different characteristics:

• Entries sorted alphabetically by author's name.
• All entries cited within document must appear in this bibliography.
• The page number where the entry has been cited must be included (something like "cited in page XX").
• This bibliography must appear in TOC.

I'm using biblatex and, so far, I cannot get the proper citation numbering at each chapter (if a work has been previously cited in another chapter it keeps its reference number despite I set resetnumbers=true), and I'm not able to change the style to get rid of numbers at the end bibliography.

My minimal working example is as follows:

\begin{filecontents*}{references.bib}
@article{ref1,
title = {An experimental study},
year = {2000},
author = {Smith, M}
}
@article{ref2,
title = {Analysis of topics},
year = {2005},
author = {Johnson, B}
}
@article{ref3,
title = {Methodological review},
year = {2010},
author = {Thompson, R}
}
\end{filecontents*}

\documentclass{book}
\usepackage[bibstyle=ieee,refsegment=chapter]{biblatex}

\begin{document}
\tableofcontents

\chapter{First chapter}
\cite{ref1} is a new reference and \cite{ref2} as well.

\chapter{Second chapter}
\cite{ref3} is again a new reference that must be numbered as one, while \cite{ref1} first appeared with number one in the previous chapter. Now it must show the number two in the following bibliography.

\end{document}


Thanks a lot!!

Unfortunately, biblatex can't do that out of the box (as far as I know), so a little hacking is required. Here's what I've done:

1. Use refsection instead of refsegment to make the bibliographies completely independent for every chapter. This has an unfortunate consequence that biblatex completely forgets about references from previous chapters.

2. To print the final bibliography I had to introduce another refsection (hence the \newrefsection command), and use \nocite{} to include all citations from all the chapters. Since maintaining this list of references manually would be error prone, I've (by a suggestion in comments) added some code to the cite key hook to append the current label to a global references list, and then I've used this list as the argument for \nocite.

3. To suppress numbering in the final bibliography I've used the answer from this question and created a special environment copied from the authortitle style file.

4. Another bit is a pretty dirty trick with patching an internal biblatex command \bbl@addbackref@i for backreferences in the main bibliography. It saves the current refsection and some other info to enable backreferencing. So instead of the current, I need it to store the last refsection, which in turn is to be saved by the new \saverefsection command. Since the references section is the very last one, I have to store it to the .aux file. This'll likely require one extra processing by LaTeX.

5. The last thing is that sorting is no longer supported by \printbibliography, hence the \newrefcontext.

The final code is:

\begin{filecontents*}{references.bib}
@article{ref1,
title = {An experimental study},
year = {2000},
author = {Smith, M}
}
@article{ref2,
title = {Analysis of topics},
year = {2005},
author = {Johnson, B}
}
@article{ref3,
title = {Methodological review},
year = {2010},
author = {Thompson, R}
}
\end{filecontents*}

\documentclass[openany]{book}
\usepackage[bibstyle=ieee,refsection=chapter,backref=true]{biblatex}

\newcommand\ReferencesList{}

% The following definition is copied from authortitle.bbx/authoryear.bbx
\defbibenvironment{nolabelbib}
{\list
{}
{\setlength{\leftmargin}{\bibhang}%
\setlength{\itemindent}{-\leftmargin}%
\setlength{\itemsep}{\bibitemsep}%
\setlength{\parsep}{\bibparsep}}}
{\endlist}
{\item}

\usepackage{etoolbox}
\makeatletter

\newcounter{savedrefsection}
\newcommand\saverefsection{%
\protected@write\@mainaux{}{\string\setcounter{savedrefsection}{\the\c@refsection}}%
}
\makeatother

\begin{document}
\tableofcontents

\chapter{First chapter}
\cite{ref1} is a new reference and \cite{ref2} as well.

\chapter{Second chapter}
\cite{ref3} is again a new reference that must be numbered as one, while \cite{ref1} first appeared with number one in the previous chapter. Now it must show the number two in the following bibliography.

\newrefsection
\saverefsection
\newrefcontext[sorting=nty]
\nocite{\ReferencesList}


• +1 Clever solution. Indeed the OP wants refsections, but the independence makes it hard to compile a complete list of references at the end. Your redefinition of \cite has the drawback of making it impossible to use optional arguments though. Maybe you could move the \AddtoRefsList to \AtEveryCitekey. – moewe May 12 '17 at 8:40
• Right, I'll update the answer. Just need some time to find out how to access the citekey in the \AtEveryCitekey code. I'm still a bit new in biblatex (and excited). – Sergei Golovan May 12 '17 at 9:06
• \thefield{citekey}. So you could do something like \AtEveryCitekey{\AddtoRefsList{\thefield{citekey}}}. – moewe May 12 '17 at 9:18
• There's the backref option for the biblatex package, but in your case it'd print the page references for the local bibliographies, and not for the main one (which is understandable as the local bibliographies do the actual citation). I have a dirty trick in mind on how to do that, and will try to implement it a bit later today. – Sergei Golovan May 12 '17 at 11:04
• I forgot to add \saverefsection. Sorry about that. It's fixed now and should work. – Sergei Golovan May 13 '17 at 18:54