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.
Feedback please.
----- 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"
local BasketA, BasketB = string.gsub (myZtring,
"beta", "BANANA")
tex.print (BasketA)
}%
}% End of \massageZtring
%
The following paragraph has been run through a Lua filter.\par
% 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"
local BasketA, BasketB = string.gsub (myZtring,
"beta", "BANANA")
tex.print (BasketA)
}%
}% End of \massageZtring
%
The following paragraph has been run through a Lua filter.\par
\massageZtring {alpha beta gamma}\par
----- CUT HERE -----