[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: conditional replace
- From: "Thomas A. Schmitz" <thomas.schmitz@...>
- Date: Mon, 17 Sep 2007 16:19:45 +0200
Hi all,
I'm very new to lua, so forgive me if this is trivial (or
impossible). I want to use lua to process TeX files. Specifically, I
want to convert some characters to Unicode, but only within a certain
environment. I have a solution for this in perl, which is like a
sledgehammer because extracting text from balanced delimiters is
difficult with a regex. I was attracted to lua because its regex
engine has the %b construct, which seems to do just what I need. What
I want to do specifically:
Read a TeX file, convert everything inside the environment \localgreek
{...} into Unicode, leave everything else exactly as it is and write
the result to a new file. I think I know how to extract my passages:
for l in string.gfind(MyText,"localgreek%b{}") do
l = string.gsub(l,'a','α')
print(l)
end
(and so on, I want to make a table of substitutions)
But how do I write the rest of the file back? Sorry if this is a
nobrainer, but I'm certainly not a programmer.
Thanks
Thomas