8

When compiling large documents (with chapters) it is often useful to put different parts in separate files. I do this with the standalone-documentclass for all my tikzpictures. That way I can compile each separate part that I'm currently working on. I'd like to do the same with chapters in books. However, the standalone-documentclass doesn't have chapters. Thus, Ive defined my own chapter-command. And, as an example, changed the counter of the section-command to be printed with the chapter number. We could do the same with figures, tables, etc. My question is: Should there be more in my definition of the chapter-command to satisfy packages which depend on the chapter-command? Does the chapter have more "offsprings" like the chapter-counter?

MWE:

\documentclass[crop=false,a4paper]{standalone}
\usepackage{lipsum}

\makeatletter
\newcounter {chapter}
\renewcommand \thechapter {\@arabic\c@chapter}
\renewcommand{\thesection}{\arabic{chapter}.\arabic{section}}
\newcommand\chaptername{Chapter}
\newcommand\chapter[1]{
\refstepcounter{chapter}
\vspace*{2em}\noindent\Huge\chaptername\hspace*{0.25em} \thechapter\\
\vspace*{.25em}\\
\noindent{#1}\\
\normalsize
}
\makeatother

\begin{document}
\chapter{A test chapter}
\section{First section}
\subsection{First sub}
\subsection{Second sub}
\lipsum[1]
\end{document}

Update:

Qrrbrbirlbel's suggested a simple and good approach using class=book as a class option:

\documentclass[class=book,crop=false,a4paper]{standalone}
\usepackage{lipsum}

\begin{document}
\chapter{A test chapter}
\section{First section}
\subsection{First sub}
\subsection{Second sub}
\lipsum[1]
\end{document}
David Carlisle
  • 757,742
DrJay
  • 1,162
  • 1
    Using standalone for chapters in your book is at least inconvenient. I would recommend you to divide the document into several files, and \include them, with the possible help of the \includeonly command. – yo' Dec 20 '12 at 21:24
  • 2
    class=book as a class option? Though, I recommend @tohecz’s tip for real books. – Qrrbrbirlbel Dec 20 '12 at 21:28
  • Outstanding Qrrbrbirlbel, that absolutely did the trick! – DrJay Dec 20 '12 at 21:30
  • @tohecz: To say that a solution is inconvenient is by all accounts a convenient way to face a problem. As mentioned this problem occurs in large documents, where it can be unsatisfactory to use the include option instead of input. One problem is the nesting of include-statements which is in no way straight forward (if even possible?). Another problem might be that a certain set of chapters in a book requires quite a high number of packages while others require only a few - and it does take time to load all these packages even if they aren't used. – DrJay Dec 20 '12 at 21:35
  • Then I would say make a common preamble to all the chapters, and ask here couple good questions about how to correctly cross-reference (ToC, \ref, ...) and how to preserve correct page numbering. I only express my opinion, there are standard ways how to treat your problem as I explained above, and not using them might be a very tough and unnecessary journey. And notice that if I were convenient, my original post would not contain usable hints and references to literature. – yo' Dec 20 '12 at 21:41
  • You should use the same class for sub documents as the main document, and include the standalone package. This will allow you to compile each chapter standalone and can also include the chapters in the main document. – Peter Grill Dec 20 '12 at 21:48
  • Ooopst, maybe my question and comment was badly written an easily misinterpreted. Sorry about that. Standard header is what we all use in these cases to have correct formatting and such. But it still doesn't answer the original question. Qrrbrbirlbel's comment is the answer. It was a simple but good answer. – DrJay Dec 20 '12 at 21:50
  • Instead of answering it in your own question, perhaps @Qrrbrbirlbel should write up an answer so this question doesn't remain unanswered? – Vivi Dec 20 '12 at 23:11
  • 1
  • @Vivi I agree. That would be best! – DrJay Dec 20 '12 at 23:21
  • @cmhughes and Peter Grill. The question never was how to create sub-documents or how to split up a document. Solutions for this exists and are mostly satisfactory, as well as extremely good documented, both here at TEX.SX and in package documentation for different packages. – DrJay Dec 20 '12 at 23:28

1 Answers1

11

The answer to your question is to include the <class> class of your main file/project as an value to the class key of the standalone class:

\documentclass[
    crop=false,
    a4paper,
    class=<class>,
]{standalone}

Though, I do believe that the answer to your problem is another one that can be found in

On the statement of nesting \includeonly: Well, no, that’s not possible (and that’s how it is supposed to work), but you can use as many \inputs inside a file that is included as you wish.

Qrrbrbirlbel
  • 119,821