[Tex/LaTex] Proper way to include unnumbered chapters in a per-chapter bibliography using biblatex

biblatexsectioningstarred-versionsubdividing

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}

\defbibheading{bibintoc}{%
  \addcontentsline{toc}{chapter}{\bibname}%
  \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}
\addbibresource{\jobname.bib}

\begin{document}

\chapter*{Introduction}

\cite{A01}

\chapter{Chapter 1}

\cite{A01,B02}

\backmatter

\printbibheading
\bibbysegment[heading = bibintoc]

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

\defbibheading{bibintoc}{%
  \addcontentsline{toc}{chapter}{\bibname}%
  \section*{References for Chapter \ref{refsegment:\therefsection\therefsegment} - \nameref{refsegment:\therefsection\therefsegment}}}

\defbibheading{bibintoc2}{%
  \addcontentsline{toc}{chapter}{\bibname}%
  \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}
\addbibresource{\jobname.bib}

\begin{document}

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

\cite{A01,B02}

\backmatter

\printbibheading
\printbibliography[section=1,heading=bibintoc2]
\bibbysegment[heading = bibintoc]

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

\defbibheading{bibintoc}{%
  \addcontentsline{toc}{chapter}{\bibname}%
  \section*{References for Chapter \ref{refsegment:\therefsection\therefsegment} - \nameref{refsegment:\therefsection\therefsegment}}}

\defbibheading{bibintoc2}{%
  \addcontentsline{toc}{chapter}{\bibname}%
  \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}
\addbibresource{\jobname.bib}

\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

\printbibheading
\printbibliography[section=1,heading=bibintoc2]
\bibbysegment[heading = bibintoc]

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

Best Answer

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}}
    {\pretocmd\@makechapterhead
       {#1%
        \csdef{subbib:\therefsection\therefsegment}{%
          Chapter~\ref{refsegment:\therefsection\therefsegment}}}
       {}{\blx@err@patch{\string\@makechapterhead}}%
     \pretocmd\@makeschapterhead
       {#1%
        \csdef{subbib:\therefsection\therefsegment}{%
          \nameref{refsegment:\therefsection\therefsegment}}}
       {}{\blx@err@patch{\string\@makeschapterhead}}}}
\makeatother
\defbibheading{subbibliography}{%
  \section*{References for \csuse{subbib:\therefsection\therefsegment}}}

\addbibresource{biblatex-examples.bib}
\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}
\printbibheading[heading=bibintoc]
\bibbysegment[heading=subbibliography]
\end{document}

enter image description here

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}}
    {\pretocmd\@makechapterhead
       {#1\csdef{subbib:\therefsection}{Chapter~\ref{refsection:\therefsection}}}
       {}{\blx@err@patch{\string\@makechapterhead}}%
     \pretocmd\@makeschapterhead
       {#1\csdef{subbib:\therefsection}{\nameref{refsection:\therefsection}}}
       {}{\blx@err@patch{\string\@makeschapterhead}}}}
\makeatother
\defbibheading{subbibliography}{\section*{References for \csuse{subbib:\therefsection}}}

\addbibresource{biblatex-examples.bib}
\begin{document}
...
\printbibheading[heading=bibintoc]
\bibbysection[heading=subbibliography]
\end{document}