[Tex/LaTex] Compiling from chapter

chapterscompiling

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{...}
% ... %

Best Answer

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.