The Speed Problem
You make one small change. You hit compile. You wait... and wait... and wait.
Every second of compilation time is a break in your flow. Over a writing session, those seconds add up to hours of lost productivity.
Let's fix that.
Understanding Compilation Speed
What Happens When You Compile
Your .tex file
↓
[First pass: Build document structure]
↓
[BibTeX/Biber: Process citations]
↓
[Second pass: Insert references]
↓
[Third pass: Finalize page numbers, ToC]
↓
[Font subsetting and embedding]
↓
[Image processing and embedding]
↓
Your .pdf fileEach step takes time. Speed up any step, and the total time drops.
Baseline Expectations
| Document Type | Expected Time | Warning Sign | |---------------|---------------|--------------| | Simple article (10 pages) | 2-5 seconds | >15 seconds | | Research paper (20 pages, figures) | 5-15 seconds | >30 seconds | | Thesis (100 pages) | 20-60 seconds | >2 minutes | | Book (300+ pages) | 1-3 minutes | >5 minutes |
If you're exceeding these, there's room to improve.
Quick Wins (5 minutes to implement)
1. Use Draft Mode
The fastest image is the one you don't process:
\documentclass[draft]{article}
% All images become placeholder boxesOr selectively:
\usepackage[draft]{graphicx}Speedup: Often 50-80% for image-heavy documents
When to use: While writing/editing. Switch to final for submission.
2. Compile Selectively
Don't compile what you're not working on:
% main.tex
\includeonly{chapters/current-chapter}
\begin{document}
\include{chapters/intro}
\include{chapters/current-chapter} % Only this compiles
\include{chapters/conclusion}
\end{document}Speedup: Proportional to excluded content (50-90%)
3. Use a Faster Engine
If you're using PDFLaTeX and don't need its specific features:
# Try LuaLaTeX (often faster for font-heavy docs)
lualatex main.tex
# Or XeLaTeX
xelatex main.texSpeedup: 10-40% depending on document
4. Enable Compiler Caching
Use latexmk with caching:
latexmk -pdf main.tex
# Only recompiles what changedCreate .latexmkrc:
$pdf_mode = 1;
$pdflatex = 'pdflatex -interaction=nonstopmode -file-line-error';Speedup: 30-70% on subsequent compiles
5. Reduce Output Verbosity
Less logging = slightly faster:
\usepackage{silence}
\WarningFilter{latex}{...}Or in compiler:
pdflatex -interaction=batchmode main.texSpeedup: 5-10% (minor but free)
Medium Effort (30 minutes to implement)
6. Optimize Images
The #1 cause of slow compilation is oversized images.
Before importing any image:
# Check image size
identify input.png
# If larger than needed, resize
# For photos (JPEG compression)
convert input.png -resize 1200x -quality 85 output.jpg
# For diagrams (keep as vector)
convert input.png output.pdfOptimal sizes:
- Print: 300 DPI at final size
- Screen: 150 DPI at final size
- Never more than 2x final display size
Speedup: 50-90% for image-heavy documents
7. Externalize TikZ
TikZ diagrams regenerate every compile. Externalize them:
\usepackage{tikz}
\usetikzlibrary{external}
\tikzexternalize[prefix=tikzcache/]
% Each diagram compiles once, then cached
\begin{tikzpicture}
% Complex diagram here
\end{tikzpicture}Speedup: 80-95% for TikZ-heavy documents
8. Optimize Bibliography
Large .bib files slow things down:
% Instead of your entire reference library
\addbibresource{all-references.bib} % 500 entries
% Use project-specific file
\addbibresource{project-refs.bib} % 50 entriesExtract only cited references:
biber --output_format=bibtex main.bcf -O minimal.bibSpeedup: 20-40% for large bibliographies
9. Reduce Package Loading
Every package has overhead:
% Audit your packages - do you need all of these?
\usepackage{package1}
\usepackage{package2} % Maybe not needed?
\usepackage{package3}Common slow packages:
tikz(load only needed libraries)minted(code highlighting, considerlistingsinstead)fontspecwith many fontsmicrotype(worth it for final, skip for drafts)
% Load only what you need from tikz
\usepackage{tikz}
\usetikzlibrary{arrows,positioning} % Not all librariesSpeedup: 10-30% by removing unused packages
10. Parallelize When Possible
Modern LaTeX can parallelize some operations:
# With latexmk
latexmk -pdf -pdflatex="pdflatex %O %S" -auxdir=aux main.texFor multi-file documents, compile chapters in parallel then combine:
# Compile chapters separately
pdflatex chapter1.tex &
pdflatex chapter2.tex &
wait
# Combine with pdfpagesSpeedup: 30-50% on multi-core systems
Advanced Optimizations
Use LuaTeX Instead of PDFTeX
For complex documents, LuaLaTeX is often faster:
% Document works with both, but may be faster with LuaLaTeX
\documentclass{article}
\usepackage{fontspec} % LuaLaTeX/XeLaTeX only
\setmainfont{TeX Gyre Termes}Precompile Preamble
For stable preambles, use format files:
# Create format (once)
pdflatex -ini -jobname=myformat "&pdflatex myformat.tex\dump"
# Use format (every compile)
pdflatex "&myformat main.tex"Speedup: 20-40% by skipping preamble processing
Incremental Compilation
Some tools support true incremental builds:
# Only recompile changed pages (experimental)
latexmk -pvc -pdf main.texHardware Acceleration
Where you compile matters:
| Storage | Relative Speed | |---------|---------------| | HDD | 1x (baseline) | | SATA SSD | 3-5x faster | | NVMe SSD | 5-10x faster | | RAM disk | 10-20x faster |
For very large documents:
# Create RAM disk (Linux)
sudo mount -t tmpfs -o size=512M tmpfs /tmp/latex
# Compile there
cp -r project /tmp/latex
cd /tmp/latex && latexmk -pdf main.texWorkflow Optimization
The Two-Compile Strategy
- During writing: Draft mode, selective compilation, fast
- For review: Full compile, all images, complete
% In preamble:
\newif\ifdraft
\drafttrue % Toggle this
%\draftfalse
\ifdraft
\usepackage[draft]{graphicx}
\usepackage[draft]{hyperref}
\fiSmart Compile Triggers
Don't compile on every keystroke:
Good: Compile on save Better: Compile on save with debounce (wait 2 seconds of no changes) Best: Compile on explicit command
Separate Long Tasks
Bibliography and index processing can be separated:
# Normal edit cycle (fast)
pdflatex main.tex
# Only when references change (slow)
biber main
pdflatex main.tex
pdflatex main.texMeasuring Improvement
Profile Your Compilation
Add timing to your build:
time pdflatex main.tex
# real 0m12.345sOr detailed profiling:
pdflatex -recorder main.tex
# Check main.fls for files accessedTrack Progress
| Optimization | Before | After | Improvement | |--------------|--------|-------|-------------| | Baseline | 45s | 45s | - | | Draft mode | 45s | 12s | 73% | | Image optimization | 45s | 28s | 38% | | TikZ externalization | 45s | 15s | 67% | | Combined | 45s | 8s | 82% |
Document your improvements to know what helps most.
When to Give Up on Optimization
Sometimes the document is just large. At that point:
- Accept the compile time for final builds
- Use selective compilation for drafts
- Consider tools without limits (local/Thetapad)
- Batch your compiles (review, then compile, repeat)
A 2-minute compile for a 300-page book with 100 figures is reasonable. Fight for seconds in daily writing, accept minutes for final builds.
Summary: The Speed Checklist
Quick (do now):
- [ ] Enable draft mode for images
- [ ] Use
\includeonlyfor active chapters - [ ] Use
latexmkfor smart caching
Medium (this week):
- [ ] Optimize all images (resize, compress)
- [ ] Externalize TikZ diagrams
- [ ] Audit packages, remove unused
Advanced (if needed):
- [ ] Precompile preamble
- [ ] Move to SSD/NVMe storage
- [ ] Profile and target specific bottlenecks
Conclusion
Slow LaTeX compilation has specific causes with specific fixes:
- Images: Optimize before importing
- TikZ: Externalize for caching
- Bibliography: Keep project-specific
- Packages: Load only what you need
- Workflow: Compile smart, not often
Implement these optimizations, and compilation becomes a non-issue. Your focus stays on writing, not waiting.
For compilation without any time limits, try Thetapad's local-first architecture.