A solution to long-running Overleaf compilation

A solution to long-running Overleaf compilation

Overleaf is a great web app for composing Latex. However, it has a 4 minute maximum compile time, which is not enough to compile large documents into PDFs.

image

To solve this problem, I devised an automated approach to compile Overleaf documents on Github. This approach takes advantage of the automated Github sync built into Overleaf.

The approach has two steps:

  1. Sync project to Github
  2. Run Github actions to compile the PDF automatically.

I’ll walk you through step-by-step how to do this.

Sync to Github Actions

You’ll need to first setup Github sync. If you don’t already have one, you’ll need a free Github account.

Inside your Overleaf project, click Menu, then Github. Once you connect your Overleaf to Github, you’ll be presented with a screen like this:

image

Click “Create a Github Repository” and wait a few minutes for everything to be setup. Afterwards, close and reopen the Github dialog in Overleaf and click “Push Overleaf changes to Github”.

image

Automatic compilation using Github Actions

We will use Github actions to compile the Latex to a PDF every time we sync from Overleaf to Github.

In your Overleaf project, create a new folder called .github (using the little folder icon circle). Inside .github, create another folder called workflows. And inside workflows create a file called compile.yml. Make sure to remove the “.tex” from the ending. It should look like this:

image

Paste the following into compile.yml

name: Build LaTeX document
on: [push]
jobs:
  build_latex:
    runs-on: ubuntu-latest
    steps:
      - name: Set up Git repository
        uses: actions/checkout@v3
      - name: Compile LaTeX document
        uses: xu-cheng/latex-action@v2
        with:
          root_file: ClassicThesis.tex
          continue_on_error: true
          args: -pdf -file-line-error -interaction=nonstopmode
      - name: Upload PDF file
        uses: actions/upload-artifact@v3
        with:
          name: PDF
          path: ClassicThesis.pdf

Replace, “ClassicThesis” with the name of your Latex file. Then, sync Overleaf to Github again. You might be asked to authorize Overleaf to use Github actions; say yes.

Next, go to the repository that you created earlier on Github. Under the Actions tab for the repository, you’ll be able to click your latest workflow run. Inside that run, there will be the new PDF under Artifacts:

image