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:\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’
.auxfiles, so chapter numbers, page numbers,\ref, and\pagerefpointing to skipped chapters stay accurate. - Remove or comment out
\includeonlybefore 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):
- Load
\usepackage{subfiles}inmain.tex(aftergraphicxif you use\graphicspath) and include chapters with\subfile{chapters/chapter1}(inline, no page break) or\subfileinclude{chapters/chapter1}(behaves like\includewith a page break and.auxfile). - Start each chapter file with
\documentclass[../main.tex]{subfiles}(adjusting the relative path tomain.tex) and wrap its body in\begin{document}...\end{document}. - Path resolution (
\subfix):subfilesautomatically adjusts paths passed to\bibliography{...}and\graphicspath{...}(whengraphicsorgraphicxis loaded beforesubfiles). For commands thatsubfilesdoes not patch—such as BibLaTeX’s\addbibresourceor explicit relative paths in\includegraphics—wrap the path in\subfix{...}(for example\addbibresource{\subfix{references.bib}}) so it resolves whether you compilemain.texor the chapter standalone. - Use
\ifSubfilesClassLoaded{\printbibliography}{}when a command should run only during a standalone chapter compile.
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:
- Syntax reference for multi-file commands: Multi-file projects
- Bibliographies: BibTeX guide and BibLaTeX guide
- Git,
.gitignore, and co-author reviews: Collaboration workflow - Converting to Word or HTML: Export LaTeX to Word and HTML
main.tex with the complete example, adding preamble.tex, introduction.tex, and results.tex to the project.