# How to working with fragments of document

I use Kile and I would like to divide my book into parts and I would like to work on each parts separately. For example let's assume that I have two files: main.tex and chapter.tex.

Here is my main.tex file:

\documentclass[a4paper,10pt]{book}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{indentfirst}

\begin{document}

\input{chapter}

\end{document}


Here is my chapter.tex file:

\chapter{Some chapter}


I had activated tab that contains a content of main.tex file and I clicked PDFLaTex button. It works. But I had got the following errors when I switched to the chapter.tex and clicked the above button again.

./chapter.tex:1:Undefined control sequence \chapter
./chapter.tex:1:Missing \begin{document}.
chapter.tex:0:Emergency stop.


I have modified chapter.tex file. Here is a modified version:

\documentclass[a4paper,10pt]{book}
\begin{document}
\chapter{Some chapter}
\end{document}


It works. But I cannot compile the main.tex file. I have got the following errors:

./chapter.tex:1:Can be used only in preamble. \documentclass
./chapter.tex:2:Can be used only in preamble. \begin{document}


Any idea?

• I had created a Kile project and I added tex files into it. The problem has solved. Jul 3 '20 at 15:23

The standard way to do this is to use the \include command instead of \input to load the parts of the document. You would not use \documentclass and \begin{document}...\end{document} You can then use the \includeonly command in the document preamble to indicate which file(s) should be processed. This allows cross-references and numbering to remain consistent.