Skip to main content
To manage a large LaTeX document such as a thesis or book, keep one master file (main.tex) and split chapters or sections into separate .tex files loaded with \input or \include. Use \includeonly to recompile only the chapter you are editing while keeping page numbers and cross-references intact, or use the subfiles package when individual chapters need to compile on their own.

Step 1: Organize your project folders

A predictable folder layout keeps long manuscripts manageable as figures, chapters, and appendices grow:
Keep \documentclass, \begin{document}, and \end{document} only in main.tex (unless you adopt subfiles in Step 4).

Step 2: Choose between \input and \include

\input and \include both pull another .tex file into main.tex, and both treat the .tex extension as optional, but they behave differently: Use \input for preamble.tex, shared macro files, and sections or large tables that should flow without a page break—you can safely call \input inside an \included chapter. Use \include at chapter boundaries in report or book documents. The compiled example below keeps its four files side by side in one folder; in a real thesis, pass relative paths such as \include{chapters/introduction}. Notice how \include places each chapter on its own page while resolving Chapter~\ref{ch:results} and page~\pageref{ch:intro} across files.
main.tex
preamble.tex
introduction.tex
results.tex
Ready to use this syntax? Continue in the browser editor when you want to adapt the example in a real project.Open LaTeX Cloud Studio

Step 3: Speed up editing with \includeonly

Once you have compiled the entire document at least once, LaTeX has written a separate .aux file for every \included chapter (introduction.aux, results.aux). To work on a single chapter without recompiling the rest of the book, add \includeonly{results} in the preamble of main.tex (or list several comma-separated paths, such as \includeonly{chapters/introduction,chapters/results}):
  • LaTeX skips typesetting any \included file not listed in \includeonly.
  • It still reads the skipped chapters’ .aux files, so chapter numbers, page numbers, \ref, and \pageref pointing to skipped chapters stay accurate.
  • Remove or comment out \includeonly before the final full compile so every chapter and the table of contents update together.

Step 4: Compile chapters standalone with subfiles

\includeonly still compiles through main.tex. If co-authors or reviewers need to compile a single chapter file on its own, use the subfiles package (v2.2 in TeX Live 2026):
  1. Load \usepackage{subfiles} in main.tex (after graphicx if you use \graphicspath) and include chapters with \subfile{chapters/chapter1} (inline, no page break) or \subfileinclude{chapters/chapter1} (behaves like \include with a page break and .aux file).
  2. Start each chapter file with \documentclass[../main.tex]{subfiles} (adjusting the relative path to main.tex) and wrap its body in \begin{document}...\end{document}.
  3. Path resolution (\subfix): subfiles automatically adjusts paths passed to \bibliography{...} and \graphicspath{...} (when graphics or graphicx is loaded before subfiles). For commands that subfiles does not patch—such as BibLaTeX’s \addbibresource or explicit relative paths in \includegraphics—wrap the path in \subfix{...} (for example \addbibresource{\subfix{references.bib}}) so it resolves whether you compile main.tex or the chapter standalone.
  4. Use \ifSubfilesClassLoaded{\printbibliography}{} when a command should run only during a standalone chapter compile.
The compiled example below keeps main.tex and chapter1.tex side by side so main.tex compiles the full document and chapter1.tex also compiles standalone:
main.tex
chapter1.tex

Step 5: Keep cross-references and project workflows clean

Standard \label, \ref, and \pageref work automatically across all files loaded by \input, \include, or \subfile. Use a consistent prefix convention (ch:, sec:, fig:, tab:, eq:) so labels never collide across chapters—see Cross-referencing. Only reach for the xr or xr-hyper package when you need to reference labels from a separately compiled LaTeX document’s .aux file. In LaTeX Cloud Studio, projects compile on TeX Live 2026 (full distribution) and full compilations run latexmk, so multi-pass cross-references and bibliography runs resolve across your project files automatically. For related large-project tasks covered on their own pages: Ready to structure a multi-chapter project in the browser? Start from the Master’s Thesis template in LaTeX Cloud Studio and replace main.tex with the complete example, adding preamble.tex, introduction.tex, and results.tex to the project.