LaTeX Compiler API Documentation

Endpoints

POST /compile

Compile LaTeX code to PDF

Request Methods:

  • File Upload: multipart/form-data with 'file' field (.tex file)
  • JSON: application/json with {"code": "LaTeX source code"}

Success Response:

Content-Type: application/pdf
PDF file binary data

Error Response:

{
  "error": "Compilation failed",
  "log": "LaTeX error log details..."
}

GET /

Serve the web frontend interface

GET /docs

Display this API documentation

Example Usage

cURL - JSON Request:

curl -X POST http://localhost:7860/compile \
  -H "Content-Type: application/json" \
  -d '{"code": "\\documentclass{article}\\begin{document}Hello\\end{document}"}' \
  --output output.pdf

cURL - File Upload:

curl -X POST http://localhost:7860/compile \
  -F "file=@document.tex" \
  --output output.pdf

Python Example:

import requests

latex_code = r"""
\documentclass{article}
\begin{document}
Hello from Python!
\end{document}
"""

response = requests.post(
    'http://localhost:7860/compile',
    json={'code': latex_code}
)

if response.status_code == 200:
    with open('output.pdf', 'wb') as f:
        f.write(response.content)
else:
    print(response.json())

⚠️ Notes

← Back to Compiler