Modular LaTeX authoring with input and include
Keep large LaTeX projects maintainable by splitting them into separate files. Learn when to use input versus include and how to verify the output.
04 Apr 2026, 13:01 UTC

The practical takeaway
If your thesis, book, or report lives in one enormous .tex file, edits are hard to review and version control produces unreadable diffs. The useful answer is to split the source into separate files and insert them from a main file. Use \input for inline insertion where page numbering and counters must continue uninterrupted. Use \include when each part should start on a new page and you want to compile only selected parts with \includeonly. Keep the document preamble—\documentclass, \usepackage, and \begin{document}—in the main file only.
Worked configuration
Create a project directory with this layout:
project/
main.tex
chapters/
intro.tex
methods.tex
main.tex:
\documentclass{book}
\usepackage[utf8]{inputenc}
\usepackage{hyperref}
\title{Example Report}
\author{Author Name}
\date{\today}
\begin{document}
\maketitle
\tableofcontents
\input{chapters/intro}
\input{chapters/methods}
\end{document}
chapters/intro.tex:
\chapter{Introduction}
This is the introduction. It can reference Section~\ref{sec:methods} defined later.
\section{Background}
Body text goes here.
chapters/methods.tex:
\chapter{Methods}
\label{sec:methods}
This chapter describes the methods.
Run the compiler from the directory that contains main.tex:
pdflatex main.tex
No special permissions are required beyond read access to the source files and write access to the output directory. TeX resolves file paths relative to the main file's directory, so chapters/intro.tex is found from main.tex.
How the mechanism works
\input is a TeX primitive. When the compiler reaches \input{chapters/intro}, it reads the named file and tokenizes its contents as if they had been typed at that exact spot. Because the file is spliced inline, section counters, page numbers, labels, and cross-references continue across files without interruption. This behavior is consistent across pdfLaTeX, XeLaTeX, and LuaLaTeX.
Files brought in with \input should contain only body content and sectioning commands such as \chapter or \section. They must not repeat the preamble.
input versus include
LaTeX also provides \include, which is not a drop-in replacement for \input.
| Behavior | \\input | \\include |
|---|---|---|
| Page break before and after | No | Yes, via \\clearpage |
| Can be nested | Yes | No |
| Supports \\includeonly | No | Yes |
| Typical use | Sections, files that must flow together | Chapters or major parts |
To compile only one chapter, add this to the preamble of main.tex:
\includeonly{chapters/intro}
Then \include{chapters/intro} is typeset while other included files are skipped. Note that \include cannot appear inside another \include file, and \input does not force a new page.
Limits and common mistakes
- Nested document structure. Never put
\documentclass,\usepackage,\begin{document}, or\end{document}inside an\inputor\includefile. Doing so produces a document-structure error because the main file already opened the document environment. - Missing files halt compilation. TeX does not silently skip a missing
\inputtarget. Ifchapters/intro.texis absent or misspelled, the compiler stops and reports that it cannot find the file. Verify paths and spelling before compiling. - File names. Avoid spaces and non-ASCII characters in file names to keep behavior portable across engines and operating systems.
- Encoding. pdfLaTeX typically needs
\usepackage[utf8]{inputenc}for UTF-8 source files; XeLaTeX and LuaLaTeX handle UTF-8 natively.
Verification
- Create
main.texandchapters/intro.texas shown above. - Run
pdflatex main.texfrom the project directory. - Open the produced PDF and confirm that the introduction text appears and that page numbering continues from the front matter into the chapter.
- Temporarily rename or move
chapters/intro.tex, rerunpdflatex main.tex, and confirm the compiler stops with a file-not-found error rather than omitting the chapter silently. Restore the file afterward. - Replace one
\inputwith\include, recompile, and confirm that the included chapter begins on a new page.
There is no database or server state to roll back; the only changed files are the generated PDF and auxiliary logs. If a compilation experiment breaks the output, delete the auxiliary files (.aux, .log, .out, .pdf) and rerun from the last known-good source.
Practical check
After splitting, run the full build twice. LaTeX needs multiple passes to resolve cross-references and table of contents entries across files. If labels and page numbers are correct in the final PDF, the modular structure is working as intended.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.