```LaTeX.wasm:浏览器中的 LaTeX 引擎```
LaTeX.wasm: LaTeX Engines in Browsers

原始链接: https://www.swiftlatex.com/

SwiftLaTeX 是一款开源的浏览器端 LaTeX 编辑器,利用 WebAssembly 直接在浏览器中运行 PdfTeX 和 XeTeX 引擎。它具有高度的兼容性,所生成的输出结果与标准的 TeXLive 或 MikTeX 发行版完全一致,其性能可达到原生二进制程序的一半。 主要功能包括对“所见即所得”编辑的支持,以及一个对开发者友好的库,允许用户通过简单的脚本标签将 LaTeX 编译功能集成到自己的网页项目中。开发者可以将源文件、图像和字体加载到内存文件系统中,触发编译,并以编程方式获取 PDF 或日志文件。 凭借其模块化 API(包括文件管理和引擎初始化方法),SwiftLaTeX 为在 Web 应用中集成专业级文档排版提供了一种无缝的解决方案,且无需任何服务器端依赖。所有源代码均已在 GitHub 上公开。

Hacker News 上关于“LaTeX.wasm”的讨论探讨了通过 WebAssembly 在浏览器中直接运行 LaTeX 文档引擎的可行性及其影响。 参与者争论了基于浏览器的排版引擎是否能够取代传统的网页标准。尽管支持者认为 WASM 实现了强大且可移植的文档处理,但怀疑论者指出了重大障碍。具体而言,将排版移至 WASM 往往会破坏无障碍访问(A11y),阻碍与系统输入法的集成,且在响应式表现上难以与 HTML/CSS 的原生流式布局相媲美。 讨论还涉及了 LaTeX 本身在网络环境下的技术局限性,例如其复杂的多轮编译要求,这对网页开发者来说往往并不直观。一些用户表达了对 DVI 等早期文档格式的怀念,而另一些用户则指出,现有的浏览器 LaTeX 实现往往非常脆弱、演示示例经常失效,或缺乏完整的生态支持(如 LuaLaTeX)。 总之,尽管将 LaTeX 引入浏览器被视为一种“滑稽”或小众的技术实验,但多数评论者一致认为,由于缺乏无障碍支持和真正的浏览器集成,它不太可能成为取代标准网页排版引擎的候选方案。
相关文章

原文
SwiftLaTeX: WYSIWYG LaTeX Editor for Browsers Fork me on GitHub

100% Browser

PdfTeX and XeTeX written in 100% WebAssembly and run in browsers.

Compatibility

Produce exact same output you would get from TexLive or MikTeX.

Library Support

Simply include a script tag and use PdfTeX or XeTeX in your own webpage.

WYSIWYG

Support WYSIWYG editing on LaTeX documents using XeTeX engine.

Speed

Run merely 2X slower than native binaries.

Open Source

Completely Open Source. You can find the code on GitHub.

It may take a few minutes to download template files for the first time. Please be patient

Step 1: Download latest release from Github. Extract the files and put them into your webpage directory.
Step 2: Include the src tag in your page.
<script src="PdfTeXEngine.js"></script>
Step 3: Initial the engine.
const engine = new LaTeXEngine();
await engine.loadEngine();
Step 4: Load the tex files/pictures/fonts to engines.
const engine = new LaTeXEngine();
engine.writeMemFSFile("main.tex", "\documentclass{...");
Step 5: Set the main file and fire the compilation.
engine.setEngineMainFile("main.tex");
let r = await engine.compileLaTeX(); // r contains PDF binray and compilation log.
  • async loadEngine(): Promise<void&gt.
      Load the webassembly engine.
  • isReady(): boolean.
      Check whether the engine is ready to compile documents.
  • writeMemFSFile(filename: string, srccode: string | Uint8Array).
      Upload source codes / assets to the engine.
  • makeMemFSFolder(folder: string).
  • setEngineMainFile(filename: string).
      Tell the engine which latex file is the entry file.
  • compileLaTeX():Promise<CompileResult>.
      Start compiling LaTeX documents and return CompileResult.
  • flushCache().
      Purge all the files uploaded.
  • closeWorker().
联系我们 contact @ memedata.com