# Proper way to include unnumbered chapters in a per-chapter bibliography using biblatex

I've been using example 3.11.4 of the biblatex documentation to generate a per-chapter bibliography at the end of my thesis. It works great, until I try to make my introduction into an unnumbered chapter. Then, the introduction does not appear in the bibliography. Here's a MWE:

\documentclass{book}

\usepackage[sorting = none, style = numeric, refsegment = chapter, cite reset = chapter]{bib latex}
\usepackage{nameref}

\section*{References for Chapter \ref{refsegment:\therefsection\therefsegment} - \nameref{refsegment:\therefsection\therefsegment}}}

\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@misc{A01,
author = {Author, A.},
year = {2001},
title = {Alpha},
}
@misc{B02,
author = {Buthor, B.},
year = {2002},
title = {Bravo},
}
@misc{C03,
author = {Cuthor, C.},
year = {2003},
title = {Charlie},
}
\end{filecontents}

\begin{document}

\chapter*{Introduction}

\cite{A01}

\chapter{Chapter 1}

\cite{A01,B02}

\backmatter

\end{document}


I found a work-around, using a refsection for the unnumbered Introduction. Here's a MWE of the workaround:

\documentclass{book}

\usepackage[sorting = none, style = numeric, refsegment = chapter, cite reset = chapter]{bib latex}
\usepackage{nameref}

\section*{References for Chapter \ref{refsegment:\therefsection\therefsegment} - \nameref{refsegment:\therefsection\therefsegment}}}

\section*{References for the \nameref{refsection:\therefsection}}}

\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@misc{A01,
author = {Author, A.},
year = {2001},
title = {Alpha},
}
@misc{B02,
author = {Buthor, B.},
year = {2002},
title = {Bravo},
}
@misc{C03,
author = {Cuthor, C.},
year = {2003},
title = {Charlie},
}
\end{filecontents}

\begin{document}

\chapter*{Introduction}
\begin{refsection}
\cite{A01}
\end{refsection}
\chapter{Chapter 1}

\cite{A01,B02}

\backmatter

\end{document}


I was content with this until I added an unnumbered Conclusion with citations. Then the code breaks down and biblatex returns a nested refsections error. Here's the MWE for that:

\documentclass{book}

\usepackage[sorting = none, style = numeric, refsegment = chapter, cite reset = chapter]{bib latex}
\usepackage{nameref}

\section*{References for Chapter \ref{refsegment:\therefsection\therefsegment} - \nameref{refsegment:\therefsection\therefsegment}}}

\section*{References for the \nameref{refsection:\therefsection}}}

\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@misc{A01,
author = {Author, A.},
year = {2001},
title = {Alpha},
}
@misc{B02,
author = {Buthor, B.},
year = {2002},
title = {Bravo},
}
@misc{C03,
author = {Cuthor, C.},
year = {2003},
title = {Charlie},
}
\end{filecontents}

\begin{document}

\chapter*{Introduction}
\begin{refsection}
\cite{A01}
\end{refsection}
\chapter{Chapter 1}

\cite{A01,B02}

\chapter*{Conclusion}
\begin{refsection}
\cite{C03}
\end{refsection}

\backmatter

\end{document}


Any ideas how to solve this? Or, even better, how to properly implement \chapter* with example 3.11.4 of the biblatex doc?

Thanks in advance for the help!

-

You can invoke \newrefsegment and \citereset manually in the unnumbered chapters:

\chapter*{Introduction}
\newrefsegment
\citereset


but the titles for the bibliography segments can't be formatted consistently. There are various ways around this. Here we handle everything with patches to both \chapter and \chapter*.

\documentclass{book}
\usepackage[sorting=none,refsegment=chapter,citereset=chapter]{biblatex}
\usepackage{nameref}

\makeatletter
% Extend biblatex's \chapter patch to \chapter* and save data for titles
\def\blx@refpatch@chapter#1{%
\ifundef\chapter
{\blx@err@nodocdiv{chapter}}
{#1%
\csdef{subbib:\therefsection\therefsegment}{%
Chapter~\ref{refsegment:\therefsection\therefsegment}}}
{#1%
\csdef{subbib:\therefsection\therefsegment}{%
\nameref{refsegment:\therefsection\therefsegment}}}
\makeatother
\section*{References for \csuse{subbib:\therefsection\therefsegment}}}

\begin{document}
\tableofcontents
\chapter*{Introduction}
\cite{reese}
\chapter{First chapter}
\cite{companion}
\chapter*{Unnumbered chapter}
\cite{glashow,weinberg}
\chapter{Second chapter}
\cite{glashow}
\chapter*{Conclusion}
\cite{reese}
\end{document}


This approach also works for reference sections by chapter.

\documentclass{book}
\usepackage[sorting=none,refsection=chapter]{biblatex}
\usepackage{nameref}

\makeatletter
% Extend biblatex's \chapter patch to \chapter*, save data for titles
\def\blx@refpatch@chapter#1{%
\ifundef\chapter
{\blx@err@nodocdiv{chapter}}
{#1\csdef{subbib:\therefsection}{Chapter~\ref{refsection:\therefsection}}}
{#1\csdef{subbib:\therefsection}{\nameref{refsection:\therefsection}}}
\makeatother

\begin{document}
...
\end{document}

-
This is what I had in mind. However, this solution seems to break \citereset. Any ideas how to fix that? – Kpantzas Aug 30 '12 at 12:28
@Kpantzas That seems unlikely. Switching the style to verbose and playing around with the citereset settings or \citereset in the above document doesn't demonstrate any issues. – Audrey Aug 30 '12 at 13:06
Well then I guess I haven't understood citereset. I thought that it was used to reset citations so that they would start from [1] after each reset (in this case each chapter). This is not the behavior I'm getting with your example. Though now that I think about it, this would be incompatible with refsegment and I should use refsection instead... any thoughts about that? – Kpantzas Aug 30 '12 at 14:41
@Kpantzas \citereset only resets the citation trackers. For independent labelnumbers you should be using reference sections, not segments. I've updated the post to demonstrate the approach with refsection=chapter. – Audrey Aug 30 '12 at 15:29
thanks for enlightening me on this topic! – Kpantzas Aug 30 '12 at 16:04

You have to use \endrefsegment to manually terminate the last segment before the unnumbered "Conclusion" chapter.

\documentclass{book}

\usepackage[sorting = none, style = numeric, refsegment = chapter, cite reset = chapter]{bib latex}
\usepackage{nameref}

\section*{References for Chapter \ref{refsegment:\therefsection\therefsegment} - \nameref{refsegment:\therefsection\therefsegment}}}

\section*{References for the \nameref{refsection:\therefsection}}}

\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@misc{A01,
author = {Author, A.},
year = {2001},
title = {Alpha},
}
@misc{B02,
author = {Buthor, B.},
year = {2002},
title = {Bravo},
}
@misc{C03,
author = {Cuthor, C.},
year = {2003},
title = {Charlie},
}
\end{filecontents}

\begin{document}

\chapter*{Introduction}
\begin{refsection}
\cite{A01}
\end{refsection}
\chapter{Chapter 1}

\cite{A01,B02}

\endrefsegment

\chapter*{Conclusion}
\begin{refsection}
\cite{C03}
\end{refsection}

\backmatter

\end{document}


While this solves your immediate problem, your workaround of using refsections for the Introduction and Conclusion results in completely independent bibliography labels for these chapters (note how the work of C. Cuthor is assigned the label "1" in the Conclusion). The following solution works only with refsegments (and hereby achieves labels unique for the whole document):

• Don't use the starred version \chapter* but \chapter also for the Introduction and Conclusion. This way, a (positive) refsegment number will be assigned to these chapters, and their respective references can be printed using \bibbysegment.

• Use \frontmatter, \mainmatter and \backmatter to make the Introduction and Conclusion non-numbered chapters. (Actually, use \boolfalse{@mainmatter} instead of \frontmatter to avoid switching to Roman page numbering.)

• Declare new counters to store the value of \therefsegment after the front- resp. the mainmatter, and use these counters in a new definition of the bibintoc2 heading to achieve the different format for front-/main-/backmatter references.

\documentclass{book}

\usepackage[sorting=none,style =numeric,refsegment=chapter,citereset=chapter]{biblatex}
\usepackage{nameref}

\newcounter{segmentendfront}
\newcounter{segmentendmain}

\section*{\refname\ for
\ifnumgreater{\therefsegment}{\value{segmentendfront}}{%
\ifnumgreater{\therefsegment}{\value{segmentendmain}}{%
the
}{%
Chapter~\ref{refsegment:\therefsection\therefsegment} --
}%
}{%
the
}%
\nameref{refsegment:\therefsection\therefsegment}%
}%
}

\usepackage{filecontents}

\begin{filecontents}{\jobname.bib}
@misc{A01,
author = {Author, A.},
year = {2001},
title = {Alpha},
}
@misc{B02,
author = {Buthor, B.},
year = {2002},
title = {Bravo},
}
@misc{C03,
author = {Cuthor, C.},
year = {2003},
title = {Charlie},
}
\end{filecontents}

\begin{document}

\boolfalse{@mainmatter}% instead of \frontmatter, which would also switch
%to Roman page numbering

\chapter{Introduction}

\cite{A01}

\mainmatter
\setcounter{segmentendfront}{\therefsection\therefsegment}

\chapter{First chapter}

\cite{A01,B02}

\chapter{Second chapter}

\cite{B02}

\backmatter
\setcounter{segmentendmain}{\therefsection\therefsegment}

\chapter{Conclusion}

\cite{C03}

\end{document}


-
While this does work, it kind of feels wrong to place the intro and conclusion in the frontmatter and backmatter respectively. Especially since there already is a frontmatter (toc,lof,lot,acknowledgements, preface) and a backmatter (bibliography, appendices, glossaries), that I'd like to separate from the main text of the thesis. Thanks for the help though! – Kpantzas Aug 30 '12 at 12:46

I think you can do this:

\chapter*{Introduction}
\begin{refsegment}
\cite{A01}
\end{refsegment}


Edit: The problem with the refsegment for the conclusion is not that there is a second refsegment but that with the option refsegment=chapter a \chapter command inserts a \begin{refsegment} (or something analog) and this isn't closed by the \chapter*.

You could stop this segment before the conclusion:

\endrefsegment

\chapter*{Conclusion}


(A better solution would be to patch \chapter* too).

-
Doesn't seem to work. – lockstep Aug 29 '12 at 16:56
Yep, I tried that too, the nested refsection becomes a nested refsegment` error – Kpantzas Aug 29 '12 at 16:59
Sorry I had used the wrong code for testing and so overlooked the conclusion problem. I have edited the answer. – Ulrike Fischer Aug 29 '12 at 17:20