Inspiration
\(\LaTeX\) is a great typesetting system, but it is famously rather arcane to program in when writing packages. This has been improved somewhat by \(\text{Lua}\TeX\), which embeds the Lua scripting language inside the \(\TeX\) engine, but what if you want to use libraries written in a different language?
What it does
\(\text{wasm}\TeX\) embeds a WebAssembly interpreter in \(\LaTeX\), allowing libraries and programs from a wide range of programming languages to be used from within \(\LaTeX\) packages and documents.
How we built it
The main component of \(\text{wasm}\TeX\) is a WebAssembly intepreter written in pure Lua 5.3 (lwasmlib). \(\text{wasm}\TeX\) then provides a \(\LaTeX\) package which loads the Lua library and provides a \(\LaTeX\) interface for loading WebAssembly binaries and calling functions.
Challenges we ran into
Lua is certainly not the best language for writing a WebAssembly interpreter. It uses one-indexed arrays, whereas everything in WebAssembly is zero-indexed, leading to difficult to debug off-by-one errors; it also only has one integer type, making support for all of WebAssembly's integer instructions difficult. \(\text{wasm}\TeX\) currently doesn't implement a few unsigned 64-bit integer instructions or any floating-point instructions, but this is still enough to run many programs and libraries.
Accomplishments that we're proud of
It feels pretty cool to have gone from nothing to having a WebAssembly interpreter capable of running real Rust programs, working by myself with no AI assistance!
What we learned
- Lua isn't a great language for implementing a WebAssembly interpreter (although it's better than trying to do it in \(\TeX\) itself...)
What's next for \(\text{wasm}\TeX\)
Implementing the remaining missing instructions, more modern WebAssembly extensions, finding all of the bugs that are undoubtedly still in there, building out the \(\LaTeX\) interface some more, ...
Log in or sign up for Devpost to join the conversation.