Hacker News 熱門

Show HN: TeXbrain, a LaTeX editor that runs pdfTeX in the browser via WASM

· 49天前
跳到正文
AI 摘要

I'm a master's engineering student and a big fan of LaTeX, which I used for my thesis and research articles. I have used Overleaf and that was fine until I wanted to git sync, which unfortunately sits behind a paywall. Since I didn't want to pay subscriptions for things that should simply just work, I built the editor I wanted in my free time, where you open a tab, write LaTeX, get your PDF and the files stay all in one folder on my disk. TeXbrain is a static site with no backend. pdfTeX is compiled to WebAssembly (SwiftLaTeX) and runs in your browser. The editor can read and write your project folder through the File System Access API, so you can use git, any local TeX install, local AI Agents, or any other editor on the same files. Git is built in through isomorphic-git for anyone who would rather not touch a terminal and clone, branch, commit, push or pull via commands. No account is needed, no analytics, and everything works offline after the first load. Try it out: https://tex.swimmingbrain.dev/ (Chromium browsers get direct folder access, while Firefox or Safari fall back to a virtual filesystem) Or for self-hosting/contributing: https://github.com/swimmingbrain/texbrain (MIT, the pdfTeX engine is EPL 2.0 / GPL 2.0 and is listed in the THIRD_PARTY_LICENSES file). The part I'm most proud of getting to work is the package loading. The engine itself is only 1.8 MB. When it asks for a file it doesn't have, then a service worker intercepts the request and resolves it through Cache Storage first, then a small bundled subset, then a TeX Live tree mirrored on jsDelivr, then a SwiftLaTeX style server as a last resort. Every file is fetched once at most and after the first successful compilation, the core subset is prefetched in the background so that the offline story actually holds. Only file names go over the network, never any document content. So far, it only supports pdfTeX (no XeTeX or LuaTeX), so fontspec or polyglossia won't work, packages are pinned to the TeX Live 2020 era to stay coherent with the engine's format file and there is no bibtex or biber in the engine yet, which is maybe the roughest edge. This is should be a good solution for people on a work laptop, a Chromebook, or a university lab PC where installing TeX Live isn't always an option, and people who don't want to maintain a TeX install at all. If you already have a local setup you like, keep it. This isn't necessarily thought as a replacement for that. Some people have already used it for their thesis in the past months and their bug reports (which I would never have hit on my own) were then most of the summer's work. The first outside PR also landed recently, so if something doesn't compile for you, an issue with the package name or the bug itself is the most useful thing you can send me! Comments URL: https://news.ycombinator.com/item?id=49441375 Points: 6 # Comments: 1

正文

texbrain logo

TeXbrain

A free, open-source LaTeX editor that runs entirely in your browser.
No accounts. No installs. No servers. Just open a tab and write.

Try it now → tex.swimmingbrain.dev

I built this because I was tired of paying for features that should be free. I wrote my thesis last year in LaTeX and spent more time fighting tooling than actually writing. Online solutions lock git sync behind a paywall. Local setups break between machines. I wanted something that just works. Open a browser, write LaTeX, get a PDF.

So I built it.

What it does

texbrain is a full LaTeX editor that compiles your .tex files to PDF directly in the browser. There is no backend. No server processing your files. Everything (the editor, the compiler, the git client) runs client-side.

You can open a local project folder, edit your files, see the PDF update, commit your changes, and push to GitHub. All from one tab.

Features

  • LaTeX compilation in the browser. Uses a WebAssembly port of pdfTeX (SwiftLaTeX). Your .tex files are compiled to PDF without ever leaving your machine. Packages are loaded on demand and cached locally, so the first compile only downloads what your document actually uses. Recompilations take 1 to 5 seconds depending on project complexity.
  • Most of CTAN, loaded on demand. Common packages ship with the app. Anything else (memoir, abntex2, KOMA-Script, you name it) is resolved automatically from a TeX Live mirror the first time a document needs it, then cached locally for offline use.
  • Live PDF preview. Rendered with pdf.js. Multi-page, zoomable, with text selection.
  • Full git integration. Clone repos, create branches, stage files, commit, push, pull, merge. All powered by isomorphic-git running in the browser. No CLI needed.
  • Local file system access. Uses the File System Access API to read and write directly to your project folder on disk (Chrome/Edge).
  • Multi-file projects. File tree, tabs, drag-and-drop. Supports .tex, .bib, .sty, .cls and more.
  • CodeMirror 6 editor. Syntax highlighting, autocomplete for 70+ LaTeX commands, bracket matching, code folding, snippets, dark/light theme.
  • Command palette. Quick access to actions via keyboard shortcut.
  • Snippet picker. Math environments, document structures, Greek letters, common commands. Searchable and categorized.
  • Works offline. Once loaded, the app works without an internet connection. Compilation is local, editing is local. Packages you've compiled with before are cached; only a package you've never used needs the network once.
  • Project templates. Start from scratch or pick a template (article, thesis, beamer, report, CV, letter, minimal).

How it works under the hood

There's no magic and no backend.

Editor. Built on CodeMirror 6 with a custom LaTeX grammar (Lezer parser), autocomplete provider, and theme system. The editor supports multiple open files via tabs and syncs content with both the local filesystem and the in-memory git working tree.

Compiler. LaTeX compilation uses SwiftLaTeX's pdfTeX engine compiled to WebAssembly. The engine runs in a memory filesystem (MEMFS), where your project files are written before each compilation. When the engine asks for a file it doesn't have (a class, package, font, ...), the service worker resolves it through a chain: previously cached files first, then the package subset bundled with the app, then a TeX Live mirror (a texmf-dist mirror on jsDelivr, with a community SwiftLaTeX server as fallback). Every resolved file is stored in the browser's cache storage, so each package is downloaded at most once. After the first successful compile, the bundled subset is also prefetched in the background so the core package set works offline.

Git. All git operations use isomorphic-git, a pure JavaScript implementation of git. The repository lives in an in-memory filesystem (LightningFS) backed by IndexedDB. Your project files are synced between the local filesystem and the git working tree. Remote operations (push/pull/clone) go through a CORS proxy since browsers can't speak the git protocol directly.

PDF viewer. Rendered with pdf.js, Mozilla's PDF rendering library. Supports multi-page rendering with a text layer for selection and search.

File system. The app uses the File System Access API to read/write your actual files on disk. This requires a Chromium-based browser (Chrome, Edge, Arc, Brave). For other browsers, there's a fallback using the Origin Private File System (OPFS).

Frontend. SvelteKit with the static adapter. The entire app is pre-built to static HTML/CSS/JS and deployed to GitHub Pages. No SSR, no API routes, no server. Tailwind CSS handles styling.

Known limitations

  • pdfTeX only. No XeTeX or LuaTeX, so fontspec, polyglossia and anything else that needs them won't compile.
  • No bibtex or biber. The engine doesn't ship either. Documents using biblatex get a plain thebibliography generated from the .bib file, so references show up but the citation style is ignored. Classic bibtex workflows need a .bbl in the project. A real bibtex in WASM is next on the list.
  • TeX Live 2020 era. Packages are pinned to the same era as the engine's format file, so newer package versions aren't available.
  • Git remotes need a CORS proxy. Browsers can't speak the git protocol directly. The default proxy is configurable, see below.
  • Direct folder access is Chromium only. Firefox and Safari fall back to a virtual filesystem, see Browser support.

Security and privacy

Everything runs in your browser. Your files never leave your machine unless you explicitly push to a remote.

  • No telemetry, no analytics, no tracking.
  • No accounts, no cookies, no data collection.
  • Git authentication tokens are stored in your browser's localStorage. They never touch a server I control.
  • LaTeX compilation happens in a WebAssembly sandbox. There are no shell commands being executed. No pdflatex, no exec(), no spawn().
  • Git operations use a JavaScript library, not CLI commands. No command injection is possible.
  • The CORS proxy for git remotes is a known trade-off. By default it uses cors.isomorphic-git.org (the isomorphic-git project's public proxy). You can point it at your own if you prefer.
  • Packages that aren't bundled are fetched from public TeX Live mirrors on demand. Only package filenames are sent, never your document content. Fetched files are cached locally, so this happens once per package. The fallback server can be changed or disabled entirely via the texliveMirror preference (empty string turns it off).
  • LaTeX and TeX are free and open-source software. This project uses them. It doesn't redistribute or modify their source.

Tech stack

Layer Technology
Framework Svelte 5 + SvelteKit (static adapter)
Editor CodeMirror 6 + custom LaTeX language support
Compiler pdfTeX via WebAssembly (SwiftLaTeX)
Git isomorphic-git + LightningFS
PDF pdf.js
Styling Tailwind CSS 4
Language TypeScript
Deployment GitHub Pages

Running locally

git clone https://github.com/swimmingbrain/texbrain.git
cd texbrain
pnpm install
pnpm dev

Open http://localhost:5173 in Chrome or Edge.

Browser support

Full functionality requires the File System Access API, which is available in Chromium-based browsers (Chrome, Edge, Arc, Brave, Opera). Firefox and Safari can still use the editor with the virtual filesystem fallback, but won't be able to read/write directly to local folders.

License

MIT

Built by Braian Plaku

查看原文(Hacker News 熱門)