Rest API for rendering LaTeX documents
Name | Type | Default Value | Description |
---|---|---|---|
FILE_SIZE_LIMIT |
Integer | 50 |
Maximum size of uploaded files in megabytes. |
FILE_COUNT_LIMIT |
Integer | 500 |
Maximum number of files that can be uploaded in a single request. |
COMPILER_TYPE |
String | PDFTex |
The LaTeX compiler to use (e.g.,PDFTex , XeTeX , etc.). |
COMPILER_ARGS |
String | undefined |
Additional arguments to pass to the LaTeX compiler. |
LOG_LEVEL |
String | info |
Logging level for the application (e.g.,debug , info ,typesetting ,warn ,error ). More info |
PASSOVER |
Integer | 2 |
Number of passes the LaTeX compiler should perform. |
PORT |
Integer | 3000 |
Port on which the server will listen. |
To pull and run the Docker container from Docker Hub:
docker run -p 3000:3000 michaelkoelle/latex-render-api:latest
To use Docker Compose with the image from Docker Hub, create a docker-compose.yml
file with the following content:
version: "3.8"
services:
latex-render-api:
image: michaelkoelle/latex-render-api:latest
ports:
- "3000:3000"
environment:
FILE_SIZE_LIMIT: 100
Then run the following commands:
# Start the services
docker-compose up
# Stop the services
docker-compose down
To compile and run the application yourself:
-
Clone the repository:
git clone https://github.com/michaelkoelle/latex-render-api.git cd latex-render-api
-
Install dependencies:
npm install
-
Build the application:
npm run build
-
Start the server:
npm start
The server will be running at http://localhost:3000
.
To render a LaTeX document, send a POST request to the /
endpoint with multipart/form-data
containing the following fields:
entry
: The relative path of the main LaTeX file (e.g.,main.tex
).file_*
: The binary content of the files (e.g.,file_1
,file_2
, etc.).path_*
: The relative paths corresponding to the uploaded files (e.g.,path_1
,path_2
, etc.).
import { readFileSync } from "fs";
// Build the form data
const formData = new FormData();
const filePath = "path/to/main.tex";
formData.append("entry", filePath);
formData.append(`file_${index}`, new Blob([readFileSync(filePath)]));
formData.append(`path_${index}`, filePath);
// Create a post request
const res = await fetch("http://localhost:3000", {
method: "POST",
body: formData,
});
const json = await res.json();
const { pdf, logs } = json;
curl -X POST http://localhost:3000/ \
-F "entry=main.tex" \
-F "path_1=main.tex" \
-F "file_1=@path/to/main.tex" \
-F "path_2=images/example.png" \
-F "file_2=@path/to/example.png"
The response will include the rendered PDF as a base64-encoded string and logs:
{
"pdf": "JVBERi0xLjQKJcfs... (truncated base64 string)",
"logs": "...compiler logs..."
}
- The
entry
field is required and should match the relative path of the main LaTeX file. - Each
file_*
field must have a correspondingpath_*
field to specify its relative path. Ensure to at least have the entry file and path listed. Entry file path must match one of thefile_*
paths - Ensure the
Content-Type
header is set tomultipart/form-data
in your request.