Show HN: TeXbrain,一个通过 WASM 在浏览器中运行 pdfTeX 的 LaTeX 编辑器
Show HN: TeXbrain, a LaTeX editor that runs pdfTeX in the browser via WASM

原始链接: https://github.com/swimmingbrain/texbrain

**texbrain** 是一款免费、开源且注重隐私的 LaTeX 编辑器,完全在浏览器中运行。它旨在消除付费服务和复杂本地安装带来的困扰,用户无需注册账户或进行服务器端处理,即可编写、编译并管理 LaTeX 项目。 **主要功能:** * **本地优先架构:** 基于 WebAssembly (pdfTeX) 构建,文件在本地编译。敏感文档绝不会离开您的设备。 * **完整的 Git 集成:** 内置基于浏览器的 Git 客户端,支持直接克隆、提交并将项目推送到 GitHub。 * **离线功能:** 基础宏包可在本地缓存,初次设置后即可在无网络连接的情况下工作。 * **现代编辑器:** 采用基于 CodeMirror 6 的界面,支持语法高亮、超过 70 条 LaTeX 命令的自动补全以及实时 PDF 预览。 * **本地文件访问:** 利用 File System Access API(适用于 Chromium 内核浏览器)直接与您电脑上的项目文件夹进行交互。 尽管目前仅限于 pdfTeX 和 TeX Live 2020 时代的宏包,但 texbrain 为追求无缝、高效 LaTeX 环境的学者和开发者提供了一个强大且“开箱即用”的解决方案。访问 [tex.swimmingbrain.dev](https://tex.swimmingbrain.dev) 即可开始使用。

TeXbrain 是一款免费的开源 LaTeX 编辑器,完全通过 WebAssembly (WASM) 在浏览器中运行。该项目由一名工程硕士研究生开发,旨在作为 Overleaf 等订阅制服务的替代方案,使用户无需注册账户或连接后端即可在本地编译 LaTeX 文档。 主要功能包括: * **本地文件访问:** 利用文件系统访问 API (File System Access API) 允许用户编辑本地文件夹,从而方便地与 Git、本地 AI 代理或其他编辑器集成。 * **高效性能:** 通过 Service Worker 按需智能获取并缓存 TeX Live 依赖项,在保持核心引擎轻量化(1.8 MB)的同时,确保了离线功能。 * **兼容性:** 目前支持基于 TeX Live 2020 的 pdfTeX。虽然在基于 Chromium 的浏览器中运行效果最佳,但同时也为 Firefox 和 Safari 提供了虚拟文件系统回退方案。 该项目目前处于活跃维护状态,开发者正致力于改进错误报告机制,并解决与更新的 LaTeX 宏包的兼容性问题。开发者也正在与 TeX Live 团队就官方 WASM 支持事宜进行沟通。源代码已在 GitHub 上开源,并采用 MIT 许可证。
相关文章

原文

texbrain logo

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.

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.

  • 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.

  • 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.

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.
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
git clone https://github.com/swimmingbrain/texbrain.git
cd texbrain
pnpm install
pnpm dev

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

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.

MIT

Built by Braian Plaku

联系我们 contact @ memedata.com