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.

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.

share|improve this question
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 –  Peter Grill Sep 30 '11 at 3:39
@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. –  Martin Scharrer Sep 30 '11 at 6:03
add comment

1 Answer

up vote 5 down vote accepted

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}
share|improve this answer
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. –  Martin Scharrer Sep 30 '11 at 6:10
@Martin: Thanks. Have revised per your suggestions. –  Peter Grill Sep 30 '11 at 16:08
Thank you both! –  duck Oct 1 '11 at 18:14
add comment

Your Answer


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.