Davide Gerosa

Github actions for latex

When writing LaTex papers with collaborators, I find it very useful to have a permanent URL that always points to the latest version of the compiled paper. People that are marginally involved can easily check the progress without messing up with the source files of those that are actually writing the paper.

I know overleaf provides a solution, but not everyone wants to use their web-based interface. I love my own editor… So, here is a solution with git and github actions that I that I find very convenient using

Quick instructions

  • Create your repository on github and put your latex paper there.
  • Copy this code I wrote into a directory called .github/workflows.
  • Edit the DIR and FILE variables in the script such that they point to your file. For instance, if your latex sources live in draft/main.tex, set DIR = draft and FILE = main.

Done, easy peasy. Now every time someone pushes something new to the repository, github does its magic and publishes the paper at a permanent URL of the form

https://github.com/[username]/[repositoryname]/blob/build/[filename].pdf

Enjoy your latex paper with github.

How does this work?

The code is here below. In practice, I’m telling github that everytime one pushes it has to start a new virtual machine with ubuntu, install latex, compile paper and bibliography with latexmk, and save the results. For how the github actions work, the result is first saved as an artifact and then moved to a dedicated orphan branch called build which provides the url we want.