跳到正文
原文
Simon Willison·· 2 天前AI 评分51

Simon Willison 用 Claude Code 构建可分享链接的 LaTeX 渲染器

LaTeX renderer

AI 导读

Simon Willison 用 Claude Code(Opus 5.5 Extra)做了 LaTeX renderer,单条展示公式由 MathJax 4.1.3 排版,完整文档或散文片段由 faster-latex 0.3.1 排版,并可在编辑与渲染视图间切换。

正文 · AI 翻译

工具 LaTeX renderer — LaTeX renderer 将 LaTeX 源码转换为渲染视图,既可以是由 MathJax 排版的单个展示公式,也可以是由 faster-latex 排版的完整文档或正文片段,编辑器旁带有实时预览,工具栏可在 Edit 与 Rendered 视图之间切换。源码可以手动输入、从 URL 或 GitHub Gist 加载,或从内置示例中选取,页面会将 LaTeX 保留在 URL fragment 中,从而可以分享为可读链接或压缩链接。

受 Paul Ford 和 Aboard Foundary 的新网页应用 Tiny Little Office 启发,该应用提供一套网页应用内容编辑器(文字处理器、大纲编辑器、演示文稿制作器、电子表格、计算器、绘图工具、图表制作器、动画制作器、日历和行程规划器)。

Tiny Little Office 的招牌技巧是把全部文档数据存储在 URL 的 #fragment 部分,因此用它创建的每份文档都会变成可收藏、可分享的链接。

它还有 一个 llms.txt 文件,告诉智能体如何构造会渲染为文档的 URL。Claude 使用了该文件 来生成 这个指向演示文稿的链接,用以说明 URL 格式的工作方式:

Screenshot of a slide deck editor in a web app with a dark-themed presentation open. The document title field reads "How a Tiny Little Office link works", with a progress ring, share icon and menu icon at top right. Below is a formatting toolbar with an "Insert" dropdown followed by icon buttons for play, bold, italic, underline, strikethrough, highlight, code, link, superscript, emoji, outdent, indent, layout and color palette. The main canvas shows slide 1 with a blue chain-link icon and the text: "The whole document is the link" "No server, no database, no account" "Everything after the # stays in your browser" and a slide counter "1 / 9". Below the canvas is a "SPEAKER NOTES" heading. A sidebar on the right shows slide thumbnails. Slide 1 (selected): "The whole document is the link" "No server, no database, no account" "Everything after the # stays in your browser". Slide 2: "Anatomy of a link" with bullets "tinylittleoffice.com/#/v1/deck/y7Vj..." "v1: the format version" "deck: which app opens it" "y: the mode letter" "7Vj...: the document, compressed and encoded". Slide 3: "Step 1: write it as text" with bullets "Every document is TLO, a Markdown variant" "Slides split on --- lines" "Charts, drawings and animations are fenced blocks" "This deck is about 1 KB of plain text". Slide 4: "Step 2: squeeze it" with bullets "Raw DEFLATE, the same algorithm as zip and gzip" "z: plain DEFLATE" "y: DEFLATE with a preset dictionary" "r: no compression at all".

Tiny Little Office 启发我 让 Claude Code(Opus 5.5 Extra)构建一个适用于 LaTeX 的类似工具。以下是我使用的提示词序列:

I want a tool where you can link to it with a fragment hash #code-here and it treats that code as LaTeX and renders it really effectively. It should also support a prefix which means the latex is compressed with a custom compression dictionary optimized for latex. Use the best available latex render library from a CDN (consider WebAssembly too). If loaded without a fragment hash show an editor you can paste latex into and then toggle to a "rendered" view. That rendered view should be bookmarkable. The #fragment view should let you switch to edit source too.

由于它是在 我的 tools 仓库 中进行的,我让它借鉴我现有的 SVG in Markdown 工具 所使用的 <iframe sandbox="..."> 机制,以防范 XSS 风险:

Safe from XSS? We could run in an iframe sandbox like we do on the SVG markdown render project

我还让它从那个工具复制了 Gist/URL 加载功能:

We should have an option to load latex from a URL (or gist) similar to the markdown SVG tool

这是 一个示例链接。该工具使用 Pako 2.1.0、MathJax 4.1.3、faster-latex 0.3.1 和 DOMPurify 3.4.16。

Screenshot of a web app titled "LaTeX renderer" with a split-pane layout. The top bar has an Edit/Rendered toggle, a blue Copy link button, and a Share button. The left pane, labeled LaTeX source with a "Document · faster-latex (WASM)" badge, has a URL/GitHub Gist input with a Load button, a code editor containing a LaTeX document, and rows of example buttons (Quadratic formula, Gaussian integral, Maxwell, Attention, Matrix, Chemistry, Prose, TikZ, Document). The right pane shows the typeset output: a paper titled "Sums of Odd Numbers" by A. Student, with a section stating a theorem that the first n odd numbers sum to n squared, a Proof section with numbered equations, and a bulleted list of small cases.

来源:Simon Willison · simonwillison.net