I've got a number of separate .tex files that are all \documentclass{article}. I'm inputting these into a \documentclass{book} file as chapters. In the book.tex file, then, I've got inputs like this:

\chapter{Chapter One!}

But I want to be able to compile article.tex separately when I need to. So in article.tex, I've kept the \begin{spacing}{1.5}, \end{spacing}, and \maketitle commands.

Is there any way to have these commands ignored when I compile book.tex? The \standaloneignore command seems to work only for ignoring things above the \documentclass declaration.

  • I believe that that files that get input should be using \documentclass{standalone}. This will then ignore the preamble in the separate .tex files up until \begin{document}. Martin provides a good example here Commented Sep 30, 2011 at 3:39
  • 1
    @PeterGrill: No, sub-files don't have to use the standalone class. It is only required if you want to crop them automatically. Just use standalone package in the main document and it will remove all preambles independent of the used class in these sub-files. Commented Sep 30, 2011 at 6:03

1 Answer 1


The subfile can use either \documentclass{article}, or \documentclass[preview=false]{standalone}. The class option [preview=false] for the standalone package is only there as you want the article.tex to compile by itself as it normally would. You could also use \documentclass{article} in the subfile, but the should also add \usepackage{standalone} \standalonetrue or \newif\ifstandlone \standalonetrue.

If there is specfic code \begin{document} in article.tex that you don't want processed use the \ifstandalone switch as shown below

In article.tex:


%% If you prefer to use the `article` class, the I would recommend
%\usepackage{standalone} \standalonetrue

\title{Artcle.tex Title}
\author{Duck Article}


   \maketitle% Test to ensure that this is not executed in book.tex


In book.tex:


\title{Book.tex Title}
\author{Duck Book}

%\maketitle Comment this out to ensure that that \maketitle form the article.tex does not get exectuted.
\chapter{Chapter One}
  • 4
    To use \ifstandalone is the correct answer, but your examples aren't that good. You should add \ifstandalone in the article.tex file and add the mentioned preview=false option. Using the standlone class is only requiered here to get the \ifstandalone switch, but \documentclass{article} \newif\ifstandlone \standalonetrue would also do it. Commented Sep 30, 2011 at 6:10
  • @Martin: Thanks. Have revised per your suggestions. Commented Sep 30, 2011 at 16:08

You must log in to answer this question.

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