How does Overleaf compile my project?

Overleaf uses the latexmk build tool to automatically build your project. Latexmk ensures that we run latex and bibtex (or other similar programs) the right number of times.

Latexmk reads a configuration file called latexmkrc that contains custom rules for building your project. By default, Overleaf automatically adds an invisible latexmkrc file to your project in order to build. It contains rules for glossaries, nomenclature, and other commonly used packages. In full, it currently reads:

# support for the glossaries package:
add_cus_dep('glo', 'gls', 0, 'makeglossaries');
add_cus_dep('acn', 'acr', 0, 'makeglossaries');
sub makeglossaries {
  system("makeglossaries \"$_[0]\"");

# support for the nomencl package:
add_cus_dep('nlo', 'nls', 0, 'makenlo2nls');
sub makenlo2nls {
  system("makeindex -s -o \"$_[0].nls\" \"$_[0].nlo\"");

# from the documentation for V. 2.03 of asymptote:
sub asy {return system("asy \"$_[0]\"");}

# metapost rule from
add_cus_dep('mp', '1', 0, 'mpost');
sub mpost {
  my $file = $_[0];
  my ($name, $path) = fileparse($file);
  my $return = system "mpost $name";
  return $return;

You can customise the build process by adding a custom latexmkrc file to your project. If you have a file called latexmkrc in your project, Overleaf will not add the default latexmkrc file, so you may want to copy the default latexmkrc above into your latexmkrc file, to make sure that the rules above are still included.

Note that some latexmk options are not compatible with Overleaf. In particular, if you set the $preview_continuous_mode or $output_dir options, that may break the preview on Overleaf.

If you want to build your Overleaf project offline, for example via the Overleaf-git bridge, using latexmk, you may want to copy the latexmkrc file to your project locally, to make sure it builds in the same way as we build it on Overleaf.

For more information about latexmkrc files, check out our blog post with tips and tricks from our friendly Overleaf TeXperts.