Skip to content

Instantly share code, notes, and snippets.

@crvdgc
crvdgc / macro.lua
Created December 7, 2024 18:00
Lua functions to find and replace macros in LaTeX strings. Good for [`pandoc` Lua filters](https://pandoc.org/lua-filters.html). For a complete example, see [this lua filter](https://github.com/yuxiliu-arm/herdtools7/blob/0f40e05ff1afe08b1aea8c9be951ef5a8b9b3a38/asllib/doc/filters/aslref.lua).
local M = {}
--- Find pattern in `s` and capture arguments into an array.
--- @param s string
--- @param pattern string
--- @param arity integer
--- @return integer|nil, integer|nil, string[]
local function matchMacroHelper(s, pattern, arity)
local i, j = s:find(pattern)
local args = {}