I want to create a multi-file project for my thesis, in which I use separate files for sections. To be able to compile these separate files I tried using the subfiles package and the standalone package.
A problem arises when I use one of these packages in conjunction with the apacite package. Then, when compiling the main.tex file, I get a LaTeX Error: Can be used only in preamble. I don't understand why get I this error. It doesn't matter if the apacite package is loaded after or before subfiles or standalone.
Example of main.tex and chapter1.tex files in case of using subfiles package:
\documentclass{article}
\usepackage{subfiles}
\usepackage{apacite}
\begin{document}
\subfile{chapter1}
\end{document}
\documentclass[main.tex]{subfiles}
\begin{document}
text
\cite{xx19xx}
\end{document}
Example of main.tex and chapter1.tex files in case of using standalone package:
\documentclass{article}
\usepackage{standalone}
\usepackage{apacite}
\begin{document}
\input{chapter1}
\end{document}
\documentclass{article}
\begin{document}
text
\cite{xx19xx}
\end{document}
In both cases I get the previous mentioned error. Is there a way in which I can use apacite and still use separate files for my project?
\includeand then use\includeonly{<chapterfilename>,...}to only include those you want. See e.g. http://tex.stackexchange.com/q/246/2975 – Martin Scharrer Jan 18 '13 at 15:40\citefromapacitechecks if it is in the preamble or not by testing the definition of\document(which is the underlying macro behind\begin{document}. However, with both packages the definition of\documentgot changes, so that the test thinks its still in the preamble and uses a preamble-only macro (\AtBeginDocument) which causes the error. I will code some solution for this and post an answer. – Martin Scharrer Jan 18 '13 at 19:25apacitepackage is used so I'll leave it. The cause is pretty-much the same though – user202729 Apr 22 '22 at 16:39