Skip to main content
The Compile API compiles LaTeX source code into PDF documents using the Tectonic typesetting engine. It handles the complete compilation pipeline including temporary file management and error reporting.

Endpoint

POST /api/compile

Request parameters

content
string
required
LaTeX source code to compile as a plain string.

Response

On successful compilation, returns a PDF file with the following headers:
Content-Type
string
application/pdf
Content-Disposition
string
inline; filename="output.pdf"

Error responses

Compilation error (400)

Returned when the LaTeX source contains syntax errors or cannot be compiled.
error
boolean
Always true for error responses
message
string
Error message from the Tectonic compiler, including line numbers and error descriptions. If no specific error message is available, returns “Unknown compilation error”.

Internal error (500)

Returned when an unexpected error occurs during the compilation process.
error
boolean
Always true for error responses
message
string
Error message describing the internal failure. Returns “Unknown error” if the error object has no message.

Compilation process

The API performs the following steps:
  1. Receive content: Accepts the LaTeX source code as a plain string
  2. Write temporary file: Saves the source as input.tex in the system temp directory
  3. Create output directories: Sets up out/ and cache/ directories for Tectonic
  4. Run Tectonic: Executes the Tectonic compiler with the following arguments:
    • -X compile - Use experimental compile mode
    • --outdir - Output directory for generated PDF
    • --synctex=false - Disable SyncTeX generation
  5. Return PDF or error: Returns the compiled PDF or error messages from stderr

Platform-specific behavior

The Tectonic binary location varies by platform:
  • Linux/Windows: bin/tectonic relative to the project root
  • macOS: /usr/local/bin/tectonic

Example request

curl -X POST https://your-domain.com/api/compile \
  -H "Content-Type: application/json" \
  -d '{
    "content": "\\documentclass{article}\n\\begin{document}\nHello, World!\n\\end{document}"
  }' \
  --output output.pdf

Example error response

{
  "error": true,
  "message": "error: LaTeX Error: File `nonexistent.sty' not found.\n\nType X to quit or <RETURN> to proceed,\nor enter new name. (Default extension: sty)\n"
}

Tips for successful compilation

  • Ensure all LaTeX packages used in the document are available in Tectonic
  • Check that the LaTeX syntax is valid before sending to the API
  • Send the LaTeX content as a plain string in the JSON body
  • Large documents may take several seconds to compile
  • The API does not support multi-file projects (use \input or \include directives within a single file)

Build docs developers (and LLMs) love