FormaTeX

\begin{article}

draft — not published

Self-Hosting LaTeX vs. Using a Compilation API: A Cost Analysis

Running your own TeX Live server seems free — until you add up the real costs. A detailed breakdown of self-hosted LaTeX infrastructure vs. a managed compilation API.

·6 min read·
Self-Hosting LaTeX vs. Using a Compilation API: A Cost Analysis

When developers evaluate LaTeX compilation options, the initial reaction is often "we will just run pdflatex on our server — it is free." This is the same reasoning that leads teams to self-host their own email, their own Postgres, and their own Redis. Sometimes it makes sense. Often it does not. Here is the full cost analysis.

Build vs. Buy Framing

The question is not whether TeX Live costs money — it does not. The question is: what does it cost to run it reliably at scale in production?

The honest answer includes:

  1. Initial setup time
  2. Ongoing maintenance time
  3. Security patching
  4. Infrastructure costs (compute, storage)
  5. Incident response when it breaks
  6. Opportunity cost (what else could that time build?)

Total Cost of Ownership: Self-Hosted

Initial Setup

Setting up a production-grade LaTeX compilation server takes more than apt install texlive-full. You need:

  • Server provisioning (VPS, AWS, etc.)
  • TeX Live installation and configuration
  • Security hardening (LaTeX can execute shell commands — this is dangerous)
  • Worker queue for async compilation (Asynq, Celery, Bull)
  • File storage for temp files and outputs
  • Monitoring and alerting
  • Docker containerization for reproducibility

A realistic estimate for a careful engineer: 2–4 weeks of initial setup.

Ongoing Maintenance

TaskFrequencyTime estimate
TeX Live version updatesAnnual4–8 hours
Package conflict debuggingMonthly1–4 hours
Security patchesQuarterly2–4 hours
Infrastructure scalingAs needed4–16 hours
Incident responseOccasional2–8 hours/incident

Conservative estimate: 5–10 hours/month of engineering time.

At a blended engineering cost of $100/hour, that is $500–1,000/month in maintenance labor. This is the cost most teams forget to include.

Hidden Costs

Shell Escape Risk

LaTeX security risks on your server are more serious than most developers expect. LaTeX is a Turing-complete language that can execute shell commands via \write18. Running user-supplied LaTeX without disabling shell escape is a critical security vulnerability. Sandboxing it correctly requires:

  • Disabling shell-escape in the pdflatex invocation
  • Running in a restricted container (no network, no persistent storage)
  • Resource limits (CPU, memory, file size)
  • Timeout enforcement at the process level

This is non-trivial to get right.

Multi-Engine Support

Supporting all four engines (pdflatex, xelatex, lualatex, latexmk) requires testing each one independently and maintaining separate configurations. LuaLaTeX in particular has known compatibility issues with some packages.

Log Management

LaTeX compilation produces verbose .log files. You need a pipeline to:

  • Capture logs from failed compilations
  • Parse them into useful error messages
  • Store them for debugging
  • Clean them up to avoid disk exhaustion

Storage and Cleanup

Each compilation creates a set of temp files (.aux, .log, .bbl, .pdf). You need a cleanup routine to prevent disk exhaustion. If you miss this: disk fills, compilation silently fails.

A LaTeX compilation with latexmk and bibliography creates 8–15 temp files per job. At 1,000 jobs/day without cleanup, you accumulate thousands of orphaned files. Disk exhaustion is one of the most common self-hosted LaTeX failure modes.

API Cost at Scale

FormaTeX pricing is per-plan, not per-compilation beyond the included amount. For most teams:

PlanMonthly costCompilations
Free$015
Pro$4.99500
Max$14.992,000
Enterprise$49.9915,000

Break-Even Analysis

At what compilation volume does self-hosting become cheaper than the API?

Assumptions:

  • Engineer cost: $100/hour
  • Self-hosting maintenance: 5 hours/month = $500/month
  • Infrastructure: $30–80/month (VPS + storage)

One major hidden factor is why TeX Live Docker images are 4 GB — the storage and bandwidth costs of pulling that image on every deploy add up faster than teams anticipate.

ScenarioSelf-hosted/moFormaTeX/moBreak-even volume
Conservative maintenance (5h)$530Enterprise plan~15,000 compilations
Realistic maintenance (10h)$1,080Enterprise planNever — API always wins

The break-even point, when you include honest engineering time, is around 15,000 compilations per month. Below that, the API is almost always cheaper total.

When to Self-Host

Self-hosting makes sense if:

  • You have legal data residency requirements that prevent sending documents to third-party APIs
  • You have 15,000+ compilations/month and a dedicated DevOps team to maintain infrastructure
  • You need offline/air-gapped compilation with no internet access
  • You have existing TeX expertise on staff and the maintenance overhead is already accounted for

For every other case — especially startups, early-stage products, and teams where PDF generation is not the core product — using an API is the rational choice. Teams building things like LaTeX certificate generation at scale or PDF invoice generators almost always find the API cheaper once all costs are included.

Even teams that ultimately self-host use the FormaTeX API to ship fast initially. You can migrate later when the volume justifies the infrastructure investment. Starting with the API gives you a working product on day one instead of week four.

Get Started

FormaTeX is now a full platform — Cloud Editor, REST API (sync, async, smart compile), AI Assistant, and MCP Server — so you get more than just a compilation endpoint.

\end{article}

Back to blog

\related{posts}

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.

Cookie policy