Skip to content
Get started

The main file

Every compile starts from one .tex file, the main file. It holds \documentclass and \begin{document}, and it pulls in the other files with \input or \include. Luzbase picks the main file for you. There is no setting to choose it in a project.

Luzbase checks these rules in order and uses the first one that matches:

  1. The project’s own main file, if it was set when the project was created and the file still exists. A project created from a template uses the template’s main file. A project imported from a .zip uses the file detected during the import.
  2. main.tex at the top level of the project (not inside a folder).
  3. A .tex file that contains \documentclass outside a comment. If there are several, the one closest to the top of the project wins.
  4. The first .tex file in the project.

A typical layout looks like this:

main.tex
references.bib
chapters/introduction.tex
chapters/method.tex
figures/setup.png

And main.tex includes the other files:

\documentclass{report}
\usepackage{graphicx}
\begin{document}
\include{chapters/introduction}
\include{chapters/method}
\bibliographystyle{plain}
\bibliography{references}
\end{document}

Write paths in \input, \include and \includegraphics from the top level of the project, for example figures/setup.png. Your own .sty, .cls, .bst and .bib files are found anywhere in the project, even inside folders, without any extra setup.

If the project was created from a template or imported from a .zip, its main file was set or detected at that point, so it can have any name, such as thesis.tex.

If the main file is renamed or deleted later, Luzbase falls back to the rules above. Deleting main.tex shows a warning, because the build breaks until another file can take over.

To compile a different file:

  1. Rename the file you want to compile to main.tex and move it to the top level of the project.
  2. If the project came from a template or a .zip import and its original main file still compiles, rename that original file too (for example to old-thesis.tex). The project’s own main file wins for as long as it exists under its original name.

When you import a project from a .zip, Luzbase looks for its main file once, in this order:

  1. A % !TEX root = … comment in the first 20 lines of a .tex file, naming the main file. If files name different main files, the one named most often wins.
  2. main.tex at the top level of the archive.
  3. The .tex file that contains both \documentclass and \begin{document} outside a comment. If there are several, the one closest to the top wins.

The file it finds becomes the project’s own main file. If none of these rules finds one, the project has no main file of its own, and the rules in How Luzbase picks the main file apply.