> For the complete documentation index, see [llms.txt](https://overleaf-pro.ayaka.space/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://overleaf-pro.ayaka.space/latex/document-structure/07-management-in-a-large-project.md).

# Management in a large project

## Introduction

In large projects, such as books, keeping parts of your document in several .tex files makes the task of correcting errors and making further changes easier. It's simpler to locate a specific word or element in a short file. For this purpose this article explains how to manage big projects.

## Inputting and including files

The standard tools to insert a LaTeX file into another are `\input` and `\include`.

**input command**

\input{filename}

Use this command in the document body to insert the contents of another file named `filename.tex`; this file should not contain any LaTeX preamble code (i.e. no `\documentclass`, `\begin{document}` or `\end{document}` ). LaTeX won't start a new page before processing the material in `filename.tex`. `\input` allows you to nest `\input` commands, in files that are already being inputted by the root file.

**include command**

\include{filename}

Use this command in the document body to insert the contents of another file named `filename.tex`; again this file should not contain any LaTeX preamble. LaTeX will start a new page before processing the material input from `filename.tex`. Make sure not to include the extension `.tex` in the filename, as this will stop the file from being input (the extension can optionally be included with `input` and `import`). It is not possible to nest `include` commands. Each file that gets `\include`d has its own .aux file storing information of created labels and contents for the table of contents, list of figures, etc. You can use `\includeonly` with a comma separated list of file names (make sure that there are no leading or trailing spaces). If you do this LaTeX will only process the files contained in that list. This can be used to enhance compilation speed if you're only working on a small part of a bigger document. Page numbers and cross references will however still work, as the .aux files of left out files will still be processed.

[Open an example of a large project on Overleaf](https://www.overleaf.com/project/new/template/20618?id=70769185\&templateName=Managing+a+large+project+on+Overleaf\&latexEngine=pdflatex\&texImage=texlive-full%3A2020.1\&mainFile=)

## Preamble in a separate file

If the preamble of your document has many user-defined commands or term definitions for the [glossary](/latex/document-structure/05-glossaries.md), you can put it in a separate file. The right way is to create a custom package, which is a file with the .sty extension. Let's see an example:

```latex
\ProvidesPackage{example}

\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage[latin1]{inputenc}
\usepackage[spanish, english]{babel}
\usepackage{graphicx}
\usepackage{blindtext}
\usepackage{textcomp}
\usepackage{pgfplots}

\pgfplotsset{width=10cm,compat=1.9}

%Header styles
\usepackage{fancyhdr}
\setlength{\headheight}{15pt}
\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\renewcommand{\sectionmark}[1]{\markright{#1}{}}
\fancyhf{}
\fancyhead[LE,RO]{\thepage}
\fancyhead[RE]{\textbf{\textit{\nouppercase{\leftmark}}}}
\fancyhead[LO]{\textbf{\textit{\nouppercase{\rightmark}}}}
\fancypagestyle{plain}{ %
\fancyhf{} % remove everything
\renewcommand{\headrulewidth}{0pt} % remove lines as well
\renewcommand{\footrulewidth}{0pt}}

%makes available the commands \proof, \qedsymbol and \theoremstyle
\usepackage{amsthm}

%Ruler
\newcommand{\HRule}{\rule{\linewidth}{0.5mm}}

%Lemma definition and lemma counter
\newtheorem{lemma}{Lemma}[section]

%Definition counter
\theoremstyle{definition}
\newtheorem{definition}{Definition}[section]

%Corolary counter
\newtheorem{corolary}{Corolary}[section]

%Commands for naturals, integers, topology, hull, Ball, Disc, Dimension, boundary and a few more
\newcommand{\E}{{\mathcal{E}}}
\newcommand{\F}{{\mathcal{F}}}
...

%Example environment
\theoremstyle{remark}
\newtheorem{examle}{Example}

%Example counter
\newcommand{\reiniciar}{\setcounter{example}{0}}
```

All the commands in this file could have been put in the preamble, but the main file would have become confusing because of this large amount of code, and to locate the actual body of the document in such large file would be a cumbersome task.

This file could also be put in a normal .tex file and imported with the command `import` (see the [next section](#importing-files)), but a .sty file prevents possible errors if the file is accidentally imported more than once.

Notice that the first line of the example is

```latex
\ProvidesPackage{example}
```

this means that we have to import this package as *example* in the main file, i.e. with the command

```latex
\usepackage{example}
```

as shown in the [introduction](#introduction).

*Note: A .sty file is far more flexible, it can be used to define your own macros and optional parameters can be passed, see* [*Writing your own package*](/latex/class-files/03-writing-your-own-package.md).

[Open an example of a large project on Overleaf](https://www.overleaf.com/project/new/template/20618?id=70769185\&templateName=Managing+a+large+project+on+Overleaf\&latexEngine=pdflatex\&texImage=texlive-full%3A2020.1\&mainFile=)

## Using the import package

As mentioned above The standard tools to insert a LaTeX file into another are `\input` and `\include`, but these are prone to errors if nested file importing is needed. For this reason you may want to consider the package **import**.

Below is an example of a book whose sections and user-defined commands are stored in separate files, and where the image files for each chapter are stored in separate folders along with the .tex file for each chapter.

```latex
\documentclass[a4paper,11pt]{book}
\usepackage{import}
\usepackage{example}

\usepackage{makeidx}
\makeindex

\begin{document}

\frontmatter
\import{./}{title.tex}

\clearpage
\thispagestyle{empty}

\tableofcontents

\mainmatter
\chapter{First chapter}
\import{sections/}{section1-1.tex}
\import{sections/}{section1-2.tex}

\chapter{Additional chapter}
\import{sections/}{section2-1.tex}

\chapter{Last chapter}
\import{sections/}{section3-1.tex}

\backmatter

\import{./}{bibliography.tex}

\end{document}
```

As you see, the example is a book with three chapters and several sections in a neat main file that pulls external files to generate the final document. The command `\frontmatter` in the book document class is used for the first pages of the document, the page numbering style is set to Roman numerals by this command; the command `\mainmatter` resets the page numbering and changes the style to Arabic, `\backmatter` disables the chapter numbering (suitable for the bibliography and appendices).

```latex
\chapter{First chapter}
\import{sections/}{section1-1.tex}
\import{sections/}{section1-2.tex}
```

First, add this line to the preamble of your document:

```latex
\usepackage{import}
```

Then use `\import{ }{ }`. The first parameter inside braces is the directory where the file is located, it can be relative to the current working directory or absolute. The second parameter is the name of the file to be imported

There is also available the command `\subimport` that has the same syntax, but if used in one of the files that are imported in the main file, the path will be relative to that sub-file. For instance, below is the contents of the file "section1-1.tex" that was imported in the previous example:

```latex
\section{First section}

Below is a simple 3d plot

\begin{figure}[h]
\centering
\subimport{img/}{plot1.tex}
\caption{Caption}
\label{fig:my_label}
\end{figure}

[...]
```

As you see, this file imports a [pgf plot](/latex/field-specific/08-pgfplots-package.md) file called "plot1.tex" that creates a 3d plot. This file is imported by

```latex
\subimport{img/}{plot1.tex}
```

from the "img" folder, contained in the folder "sections".

If `\import` were used instead, the path *img/* would be relative to the main file, instead of the folder "sections" where "section1-1.tex" is saved.

[Open an example of a large project on Overleaf](https://www.overleaf.com/project/new/template/20618?id=70769185\&templateName=Managing+a+large+project+on+Overleaf\&latexEngine=pdflatex\&texImage=texlive-full%3A2020.1\&mainFile=)

## Further reading

For more information see:

* [Multi-file LaTeX projects](/latex/document-structure/08-multi-file-latex-projects.md)
* [Cross referencing sections and equations](/latex/document-structure/03-cross-referencing-sections-equations-and-floats.md)
* [Indices](/latex/document-structure/04-indices.md)
* [Glossaries](/latex/document-structure/05-glossaries.md)
* [Hyperlinks](/latex/document-structure/09-hyperlinks.md)
* [Page numbering](/latex/formatting/03-page-numbering.md)
* [Single sided and double sided documents](/latex/formatting/08-single-sided-and-double-sided-documents.md)
* [Multiple columns](/latex/formatting/09-multiple-columns.md)
* [Paragraph formatting](/latex/formatting/04-articles-how-to-change-paragraph-spacing-in-latex.md)
* [Page size and margins](/latex/formatting/07-page-size-and-margins.md)
* [Counters](/latex/formatting/10-counters.md)
* [Margin notes](/latex/formatting/15-margin-notes.md)
* [Bold, italics and underlining](/latex/latex-basics/03-bold-italics-and-underlining.md)
* [Font sizes, families, and styles](/latex/fonts/01-font-sizes-families-and-styles.md)
* [Font typefaces](/latex/fonts/02-font-typefaces.md)
* [Supporting modern fonts with XeLaTeX](/latex/fonts/03-xelatex.md)
* [International language support](/latex/languages/03-international-language-support.md)
* [Font sizes, families, and styles](/latex/fonts/01-font-sizes-families-and-styles.md)
* [Writing your own package](/latex/class-files/03-writing-your-own-package.md)
* [Writing your own class](/latex/class-files/04-writing-your-own-class.md)
* [The not so short introduction to LaTeX2ε](http://www.ctan.org/tex-archive/info/lshort/)
* [`import` package documentation](ftp://sunsite.icm.edu.pl/pub/CTAN/macros/latex/contrib/import/import.pdf)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://overleaf-pro.ayaka.space/latex/document-structure/07-management-in-a-large-project.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
