Hi all, I've started writing a technical book using Quarto markdown, which uses pandoc with Lua filters under the hood to produce a website as well as the publisher's pdf format (via LaTeX). I quite like to keep the source document as plain as possible, and I'm wondering if I could avoid the use of [concept]{.index}, which gets turned into \index{concept}, and instead write a Lua filter with my custom list of keywords, and have pandoc automatically match them as they appear in the text. As a proof of principle I wrote the following code (see below), which matches specific keywords, and reformats them as small-caps. I quickly realised that trailing punctuation, such as "concept, ..." will fail to match, so I'm using gsub to strip such punctuation before matching. It works, but I'm a bit worried: - what's the overhead of such a filter, in practice? From what I understand, every single string element in the AST will be processed by gsub then tested for a match. Are Lua filters walking down the AST fast enough that I shouldn't worry about it? (as far as I can tell on small examples, it seems fine) - assuming this idea is reasonable, I might want to do a few similar operations, e.g. reformatting program languages (as in this example code), wrapping keywords in \index{}, etc., and the exact format will often depend on the output target (html vs TeX etc.). Is there a better construct for this than successive if/else statements to look for matches? (I don't know much Lua) Best regards, baptiste Lua filter: ----- local text = require 'text' local pandoc = require 'pandoc' -- keywords to look for in the document local langs = {"Matlab", "R", "Julia", "C++"} function Includes(tab, val) -- strip trailing punctuation before matching local bare = string.gsub(val,"[%.|,|;|:]", "") for index, value in ipairs(tab) do if value == bare then return true end end return false end function Replace_langname(elem) if Includes(langs, elem.text) then return pandoc.SmallCaps(text.lower(elem.text)) else return elem end end return {{Str = Replace_langname}} -- You received this message because you are subscribed to the Google Groups "pandoc-discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/7f570676-2876-4e29-a8c0-9a765617f141n%40googlegroups.com.