A long document is easier to manage when split into files — one per chapter, figures in their own files. LaTeX offers several ways to stitch them back together, each for a different need: \input to paste anywhere, \include for chapter-level pieces (with \includeonly for partial builds), and the subfiles / standalone packages that let each piece also compile on its own. This page is about choosing among them.
\input — paste anywhere
\input{file} inserts that file’s content exactly where the command sits — as if you had typed it there. It causes no page break, works in the preamble or the body, and can be nested. The .tex extension is assumed. It suits small fragments: a shared preamble, a table, a short section.
% main.tex
\documentclass{report}
\input{preamble/common}
\begin{document}
\input{sections/intro}
\input{tables/experiment-settings}
\end{document}\include — split by chapter
\include{file} does a \clearpage before and after the inclusion, and switches to a separate .aux file just for that chunk. It is built for large units like chapters. You cannot nest \include (though an \included file may \input others). Use it for chapter-level splits that should start on a fresh page.
\include{chapters/ch1}\includeonly — compile just part, fast
Put \includeonly{ch2,ch3} in the preamble and LaTeX processes only those chapters. Because each \include keeps its own .aux, the page numbers and cross-references of the skipped chapters stay correct from the last full build. So after one complete run, you can rebuild just the chapter you are editing in a fraction of the time. (This works only with \include, not \input.)
\includeonly{chapters/ch3} % プリアンブルに置く / put in the preamblesubfiles / standalone — compile a file on its own
The \include approach only builds from the main file. The subfiles package lets each subfile compile on its own, while automatically inheriting the main file’s preamble. The main file uses \subfile{...}, and each subfile begins with \documentclass[../main.tex]{subfiles}. Handy for checking a single chapter without building the whole book.
% main.tex
\documentclass{book}
\usepackage{subfiles}
\begin{document}
\subfile{chapters/ch1}
\end{document}
% chapters/ch1.tex
\documentclass[../main.tex]{subfiles}
\begin{document}
\chapter{はじめに}
\end{document}The similar standalone package/class gives each file its own preamble. It is more flexible but more involved to write. It shines for figures and TikZ: keep a figure as a standalone file that compiles to its own cropped PDF/image, yet can also be pulled into the main document.
Which to use
It helps to design the split at the directory level first. Put body chapters in chapters/, long sections or tables in sections/ or tables/, graphics in figures/, and shared setup in preamble/. Avoid spaces in filenames; use letters, digits, hyphens, and underscores. When the project later builds in CI or on another operating system, these plain naming rules become reproducibility.
- Small fragments, a shared preamble →
\input. - Chapter-level units with a fresh page →
\include(plus\includeonlyfor partial builds). - Compile each chapter on its own, shared preamble →
subfiles. - Standalone figures reused in the body, own preamble →
standalone.
And since latexmk tracks included files as dependencies, splitting the document does not break automated builds or on-save recompilation. If a newly split project reports “file not found,” first check that paths are relative to the main file, that you did not duplicate the .tex extension unnecessarily, and that you are running the build from the project root rather than a subdirectory.
Another common failure is compiling a subordinate file directly. A file brought in with \input or \include usually has no \documentclass and no preamble, so it is not a standalone document. If you need to compile a chapter alone, use subfiles; if you need an independent figure PDF, use standalone. Keep that boundary clear instead of forcing ordinary chapter files to compile by themselves.