Regular Memory

Run Latex inside a Docker Container

Posted at — Nov 14, 2019

This is a quick guide about how to run Latex inside a Docker container. Latex can be cumbersome to install, and the process is different on different platforms. Docker removes installation difficulty, and lets one install Latex easily on any platform.

Latex: a document preparation system for high-quality typesetting. Most often used for medium-to-large technical or scientific documents, but it can be used for almost any form of publishing.

Docker: a tool that makes it easier to create, deploy, and run applications using containers. Containers allow a developer to bundle an app with all its dependencies, and ship it as one package.

Install Docker

Use this link to install Docker CE

Get the Latex Container from Docker Hub

Docker Hub is a site where any developer can publicly host their Docker containers, so anyone else can use and extend them. Visit the following page and examine the container we’ll be using: schickling/latex.

Download and Run the Container

Note, the Docker process (application) must be running for the following steps to work.

Run the command below to automatically download the container. If the container is already locally present download will be skipped. Once the container downloads, it will mount our current directory into the container and give us a bash shell into the running container.

docker run --rm -it -v $(pwd):/source schickling/latex

Add a TEX file to the container

The directory we were in when we executed docker run is now temporarily mounted into our container. Any files we place in this directory will be accessible inside the container. Place a .tex document in the current directory, and run ls inside the container. You’ll see the name of your .tex document among the returned results. Here’s an example .tex document if you need one.

Compile a PDF

Finally, if my-document.tex is the name of your .tex document, run the following command inside the container:

pdflatex my-document.tex

This uses Latex to generate a PDF, which is now available in the mounted directory!

comments powered by Disqus