Skip to content

lambdao-dev/latex-compile-server

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

latex-compile-server

A webserver, running in a Docker container, that can receive and compile LaTeX documents. The server accepts zip-files sent to it via Rest Post-calls to http://localhost:58404/compile, and it unzips the given files, compiles them with pdflatex (by default) and sends the resulting pdf back.

Running the Docker container

Build and run it with Docker with two simple commands. Note that this will download at least 2-3 GB of data, and the resulting image will be at least 5 GB large!

docker build -t latex-compile-server .

docker run -p 58404:58404 -e API_KEYS="your-secret-key-1,your-secret-key-2" latex-compile-server

API Key Authentication: The server requires valid API keys to process requests. Set one or more comma-separated API keys using the API_KEYS environment variable when running the container.

What this project is

  • Convenient - no need to clutter your file system with LaTeX packages. Just call a Rest service.
  • Distributable - you can run this on any computer with Docker installed.

What this project is not

  • Small - this will download at least 2-3 GB, and the container will take around 5 GB of disk size.
  • Fully secure - this is intended to be run locally or in trusted environments. While API key authentication is required, no additional security hardening has been implemented.

Example usage

There is a personal invitation sample in the example directory, which will produce a document that is typeset with pgfornament by Alain Matthes et al. The layout and "main document" is in example/invite.tex, and the personal information is in example/personalinfo.tex.

To compile it, run the Docker container. Compress the two files to a zip: zip -rj doc.zip example. Then run:

curl -X POST -H "Content-Type: multipart/form-data" -H "X-API-Key: your-secret-key-1" -F "mainFile=invite" -F "data=@doc.zip" http://localhost:58404/compile --output invite.pdf

In the curl command, we have specified a few things:

  • -H "X-API-Key: your-secret-key-1" - The API key for authentication (must match one of the keys set in the API_KEYS environment variable)
  • -F "mainFile=invite" - The main tex file to compile is called invite.tex, so we here specify the name of that file (note that we specify "invite", not "invite.tex" in the curl command)
  • -F "data=@doc.zip" - The zip of the documents is called doc.zip, so we specify that here
  • --output invite.pdf - latex-compile-server sends a pdf back, and we here specify the name and location of where to save it

LaTeX Engine Selection: By default, the server uses pdflatex for compilation. To use xelatex instead, add the latexEngine parameter to your curl command:

curl -X POST -H "Content-Type: multipart/form-data" -H "X-API-Key: your-secret-key-1" -F "mainFile=invite" -F "latexEngine=xelatex" -F "data=@doc.zip" http://localhost:58404/compile --output invite.pdf

Error Handling: If compilation fails, the server returns HTTP 500 with the full LaTeX compilation output in the response body. The compilation runs in non-interactive mode (-interaction=nonstopmode), so it won't hang waiting for user input on errors.

PDF from example

About

Server running in Docker and compiles LaTeX documents

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TeX 71.7%
  • Kotlin 21.8%
  • Dockerfile 6.5%