When One File Isn't Enough
A 10-page paper? Open one file, write, compile. Simple.
A 200-page thesis with 12 chapters, 50 figures, and 300 references? That's not a file. That's a project.
Single files become unwieldy. Scrolling takes forever. Compilation slows to a crawl. Your editor chokes. And if you need to reorganize chapters, you're in for a world of pain.
The solution: multi-file LaTeX architecture. One master document, separate files for each chapter, intelligent compilation that rebuilds only what changed. Here's how to set it up from the start—or retrofit an existing monster document. (See also our thesis templates for pre-organized project structures.)
File Organization
The Master Document Pattern
Create a main file that includes others:
thesis/
├── main.tex # Master document
├── preamble.tex # Packages and settings
├── chapters/
│ ├── introduction.tex
│ ├── literature.tex
│ ├── methods.tex
│ ├── results.tex
│ └── conclusion.tex
├── frontmatter/
│ ├── abstract.tex
│ ├── acknowledgments.tex
│ └── dedication.tex
├── appendices/
│ ├── appendix-a.tex
│ └── appendix-b.tex
├── figures/
│ ├── chapter-3/
│ └── chapter-4/
└── references.bibThe Master File
% main.tex
\documentclass[12pt, a4paper]{book}
\input{preamble}
\begin{document}
\frontmatter
\input{frontmatter/titlepage}
\input{frontmatter/abstract}
\input{frontmatter/acknowledgments}
\tableofcontents
\listoffigures
\listoftables
\mainmatter
\include{chapters/introduction}
\include{chapters/literature}
\include{chapters/methods}
\include{chapters/results}
\include{chapters/conclusion}
\backmatter
\appendix
\include{appendices/appendix-a}
\include{appendices/appendix-b}
\bibliographystyle{apalike}
\bibliography{references}
\end{document}\input vs \include
\input
Inserts content exactly where called:
\input{sections/intro}
% Content of intro.tex appears hereCharacteristics:
- Can be nested (input within input)
- Can be used anywhere
- No page break before or after
- Cannot be selectively included
\include
For major document sections:
\include{chapters/methods}
% Starts new page, includes chapterCharacteristics:
- Cannot be nested
- Starts on new page
- Creates .aux file per include
- Works with \includeonly
\includeonly
Compile only specific chapters:
\includeonly{chapters/methods, chapters/results}
% In document:
\include{chapters/introduction} % Skipped
\include{chapters/literature} % Skipped
\include{chapters/methods} % Compiled
\include{chapters/results} % Compiled
\include{chapters/conclusion} % SkippedBenefits:
- Much faster compilation
- Cross-references preserved (from aux files)
- Switch quickly between sections
Comment out \includeonly for final compilation.
Compilation Strategies
Draft Mode
Speed up compilation during writing:
\documentclass[draft]{book}Draft mode:
- Shows overfull/underfull box warnings
- Replaces images with placeholders
- Faster compilation
Selective Compilation
Using \includeonly:
% Working on methods chapter
\includeonly{chapters/methods}
% Later, working on results
\includeonly{chapters/results}
% Final compilation (comment out)
% \includeonly{...}Parallel Compilation
Some build systems compile parts in parallel. Check if your setup supports:
latexmkwith appropriate configuration- IDE-specific parallel compilation
- Custom build scripts
Managing Cross-References
Labels Across Files
Labels work across included files:
% In chapters/methods.tex
\section{Data Collection}
\label{sec:data-collection}
% In chapters/results.tex
As described in Section \ref{sec:data-collection}...Checking References
Find undefined references:
grep "LaTeX Warning.*undefined" main.logOr search your PDF for "??" symbols.
The \ref* Command
With hyperref, \ref* creates non-hyperlinked reference:
\ref{sec:intro} % Hyperlinked
\ref*{sec:intro} % Plain numberBibliography Management
Single Bibliography
Most common approach:
% At end of main.tex
\bibliographystyle{apalike}
\bibliography{references}Per-Chapter Bibliographies
Using biblatex with refsection:
\usepackage[refsection=chapter]{biblatex}
% Each chapter gets its own bibliography
\begin{refsection}
\include{chapters/literature}
\printbibliography[heading=subbibliography]
\end{refsection}Large Bibliography Files
Organize .bib files by topic:
\bibliography{general, methods, datasets}Or keep one file but organize internally:
%%% FOUNDATIONAL PAPERS %%%
@article{...}
%%% METHODOLOGY %%%
@article{...}
%%% DATASETS %%%
@misc{...}Handling Figures
Figure Organization
figures/
├── chapter-1/
│ ├── overview.pdf
│ └── timeline.pdf
├── chapter-3/
│ ├── setup.pdf
│ ├── results-1.pdf
│ └── results-2.pdf
└── chapter-4/
└── comparison.pdfGraphics Path
\graphicspath{
{figures/}
{figures/chapter-1/}
{figures/chapter-3/}
{figures/chapter-4/}
}
% Then in text:
\includegraphics{overview} % Found in figures/ or subfoldersExternal Figure Files
For complex TikZ figures, externalize:
\usetikzlibrary{external}
\tikzexternalize[prefix=tikz-cache/]TikZ figures compile once and are cached as PDFs.
Custom Commands and Styles
The Preamble File
Keep customizations in one place:
% preamble.tex
% Packages
\usepackage{amsmath, amssymb}
\usepackage{graphicx}
\usepackage{booktabs}
\usepackage{hyperref}
\usepackage{cleveref}
% Custom commands
\newcommand{\todo}[1]{\textcolor{red}{TODO: #1}}
\newcommand{\myterm}{Technical Term}
% Document settings
\setlength{\parindent}{0pt}
\setlength{\parskip}{1em}Class Files
For extensive customization, create a class file:
% mythesis.cls
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{mythesis}[2025/01/01 My Thesis Class]
\LoadClass[12pt, a4paper]{book}
\RequirePackage{...}
% Additional configurationUse in main:
\documentclass{mythesis}Version Control
Git for LaTeX
Git works excellently with LaTeX:
git init
git add .
git commit -m "Initial structure".gitignore for LaTeX
# LaTeX auxiliary files
*.aux
*.log
*.bbl
*.blg
*.out
*.toc
*.lof
*.lot
*.fls
*.fdb_latexmk
*.synctex.gz
# Build output (optional)
*.pdf
# Editor files
*.swp
.DS_StoreMeaningful Commits
git commit -m "Complete first draft of methods chapter"
git commit -m "Add figures for experimental results"
git commit -m "Revise introduction based on advisor feedback"Branching for Major Revisions
git checkout -b major-revision
# Make significant changes
git commit -m "Restructure literature review"
git checkout main
git merge major-revisionCompilation Workflows
Using latexmk
Automate the compile sequence:
latexmk -pdf main.texlatexmk automatically runs LaTeX, BibTeX, and recompiles as needed.
Makefile
For complex builds:
all: main.pdf
main.pdf: main.tex chapters/*.tex references.bib
latexmk -pdf main.tex
clean:
latexmk -c
distclean:
latexmk -CContinuous Compilation
Watch for changes and recompile:
latexmk -pdf -pvc main.texCommon Problems
Slow Compilation
Solutions:
- Use
\includeonly - Enable draft mode
- Externalize TikZ graphics
- Reduce image resolution during drafting
Auxiliary File Pollution
Solution: Redirect to build folder:
latexmk -pdf -auxdir=build -outdir=build main.texCross-Reference Errors
Symptom: Wrong chapter/section numbers after using \includeonly.
Solution: Compile full document occasionally to update all .aux files.
Bibliography Issues
Symptom: Citations show [?] after adding new references.
Solution: Full compile sequence: LaTeX → BibTeX → LaTeX → LaTeX.
Project Templates
Thesis Template Structure
thesis/
├── main.tex
├── preamble.tex
├── mythesis.cls # Optional custom class
├── frontmatter/
│ ├── titlepage.tex
│ ├── abstract.tex
│ ├── acknowledgments.tex
│ └── symbols.tex # List of symbols/abbreviations
├── chapters/
│ ├── 01-introduction.tex
│ ├── 02-background.tex
│ ├── 03-methods.tex
│ ├── 04-results.tex
│ └── 05-conclusion.tex
├── appendices/
├── figures/
├── tables/ # Optional: external table files
├── references.bib
├── .gitignore
└── MakefileBook Template Structure
book/
├── main.tex
├── preamble.tex
├── parts/
│ ├── part1.tex
│ └── part2.tex
├── chapters/
├── appendices/
├── frontmatter/
│ ├── preface.tex
│ └── foreword.tex
├── backmatter/
│ └── index.tex
├── figures/
└── references.bibQuick Reference
File Inclusion Commands
| Command | New Page | Nestable | \includeonly |
|---------|----------|----------|--------------|
| \input{} | No | Yes | No |
| \include{} | Yes | No | Yes |
Compilation Optimization
| Technique | Speed Gain | |-----------|-----------| | Draft mode | High | | \includeonly | High | | TikZ externalize | Medium-High | | Reduced image quality | Medium | | SSD storage | Medium |
Essential Commands
% Structure
\frontmatter, \mainmatter, \backmatter
\appendix
% File inclusion
\input{file}, \include{file}
\includeonly{file1, file2}
% Graphics
\graphicspath{{path/}}
% References
\tableofcontents
\listoffigures
\listoftablesConclusion
Large documents require organization:
- Split into logical files using \include
- Use \includeonly for fast partial compilation
- Organize figures and references systematically
- Version control with Git
- Automate builds with latexmk or Makefile
The initial setup takes time, but pays off across months of writing. A well-organized project is easier to navigate, faster to compile, and more maintainable.
Start organized. Stay organized. Finish successfully.