# Citations in separate tex file from bibliography

I'm compiling a thesis where the main TeX file contains all my preamble declarations before including the thesis chapters as individual TeX files. I'd prefer, however, to have a single bibliography at the end of the thesis but before any appendices. However, when I try to do this none of my citations appear correctly in the chapters, i.e. they are replaced with "?", even though they all appear in the bibliography.

I discovered the xcite package, which I've attempted to use to solve this problem but haven't got it working correctly. Probably a simple misunderstanding on my part of how to implement it.

The main file creates the main thesis from several chapters and the bibliography:

\documentclass{report}
\usepackage[authoryear,comma,nonamebreak,round,sort&compress]{natbib}
\usepackage{xcite}

\bibliographystyle{plainnat}
\externalcitedocument{Chapter1}
\externalcitedocument{Chapter2}
...
\externalcitedocument{Chaptern}
\externalcitedocument{Appendix}

\begin{document}
\include{Chapter1}
\include{Chapter2}
....
\include{Chaptern}

\bibliography{Bibliography}

\appendix
\include{Appendix}
\end{document}


And the each chapter or appendix only contains text content, i.e. no preamble or \begin{document} and \end{document} commands. Citations within the text are made in the format:

...as found in \citet{Smith2013}...


I've tried moving \externalcitedocument{Chapteri} to the ith. chapter TeX file but it made no difference. I'm using WinEdt7 PDFTeXify to compile my document and JabRef to create the bibliography.

It seems like such a straightforward action that I can only assume I've not used xcite correctly.

-
It should just work with \include and \cite. Of course if you have \inclueonly set you will need to do a run without that so everything picks up. have you run latex, bibtex latex the usual reason for getting ? is you haven't run the full sequence of commands. Impossible to say without a working example. –  David Carlisle Mar 12 '13 at 16:35
I've tried running latex, bibtex, latex and it makes no difference. In fact I think that's what PDFTeXify does with one command. And I'm not using \includeonly. –  Jonathan Allen Mar 12 '13 at 16:47
@JonathanAllen Are you using a thesis template from a university or crafting one on your own? I can point you to a pre-made template from my grad school that you can play with as you so choose... –  BoZiffer Mar 12 '13 at 23:08
You are using xcite incorrectly in the sense that it was not designed for doing what you are trying to do. (You are trying to do something much simpler, which standard LaTeX can handle just fine on its own, as @Kurt has shown in his answer.) –  jon Mar 13 '13 at 3:09
@BoZiffer My university are reasonable strict on the look of the thesis, therefore I've crafted my own LaTeX template to fit their demands. –  Jonathan Allen Mar 13 '13 at 10:47

Just to show you that xcite is not necceccary and how to build an MWE for your problem please check the following MWE (with commented xcite). It includes with package filecontents three chapter files and a bib file. If you copied this MWE into file mwe.tex then \jobname becomes mwe.

\RequirePackage{filecontents}
\begin{filecontents*}{testxcite1.tex}
\chapter{Chapter One}
\end{filecontents*}
\begin{filecontents*}{testxcite2.tex}
\chapter{Chapter Two}
Text \cite{companion}
\end{filecontents*}
\begin{filecontents*}{testxcite3.tex}
\chapter{Chapter Three}
\end{filecontents*}
\begin{filecontents*}{\jobname.bib}
@Book{companion,
author    = {Goossens, Michel and Mittelbach, Frank and Samarin, Alexander},
title     = {The LaTeX Companion},
edition   = {1},
year       = {1994}
}
title     = {The Restaurant at the End of the Universe},
series    = {The Hitchhiker's Guide to the Galaxy},
publisher = {Pan Macmillan},
year      = {1980}
}
\end{filecontents*}

\listfiles   % to show used packages and versions
\documentclass{report}
\usepackage[authoryear,comma,nonamebreak,round,sort&compress]{natbib}
%\usepackage{xcite}

\bibliographystyle{plainnat}
%\externalcitedocument{testxcite1}
%\externalcitedocument{testxcite2}
%\externalcitedocument{testxcite3}

\begin{document}
\include{testxcite1}
\include{testxcite2}
\include{testxcite3}
\bibliography{\jobname}
\end{document}


Compile this MWE with latex, bibtex, latex, latex and you will get a pdf file and four warnings, coming from package filecontents (they are okay and can be ignored). If you have still ? instead of a correct citation there is something other wrong with your system or way to build the pdf file.

-
@jon I deleted the appendix because in the given example of op the appendix has nothing to do with the question, because it was not said, that there are also citings in the appendix. At last it is only one more \include{appendix} and another \begin{filecontents*}.... Leaving it out makes the MWE shorter with the same functionality. The reason you see the comment xcite parts is only to show xcite is not needed. –  Kurt Mar 13 '13 at 3:37
Great, that's fixed the problem, both the MWE and my document itself work perfectly now - I just need to find an excuse to cite the Hitchiker's Guide somewhere in my thesis... –  Jonathan Allen Mar 13 '13 at 10:45
@JonathanAllen LOL. If I helped you have you considered to upvote and accept my answer? –  Kurt Mar 13 '13 at 15:59
I have now :) Thanks again! –  Jonathan Allen Mar 15 '13 at 10:49