Continuous integration is a necessary part of modern software development and you should take advantage of it in all your projects. The includes the LaTeX ones, which are often overlooked. For example, on GitHub, you can easily set up testing environment using Travis CI. Even if you always compile your documents locally, errors might slip through, particularly if you use tools automating your builds. Travis CI let’s you trigger builds for commits and pull requests, thus making sure you or your collaborators don’t break your documents.
To set up Travis CI, put the following in the
.travis.yml file in your repository:
The snippet installs a full TeX Live distribution before compiling the documents in your project. TeX Live is a popular distribution chosen for consistency, since that’s what I use on my machine. The distribution is pretty big, and based on my experience, its installation typically takes around 7 minutes. To speed up the build, you could install a subset of packages needed for your document only. However, in practice, I typically don’t want to bother fixing bugs in the CI configuration after I add packages to my documents, and I prefer to sacrifice speed for reliability and convenience.
The actual installation step of the build consists of running
pdflatex on all TeX files in the project’s root directory. I’m using
pdflatex in this example, because I usually generate PDFs from my source files. Usage of other commands, such as
xelatex, is analogous.
-interaction=nonstopmode sets the interaction mode to nonstop, which makes TeX run without requiring feedback from the user, through the errors.
-halt-on-error ensures TeX exits with an error code when an error is encountered during processing, thus failing the build in Travis CI.
You can see a real-life example of CI in a LaTeX project e.g. in this repository (see also the corresponding configuration and builds).