Skip to content
EasyLaTeXDocs

Multi-File Projects

Save each section or chapter in a separate .tex file. Keep the document class, packages, global settings, and content order in the main file. This simplifies collaboration, debugging, and reuse.

EasyLaTeX compiler setting: pdfLaTeX; no additional package is needed for the basic approach. Use project-relative paths for included files.

Inserting Content with \input

\input{filename} reads another file at the current position. The .tex extension is usually omitted:

latex
\section{Introduction}
\input{chapters/introduction}

Included files contain body content only. Do not repeat \documentclass, \begin{document}, or \end{document}.

Managing Chapters with \include

\include suits substantial, independent chapters. It inserts page breaks before and after the content and creates a separate auxiliary file for each chapter:

latex
\include{chapters/method}
\include{chapters/results}

The platform still compiles the selected main file. \includeonly{chapters/results} can preview selected chapters, but references to skipped chapters depend on auxiliary information that is not guaranteed across jobs. Remove it and compile the whole document before final checks.

Choosing \input or \include

CommandBehaviorSuitable content
\inputNo page break; can be nested; fine-grainedSections, figures, tables, abstract fragments
\includeAutomatic page breaks; cannot be nested; supports \includeonlySubstantial standalone chapters

Do not mix both methods to control page breaks for the same chapter. Let the main file define chapter boundaries.

Organizing Directories and Paths

Give directories names that describe their purpose:

latex
project/
├── main.tex
├── chapters/
│   ├── introduction.tex
│   └── results.tex
└── figures/

Paths are resolved relative to the main file. Prefer letters, numbers, and hyphens in filenames; spaces and special characters can cause cross-platform problems.

Compiling a Chapter Separately

Ordinary chapter files depend on the main preamble and cannot be compiled alone. If you need standalone previews, use subfiles to share the preamble:

latex
% main.tex
\usepackage{subfiles}
\subfile{chapters/introduction}
latex
% chapters/introduction.tex
\documentclass[../main.tex]{subfiles}
\begin{document}
Chapter content.
\end{document}

On the platform, select a child file as the main file only when it has a complete standalone entry structure. After a chapter preview, restore the project's main-file selection. Keeping main.tex selected is simpler for ordinary projects.

Common Problems

File Not Found

Check capitalization, relative paths, and extensions. On case-sensitive systems, \input{chapters/a} does not identify chapters/A.tex.

\documentclass Causes an Error in a Child File

Basic \input and \include files must contain only body content. Move the document class and packages back to the main file.

Cross-References Display ??

Compile the complete main file in EasyLaTeX and wait for the job to finish. The platform handles the passes needed for references. If ?? remains, check label spelling, duplicate names, placement, and the first log error.

Complete Example

Main file, main.tex:

latex
\documentclass[a4paper,12pt]{article}
\usepackage[colorlinks=true,linkcolor=blue]{hyperref}

\begin{document}
\tableofcontents
\input{chapters/introduction}
\input{chapters/results}
\end{document}

chapters/introduction.tex:

latex
\section{Introduction}\label{sec:introduction}
This is the introduction.

chapters/results.tex:

latex
\section{Results}
For the background to these results, see Section  \ref{sec:introduction}.
Multi-File Projects | EasyLaTeX | EasyLaTeX