# LaTeX to PDF Compiler API (`josefbednar/latex-to-pdf-api`) Actor

Compile LaTeX to PDF via API. Send LaTeX source (or a zip of a multi-file project), get back a rendered PDF. Powered by Tectonic — no TeX installation needed. Works as an MCP tool for AI agents.

- **URL**: https://apify.com/josefbednar/latex-to-pdf-api.md
- **Developed by:** [Josef Bednář](https://apify.com/josefbednar) (community)
- **Categories:** Developer tools, Automation
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $1.00 / 1,000 results

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

Actors are web data automations that power AI and operations. They run on the Apify platform to scrape websites, process data, connect APIs, and automate workflows.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.
Actors are written with capital "A".

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.
The best way to integrate Actors is as follows.

- **AI agents and MCP clients** — the [Apify MCP server](https://docs.apify.com/integrations/mcp.md) at `https://mcp.apify.com` (remote, streamable HTTP, OAuth on first use).
- **Agentic workflows and local Actor development** — [Agent Skills](https://apify.com/.well-known/agent-skills/index.json) with the [Apify CLI](https://docs.apify.com/cli/docs.md): `npm install -g apify-cli`, then `apify login`.
- **JavaScript/TypeScript projects** — the official [JS/TS client](https://docs.apify.com/api/client/js/docs.md): `npm install apify-client`.
- **Python projects** — the official [Python client](https://docs.apify.com/api/client/python/docs.md): `pip install apify-client`.
- **Any other language** — the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).

# README

## LaTeX to PDF Compiler API

Compile LaTeX to PDF via a simple API call — no TeX installation, no Docker setup, no
2 GB TeX Live download. Send LaTeX source (or a zip with a full multi-file project) and
get back a rendered PDF. Runs [Tectonic](https://tectonic-typesetting.github.io/), a
modern XeTeX-based engine, with common packages pre-cached for fast compiles.

Works great as a building block in automation pipelines (invoices, reports, resumes,
certificates) and as an **MCP tool for AI agents** — LLMs write LaTeX well, and this
actor turns that LaTeX into an actual PDF.

### Features

- **Plain LaTeX in, PDF out** — paste source or point to a zip of a full project
- **Multi-file projects** — images, chapters, `.bib` files via `filesZipUrl`
- **Modern engine** — Tectonic (XeTeX core): UTF-8 native, auto-fetches missing packages
- **Fast** — common packages (amsmath, geometry, hyperref, booktabs…) are pre-cached
- **Safe** — shell-escape is disabled; each compile runs in an isolated container
- **Failure logs** — on error you get the compiler log tail to fix your document

### Input

| Field | Type | Description |
|---|---|---|
| `texSource` | string | LaTeX document source |
| `filesZipUrl` | string | URL of a zip with a multi-file project (overrides `texSource`) |
| `mainFile` | string | Entry `.tex` file, default `main.tex` |
| `timeoutSecs` | integer | Compile timeout, default 120 |

### Output

The PDF is stored as `output.pdf` in the run's key-value store. The dataset record
gives you the direct download URL:

```json
{
    "status": "SUCCESS",
    "pdfUrl": "https://api.apify.com/v2/key-value-stores/<storeId>/records/output.pdf",
    "sizeBytes": 24817,
    "compileTimeMs": 1843
}
```

### Usage from code

```bash
curl -s "https://api.apify.com/v2/acts/josefbednar~latex-to-pdf-api/run-sync-get-dataset-items?token=<YOUR_TOKEN>" \
  -X POST -H 'Content-Type: application/json' \
  -d '{"texSource": "\\documentclass{article}\\begin{document}Hello PDF\\end{document}"}'
```

### FAQ

**Which LaTeX engine is this?**
Tectonic, built on XeTeX. It handles modern LaTeX, UTF-8, and system-font-free
documents. Most documents that compile with `pdflatex`/`xelatex` work unchanged.

**Can I compile a whole thesis/project?**
Yes — zip the project folder, host the zip anywhere reachable, pass `filesZipUrl`
and set `mainFile` to your entry file.

**Is BibTeX supported?**
Tectonic runs the full compile loop including bibliography processing for most
standard setups (`biblatex` with the default backend works; classic `bibtex` workflows
may need a pre-generated `.bbl` in the zip).

**Why did my compile fail?**
Check the `logTail` in the output record or the full `compile-log.txt` in the
key-value store — it contains the standard LaTeX error output.

# Actor input Schema

## `texSource` (type: `string`):

The LaTeX document to compile. For multi-file projects use 'Project zip URL' instead.

## `filesZipUrl` (type: `string`):

URL of a .zip containing a full LaTeX project (images, .bib, chapters…). Overrides 'LaTeX source' if set.

## `mainFile` (type: `string`):

Entry point .tex file to compile (relevant for zip projects).

## `timeoutSecs` (type: `integer`):

Hard limit for the LaTeX compiler.

## Actor input object example

```json
{
  "texSource": "\\documentclass{article}\n\\usepackage{amsmath}\n\\begin{document}\n\\section*{Hello from LaTeX}\nThe quadratic formula: $x = \\frac{-b \\pm \\sqrt{b^2-4ac}}{2a}$\n\\end{document}\n",
  "mainFile": "main.tex",
  "timeoutSecs": 120
}
```

# Actor output Schema

## `pdf` (type: `string`):

No description

## `result` (type: `string`):

No description

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "texSource": `\documentclass{article}
\usepackage{amsmath}
\begin{document}
\section*{Hello from LaTeX}
The quadratic formula: $x = \frac{-b \pm \sqrt{b^2-4ac}}{2a}$
\end{document}`
};

// Run the Actor and wait for it to finish
const run = await client.actor("josefbednar/latex-to-pdf-api").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = { "texSource": """\\documentclass{article}
\\usepackage{amsmath}
\\begin{document}
\\section*{Hello from LaTeX}
The quadratic formula: $x = \\frac{-b \\pm \\sqrt{b^2-4ac}}{2a}$
\\end{document}
""" }

# Run the Actor and wait for it to finish
run = client.actor("josefbednar/latex-to-pdf-api").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "texSource": "\\\\documentclass{article}\\n\\\\usepackage{amsmath}\\n\\\\begin{document}\\n\\\\section*{Hello from LaTeX}\\nThe quadratic formula: $x = \\\\frac{-b \\\\pm \\\\sqrt{b^2-4ac}}{2a}$\\n\\\\end{document}\\n"
}' |
apify call josefbednar/latex-to-pdf-api --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,josefbednar/latex-to-pdf-api"
        }
    }
}

```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/9uLmJZsXvGTalsEUT/builds/TRGnkO8dSxNV2lQQS/openapi.json
