LaTeX is a software for document preparation. You write your content in plain text .tex files, much like a very basic programming language, and compile it afterwards in the designated format, e.g. pdf. LaTeX is heavily used in academia as it provides an easy way to express mathematical formulae. Besides that most universities provide a template, so you don’t have to think about margins, citation style (and more) and can simply focus on your content. And this is exactly the reason why I use LaTeX.

Overview

As a computer science student I had to write lab reports and finally a final thesis. Most of these were written with LaTeX, as it is easy to add formulas, and it looks quite nice. It is also very convenient if you get a template, so you can focus on your content instead of optics of your document. As a developer it is also easy to use your favorite version management tool, as TeX files are simply text file. But it can be annoying to set up LaTeX on your local machine, therefore I tend to use the same container on my local machine as on a CI server, to ensure I can always build my document with the same version of all needed libraries.

Template

As I use this setup to have reproducible build of my thesis, I rely on a template provided by my university. If you are interested in the template you can find it here. The template also provides a simple Makefile, which I’ll use later. Besides styling the template also provided Dockerfile, but these are based on Ubuntu and I prefer to use the same versions of tools than on my local machine, so I will stick with Arch Linux for the containers as well.

The build container

To ensure I have the latest release of all used libraries, I use Arch Linux as base layer. It’s also handy that Arch provides all needed LaTeX libraries in the distribution repositories.

FROM archlinux:latest

RUN pacman -Syu --noconfirm texlive-most texlive-latexextra texlive-bibtexextra make ghostscript biber

After building the image with docker build -t gitlab.com/andre/masterarbeit/latex-build:ci -f Dockerfile . it must be pushed to the GitLab container registry with docker push gitlab.com/andre/masterarbeit/latex-build:ci. These are quite big, so be ready to wait a few minutes, depending on your internet speed.

GitLab CI

This setup requires that you have already set up a runner for your GitLab project and can use the internal container registry.

With the artifacts setting, GitLab will expose the created PDF directly from the overview page of your run. This is useful if you are working on a machine without TeX installed, but still want to see if you can build your PDF after some changes. The setting expire_in: 4 week ensures that I don’t keep all build versions forever on the server. make all in the script section refers to the earlier mentioned Makefile provided by the template, you can find it here.

compile-thesis:
  image: gitlab.com/andre/masterarbeit/latex-build:ci
  script:
    - make all
  artifacts:
    paths:
      - thesis.pdf
    expire_in: 4 week

Local Build

To ensure I get the same results locally, I also use the earlier build container for local builds. The following script will simply mount the current directory in the container and execute make all. It also deletes the container afterwards.

#!/bin/sh

docker run --name paper-build --user $(id -u):$(id -g) --volume $(pwd):/thesis-template/ gitlab.com/andre/masterarbeit/latex-build:ci make --directory /thesis-template/ all
docker rm paper-build

Conclusion

The setup is rather simple, but I don’t want to have build problems on my local machine, with the day of delivery in mind. Also, I can give prove readers access to the artifacts, so they always read the latest version.