\usepackage{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.
\section{Basic Compile}
Send a POST request to /v1/compile/sync with your LaTeX source. The response body is the raw PDF binary — save it directly with --output.
curl -X POST https://api.formatex.io/v1/compile/sync \
-H "Authorization: Bearer $FORMATEX_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"source": "\\documentclass{article}\\begin{document}Hello World\\end{document}",
"engine": "pdflatex"
}' \
--output output.pdf\section{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.
# pdfLaTeX (fastest)
curl -X POST https://api.formatex.io/v1/compile/sync \
-H "Authorization: Bearer $FORMATEX_API_KEY" \
-H "Content-Type: application/json" \
-d '{"source": "...", "engine": "pdflatex"}' \
--output pdflatex.pdf
# XeLaTeX (Unicode + system fonts)
curl -X POST https://api.formatex.io/v1/compile/sync \
-H "Authorization: Bearer $FORMATEX_API_KEY" \
-H "Content-Type: application/json" \
-d '{"source": "...", "engine": "xelatex"}' \
--output xelatex.pdf\section{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.
# Read from file using shell substitution
curl -X POST https://api.formatex.io/v1/compile/sync \
-H "Authorization: Bearer $FORMATEX_API_KEY" \
-H "Content-Type: application/json" \
-d "{\"source\": $(cat main.tex | jq -Rs .), \"engine\": \"pdflatex\"}" \
--output output.pdf
# Or use jq to build the JSON properly
jq -n --rawfile src main.tex '{"source": $src, "engine": "pdflatex"}' | \
curl -X POST https://api.formatex.io/v1/compile/sync \
-H "Authorization: Bearer $FORMATEX_API_KEY" \
-H "Content-Type: application/json" \
-d @- \
--output output.pdf\section{Response Headers}
Use --dump-header to capture response headers. The API returns X-Compile-Duration-Ms and X-Engine on every successful compile.
curl -X POST https://api.formatex.io/v1/compile/sync \
-H "Authorization: Bearer $FORMATEX_API_KEY" \
-H "Content-Type: application/json" \
-d '{"source": "...", "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}
| Method | Endpoint | Description |
|---|---|---|
| POST | /v1/compile/sync | Compile LaTeX synchronously. Returns raw PDF bytes. |
| POST | /v1/compile/async | Submit 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}
All requests require an Authorization header with a Bearer token. Export your key as an environment variable so you can reference it in every command.
export FORMATEX_API_KEY=your-api-key~/.bashrc or ~/.zshrc to persist it across sessions.\section{Other SDKs}
\end{curl}
Get your API key, run the quickstart command, and have a PDF in under a second — directly from your terminal.
One quick thing
We track anonymous usage — page views, feature usage, compilation events — to understand what works and what doesn't. No ads, no personal data, no third-party sharing.