Back to Blog

Splitting a Long LaTeX Document Into Files That Stay Compilable

Shihab Shahriar AntorSeptember 2, 2026

Split the document by chapter, keep one figures directory, and make every piece compile on its own. The first two are what everyone does. The third is what separates a project that survives a coauthor from one where a stranger's edit breaks a build nobody can reproduce.

The layout

main.tex            % preamble, \include lines, nothing else
preamble.tex        % packages and macros, \input from main
chapters/
  introduction.tex
  method.tex
  results.tex
figures/            % every image, one place
refs.bib

A main file that holds only the preamble and a list of chapters is a file two people almost never touch at the same time, which removes most conflicts before they happen.

Input, include, or subfiles

Three mechanisms, and the choice is not stylistic:

  • \input pastes the file where it sits. Nestable, no page break. Right for a preamble fragment or a table you keep separately.
  • \include forces a page break and writes its own aux file, which is what makes \includeonly possible. Right for chapters. Not nestable.
  • subfiles makes each chapter a complete document with its own \documentclass, so you can open one and compile it alone. Right when several people work on different chapters at once.

With subfiles, each chapter starts with a line pointing back at the main file, and the shared preamble is used in both directions:

% chapters/method.tex
\documentclass[../main.tex]{subfiles}
\begin{document}
\chapter{Method}
...
\end{document}

The graphics path trap

This is the failure that wastes an afternoon. Paths in \includegraphics resolve relative to the file being compiled, so a chapter that says figures/plot.pdf works in the full build and fails when you compile the chapter alone, or the reverse. Set the search path once, in the shared preamble, with both roots:

\graphicspath{{figures/}{../figures/}}

Then every \includegraphics{plot} resolves from either direction. Leaving the extension off lets the engine pick the format it prefers, which also stops a PDF-only figure breaking a build somebody runs differently.

Doing the split without breaking references

Splitting an existing document is exactly the sort of mechanical, high-volume edit that goes wrong by hand at 1am: a moved block, a path not updated, a label silently dropped. Two things make it safe. Move files rather than copying and deleting, so nothing is ever gone. Compile at the end, so a broken path surfaces immediately rather than in a coauthor's pull.

What you want

Split main.tex into one file per chapter under chapters/, replace each with an \include, and keep the preamble where it is. Do not delete anything and do not renumber the labels.

Why this wording. Names the destination, the mechanism and two boundaries. Labels are the thing that silently breaks: a lost \label turns into a ?? in a cross-reference forty pages away.

What runs

  1. read_file
  2. create_file
  3. move_file
  4. propose_edit
  5. compile

What changes in the file

+ \include{chapters/introduction}
+ \include{chapters/method}
+ \include{chapters/results}

Ask it the vague way instead. Ask it to "organise my project" and it may consolidate rather than split, or rewrite your preamble on the way past.

When several people are in it at once

File structure fixes conflicts inside a document; it does nothing about two people editing the same paragraph. That is what live collaboration is for, and the two solve different halves of the same problem, so use both. The collaboration problems guide covers the half that structure cannot reach, and the large document guide goes further into build times.

Frequently asked questions

What is the difference between \input and \include in LaTeX?

\input pastes the file in place and can be nested anywhere. \include starts a new page, cannot be nested, and works with \includeonly so you can build a subset of chapters. Use \input for fragments and \include for chapters you want to compile selectively.

How do I compile just one chapter of a long thesis?

Two ways. \includeonly{chapters/methods} in the preamble builds only that chapter while keeping cross-references and page numbers from the last full run. The subfiles package goes further: each chapter file is a complete document you can compile on its own.

Where should images live in a multi-file LaTeX project?

In one figures directory with \graphicspath set once in the preamble. Per-chapter image folders mean every \includegraphics path is relative to the main file rather than to the chapter, which is the most common reason a chapter compiles alone and fails in the full build.

Does splitting a document make compiling slower?

No, and with \includeonly it is substantially faster, because you rebuild one chapter instead of two hundred pages. The aux files from the last full run keep your references resolved.

Ready to try LetX?

Join researchers and students focusing on their work, not the tools.

Get Started Free

Written by Shihab Shahriar Antor , AI Engineer & Founder of Shahriar Labs. Builder of LetX (collaborative LaTeX) and QuantumSketch (AI STEM video).