# Compiling from chapter

I'm new to LaTeX. I created a new document with the following structure

\documentclass{scrreprt}
\usepackage[english]{babel}
\usepackage{appendix}

% ... %

\begin{document}

\maketitle
\tableofcontents

\input{./content/1-Introduction}
% ... %
\input{./content/7-Appendix}

\end{document}


When I compile it from the "main" file, everything works. But when I compile it from one of my chapter files, it says:

! Undefined control sequence.
l.1 \chapter
! LaTeX Error: Missing \begin{document}.


A chapter looks like this:

\chapter{My Chapter}
% ... %
\section{...}
% ... %

• I assume, you tried pdflatex 1-Introduction? That won't work, as a \chapter is a command only available in documentclass like report or book (or scrreprt) -- you are looking after the \includeonly stuff
– user31729
Feb 27, 2015 at 21:07
• @ChristianHupfer: I have a chapter named "1-Introduction", but the error also occurs with other chapters. Besides, my document is of class scrreprt. Feb 27, 2015 at 21:09
• @user1170330 In main file go to options than to Define current... Now you can compile from others files Feb 27, 2015 at 21:12
• Hint: With scrreprt you most likely don't need package appendix. Feb 27, 2015 at 21:50
• Since you have some responses below that seem to answer your question, please consider marking one of them as ‘Accepted’ by clicking on the tickmark below their vote count (see How do you accept an answer?). This shows which answer helped you most, and it assigns reputation points to the author of the answer (and to you!). It's part of this site's idea to identify good questions and answers through upvotes and acceptance of answers. Mar 3, 2015 at 18:12

Every LaTeX document must start with \documentclass, include \begin{document} and end with \end{document}. Your chapter files don't have that so they can't compile by themselves.

But if you use \include instead of \input in the main file, then you can select parts to compile by using \includeonly in the preamble.

For example, use \include{chapters/first} \include{chapters/second} in the main document, and then add a line \includeonly{chapters/first} to the preamble and compile the main document.

• You were quicker (good explanation +1);-)
– user31729
Feb 27, 2015 at 21:20

This shows the \includeonly approach, specifying only some of the files, although 'all' of them are given in the document as \include{chapter1.tex} etc.

\documentclass{scrreprt}
\usepackage[english]{babel}
\usepackage{appendix}

\usepackage{blindtext}

\usepackage{filecontents}

\begin{filecontents}{chapter1.tex}
\chapter{This is chapter one}
\blindtext

\end{filecontents}

\begin{filecontents}{chapter2.tex}
\chapter{This is chapter two}
\blindtext

\end{filecontents}

\begin{filecontents}{chapter3.tex}
\chapter{This is chapter three}
\blindtext

\end{filecontents}

\title{Some title}

% ... %

\includeonly{chapter1,chapter2}
\begin{document}

\maketitle
\tableofcontents

\include{chapter1}
\include{chapter2}
\include{chapter3}

%\input{./content/1-Introduction}
% ... %
%\input{./content/7-Appendix}

\end{document}


• Good example! (+1) we might just paste the two together. Feb 27, 2015 at 21:40

You should write every chapter in a separate file (with \chapter issued right after \begin{document}), then load the package docmute in the main file: this package suppress \end{document} and all before \begin{document} included when you \input the chapter files.

Example:

ch01.tex:

\documentclass{book}
\begin{document}
\chapter{Chapter One}
...text...
\end{document}


ch02.tex:

\documentclass{book}
\begin{document}
\chapter{Chapter Two}
...text...
\end{document}


main.tex:

\documentclass{book}
\usepackage{docmute}
\begin{document}
\input{ch01}
\input{ch02}
\end{document}