0

I am writing my PhD thesis, which is split into multiple chapter subfiles with a masterfile that combines them all for convenience of editing.

I have attempted to implement citations in the subfiles so I can see my references when I am editing my subfiles by defining the command \biblio in the masterfile for use in the subfiles as follows:

\providecommand{\main}{.}
\documentclass[12pt]{report}
\usepackage[numbers]{natbib}
\usepackage{subfiles}

\def\biblio{\bibliographystyle{ieeetran}\bibliography{\main/references}}  % *Modification: added `\main/` to specify relative file location. 

\begin{document}
    \def\biblio{} 

\chapter{Chapter 1}

\subfile{ThesisSubfiles/Chapter 1}

\chapter{Chapter 2}

\subfile{ThesisSubfiles/Chapter 2}

\chapter{Chapter 3}

\subfile{ThesisSubfiles/Chapter 3}

\bibliographystyle{ieeetran}
\bibliography{references.bib}

\end{document}

With each chapter subfile calling \biblio as follows:

%!TeX root = Chapter 1.tex
\providecommand{\main}{..}
\documentclass[../ThesisMasterfile.tex]{subfiles}

\begin{document}
    \section{Section 1}
    Some text.

    \section{Section 2}
    Some text.
    
\biblio

\end{document}

This works fine on my laptop, but when I attempt to compile the same script on my desktop PC, any new citations (invoked using \cite{}) added to any subfile which I compile on its own just appear as question marks with the warning "Citation 'citation' on page x undefined". Even stranger is that if I compile it on my laptop to make it work and then recompile it on my desktop PC, the new references then show up. Both PCs use the same relative file paths (the files are all saved to a shared cloud storage), both are running Windows 10 and MikTex with TexStudio editor. The only differences is, the packages on the desktop PC have been updated more recently.

Does anyone have any idea what the problem is? Thanks in advance!

1 Answer 1

0

Your problem description is not self-contained, so it is difficult to reproduce the problem. When I try to reconstruct the issue, it works (with a recent TeX distribution).

Some suggestions:

  • When you typeset the subfile on its own, you have to perform the same cycle as with the main document: latex ..., bibtex ..., latex ..., latex ...

    Your statement that typesetting worked after returning from the other computer and rerunning latex, seems like there haven't been enough runs of latex and bibtex.

  • Update your LaTeX distribution, on all of your computers. This will solve many problems, or at least should lead to a consistent and reproducible behavior.

  • Take a look at section 3.3 of the subfiles documentation, which explains how to solve your use case with an optional bibliography in the subfile.

  • Since quite some time now, subfiles handles most cases of path adjustments itself, and offers \subfix in case it can't do it.

As I said in the beginning, your files seem to work fine (if I complete them to a minimal working example), but the setup could be simplified as follows, without the need for \main and \biblio:

% ThesisMasterfile.tex
\documentclass[12pt]{report}
\usepackage[numbers]{natbib}
\usepackage{subfiles}
\bibliographystyle{ieeetran}% set bibliographystyle for main and subfile
\begin{document}
\chapter{Chapter 1}
\subfile{ThesisSubfiles/Chapter 1}
\bibliography{references.bib}
\end{document}

% ThesisSubfiles/Chapter 1
\documentclass[../ThesisMasterfile]{subfiles}
\begin{document}
    \section{Section 1}
    Some text.
\ifSubfilesClassLoaded{%    
   \bibliography{../references}% file paths are always relative to the current main or subfile
}{}
\end{document}

If you use biblatex and biber instead, you would have to add

\addbibresource{\subfix{references.bib}}

to the preamble of the main document and to replace the two occurrences of \bibliography{...} by \printbibliography.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .