Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

For my bachelor thesis, I want to write my chapters in separate files and be able to compile them separately. To combine them, I use the subfiles package. For citations, I have to use Apa style via the apacite package.

As already discussed in Use of apacite package with subfiles package or standalone package results in LaTeX Error: Can be used only in preamble, apacite and subfiles don't go together well. To fix this problem I use the solution as posted:

\usepackage{etoolbox}
\makeatletter
\patchcmd{\nocite}{\ifx\@onlypreamble\document}{\iftrue}{}{}
\makeatother

This works fine, but I want my reference list to be in English (not in French as is standard with apacite). Normally, I use the babel package to correct this problem, but with the subfiles package this results in the following error:

! LaTeX Error: Can be used only in preamble.
l.4 \cite{test}

Does anyone know how to fix this?

The code I used:

main.tex

\documentclass{article}
\usepackage{subfiles}
\usepackage{apacite}
\usepackage[english]{babel} % works fine without babel
\usepackage{etoolbox}
\makeatletter
\patchcmd{\nocite}{\ifx\@onlypreamble\document}{\iftrue}{}{}
\makeatother

\begin{document}
\subfile{chapter1}

% Bibliography:
\newpage
\bibliographystyle{apacite} 
\bibliography{../ref/references} 

\end{document}

chapter1.tex:

\documentclass[./main.tex]{subfiles}
\begin{document}
text
\cite{test}
\end{document}
share|improve this question
    
Welcome to TeX.SX. –  Claudio Fiandrino Jan 23 '13 at 11:05
    
Thank you! I already used the site a lot, but never registered! @ClaudioFiandrino –  Quico Spaen Jan 23 '13 at 11:10
add comment

1 Answer

up vote 0 down vote accepted

Setting \errorcontextlines=\maxdimen helps to reveal what's going on.

babel saves the old definition of \nocite in \org@nocite, so either:

  1. Patch \nocite before loading babel, or
  2. Patch \org@nocite as well, after loading babel.

The first is probably the better solution:

\documentclass{article}
\errorcontextlines=\maxdimen
\usepackage{subfiles}
\usepackage{etoolbox}
\usepackage{apacite}
\makeatletter
\patchcmd{\nocite}{\ifx\@onlypreamble\document}{\iftrue}{}{}
\makeatother
\usepackage[english]{babel} % works fine without babel

\begin{document}
\subfile{94989-chapter1}

% Bibliography:
\newpage
\bibliographystyle{apacite} 
\bibliography{../ref/references} 

\end{document}
share|improve this answer
    
Works like a charm. Thanks for the help! –  Quico Spaen Jan 23 '13 at 11:46
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.