\begin{article}
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.

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:
- Initial setup time
- Ongoing maintenance time
- Security patching
- Infrastructure costs (compute, storage)
- Incident response when it breaks
- 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
| Task | Frequency | Time estimate |
|---|---|---|
| TeX Live version updates | Annual | 4–8 hours |
| Package conflict debugging | Monthly | 1–4 hours |
| Security patches | Quarterly | 2–4 hours |
| Infrastructure scaling | As needed | 4–16 hours |
| Incident response | Occasional | 2–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:
| Plan | Monthly cost | Compilations |
|---|---|---|
| Free | $0 | 15 |
| Pro | $4.99 | 500 |
| Max | $14.99 | 2,000 |
| Enterprise | $49.99 | 15,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.
| Scenario | Self-hosted/mo | FormaTeX/mo | Break-even volume |
|---|---|---|---|
| Conservative maintenance (5h) | $530 | Enterprise plan | ~15,000 compilations |
| Realistic maintenance (10h) | $1,080 | Enterprise plan | Never — 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.
- Sign up for free — zero infrastructure, 15 compilations/month
- Try the Playground — test compilation without an account
- Pricing details — full plan comparison
- API documentation — integration reference
Related Articles
- Why TeX Live Docker Images Are 4 GB — Understand the storage and size penalty that makes self-hosted TeX Live painful to containerize and deploy
- LaTeX Security Risks on Your Server — Shell escape and file-read vulnerabilities you inherit when running pdflatex on user input
- The Complete Guide to LaTeX Engines — What you need to support when self-hosting pdfLaTeX, XeLaTeX, LuaLaTeX, and latexmk
- Getting Started with FormaTeX — First API key, first compilation, and error handling — the fastest path from zero to PDF
- The Best LaTeX PDF APIs in 2026 — Side-by-side comparison of every managed LaTeX compilation API to help you choose
\end{article}
\related{posts}




