FormaTeX

\usepackage{curl}

FormaTeX REST API with curl

Compile LaTeX to PDF from the terminal in a single curl command. No SDK, no dependencies — just the REST API and your API key.

Also available in:Python·Node.js·Go·PHP·Ruby·Rust·cURL|Full API reference

\section{Basic Compile}

Basic compile

Send a POST request to /api/v1/compile with your LaTeX source. The response body is the raw PDF binary — save it directly with --output.

terminal
curl -X POST https://api.formatex.io/api/v1/compile \
  -H "X-API-Key: $FORMATEX_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "latex": "\\documentclass{article}\\begin{document}Hello World\\end{document}",
    "engine": "pdflatex"
  }' \
  --output output.pdf

\section{Engine Selection}

Engine selection

Set the engine field to switch compilers. Use xelatex for Unicode and system fonts, or lualatex for Lua scripting. See engine documentation for the full comparison.

terminal
# pdfLaTeX (fastest)
curl -X POST https://api.formatex.io/api/v1/compile \
  -H "X-API-Key: $FORMATEX_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"latex": "...", "engine": "pdflatex"}' \
  --output pdflatex.pdf

# XeLaTeX (Unicode + system fonts)
curl -X POST https://api.formatex.io/api/v1/compile \
  -H "X-API-Key: $FORMATEX_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"latex": "...", "engine": "xelatex"}' \
  --output xelatex.pdf

\section{From a .tex file}

Compile from a .tex file

Use jq to safely escape the file contents into a JSON string before passing it to curl. This handles newlines and special characters correctly.

terminal
# Read from file using shell substitution
curl -X POST https://api.formatex.io/api/v1/compile \
  -H "X-API-Key: $FORMATEX_API_KEY" \
  -H "Content-Type: application/json" \
  -d "{\"latex\": $(cat main.tex | jq -Rs .), \"engine\": \"pdflatex\"}" \
  --output output.pdf

# Or use jq to build the JSON properly
jq -n --rawfile src main.tex '{"latex": $src, "engine": "pdflatex"}' | \
  curl -X POST https://api.formatex.io/api/v1/compile \
    -H "X-API-Key: $FORMATEX_API_KEY" \
    -H "Content-Type: application/json" \
    -d @- \
    --output output.pdf

\section{Response Headers}

Check response headers

Use --dump-header to capture response headers. The API returns X-Compile-Duration-Ms and X-Engine on every successful compile.

terminal
curl -X POST https://api.formatex.io/api/v1/compile \
  -H "X-API-Key: $FORMATEX_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"latex": "...", "engine": "pdflatex"}' \
  --output output.pdf \
  --dump-header headers.txt

# X-Compile-Duration-Ms: 94
# X-Engine: pdflatex
# Content-Type: application/pdf
cat headers.txt

\section{Endpoints}

API endpoints

MethodEndpointDescription
POST/api/v1/compileCompile LaTeX synchronously. Returns raw PDF bytes.
POST/api/v1/compile/asyncSubmit a compile job. Returns a job ID to poll.

Response codes: 200 — PDF binary, 401 — invalid/missing API key, 422 — LaTeX compilation error (JSON body with error field).

\section{Authentication}

Authentication

All requests require an X-API-Key header. Export your key as an environment variable so you can reference it in every command.

export FORMATEX_API_KEY =your-api-key
  • → Generate API keys from your dashboard after signing up.
  • → Keys are shown once on creation — save yours immediately.
  • → Add the export line to your ~/.bashrc or ~/.zshrc to persist it across sessions.

\end{curl}

Start compiling LaTeX with curl

Get your API key, run the quickstart command, and have a PDF in under a second — directly from your terminal.