Skip to content

The main document in Overleaf is the file which LaTeX will be told to compile first. It is the main file of the project, which all other parts (classes, packages, chapters etc.) will be inputted into. When this is not set manually, Overleaf will choose a document in the project which includes the \documentclass[...]{...} command. For this reason, if you have a separate file for your preamble, it is better not to include the \documentclass[...]{...} command in the preamble file, but rather at the start of the main document. If you do not do this, only the preamble will be compiled. To set the main document on a project, simply click into the menu in the top lefthand corner:

Lefthandmenu.PNG

and go to Main document:

Maindocument.PNG

See here to learn more about managing large projects in LaTeX.

Compiling several documents in the same project

To allow you to quickly compile different documents in the same project, Overleaf will compile whichever file is open in the editor as the main document once it includes the \documentclass[...]{...} command. This is particularly convenient for editing with the subfiles package.

Issues with main file selection

The main file should always be in the root directory (outside of any folders), to ensure that all of the compilation steps will be run in the correct directory and to ensure that the required auxiliary files are available, for instance, when adding an index. See some tips on reorganising your project to compile on Overleaf here.

If the selected main file is contained in a folder and there is a file of the same name in the root directory, the file with that name in the root directory will be compiled rather than the selection. E.g. , if version1/main.tex is set as the main file but main.tex is also in the project, main.tex will be compiled. This problem is due to the way Latexmk is run on Overleaf. To avoid issues from this, give any files you will want to compile on Overleaf a unique name.

Overleaf guides

LaTeX Basics

Mathematics

Figures and tables

References and Citations

Languages

Document structure

Formatting

Fonts

Presentations

Commands

Field specific

Class files

Advanced TeX/LaTeX