The ConTeXt wiki has an article about string manipulation, however, when I copy the code directly into my tex file, it compiles this code as text and does not try to compile it. There must be some syntax to place before and after this code, but I cannot find any details about this in the documentation.
\starttext
str = "Luxury Yacht"
rep = {
[1] = { "Luxury", "Throatwobbler" },
[2] = { "Yacht", "Mangrove" },
}
print("My name is spelled “" .. str .. "”, but it's pronounced “" .. lpeg.replacer(rep):match(str) .. "”.")
\stoptext
- How can I use this feature in my document?
- Can I place all of the text from my document inside
print()to perform some changes to all of the text? E.g., to replace all occurrences of "apple" with "fruit" in the document?
I am particularly interested in using the lpeg.replacer(table) feature.
\directlua? – Psirus Jan 17 '12 at 13:05\directluain the manual. I have tried placing\directlua{}around the code, but this is an "Undefined control sequence." – Village Jan 17 '12 at 13:17\directluaprimitive is wrapped up as\ctxlua. – Joseph Wright♦ Jan 17 '12 at 13:46