Possible subfiles/setspace issues

setspacesubfiles

I seem to be having difficulty preventing my document from overwriting \doublespacing commands. I have a document using a subfiles structure (a Main.tex) that calls a number of subfile .tex's for each chapter of the document, each of which begin something like:

\documentclass[Main.tex]{subfiles}

\doublespacing

\begin{document}

 ...

\end{document}

Each subfile that requires double spacing sets \doublespacing rather than setting it once in Main.tex, so as not to affect the various single-spaced lists of symbols, acronyms, etc, that are subfile'd in Main.tex prior to the main chapters.

However, something appears to be overwriting each chapter's internal \doublespacing command, as everything is single spaced when Main.tex is pdflatex'd. Of course, the individual subfiles have the correct double spacing when compiled. This only occurred after an update to MikTex, and it did not happen before. So my thought is that a newer version of a certain package is interfering with either subfiles or setspace, but am unsure where it's happening. I hesitate to include my preamble, as it's a custom .cls used by Main.tex that I made, with a very large number of packages. Is this a simple fix?

EDIT: so I've stripped everything away in the pre-amble, yet it still doesn't work. I have two files, in totality:

% Main.tex
\documentclass{article}
\usepackage{lipsum}
\usepackage{setspace}
\usepackage{subfiles}

\begin{document}

\subfile{testsub.tex}
\newpage

\end{document}

and

% Subfile #X
\documentclass[Main.tex]{subfiles}

\doublespacing

\begin{document}

\section{Introduction}
\lipsum

\end{document}

My older version of MikTex didn't ignore the \doublespacing within the subfile. Can I change this somehow?

Best Answer

I don't know if it's a recent change, but subfiles' documentation suggests this is by design.

Now there are two possibilities.

  • If LaTeX is run on the subfile, the line \documentclass[..]{subfiles} is replaced by the preamble of the main file (including its \documentclass command). The rest of the subfile is processed normally.

  • If LaTeX is run on the main file, the subfile is loaded like with an \input command, except that the preamble of the subfile up to \begin{document} as well as \end{document} and the lines following it are ignored.

How much beyond \doublespacing do you have in your subfiles' preambles? If it's just the \doublespacing command, can you define a command like \newcommand[1]{\doublespacedfile}{\begingroup\doublespacing\subfile{#1}\endgroup}? And then indicate in your main.tex which files should be doublespaced by choice of \subfile or \doublespacedfile?