If at all possible you should try to avoid templates in general. See Why should you avoid using (complex) templates? and https://github.com/johannesbottcher/templateConfusion. Most templates are fine while they are working and giving you exactly the output you want, but it can become increasingly complicated to modify them. Bad templates may contain outdated or outright wrong code and may blow up in your face at any moment.
This particular template (Link to the Overleaf version) is also available on https://github.com/kks32/phd-thesis-template and is intended to be a PhD thesis template for Cambridge University Engineering Department (CUED). If that's not where you will be submitting your thesis, it is probably better not to use that template because you will have to modify it.
I have not had a much closer look at the template than needed for this answer, but I did not see any obvious TeXnical blunders (apart from the counter-intuitive option handling below). My concerns at this moment are mainly conceptual (this template does a lot and is intended for a particular university department) and pedagogical (the code in the template can look frightening, the many options and settings can be overwhelming and even the basic thesis.tex
is long and contains many additional \input
s, \include
s and conditionals).
The class has several bibliography-related options and custombib
would hand all control over the bibliography back to you if you had not also used the option numbered
. The way these options are handled means that (counter-intuitively) the earlier option numbered
just overrides the custombib
and loads natbib
instead. Note that the class does not care about the order of these bibliography options, the outcome is determined by the particular nesting of tests in the implementation of the class. And the outcome of using conflicting options is not at all clear from the outside.
In Preamble/preamble.tex
, specifically with
\ifuseCustomBib
%\usepackage[backend=biber,refsection=section, style=numeric-comp, citestyle=numeric, sorting=nty]{biblatex}
\usepackage[firstinits=true,
bibencoding=inputenc,
hyperref=auto,
pagination=none,
%style=standard,
refsection=chapter]
{biblatex}
\bibliographystyle{aipnum4-1.bst}
\fi
you try to explicitly load the biblatex
package, yet in the next line of code you write
\bibliographystyle{aipnum4-1.bst}
which is a command of traditional BibTeX bibliographies that is incompatible with biblatex
(and also slightly incorrect: the style in \bibliographystyle
should be given without file extension, \bibliographystyle{aipnum4-1}
would be correct).
Be that as it may, the numbered
option quashes your attempt to define the bibliography anyway. It just causes natbib
to be loaded and ignores your definitions because they are guarded by \ifuseCustomBib
(which is false).
In the chapters (e.g. Chapter5/chapter5.tex
) you then produce a bibliography with
I know this seems kind of extra, it's so that no extra white page is added in between the text and the references.
\begingroup
\makeatletter
\renewcommand{\chapter}{
\if@openright\clearpage\else\clearpage\fi
\thispagestyle{empty}%
\global\@topnum\z@
\@afterindentfalse
\secdef\@chapter\@schapter
}
\makeatother
\bibliographystyle{aipnum4-1.bst}
\setstretch{0.9}
\bibliography{Chapter5/biblio5.bib}
\endgroup
\thispagestyle{empty}
\clearpage
%\if@openright\cleardoublepage\else\clearpage\fi
\mbox{}
\thispagestyle{empty}
which looks wrong on quite a few levels. But again we can take away from this bit of code that you are using traditional BibTeX methods and not biblatex
– this time explicitly.
There are several methods to obtain split bibliographies (see Sectioning bibliography by type of referred item) and there are BibTeX-compatible way to obtain per-chapter bibliographies as well (see References at the end of each chapter and for example How to use chapterbib package: syntax and Bibliography in each chapter). Yet I believe that biblatex
offers the easiest and most convenient way to per-chapter bibliographies.
Have a look at What to do to switch to biblatex? to see what you have to do to switch to biblatex
.
Remove all the \bibliographystyle
and the \bibliography
instructions in the document body.
The following is a "minimal" example using PhDThesisPSnPDF
that shows how you could use biblatex
in your document. Please read the comments carefully, they should explain how this works.
% no option numbered
\documentclass[a4paper,12pt,times,preprint,index, custombib]{Classes/PhDThesisPSnPDF}
% in Preamble/preamble.tex you need
\ifuseCustomBib
\usepackage[
backend=biber,
style=numeric,
refsection=chapter]
{biblatex}
% you also need to declare your bib file
\addbibresource{biblatex-examples.bib}
% biblatex-examples.bib is an example file
% that is available everywhere where biblatex is installed
% you'll need something like
% \addbibresource{biblio.bib}
% and maybe
% \addbibresource{Chapter5/biblio5.bib}
% etc. you can have several of these lines
\fi
\begin{document}
% in your chapters you'll have
\chapter{Lorem}
Lorem ipsum~\cite{sigfridsson} dolor~\cite{worman}.
% just use \cite as normal
\printbibliography[heading=subbibliography] % this prints the bibliography
% next chapter
\chapter{Dolor}
Dolor~\cite{nussbaum} sit~\cite{sigfridsson}
\printbibliography[heading=subbibliography]
\end{document}

It seems that in your case the option refsection=chapter
produces the error
! Package biblatex Error: Patching \@makechapterhead failed.
See the biblatex package documentation for explanation.
Type H <return> for immediate help.
...
l.21 \begin{document}
This is an internal issue typically caused by a conflict
between biblatex and some other package. Modifying
the package loading order may fix the problem.
on Overleaf. This error does not occur on my local installation (MikTeX 2.9 on Win 10 updated this morning) with up to date packages.
The problem seems to be that the definition of \@makechapterhead
is botched as \tracingpatches
shows
[debug] tracing \ifpatchable on input line 142
[debug] analyzing '\@makechapterhead'
[debug] ++ control sequence is defined
[debug] ++ control sequence is a macro
[debug] ++ control sequence is a macro with parameters
[debug] -- macro cannot be retokenized cleanly
[debug] -> the macro may have been defined under a category
[debug] code regime different from the current one
[debug] -> the replacement text may contain special control
[debug] sequence tokens formed with \csname...\endcsname;
[debug] -> the replacement text may contain carriage return,
[debug] newline, or similar characters
I did not manage to find the culprit (between a completely outdated TeX system with biblatex
3.7, a massively complicated template and a system I have no proper access to that was just too much for now), but you can remove the option refsection=chapter
and emulate it by hand with \begin{refsection}...\end{refsection}
.
% no option numbered
\documentclass[a4paper,12pt,times,preprint,index, custombib]{Classes/PhDThesisPSnPDF}
% in Preamble/preamble.tex you need
\ifuseCustomBib
\usepackage[
backend=biber,
style=numeric,
]
{biblatex}
% you also need to declare your bib file
\addbibresource{biblatex-examples.bib}
% biblatex-examples.bib is an example file
% that is available everywhere where biblatex is installed
% you'll need something like
% \addbibresource{biblio.bib}
% and maybe
% \addbibresource{Chapter5/biblio5.bib}
% etc. you can have several of these lines
\fi
\begin{document}
% in your chapters you'll have
\begin{refsection}
\chapter{Lorem}
Lorem ipsum~\cite{sigfridsson} dolor~\cite{worman}.
% just use \cite as normal
\printbibliography[heading=subbibliography] % this prints the bibliography
\end{refsection}
% next chapter
\begin{refsection}
\chapter{Dolor}
Dolor~\cite{nussbaum} sit~\cite{sigfridsson}
\printbibliography[heading=subbibliography]
\end{refsection}
\end{document}
A different workaround would be to issue
\makeatletter
\def\@makechapterhead#1{%
\vspace *{50\p@ }{\parindent \z@ \raggedright \normalfont \ifnum \c@secnumdepth >\m@ne \if@mainmatter \huge \bfseries \@chapapp \space \thechapter \par \nobreak \vskip 20\p@ \fi \fi \interlinepenalty \@M \Huge \bfseries #1\par \nobreak \vskip 40\p@ }}
\makeatother
directly before you load biblatex
.
\bibliographystyle
is incompatible withbiblatex
. If you get??
for unprocessed references you are not even usingbiblatex
(in which case you would get bold entry keys). Unfortunately the link to the template on Overleaf is not enough. The template offers a great many options and we don't know which you use. Please show us an example document that explains what you are doing (tex.meta.stackexchange.com/q/228/35864 and tex.meta.stackexchange.com/q/4407/35864). – moewe Jan 11 '19 at 4:37PhDThesisPSnPDF.cls
alone in its current form is 1200 lines long andthesis.tex
inputs another few hundred lines fromPreamble/preamble.tex
. – moewe Jan 11 '19 at 4:39biblatex
was more complicated: While you were not actually using the package, that was only due to a weird coincidence. I have added the tag back in and tried to address the issues in my answer. – moewe Jan 11 '19 at 6:09