[Tex/LaTex] Splitting a document per chapter with preample for Latexian live preview

chapterslatexianpreamble

Currently, I have my main LaTeX document set up as follows:

\documentclass[12pt]{report}
\usepackage{mystyle}
\title{Mytitle} \author{Me} \date{}

\begin{document}
\pagestyle{plain}
\maketitle
\chapter{Introduction}
\input{chapters/chapter01}
\end{document}

While my chapters themselves contain no preamble, no begin/end document etc, just the contents of the chapter itself.

I use Latexian and really enjoy the live preview function in a split screen. I would like to write each individual chapter and use the live preview feature, however, I cannot compile/preview each chapter on its own without its own preamble, begin/end document etc.

Is there a way around this? It feels very clunky to have to switch back and forth between a window containing just my chapter and one containing the entire thesis. Similarly, it feels very clunky to have each chapter contain everything necessary to compile and then manually comment out the extra lines from every single chapter when I wish to compile them all together.

Best Answer

Convert your chapters in complete documents (with the same preample that the main document) and then go to CTAN to known about the topic subdoc: in­clude com­plete doc­u­ments in other doc­u­ments. In particular, docmute or standalone packages is what your are looking for. It is a simple as add one of these packages to the preamble of the main document (there are many examples of use of both packages in this site, for example this answer.

I suggest also move rest of the preamble to a preamble.tex file and left in the main document only \input{preamble} and use only this command in the preambles of the child fles, because if you need change some change in the preambles, you only have to do once, avoiding mistakes.

Alternatively, as suggested in the other answer, you can also preview the main document with only a chapter, using \includeonly{...} in the preamble of the main document, but note that this command affect to \include commands, not to \input (see When should I use \input vs. \include?), so in your example, you should change \chapter{...}\input{...} by only \include{...} with \chapter{...} included in the child document.

Related Question