# [luatex] Using Lua to filter a macro argument

Craig Parker-Feldmann tschaka-doung at email.de
Fri Oct 6 17:30:38 CEST 2017

The following example uses the Lua “string.gsub” function.
I can imagine many of the LaTeX packages of the past could be replaced by processing things with Lua.
What I want to know is: am I going about this in a sensible way? Is using the “string.gsub” function a good idea? I am aware of the LPEG library, but, to be honest, learning it is pretty daunting. I am also unsure as to which strategy I would use to implement the percent character in a pattern expression.

----- CUT HERE -----
% Implements \directlua.
% Takes a TeX stream, and runs it through the
% equivalent of the *NIX “sed” utility in conjunction with
% the “gsub” function.
% Searches for the string “beta” and replaces it with the
% string “BANANA”.
%
\def \massageZtring#1{%
\directlua0{
local myZtring = "#1"
"beta", "BANANA")
}%
}% End of \massageZtring
%
The following paragraph has been run through a Lua filter.\par

\massageZtring {alpha beta gamma}\par
----- CUT HERE -----