Skip to content

ufraaan/tex-leaf

Repository files navigation

TexLeaf

TexLeaf Banner

CI Docker Pulls

A web-based LaTeX editor with real-time preview, syntax highlighting, and PDF compilation.

Quick Start

# Start the server
cd backend
go run .

Then open http://localhost:8080 in your browser.

Docker

# Build and run
docker-compose up -d

# Access at http://localhost:8080

Data is persisted in a Docker volume.

Architecture Overview

┌─────────────────────────────────────────────────────────────────┐
│                      Browser  ·  Frontend                       │
├───────────────┬────────────────┬────────────────┬───────────────┤
│  Monaco       │   Sidebar      │   Topbar       │  PDF Viewer   │
│  Editor       │   (files)      │   (actions)    │               │
└───────────────┴────────────────┴────────────────┴───────────────┘
                               │
                    HTTP API · port 8080
                               │
                               ▼
┌─────────────────────────────────────────────────────────────────┐
│                    Go Backend  ·  Port 8080                     │
├───────────────────┬──────────────────┬──────────────────────────┤
│   Handlers        │   SQLite         │   Temp Dir               │
│   routes.go       │   db.go          │   (compile)              │
└────────┬──────────┴────────┬─────────┴──────────────────────────┘
         │                   │
         ▼                   ▼
┌─────────────────┐ ┌─────────────────────────────────────────────┐
│  compile/       │ │  data/                                      │
│  latex.go       │ │  texleaf.db  ◄── all data stored here       │
└─────────────────┘ └─────────────────────────────────────────────┘

Data Storage

All project data is stored in a single SQLite database (data/texleaf.db):

  • Projects table: Project metadata (id, uuid, name, main_file, timestamps)
  • Project files table: All project files (project_id, filename, content as BLOB)
  • Output PDF: Stored in DB as binary
  • Compile logs: Stored in DB as text

No file system storage for project content - everything is in SQLite.

Compilation Flow

  1. User clicks "Compile" in the editor
  2. Backend receives request with project UUID
  3. Step 1: All files are fetched from SQLite and written to a temp directory
  4. Step 2: pdftex is executed in the temp directory with the main .tex file
  5. Step 3: The generated PDF is read from temp dir and stored in SQLite
  6. Step 4: Compile log is stored in SQLite
  7. Step 5: Temp directory is cleaned up
  8. Browser receives PDF via GET /output.pdf

Draft vs Full Mode

  • Draft mode: Runs pdftex with -draftmode flag (fast, no PDF output, just checks for errors)
  • Full mode: Generates actual PDF, may run twice for cross-references

Tech Stack

  • Backend: Go
  • Database: SQLite
  • Editor: Monaco Editor
  • PDF: PDF.js

Requirements

  • Local: Go 1.23+, TeX Live or MacTeX
  • Docker: Docker + Docker Compose

LaTeX Benchmark Results

Test Description Time (s)
T1 10000 macro expansions (\foreach, integer print only) 0.19
T2 3000 blocks of text using \lipsum[1] (no page breaks) 9.2
T3 1500 iterations of multi-paragraph \lipsum[1-4] 1.07
T4 500 sections with forced \newpage after each block 0.61
T5 400 blocks with itemize lists + horizontal rules 0.47
T6 300 mixed blocks (sections + paragraphs + lists + pages) 6.8

Acknowledgments

About

Local-first web LaTeX editor with browser UI and native pdfTeX compilation.

Resources

License

Contributing

Stars

Watchers

Forks

Contributors