[Tex/LaTex] How to insert a specific unicode character (such as the ZWNJ symbol) into the text stream via lua code compiled by Lua(La)TeX

luatexsymbolsunicode

How does one instruct Lua(La)TeX — specifically, the lua code invoked via a \directlua directive — to insert a non-ASCII unicode symbol, such as a "zero width non-joiner" symbol (code U+200C), into the text stream? I already know how to do this inside the body of a (Lua)LaTeX document — I'd type something like

 stuff\char"200C{}morestuff

But how does one do this from inside lua code?


Addendum to (hopefully…) clarify what I'm trying to get done. If there's a string in the input stream such as xyz123, I'd like to insert a specific character (this evil invisible ZWNJ character…) between xyz and 123, so that the input stream now is

xyz<ZWNJ>123

I already have the code to (i) find all instances of xyz123 in the input stream and (ii) find the insertion point for the ZWNJ character inside the string xyz123. What I'm stuck with is trying to figure out how to insert the ZWNJ character (a "node" in luatex speak? of what type?) at the insertion location.

Best Answer

In luatex, there is unicode library included. It acts as replacement for string library, so to print some unicode code point, you can use the char function:

function unicode2utf(c)
  -- As parameter pass hexadecimal unicode code point
  return unicode.utf8.char(tonumber(c,16))
end

print(unicode2utf("038F"))    

This will print the omega symbol, as invisible space isn't best character to test :)