DEV Community

Sia
Sia

Posted on

A LaTeX editor in the browser: Rust converts to Typst, all in WebAssembly

Scissor LaTeX is an editor that typesets LaTeX documents in the browser, with no server and no TeX installation: https://latex.scissor.studio/app/
You write LaTeX on the left, and the pages appear on the right as you type.

The Scissor LaTeX editor with LaTeX source on the left and the typeset page on the right

It also has small tools for single jobs: an equation editor, LaTeX to PNG and SVG, a BibTeX formatter, LaTeX to HTML and Markdown. This post is about the editor and how it works.

LaTeX is converted, not compiled

A browser can't run a full TeX distribution in any reasonable size. So Scissor LaTeX doesn't run TeX at all. A converter written in Rust reads the LaTeX and writes Typst markup, and Typst 0.15 typesets it. Math is handed to mitex, which turns LaTeX math into Typst math.

Here is a real input and what the converter makes of it:

\section{Results}
We have $E = mc^2$ and
\begin{equation}
  \int_0^1 x^2\,dx = \tfrac{1}{3}.
\end{equation}
Enter fullscreen mode Exit fullscreen mode
// L4
= Results

// L5
We have #__math(block: false, numbered: false, label: "", "E = mc^2") and

// L6
#__math(block: true, numbered: true, label: "", "\\int_0^1 x^2\\,dx = \\tfrac{1}{3}.")
Enter fullscreen mode Exit fullscreen mode

The // L4 comments are source lines. When Typst reports an error, the editor maps it back to the line you wrote. The #__math and #__setup calls go to a small Typst library that does the class layout, numbering and labels.

Both engines are Rust compiled to WebAssembly. Typesetting runs in a Web Worker, so typing never waits for it. The preview is SVG pages, and Export → PDF uses Typst's PDF writer.

Packages are implemented one by one

Since no package code runs, every package is something the converter knows. Right now it recognises 728 package names and 45 document classes. Recognised doesn't mean complete. Each package has a docs page with a table of what works, what works partly and what doesn't.

There are three cases:

  • Implemented: amsmath, graphicx, booktabs, pgfplots, a subset of TikZ, biblatex citations and many more.
  • Known, without effect: fancyhdr, titlesec, microtype. They're accepted, but running headers and heading styles don't change.
  • Unknown: a publisher's .sty, a typo. The Problems tab says the package isn't supported yet, and unknown commands are listed there too. Their text usually stays, without the formatting.

If a .sty or .cls file is in the project, the converter reads part of it: \newcommand definitions, the packages it loads, colours and margins. Anything else in it is ignored.

Missing packages drive the work

When a document loads an unknown package, the editor sends one report with the package's name, once per browser. The document and the other files are never sent. There's also a Request support button on the note.

The list of names is my to-do list. This month it brought the resume CV class, tkz-tab for the sign and variation tables that French maths teaching uses, fvextra and calligra. tkz-tab was the biggest: its tables are now drawn in Typst, from the same sizes that tkz-tab.sty uses.

Sizes and licences

The core engine is 6.6 MB of WebAssembly, or 1.7 MB compressed. It loads on every page. The typesetter is 25.6 MB, or 9.8 MB compressed, and loads only when something needs typesetting. A service worker caches both, so the editor also works offline after the first visit.

The fonts are Latin Modern and New Computer Modern for text and math, under the GUST Font License. The calligra script is TeX Gyre Chorus, also under GUST, and it's downloaded only the first time a document uses it. Typst, mitex and the other Rust crates are listed with their licences at https://latex.scissor.studio/licenses/. Every dependency has to be free for commercial use.

Your documents stay on your device

Projects are saved in the browser's IndexedDB. There is no upload endpoint, and the Content Security Policy allows only the site itself and, if you use it, Google Drive. Drive uses the drive.file scope, so the editor sees only the files you open or create with it.

In Chrome and Edge you can also open a folder on your disk as a live project. Saving writes straight to the files, and changes made in another editor show up in the preview.

Limits

  • There is no TeX engine, so the output is close to LaTeX's but not identical. Line breaks and page breaks can differ.
  • TeX programming beyond simple macros doesn't run: \def tricks, expl3 code, anything that inspects boxes.
  • TikZ is a subset. The picture environment isn't drawn.
  • Packages that only change layout details, like fancyhdr and titlesec, have no effect yet.

Try it: https://latex.scissor.studio/app/
It's free and needs no account.

If you open one of your own documents, which package or command breaks it first? That answer decides what I build next.

Top comments (0)