<html><head></head><body><div style="font-family: Verdana;font-size: 12.0px;"><div>The following example uses the Lua “string.gsub” function.</div>
<div>I can imagine many of the LaTeX packages of the past could be replaced by processing things with Lua.</div>
<div>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.</div>
<div>Feedback please.</div>
<div>
<div> </div>
<div>----- CUT HERE -----</div>
<div>
<div>% Implements \directlua.<br/>
% Takes a TeX stream, and runs it through the<br/>
% equivalent of the *NIX “sed” utility in conjunction with<br/>
% the “gsub” function.<br/>
% Searches for the string “beta” and replaces it with the<br/>
% string “BANANA”.<br/>
%<br/>
\def \massageZtring#1{%<br/>
\directlua0{<br/>
local myZtring = "#1"<br/>
local BasketA, BasketB = string.gsub (myZtring,<br/>
"beta", "BANANA")<br/>
tex.print (BasketA)<br/>
}%<br/>
}% End of \massageZtring<br/>
%<br/>
The following paragraph has been run through a Lua filter.\par</div>
<div> </div>
<div>\massageZtring {alpha beta gamma}\par</div>
----- CUT HERE -----</div>
</div></div></body></html>