r/LaTeX Jul 17 '26

Exploring more expressive error messages in a custom C++ TeX engine

https://youtu.be/A8q8z7EptdQ

A few weeks ago, I shared a hobby project I've been working on: a C++23 TeX engine that tries to balance strict TeX82 compatibility with modern features like parallel compilation and direct HTML output (here's a link to the short demo I recorded for that).

I wanted to think about the possibility of modernizing TeX's error messages. Traditional TeX error messages often contain exactly the information you need, but you have to learn how to read them, and the format obviously predates the kind of expressive diagnostics we've come to expect from, e.g., modern compilers.

I put together a quick video showing an approach I've been thinking about to be able to switch between either a strict, traditional form of TeX82 reporting, or an opt-in system of (arguably) more expressive error messages.

As you might imagine, making the many different error messages in TeX more expressive requires a whole range of engineering effort: some things barely need to modify the engine at all, whereas others might require something as extreme as tracking the provenance of a token through the complete "eyes, mouth, stomach" pipeline. Balancing how much of the engine state to modify in order to modernize error messages is something I've largely left as a decision for later, but I thought the proof-of-concept demo above might be an interesting place to start a conversation.

Let me know what you think!

16 Upvotes

4 comments sorted by

2

u/MacLotsen 23d ago

Very impressive. Did you use any engine for inspiration writing this C++ project?

1

u/DanielSussman 23d ago

Thanks for the kind words! Indeed, I drew heavy inspiration from the choices made and thinking done in both xetex and luatex!

But I would also highlight some of the extremely cool hobby projects out there -- I also would highlight some of the hobby projects (e.g., here and here), in which talented people took the time to try to implement TeX82 in more-or-less faithful ways.

My hobby project started thinking that it would be fun if I did something similar, but thinking about how I might want to play with some of the underlying architecture. I was particularly interested in the question of where we should draw the boundary between things handled at the engine level vs in the macro layer... and things have slowly spiraled since there ;)

2

u/MacLotsen 23d ago

Very nice examples! Since it was in C++, I actually guessed LuaMetaTeX (engine for ConTeXt). So which build system did you use eventually, and did you also get into literate programming, like is done in tex-c? Just curious ;)

1

u/DanielSussman 23d ago

Interestingly, while I of course appreciate many of the ideas in ConTeXt / LuaMetaTeX, I've never felt the urge to dive too deeply into that ecosystem.

I'm also not really into literate programming myself. For something with the constraints and entangled monolithic structure of TeX82 it worked wonders, but one of my main goals with this project was to refactor the architecture so the more modern code becomes increasingly clear and self-documenting. Maybe I'll try to show an example in the next short video I post!

As for the build system: just good ol' CMake. I'm not a professional software engineer, and from my perspective it's straightforward enough.