Prerequisites: Basic LaTeX knowledge, understanding of document classes
Time to complete: 35-40 minutes
Difficulty: Advanced
What you’ll learn: Project structure, input/include commands, subfiles, cross-referencing, and build optimization
Time to complete: 35-40 minutes
Difficulty: Advanced
What you’ll learn: Project structure, input/include commands, subfiles, cross-referencing, and build optimization
Why Split Large Documents?
Benefits of Modular Structure
Faster Compilation
Compile only changed sections during development
Better Organization
Logical file structure mirrors document structure
Team Collaboration
Multiple authors can work on different sections
Version Control
Track changes at the chapter/section level
When to Split Documents
Consider splitting when:
- Document exceeds 50 pages
- Multiple authors collaborate
- Chapters have distinct topics
- Compilation takes over 30 seconds
- You need different formatting per section
- Managing bibliography becomes complex
Project Structure
Standard Directory Layout
my-thesis/
├── main.tex # Master document
├── preamble/
│ ├── packages.tex # Package imports
│ ├── settings.tex # Document settings
│ ├── commands.tex # Custom commands
│ └── environments.tex # Custom environments
├── frontmatter/
│ ├── titlepage.tex # Title page
│ ├── abstract.tex # Abstract
│ ├── dedication.tex # Dedication
│ └── acknowledgments.tex # Acknowledgments
├── chapters/
│ ├── introduction.tex # Chapter 1
│ ├── literature.tex # Chapter 2
│ ├── methodology.tex # Chapter 3
│ ├── results.tex # Chapter 4
│ └── conclusion.tex # Chapter 5
├── appendices/
│ ├── appendix-a.tex # Appendix A
│ └── appendix-b.tex # Appendix B
├── backmatter/
│ ├── bibliography.bib # References
│ └── index.tex # Index entries
├── figures/ # All images
│ ├── chapter1/
│ ├── chapter2/
│ └── shared/
├── tables/ # Complex tables
└── build/ # Build artifacts
Master Document Setup
\documentclass[12pt, twoside, openright]{book}
% Load preamble components
\input{preamble/packages}
\input{preamble/settings}
\input{preamble/commands}
\input{preamble/environments}
% Document metadata
\title{Your Document Title}
\author{Your Name}
\date{\today}
\begin{document}
% Front matter
\frontmatter
\input{frontmatter/titlepage}
\input{frontmatter/dedication}
\input{frontmatter/acknowledgments}
\input{frontmatter/abstract}
\tableofcontents
\listoffigures
\listoftables
% Main matter
\mainmatter
\input{chapters/introduction}
\input{chapters/literature}
\input{chapters/methodology}
\input{chapters/results}
\input{chapters/conclusion}
% Appendices
\appendix
\input{appendices/appendix-a}
\input{appendices/appendix-b}
% Back matter
\backmatter
\printbibliography[heading=bibintoc]
\printindex
\end{document}
% Essential packages for large documents
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
% Page layout
\usepackage[
top=1in,
bottom=1in,
left=1.5in,
right=1in,
headheight=14pt
]{geometry}
% Graphics and colors
\usepackage{graphicx}
\usepackage{xcolor}
\usepackage{tikz}
% Tables and lists
\usepackage{booktabs}
\usepackage{longtable}
\usepackage{array}
\usepackage{enumitem}
% Mathematics
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
% References and links
\usepackage{hyperref}
\usepackage{cleveref}
\usepackage[nameinlink]{cleveref}
% Bibliography
\usepackage[
backend=biber,
style=authoryear,
sorting=nyt
]{biblatex}
\addbibresource{backmatter/bibliography.bib}
% Index
\usepackage{imakeidx}
\makeindex[intoc]
% Headers and footers
\usepackage{fancyhdr}
\usepackage{emptypage}
% Code listings
\usepackage{listings}
\usepackage{minted}
% Subfigures
\usepackage{subcaption}
% Todo notes
\usepackage[disable]{todonotes} % Enable during writing
Input vs Include
Understanding the Differences
- \input
- \include
- \includeonly
% Direct text insertion
\input{filename} % No .tex extension needed
% Characteristics:
% - No page break before/after
% - Can be nested
% - Good for preamble files
% - Compiles every time
% Example usage:
\input{preamble/packages}
\input{chapters/section1}
% Chapter-level inclusion
\include{filename} % No .tex extension
% Characteristics:
% - Starts new page before
% - Clears page after
% - Cannot be nested
% - Works with \includeonly
% - Creates .aux file
% Example usage:
\include{chapters/introduction}
\include{chapters/methodology}
% Selective compilation
\includeonly{
chapters/introduction,
chapters/results
}
% Only compiles listed files
% Preserves numbering/references
% Massive time savings
% Perfect for focused editing
Practical Examples
% During writing - compile only current chapter
\includeonly{chapters/methodology}
\begin{document}
% ... front matter ...
\include{chapters/introduction} % Skipped
\include{chapters/literature} % Skipped
\include{chapters/methodology} % Compiled
\include{chapters/results} % Skipped
\include{chapters/conclusion} % Skipped
% chapters/methodology.tex
\chapter{Methodology}
\label{ch:methodology}
\section{Overview}
This chapter describes our research methodology.
% Include section files
\input{chapters/methodology/data-collection}
\input{chapters/methodology/analysis}
\input{chapters/methodology/validation}
\section{Summary}
The methodology ensures reliable results...
The Subfiles Package
Independent Compilation
\documentclass{book}
\usepackage{subfiles}
% ... other packages ...
\begin{document}
\subfile{chapters/introduction}
\subfile{chapters/literature}
\subfile{chapters/methodology}
\end{document}
\documentclass[../main.tex]{subfiles}
\begin{document}
\chapter{Introduction}
\label{ch:intro}
This thesis investigates...
% Can be compiled independently!
% Run: pdflatex introduction.tex
\section{Background}
The research background...
\section{Objectives}
Our main objectives are...
\end{document}
% Alternative: standalone package
\documentclass{standalone}
\usepackage{import}
% Stand-alone compilable
\begin{document}
\import{../}{preamble}
\chapter{Standalone Chapter}
Content here...
\end{document}
Subfiles Best Practices
Subfiles workflow tips:
- Each chapter can be compiled separately
- Graphics paths are relative to main file
- Bibliography works in both modes
- Perfect for author collaboration
- Faster development cycles
Cross-referencing
Managing References Across Files
% Enable smart referencing
\usepackage{xr} % Cross-references to external documents
\usepackage{xr-hyper} % With hyperref support
\usepackage{cleveref}
% Reference another document
\externaldocument[ext:]{external-doc}
% In chapters/introduction.tex
\chapter{Introduction}
\label{ch:intro}
\section{Motivation}
\label{sec:intro:motivation}
As discussed in \cref{ch:methodology}, our approach...
% In chapters/methodology.tex
\chapter{Methodology}
\label{ch:methodology}
Building on \cref{sec:intro:motivation}, we develop...
% Cleveref automatically handles:
% "Chapter 3" vs "Section 1.2" vs "Figure 4.5"
% Systematic labeling convention
\label{type:chapter:section:subsection}
% Examples:
\label{ch:intro} % Chapter
\label{sec:intro:background} % Section
\label{subsec:intro:background:history} % Subsection
\label{fig:results:accuracy} % Figure
\label{tab:data:summary} % Table
\label{eq:methodology:formula} % Equation
\label{alg:analysis:process} % Algorithm
\label{thm:theory:main} % Theorem
\label{def:terms:important} % Definition
% Easy to find and maintain
% Avoids naming conflicts
% Self-documenting
Advanced Cross-referencing
% Create a references file
% refs/labels.tex
\newcommand{\introduction}{\cref{ch:intro}}
\newcommand{\methodology}{\cref{ch:methodology}}
\newcommand{\maintheorem}{\cref{thm:main}}
\newcommand{\resultsfigure}{\cref{fig:results:main}}
% Use semantic references
As shown in \resultsfigure, our method outperforms...
The proof follows from \maintheorem...
% Benefits:
% - Central management
% - Easy to update
% - Semantic naming
% - Find/replace friendly
% Check for undefined references
\usepackage{refcheck}
% Shows unused labels
\usepackage{showlabels}
% During development only:
\usepackage[notref,notcite]{showkeys}
% Custom warning for missing refs
\makeatletter
\def\@refundefined#1{%
\textbf{[REF: #1??]}%
\@latex@warning{Reference `#1' undefined}%
}
\makeatother
Compilation Strategies
Build Systems
- Makefile
- latexmk
- VS Code Tasks
# Makefile for large LaTeX projects
MAIN = main
CHAPTERS = $(wildcard chapters/*.tex)
FIGURES = $(wildcard figures/**/*.pdf)
BIBTEX = biber
# Default target
all: $(MAIN).pdf
# Main compilation
$(MAIN).pdf: $(MAIN).tex $(CHAPTERS) $(FIGURES)
pdflatex $(MAIN)
$(BIBTEX) $(MAIN)
pdflatex $(MAIN)
pdflatex $(MAIN)
# Quick build (no bibliography)
quick:
pdflatex $(MAIN)
# Clean auxiliary files
clean:
rm -f *.aux *.log *.out *.toc *.lof *.lot
rm -f *.bbl *.blg *.bcf *.run.xml
rm -f chapters/*.aux
# Clean everything
distclean: clean
rm -f $(MAIN).pdf
# Watch for changes
watch:
latexmk -pdf -pvc $(MAIN)
.PHONY: all quick clean distclean watch
# .latexmkrc configuration
$pdf_mode = 1; # Use pdflatex
$bibtex_use = 2; # Use biber
$out_dir = 'build'; # Output directory
# Custom dependencies
add_cus_dep('glo', 'gls', 0, 'run_makeglossaries');
add_cus_dep('acn', 'acr', 0, 'run_makeglossaries');
sub run_makeglossaries {
if ( $silent ) {
system "makeglossaries -q '$_[0]'";
} else {
system "makeglossaries '$_[0]'";
};
}
# Continuous preview
$preview_continuous_mode = 1;
$pdf_previewer = 'open -a Skim';
# Clean extensions
$clean_ext = 'synctex.gz acn acr alg aux bbl bcf blg brf fdb_latexmk glg glo gls idx ilg ind ist lof log lot out run.xml toc';
// .vscode/tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "Build LaTeX",
"type": "shell",
"command": "latexmk",
"args": [
"-pdf",
"-synctex=1",
"-interaction=nonstopmode",
"-file-line-error",
"main.tex"
],
"group": {
"kind": "build",
"isDefault": true
}
},
{
"label": "Quick Compile",
"type": "shell",
"command": "pdflatex",
"args": ["main.tex"],
"problemMatcher": []
},
{
"label": "Clean Auxiliary",
"type": "shell",
"command": "latexmk",
"args": ["-c"],
"problemMatcher": []
}
]
}
Compilation Optimization
% Fast draft compilation
\documentclass[draft]{book}
% Images shown as boxes
% Overfull boxes marked
% Much faster compilation
% Conditional draft mode
\usepackage{ifdraft}
\ifdraft{
\usepackage[disable]{todonotes}
\overfullrule=5pt
}{
\usepackage{todonotes}
\overfullrule=0pt
}
% Skip expensive operations
\ifdraft{
\renewcommand{\includegraphics}[2][]{%
\fbox{#2}% Just show filename
}
}{}
% Externalize TikZ pictures
\usepackage{tikz}
\usetikzlibrary{external}
\tikzexternalize[prefix=tikz/]
% Compile once, reuse many times
\begin{tikzpicture}
% Complex diagram
% Only recompiled if changed
\end{tikzpicture}
% Externalize other content
\usepackage{standalone}
\usepackage{docmute}
% In main.tex:
\input{figures/complex-diagram}
% Can also compile standalone
Version Control
Git Best Practices
# LaTeX auxiliary files
*.aux
*.lof
*.log
*.lot
*.fls
*.out
*.toc
*.fmt
*.fot
*.cb
*.cb2
.*.lb
# Bibliography auxiliary
*.bbl
*.bcf
*.blg
*-blx.aux
*-blx.bib
*.run.xml
# Build artifacts
build/
*.pdf
!figures/*.pdf
!templates/*.pdf
# Editor files
.vscode/
*.swp
*.swo
*~
.DS_Store
# Temporary files
*.tmp
*.bak
*.backup
# Meaningful commits for documents
git add chapters/methodology.tex
git commit -m "Add data analysis section to methodology"
git add figures/chapter3/*.pdf
git commit -m "Add experimental results figures"
git add preamble/commands.tex
git commit -m "Define custom theorem environments"
# Tag milestones
git tag -a v1.0-draft -m "First complete draft"
git tag -a v2.0-submission -m "Journal submission version"
# Branch for major revisions
git checkout -b revision-reviewer-1
git checkout -b conference-version
Collaboration Strategies
Team collaboration tips:
- One sentence per line - Easier diffs
- Semantic linebreaks - Break at clauses
- Chapter ownership - Assign primary authors
- Regular integration - Daily merges
- Automated builds - CI/CD for PDFs
Managing Bibliography
Modular Bibliography
% Split bibliography by chapter
\usepackage[refsection=chapter]{biblatex}
\addbibresource{references/intro.bib}
\addbibresource{references/theory.bib}
\addbibresource{references/experiments.bib}
% Print chapter bibliographies
\printbibliography[heading=subbibintoc]
% Or global bibliography
\printbibliography[heading=bibintoc]
% Bibliography categories
\DeclareBibliographyCategory{own}
\addtocategory{own}{myarticle2020,mybook2021}
\printbibliography[
category=own,
title={Own Publications}
]
% Organize by topic
% references/machine-learning.bib
@article{lecun2015deep,
title={Deep learning},
author={LeCun, Yann and Bengio, Yoshua and Hinton, Geoffrey},
journal={Nature},
volume={521},
number={7553},
pages={436--444},
year={2015}
}
% references/statistics.bib
@book{hastie2009elements,
title={The elements of statistical learning},
author={Hastie, Trevor and Tibshirani, Robert and Friedman, Jerome},
year={2009},
publisher={Springer}
}
Multi-format Output
Conditional Formatting
% Different formats from same source
\usepackage{ifthen}
\newboolean{printversion}
\setboolean{printversion}{true} % or false
% Conditional content
\ifthenelse{\boolean{printversion}}{
% Print version
\usepackage[colorlinks=false]{hyperref}
\geometry{twoside}
}{
% Digital version
\usepackage[colorlinks=true]{hyperref}
\geometry{oneside}
}
% Format-specific content
\newcommand{\printonly}[1]{%
\ifthenelse{\boolean{printversion}}{#1}{}%
}
\newcommand{\digitalonly}[1]{%
\ifthenelse{\boolean{printversion}}{}{#1}%
}
% Usage
\digitalonly{\href{https://example.com}{Click here for details}}
\printonly{See \url{https://example.com} for details}
Troubleshooting Large Documents
Common Issues
Large document problems and solutions:
-
Undefined references
% Run LaTeX multiple times pdflatex main && pdflatex main && pdflatex main -
Memory errors
# Increase memory limits export extra_mem_top=2000000 export extra_mem_bot=2000000 -
Slow compilation
- Use
\includeonlyduring writing - Enable draft mode
- Externalize graphics
- Use
-
File not found
% Check paths \input{./chapters/intro} % Explicit path \graphicspath{{./figures/}{./images/}} -
Conflicting packages
- Load hyperref last
- Check package documentation
- Use compatibility options
Complete Example Project
% main.tex - Complete thesis example
\documentclass[
12pt,
a4paper,
twoside,
openright,
english,
bibliography=totoc,
listof=totoc
]{scrbook}
% ====== PREAMBLE SETUP ======
\input{preamble/packages}
\input{preamble/settings}
\input{preamble/commands}
% Conditional compilation
\includeonly{
chapters/introduction,
chapters/methodology,
chapters/results
}
% ====== DOCUMENT INFO ======
\title{Advanced Research in LaTeX Document Management}
\author{Your Name}
\date{\today}
\begin{document}
% ====== FRONT MATTER ======
\frontmatter
\input{frontmatter/titlepage}
\input{frontmatter/declaration}
\input{frontmatter/abstract}
\input{frontmatter/acknowledgments}
\tableofcontents
\listoffigures
\listoftables
\input{frontmatter/abbreviations}
% ====== MAIN MATTER ======
\mainmatter
\include{chapters/introduction}
\include{chapters/literature}
\include{chapters/theory}
\include{chapters/methodology}
\include{chapters/implementation}
\include{chapters/results}
\include{chapters/discussion}
\include{chapters/conclusion}
% ====== APPENDICES ======
\appendix
\include{appendices/code}
\include{appendices/data}
\include{appendices/proofs}
% ====== BACK MATTER ======
\backmatter
\printbibliography[heading=bibintoc]
\include{backmatter/glossary}
\printindex
\end{document}
#!/bin/bash
# Setup script for large LaTeX project
# Create directory structure
mkdir -p {preamble,frontmatter,chapters,appendices,backmatter}
mkdir -p {figures,tables,build}
mkdir -p figures/{chapter1,chapter2,shared}
# Create preamble files
touch preamble/{packages,settings,commands,environments}.tex
# Create chapter files
for i in {1..8}; do
touch chapters/chapter$i.tex
done
# Create front/back matter
touch frontmatter/{titlepage,abstract,acknowledgments}.tex
touch backmatter/bibliography.bib
# Create Makefile
cat > Makefile << 'EOF'
MAIN = main
LATEX = pdflatex
BIBTEX = biber
BUILDDIR = build
all: $(MAIN).pdf
$(MAIN).pdf: $(MAIN).tex
$(LATEX) -output-directory=$(BUILDDIR) $(MAIN)
cd $(BUILDDIR) && $(BIBTEX) $(MAIN)
$(LATEX) -output-directory=$(BUILDDIR) $(MAIN)
$(LATEX) -output-directory=$(BUILDDIR) $(MAIN)
cp $(BUILDDIR)/$(MAIN).pdf .
clean:
rm -rf $(BUILDDIR)/*
.PHONY: all clean
EOF
echo "Project structure created!"
Best Practices Summary
✅ Large document checklist:
- Logical file structure
- Consistent naming convention
- Modular preamble
- Smart cross-referencing
- Version control setup
- Build automation
- Backup strategy
- Collaboration guidelines
- Documentation/README
- Regular integration builds
Next Steps
Continue mastering advanced LaTeX:Collaboration Workflow
Team collaboration strategies
Using Templates
Create and use document templates
Fixing Errors
Troubleshoot compilation issues
Book Publishing
Professional book creation
Knowledge Base Docs
Keep the core papers and source PDFs for a large project inside the same workspace as the document tree.
AI Research Agent Docs
Use accepted-source expansion and literature follow-up work when a chapter needs stronger evidence.
Large Document Structure Toolkit
- Sections and chapters
- Table of contents
- Glossaries and acronyms
- Indexes
- Hyperlinks
- Multi-file projects
- filecontents package
- BibLaTeX guide
Pro tip: Start with a well-organized structure from the beginning. It’s much harder to reorganize a monolithic document later. Use version control from day one and establish clear naming conventions for your team.
