[Tex/LaTex] Standalone document with chapter

chapterscountersstandalone

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}

Best Answer

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.

Related Question