Compile LaTeX to PDF with FormaTeX MCP in Claude Code and Cursor

Connect FormaTeX MCP with Claude Code and Cursor to enable your AI agent to seamlessly write, check, and compile LaTeX documents to PDF.

FormaTeX MCP Server: Compile LaTeX Directly from Claude Code and Cursor

By Elhassane Mehdioui — AI & Automation Consultant


LaTeX has always been the gold standard for producing publication-quality documents — academic papers, technical reports, CVs, and mathematical proofs. The problem is that the compile-debug loop is tedious: you write markup, run a command, hunt through log output, fix errors, and repeat. AI coding assistants like Claude Code and Cursor have already changed how developers write code. Now, with the FormaTeX MCP server, those same assistants can write and compile LaTeX, returning a finished PDF in a single conversation turn.

This post walks through what the FormaTeX MCP server is, how to wire it up in Claude Code and Cursor, and how to use it in a real workflow — from a blank .tex file to a downloadable PDF.


What Is an MCP Server?

Model Context Protocol (MCP) is an open standard that lets AI assistants call external tools over HTTP. Think of it as a plugin system for large language models: instead of the model guessing at an answer, it can invoke a real API, receive structured data back, and incorporate that data into its response.

An MCP server exposes a set of named tools. The AI can call those tools mid-conversation — for example, to run a database query, send an email, or, in our case, compile a LaTeX document. The result comes back to the model, which then explains it to you or takes the next action automatically.

MCP servers are transport-agnostic. FormaTeX uses HTTP transport, which means no local daemon, no Docker container, and no npm package to install. You point your client at a URL, supply a Bearer token, and you are done.


Introducing the FormaTeX MCP Server

FormaTeX is a hosted LaTeX compilation service exposed as an MCP server at:

https://mcp.formatex.io/mcp

It supports five tools out of the box:

ToolWhat it does
compile_smartDetects the best engine for your document and compiles it
compile_latexCompiles with an explicitly chosen engine
check_syntaxValidates your LaTeX markup — never uses quota
list_enginesLists the available LaTeX engines on your plan
get_usageReturns your current quota consumption

The free plan gives you access to pdflatex and xelatex. Paid plans unlock additional engines such as lualatex and latexmk. PDFs are returned as base64-encoded strings, which Claude or Cursor can decode and save to disk for you.

The check_syntax tool deserves a special mention: it performs a full parse of your LaTeX source and reports errors or warnings without touching your monthly compilation quota. If you are iterating heavily on a document, you can call check_syntax as many times as you like at zero cost, then fire compile_smart only when the document is clean.


Step-by-Step Setup for Claude Code

Claude Code supports MCP servers through the claude mcp add command. Open your terminal and run:

claude mcp add formatex \
  --transport http \
  --url https://mcp.formatex.io/mcp \
  --header "Authorization: Bearer YOUR_API_KEY"

Replace YOUR_API_KEY with the token you received when you signed up at formatex.io. The configuration is stored in your Claude Code profile, so you only need to run this command once.

To confirm the server registered correctly:

claude mcp list

You should see formatex in the output with its endpoint URL. You can now open any Claude Code session and the compile_smart, compile_latex, check_syntax, list_engines, and get_usage tools will be available automatically.


Step-by-Step Setup for Cursor

Cursor exposes MCP configuration through its settings file. Open your Cursor settings (Ctrl+, on Windows/Linux, Cmd+, on macOS) and navigate to MCP Servers, or edit ~/.cursor/mcp.json directly:

{
  "mcpServers": {
    "formatex": {
      "transport": "http",
      "url": "https://mcp.formatex.io/mcp",
      "headers": {
        "Authorization": "Bearer YOUR_API_KEY"
      }
    }
  }
}

Save the file and restart Cursor. The Composer agent in Cursor will now have access to all FormaTeX tools. You can verify this by opening a Composer chat and typing: "List the available LaTeX engines." Cursor will invoke list_engines and display the results inline.


Demo Workflow: AI Writes LaTeX, FormaTeX Compiles It

Here is a concrete end-to-end example you can reproduce right now.

1. Ask the AI to write a LaTeX document

In Claude Code, open a new chat and type:

Write a two-page LaTeX document for a conference paper abstract. Include a title, author, abstract section, introduction, and a sample equation. Save it as paper.tex.

Claude will generate a complete .tex file and write it to disk. A typical output looks like this (abbreviated):

\documentclass[12pt]{article}
\usepackage{amsmath}
\title{Attention Mechanisms in Transformer Architectures}
\author{Elhassane Mehdioui}
\date{\today}

\begin{document}
\maketitle

\begin{abstract}
This paper explores the role of scaled dot-product attention...
\end{abstract}

\section{Introduction}
Transformer models have become the dominant architecture...

\begin{equation}
  \text{Attention}(Q, K, V) = \text{softmax}\!\left(\frac{QK^\top}{\sqrt{d_k}}\right)V
\end{equation}

\end{document}

2. Check syntax before compiling

Before spending quota on a compile, ask Claude to validate the markup:

Run check_syntax on paper.tex and tell me if there are any errors.

Claude calls check_syntax with the file contents. If the document is clean, you will see a response like:

No errors found. The document is valid LaTeX.

If there are issues — a missing \end{equation}, an undefined command — Claude reports them in plain English and offers to fix them. This round-trip costs zero quota.

3. Compile to PDF

Once the syntax check passes:

Compile paper.tex to PDF using compile_smart and save the result as paper.pdf.

Claude calls compile_smart. FormaTeX selects pdflatex (or xelatex if your document loads font packages that require it), runs the full compilation pipeline, and returns the PDF as a base64 string. Claude decodes it and writes paper.pdf to your project directory. The whole process takes a few seconds.

Open paper.pdf — you have a fully typeset, print-ready document without ever touching a terminal LaTeX installation.


compile_smart vs compile_latex: Which Should You Use?

The choice comes down to how much control you need.

compile_smart is the right default for most users. It inspects your document's preamble — looking at \documentclass, \usepackage directives, and font declarations — and picks the most appropriate engine automatically. If you load fontspec or polyglossia, it will select xelatex. If you use a plain article class with standard packages, it will choose pdflatex. You get the correct output without having to think about engine compatibility.

compile_latex is for cases where you need deterministic control over the engine. This is useful when:

  • You are reproducing a build for a journal submission that specifies a particular engine.
  • You are debugging an engine-specific rendering difference.
  • You want to test how your document behaves under both pdflatex and xelatex.

Pass the engine name explicitly:

compile_latex(source="...", engine="xelatex")

On the free plan, both pdflatex and xelatex are available. Call list_engines at any time to see what your current plan supports.


Quota-Free Syntax Checking: Why It Matters for Agentic Workflows

When an AI agent is generating LaTeX autonomously — perhaps producing dozens of slides, a multi-section report, or a set of homework assignments — it may iterate many times before the document is right. If every iteration consumed compilation quota, costs would escalate quickly.

check_syntax removes that constraint. An agent can run a tight inner loop:

  1. Generate or modify LaTeX source.
  2. Call check_syntax.
  3. If errors exist, fix them and go to step 2.
  4. When clean, call compile_smart once to produce the final PDF.

Only the last step touches your quota. This pattern makes FormaTeX genuinely practical for automation scenarios: nightly report generation, CI pipelines that produce PDF artifacts, or batch document processing driven by an AI agent.


Checking Your Usage

You can inspect your remaining quota at any time:

How much of my FormaTeX quota have I used this month?

Claude calls get_usage and returns a summary. This is useful before kicking off a large batch job, or if you want to confirm that your syntax checks are not being counted against your limit (they are not).


Why This Combination Is Powerful

Connecting a LaTeX compiler to an AI assistant closes a loop that has been open for a long time. Previously, even if an AI wrote perfect LaTeX, you had to leave your editor, run the compiler, interpret log output, and come back. That friction was enough to make most people keep LaTeX at arm's length.

With FormaTeX wired into Claude Code or Cursor:

  • No local LaTeX installation required. The compilation happens in the cloud.
  • Errors are explained in plain English. The model reads compiler output and translates it for you.
  • The full document lifecycle lives in one conversation. Write, validate, compile, iterate.
  • Agentic workflows become practical. Quota-free syntax checking means you can automate document generation without runaway costs.

Whether you are an academic submitting to arXiv, an engineer producing technical documentation, or a consultant generating client-facing reports, the FormaTeX MCP server turns your AI assistant into a complete LaTeX authoring environment.


Getting Started

  1. Sign up at formatex.io to get your API key.
  2. Add the server to Claude Code with claude mcp add formatex --transport http --url https://mcp.formatex.io/mcp --header "Authorization: Bearer YOUR_KEY".
  3. Open a chat and ask Claude to write you a LaTeX document.
  4. Let it check syntax and compile — your PDF will be on disk in seconds.

The free plan is a good starting point for individual use. If you are building a pipeline that compiles many documents, review the paid plans for higher quotas and additional engines.


Elhassane Mehdioui is an AI and automation consultant helping teams integrate large language models into real workflows. Connect on LinkedIn or follow his writing for more guides on practical AI tooling.

Need a React or Next.js interface?

Modern, responsive front-ends built to perform.

I build fast, accessible UIs with React, Next.js, TypeScript and Tailwind CSS.

HassanOSSYS-00
SECURE CHANNEL · ACTIVE
INIT://