Are Lua Filters Really as Scary as They Look?

Guten Tag! 👋 

Many greetings from Munich, Germany. In my last email I mentioned there’s a piece of the branded-PDF puzzle I hadn’t explained yet.

If you recall, that piece is called Lua. It allows us to translate things that Quarto has no built-in idea how to handle.

Lets make this specific. In my last email I’ve shared this Quarto file:

And in this code, there is some inline notation to colorize text:

And this actually renders to colored text in HTML:

And also in PDF:

But Quarto on its own would never be able to pull that off. That’s the power of Lua filters. However, as powerful as they can be, they can be quite scary.

Thankfully, many Lua filters you’ll write for Typst output follow the same three-step shape:

  • Recognize the piece of content you care about (eg. a div with a specific class)

  • Hand that piece’s contents to Pandoc and ask it to turn that into valid Typst syntax

  • Glue that Typst syntax into a call to a Typst function that already knows how to lay it out

That’s it. The filter’s job is never to hand-build styled Typst code by gluing raw strings together.

I mean, sure you can let Lua do that. But that’s unnecessarily hard and a pain to debug. Instead, use Lua to find the right content and hand it off to some Typst function.

Of course, the same thing can be done for the HTML output.

How hard is this?

Of course, I’m not going to pretend there’s zero learning curve here. There’s some Lua syntax to get comfortable with, and Quarto’s internal document structure has a few quirks worth knowing about.

But it’s nowhere near as scary as “write a Lua filter” makes it sound from the outside.

And if you care about branded, reusable PDF output (or if your job makes you care), then figuring out how to deal with Lua filers is a pretty important skill to pick up.

This is actually one of the core things I want to walk through in my upcoming live online workshop. I’ll share the full infos about that in my next email. You know, stuff like what’s covered and how the workshop is structured. That sort of thing.

Until then, I’m curious: have you ever hit a spot where Quarto just didn’t know how to translate something to PDF? What was it? Hit reply and tell me.

Talk soon,
Albert

Whenever you’re ready, there are three I can help you:

  1. Automate Your Data Reports: This course helps data analysts eliminate manual copy-paste reporting by automating PDF reports end-to-end, saving hours every cycle and preventing costly mistakes. (Using the lovely Typst language 😍)

  2. Generate Insights in Minutes, not Hours: This comprehensive course teaches you to handle data faster, smarter, and more efficiently.

  3. Bespoke Data Science Solutions: I’ve helped clients build their own data science solutions. Whether building custom web apps, PDF reports, AI automations or teaching workshops, I’ve got you covered. You can reach out to me via this form (or simply hit reply to this email)

Reply

or to participate.