How I Built a Real-Time Collaborative LaTeX Editor
How I built LetX, a real-time collaborative LaTeX editor: Yjs sync, a Go API, and a queued TeX Live compile worker on AWS. The architecture and what broke.
LetX is a real-time collaborative LaTeX editor I built at Shahriar Labs. Several people edit the same document at once, and a server compiles it on a full TeX Live installation, so pdfLaTeX, XeLaTeX and LuaLaTeX behave the way they do on a desktop. It is live at letx.app, with 7,100+ registered users at 500+ institutions in 70 countries in the figures it published on 19 October 2026.
This is how it is put together, and the parts that broke.
The architecture in one table
| Layer | What it does | Tech |
|---|---|---|
| Editor | Editing, highlighting, the PDF preview | React, TypeScript, Vite, CodeMirror 6, pdf.js |
| Collaboration | Several authors in one document | Yjs CRDTs over WebSockets |
| API | Projects, files, permissions, billing | Go and Gin, PostgreSQL 15 through pgx and sqlc, Redis |
| Compile | Turn .tex into a PDF | A queue (AWS SQS) feeding Go workers that run latexmk on TeX Live |
| Storage and hosting | Files, PDFs, the site | S3, ECS Fargate in ap-south-1, Cloudflare Pages for the frontend |
The browser does the editing. The server does everything that has to be true for every author at once: who may see a project, which version of a file is current, and what the PDF looks like.
Why the compile runs on a server
A complete TeX Live is several gigabytes, and real papers need it: BibTeX or biber, fontspec under XeLaTeX, a journal class nobody has heard of. Shipping that to the browser either means a cut-down distribution that fails on the second package or a download no researcher will wait for. So the compile is a job:
- The API puts a compile request on the queue. A second request for the same project within a few seconds returns the job already waiting, so a nervous double-click does not compile twice.
- A worker takes the job, holds a lock so each project has one build at a time, and writes the project's files to a build directory.
- It picks the main document: the one the author set, otherwise the file that looks most like one (
documentclass,egin{document}, a name likemain.tex). - It hashes every input. If that exact set of inputs compiled before, the stored PDF comes back immediately.
- It restores the auxiliary files (
.aux,.bbl,.toc) from the last run, so references and the bibliography do not need a full rebuild every time. - It runs
latexmkwith the project's engine and SyncTeX on, inside a sandbox with a time budget. - It uploads the PDF, the SyncTeX map and the log, and marks the job done.
End to end that takes a few seconds for a typical paper. The SyncTeX map is what lets you click a word in the PDF and land on the line that produced it.
Collaboration: from a relay to one owner per document
I chose CRDTs (specifically Yjs) over Operational Transform because two authors' edits merge without a central transformer deciding the order. The CRDT vs OT note has the longer version.
The first design was a relay. The server forwarded Yjs updates between browsers without understanding them, and when no stored history existed a browser rebuilt the document from its text. That works until two browsers rebuild at the same moment. Two independent histories of the same text merge into a document with every paragraph twice.
No rule about which browser rebuilds can prevent that, because the race is in the design. The fix was to stop relaying: a collaboration server now owns exactly one history per document, stores it with a compare-and-set on its revision, and is the only thing allowed to create it. Writes that come from outside the editor, such as a GitHub pull or an AI edit, go through that same server as small edits instead of replacing the text.
What broke, and what it taught me
- A compile error that nobody could see.
latexmkexiting with an error code was once treated as a warning, and the editor only fetched the log for failed jobs. So every real LaTeX error was invisible. Now a non-zero exit is a failure, full stop. - A health check that always said yes. A worker's health endpoint used to answer "ok" unconditionally, so a stuck worker looked healthy. It now reports unhealthy when a build slot has stalled, and the process restarts.
- Jobs that waited forever. After an outage, jobs that were queued but never picked up sat in "queued" for good. A reaper now fails them after twenty minutes with a message to press Recompile.
- Folders written as files. One import path wrote folder entries to disk as empty files, which hid every file inside those folders from the compiler. Folders are now created as directories, with a test that fails if that regresses.
None of these were clever bugs. Each was a place where the system reported success without checking it.
What it has now
Beyond editing and compiling: Lexi, an assistant inside the editor that edits the document, compiles it and fixes the line LaTeX actually complained about; an MCP server so Claude or ChatGPT can search templates, edit a project and compile it from a chat; two-way GitHub sync; and 1,000+ templates. There is a free plan and paid plans for heavier use.
If you write papers in LaTeX, try LetX and tell me what is missing. The LetX case study covers the product side.
Questions & answers
Does LetX compile LaTeX in the browser?
No. LetX compiles on a server with a complete TeX Live installation, through a queue and a pool of workers running latexmk. That is what lets pdfLaTeX, XeLaTeX and LuaLaTeX projects, BibTeX and biber all work without missing packages.
How fast is a LetX compile?
A few seconds end to end for a typical paper. Unchanged inputs return the stored PDF straight away, and auxiliary files from the previous run are reused so references do not need a full rebuild each time.
Can I import an Overleaf project into LetX?
Yes. Download the project from Overleaf as a .zip and upload it to LetX; the files, folders and images come across as a new project.
Is LetX free?
LetX has a free plan with real-time collaboration, and paid plans for heavier use. Current details are on letx.app/pricing.
