You’re Using Pandoc Wrong. Here’s How to Actually Build a Document Pipeline.

You know the pain: hours spent tweaking margins, fixing footnotes, chasing inconsistent formatting across documents. It’s tedious. Error-prone. Soul-crushing. But what if I told you there’s a way to turn that drudgery into a single, elegant command?

Meet Pandoc Lua filters. They transform a simple converter into a programmable document processor that makes your formatting problems vanish into thin air. Pandoc Lua filters collapse multi-tool workflows into one script—turning a humble converter into a hidden platform for document engineering.

Most users treat filters as afterthoughts for minor tweaks. That’s like using a Ferrari to buy groceries. They add a tiny Lua script to swap a font or add a footer, never realizing that the real power lies in deep structural transformations—automating table layouts, cross-references, footnotes, even entire section reorganizations.

I learned this the hard way. For months, I bounced between Markdown editors, LaTeX compilers, and manual HTML fixes. My weekly reports took three hours. After one weekend learning how to write a Lua filter that walks Pandoc’s internal AST, my scripting time dropped to twenty minutes. You don’t need to be a programmer to do this—you just need to feel the rage of repeating the same formatting mistake three times in a row.

Here’s the twist: you thought Pandoc was just a Markdown-to-PDF tool. But it’s actually a programmable platform. The same AST that powers simple conversions can be manipulated to insert running headers, generate index entries, or even rewrite the entire document structure based on metadata. You’re not just converting files—you’re building a custom document pipeline that thinks for you.

Take a side: this is brilliant. If you’re not using Lua filters, you’re wasting time. Neutrality is death. Commit to the idea that your current workflow is broken and that a single, well-crafted Lua script can replace five separate tools. I’ve seen teams collapse Confluence exports, Google Doc templates, and LaTeX preambles into one Pandoc command. The best documents aren’t written—they’re generated.

Start by writing a filter that adds a chapter title to every second-level header. Then experiment with pandoc.List manipulation. The steep learning curve is worth it. After you taste the thrill of watching a 200-page PDF assemble itself from a Markdown file, you’ll never go back to manual formatting.

FAQ

Q: I already use Pandoc for conversions. Do I really need Lua filters?

A: Only if you want to eliminate repetitive manual formatting. If your documents are simple Markdown-to-PDF and you never touch styles, you can skip them. But if you ever fix margins, footnotes, or cross-references by hand, Lua filters will save you hours.

Q: How do I start using Lua filters? What's the minimal effort?

A: Write a short Lua script that modifies the AST — for example, adds a running header to every page. Save it as a .lua file and pass `--lua-filter=yourfile.lua` to Pandoc. That’s it. One filter, one line, and your formatting problem disappears.

Q: Isn't this overkill? Shouldn't I just learn LaTeX instead?

A: LaTeX is powerful but punishing for quick documents. Lua filters let you stay in Markdown while applying deep LaTeX-level transformations on demand. Plus, you write one script and reuse it across any output format. That’s flexibility LaTeX can’t match.

📎 Source: View Source