Quickstart

Get up and running with the LaTeXLite API in minutes.

1. Get an API Key

Visit latexlite.com/get-demo-key for a free demo API key, then export it as environment variables:

# Demo API key (rate limited)
export API_KEY="<your-api-key>"
export URL="https://latexlite.com"

2. Inline Template Without Data

The simplest request — send a self-contained LaTeX template as a JSON string:

curl -sS -X POST "${URL}/v1/renders-sync" \
  -H "Authorization: Bearer ${API_KEY}" \
  -H "Content-Type: application/json" \
  -o output.pdf \
  -d '{
    "template": "\\documentclass{article}\n\\begin{document}\nHello, World!\n\\end{document}"
  }'

This saves the PDF directly to output.pdf.

3. Inline Template With Data

Use [[.FieldName]] placeholders in your template and pass a data object to inject values:

curl -sS -X POST "${URL}/v1/renders-sync" \
  -H "Authorization: Bearer ${API_KEY}" \
  -H "Content-Type: application/json" \
  -o output-with-data.pdf \
  -d '{
    "template": "\\documentclass{article}\n\\begin{document}\nHello, [[.Who]]!\n\\end{document}",
    "data": { "Who": "world" }
  }'

4. Raw .tex File Without Data Injection

Send a self-contained .tex file directly — no JSON escaping needed. Use text/plain, text/x-tex, or application/x-tex as the Content-Type:

curl -sS -X POST "${URL}/v1/renders-sync" \
  -H "Authorization: Bearer ${API_KEY}" \
  -H "Content-Type: text/plain" \
  --data-binary @simple.tex \
  -o simple-from-file.pdf

Example simple.tex:

\documentclass{article}

\begin{document}

Hello, World!

\end{document}
Note: The file must be self-contained (no [[.Field]] placeholders) when using this method.

5. File Upload With Data Injection (Inline JSON)

When your template has [[.Field]] placeholders and you want to inject data inline via multipart:

curl -sS -X POST "${URL}/v1/renders-sync" \
  -H "Authorization: Bearer ${API_KEY}" \
  -F "[email protected]" \
  -F 'data={"CompanyName":"Acme Corp","InvoiceNumber":"INV-001","ClientName":"Client Ltd","Items":[{"Description":"Web Design","Qty":"1","UnitPrice":"\\$2,500","Total":"\\$2,500"}],"TotalDue":"\\$2,500"}' \
  -o invoice-inline.pdf

Example invoice.tex:

\documentclass{article}
\usepackage[margin=1in]{geometry}
\usepackage{array}

\begin{document}

\begin{center}
{\Large \textbf{INVOICE}}
\end{center}

\vspace{1em}

\noindent
\textbf{[[.CompanyName]]}

\vspace{2em}

\noindent
\textbf{Invoice \#:} [[.InvoiceNumber]]

\vspace{1em}

\noindent
\textbf{Bill To:} \\
[[.ClientName]]

\vspace{2em}

\begin{tabular}{|p{6cm}|c|r|r|}
\hline
\textbf{Description} & \textbf{Qty} & \textbf{Unit Price} & \textbf{Total} \\
\hline
[[range .Items]][[.Description]] & [[.Qty]] & [[.UnitPrice]] & [[.Total]] \\
\hline
[[end]]\end{tabular}

\vspace{1em}

\noindent
\textbf{Total Due:} [[.TotalDue]]

\vspace{2em}

\noindent
Thank you for your business!

\end{document}
Note: When writing JSON inline in curl, escape backslashes — use \\$ for dollar signs in LaTeX.

6. File Upload With Data Injection (From JSON File)

Read data from a separate JSON file using jq to ensure proper formatting:

curl -sS -X POST "${URL}/v1/renders-sync" \
  -H "Authorization: Bearer ${API_KEY}" \
  -F "[email protected]" \
  -F "data=$(cat invoice.json | jq -c '.')" \
  -o invoice.pdf

Example invoice.json:

{
  "CompanyName": "Acme Digital Ltd",
  "InvoiceNumber": "INV-2024-0042",
  "ClientName": "Widgets and Co Ltd",
  "Items": [
    {
      "Description": "Website Redesign",
      "Qty": "1",
      "UnitPrice": "£2,500.00",
      "Total": "£2,500.00"
    },
    {
      "Description": "SEO Optimization",
      "Qty": "1",
      "UnitPrice": "£500.00",
      "Total": "£500.00"
    }
  ],
  "TotalDue": "£3,000.00"
}
Tip: Using jq -c '.' validates and compacts the JSON, properly handling special characters like £, &, etc.

7. Request JSON Response (Debugging)

Set Accept: application/json to receive a base64-encoded PDF instead of binary — useful for inspecting or piping into other tools:

curl -sS -X POST "${URL}/v1/renders-sync" \
  -H "Authorization: Bearer ${API_KEY}" \
  -H "Accept: application/json" \
  -H "Content-Type: application/json" \
  -d '{
    "template": "\\documentclass{article}\n\\begin{document}\nHello, [[.Who]]!\n\\end{document}",
    "data": { "Who": "world" }
  }' | jq '.'

Response:

{
  "success": true,
  "data": {
    "content_type": "application/pdf",
    "pdf_base64": "JVBERi0xLjQKJeLjz9MKMyAwIG9iaiA8PC..."
  }
}

8. Math: Render LaTeX Equation to PNG

Use /v1/math-sync to render a LaTeX math expression to a PNG image. The math string must start and end with $ or $$:

curl -sS -X POST "${URL}/v1/math-sync" \
  -H "Authorization: Bearer ${API_KEY}" \
  -H "Content-Type: application/json" \
  -o equation.png \
  -d '{
    "math": "$\\int_0^1 x^2 \\, dx = \\frac{1}{3}$"
  }'
Note: In JSON, backslashes must be escaped. Use \\int, \\frac, \\, etc. However, \n and \t are JSON escape sequences and should remain single backslash.

9. Math: Request JSON Response

Set Accept: application/json to receive the PNG as base64:

curl -sS -X POST "${URL}/v1/math-sync" \
  -H "Authorization: Bearer ${API_KEY}" \
  -H "Accept: application/json" \
  -H "Content-Type: application/json" \
  -d '{
    "math": "$E = mc^2$"
  }' | jq '.'

Response:

{
  "success": true,
  "data": {
    "content_type": "image/png",
    "png_base64": "iVBORw0KGgoAAAANSUhEUgAA..."
  }
}

Best Practices

Choose the right input type

  • Use application/json for inline templates with data injection
  • Use text/plain (or text/x-tex, application/x-tex) for raw .tex files without data — no JSON escaping needed
  • Use multipart/form-data when uploading .tex files with [[.Field]] placeholders

Escape LaTeX in inline JSON

Backslashes must be doubled in JSON strings: \ becomes \\. Exception: \n and \t are JSON escape sequences and stay single.

{
  "template": "\\documentclass{article}\n\\begin{document}\nHello \\textbf{World}!\n\\end{document}"
}

Handle rate limits

Respect the X-RateLimit-Limit, X-RateLimit-Remaining, and X-RateLimit-Reset response headers.

Optimize templates

Keep templates under 200KB and avoid computationally expensive LaTeX packages to stay within the 8-second timeout.

Ready for more?

See the full API reference for all endpoints, content types, limits, and error codes.

API Reference →