Featured image of post Self-hosted Online LaTeX Compilation and Preview Service: Overleaf Community Edition

Self-hosted Online LaTeX Compilation and Preview Service: Overleaf Community Edition

Build your own online LaTeX compilation and preview service using Overleaf Community Edition

Motivation

I have been using Overleaf to collaborate on LaTeX documents with others when working on assignments or papers. Although it is not as customizable as local editors (such as VS Code), it is still very convenient to collaborate with others. When writing my doctoral dissertation, I purchased a one-year student subscription for Git synchronization. Due to the reduced frequency of use after graduation, I did not renew it. Recently, I needed to recompile my doctoral dissertation, only to find that the compilation time for free users of Overleaf is limited. Due to the large size of the doctoral dissertation, the compilation time exceeded the limit, which prevented me from compiling successfully.

I have also tried to use the open-source community version of Overleaf to build an online LaTeX service, but after setting it up, I still used the official Overleaf service more, so I did not maintain my own service. This time, because I need to recompile my doctoral dissertation, I tried to compile it on my own Overleaf, but found that many packages were missing, which prevented me from compiling. So I decided to rebuild an Overleaf open-source community version service and install the full version of TeX Live to be able to compile all LaTeX documents.

Introduction to Overleaf

Overleaf is an online LaTeX editor that supports collaborative editing, provides rich templates and packages, and can compile LaTeX documents online. Overleaf has a free version and a paid version. The free version has some limitations, such as compilation time limits and project number limits. The paid version of Overleaf provides more features, such as unlimited compilation time, unlimited number of projects, Git synchronization, etc.

The open-source community version of Overleaf is the open-source version of Overleaf, which allows you to build a LaTeX online editor similar to Overleaf on your own server. The Overleaf open-source community version provides similar features to the official Overleaf service, such as online compilation of LaTeX documents, collaborative editing, template and package support, etc. Unfortunately, the Overleaf community version does not support integrated Git synchronization. If you want to use Git synchronization and some other features, you need to purchase Overleaf Server Pro. Here I only need the Overleaf community version.

Prerequisites

  • Docker and Docker Compose
  • Domain name (second-level domain name is sufficient)

Installation of Overleaf Community Edition

We can use Docker to easily and quickly build the Overleaf community edition service. There are two installation methods: one is to use the docker-compose.yml file provided by the Overleaf community edition repository, and the other is to use the toolbox provided by Overleaf. Overleaf officially recommends the second method, but here are both methods.

Method 1: Install using the docker-compose.yml file

You can find the docker-compose.yml file in the Overleaf community edition repository and download it to your local machine, then use Docker Compose to start the service.

You may need to modify the docker-compose.yml file according to your actual situation, such as changing the port, data volume path, etc. After modifying it, use the following command to start the service:

1
docker-compose up -d

Reference: Overleaf Community Edition Quick Start Guide.

Method 2: Install using the Overleaf toolbox

Overleaf provides a toolbox, which wraps some common docker commands and can be used to initialize, start, stop, diagnose, and upgrade the Overleaf service. Although I think this toolbox makes the process of deploying docker more complicated compared to using docker-compose.yml directly, this toolbox does provide more flexible customization options.

To deploy the Overleaf community edition service using this toolbox, you can refer to the Overleaf Community Edition Toolbox Documentation. In short, there are several steps:

  1. Download the toolbox:

    1
    
    git clone https://github.com/overleaf/toolkit.git
    
  2. Enter the toolbox directory:

    1
    
    cd toolkit
    
  3. Initialize the installation configuration:

    1
    
    bin/init
    

    Running this command will generate a config folder in the current directory, which contains three configuration files:

    • overleaf.rc: Overleaf configuration file. Users can configure some parameters of Overleaf in this file, such as port, data volume path, etc.
    • variables.env: Environment variable configuration file
    • version: Select the Overleaf version. Note that after version 5.0.0, Overleaf replaced the original ShareLaTeX trademark with the Overleaf trademark, so if the environment variable configuration file uses variables with the OVERLEAF prefix, you need to select a version after 5.0.0.
  4. After modifying the configuration files, run the following command to start the service (may need to elevate permissions with sudo):

    1
    
    bin/up
    

    This command will start the service in command line debug mode, and you can see the output log of the service after running it. If you want to stop the service, you can press Ctrl+C.

    If you want to start the service in the background mode, you can use the following command (may need to elevate permissions with sudo):

    1
    
    bin/up -d
    
  5. If you want to stop the service, you can use the following command (may need to elevate permissions with sudo):

    1
    
    bin/stop
    

Configure Nginx Reverse Proxy

The Overleaf community edition docker-compose.yml file contains an nginx container, and if you use the Overleaf toolbox, you can also configure Nginx in the overleaf.rc configuration file. If you need TSL/SSL encryption, you can use the bin/init --tls command when initializing. This will generate an nginx folder in the config directory, which contains Nginx configuration files and an example SSL certificate.

However, since I had already deployed a separate Nginx service on the server to manage all websites, I chose to use a separate Nginx service to reverse proxy the Overleaf service. The specific process can be found in Building a Personal Website (II): Building a Personal Website Using the Hugo Framework.

Upgrade TeX Live

The Overleaf docker image comes with a basic version of TeX Live, but this version may not include all packages. If you need to compile some special LaTeX documents, you may need to install the full version of TeX Live. You can refer to the Overleaf toolbox documentation on upgrading TeX Live. The main steps are as follows:

Install the full version of TeX Live

  1. Use the following command to enter the Overleaf container:

    1
    
    docker exec -it sharelatex bash
    
  2. Check the current TeX Live version:

    1
    
    tlmgr --version
    
  3. Update TeX Live:

    1
    
    tlmgr install scheme-full
    

    When I ran this command, I encountered the following problem:

    1
    2
    3
    4
    
    tlmgr: Local TeX Live (2023) is older than remote repository (2024).
    Cross release updates are only supported with
    update-tlmgr-latest(.sh/.exe) --update
    See https://tug.org/texlive/upgrade.html for details.
    

    This is because the versions of TeX Live are different. You can use the following command to specify the appropriate version of TeX Live:

    1
    
    tlmgr option repository https://ftp.math.utah.edu/pub/tex/historic/systems/texlive/2023/tlnet-final
    

    After specifying the appropriate version, run the update command again:

    1
    
    tlmgr install scheme-full
    

    If everything goes well, this command will download and install the full version of TeX Live. This will install more than 4000 packages and may take some time.

  4. Add the path:

    After the installation is complete, you need to use the following command to add the path:

    1
    
    tlmgr path add
    

    If you do not run this command, you may encounter problems such as being unable to compile EPS images when compiling LaTeX documents in Overleaf.

Save changes to the image

After making the above changes, the upgraded TeX Live will only be saved in the current container. If the container is deleted, these changes will also be lost. If you want to save these changes to the image and use them when creating containers later, you can perform the following steps:

  1. Use the following command to update the image (may need to elevate permissions with sudo):

    1
    
    docker commit sharelatex sharelatex/sharelatex:with-texlive-full
    
  2. Then you can add a docker-compose.override.yml file in the config directory to specify the new image when creating containers later:

    1
    2
    3
    4
    5
    
    ---
    version: '2.2'
    services:
        sharelatex:
            image: sharelatex/sharelatex:with-texlive-full
    
  3. Stop and delete the previous container, then recreate the container (may need to elevate permissions with sudo):

    1
    2
    3
    
    bin/stop
    bin/docker-compose rm -f sharelatex
    bin/up -d
    
comments powered by Disqus