Skip to content

Project Detection

Patrick Förster edited this page Jan 21, 2023 · 1 revision

Discovery

Whenever you open a TeX file in the editor, texlab tries to find out all files that are part of the same project, meaning they are compiled into the same document. The server needs this information to implement most of its features. For example, packages imported in the preamble should be visible in other project files as well. In particular, the project is also used determine the root document, which is passed to the TeX engine when compiling.

Algorithm

The server does the following steps to figure out the project:

  • Walk up the directory tree until we either reach the file system root (/) or the end of the workspace folder (if any). For each directory along the way, we load all contained TeX files that we have not opened yet.
  • Next, we build a dependency tree by resolving include commands such as \input or \import. The referenced files are added to the workspace.
  • Repeat this procedure until there are no more changes to the workspace

Root directory

Due to the way, the TeX engine is designed, commands such as \input operate on the working directory of the TeX engine instead on the directory of the parent source file. That's why we need to determine the root directory in the server. texlab tries the following (in this order):

  1. If set, append texlab.rootDirectory to the directory of source file and use the result as the directory (deprecated)
  2. Walk up the directory tree until we find one of these files:
    • .texlabroot
    • texlabroot
    • Tectonic.toml If there is such a file, then use its directory as the main directory.
  3. Use the directory of the root source file (files that include the subfiles documentclass are not considered as possible roots)

NOTE: In short, you can use texlabroot to manually set the root directory if required. Otherwise, texlab uses the directory of the root file.

Clone this wiki locally