I came across an interesting issue (for me), which is probably the
beginner, but accompanied me for a long time. The problem is probably
that I do not understand very well the principles of operation LuaTeX
and while I want to do more complex things.
I think many beginners will love it when someone indicate solutions.
My problem is that I need in my complex application, evaluate parameters
of Lua functions, which are a TeX macros (respectively their expanded
contents). I did not discover the possibility of expansion of TeX
macros, which is a parameter Lua function.
Here are three examples in which I demonstrate the problem.
1. In first example is function parameter a text string.
\ctxlua{pars('a,b,c,d,e')}
Everything works as expected - evaluation of parameter was carried out
OK - comma separator was found and replaced.
2. In second example is a function parameter a TeX macro \printaction.
Macro expanded before entering the function. Everything works as
expected too - comma separator is found and replaced:
\ctxlua{pars('\printaction')}
3. The third example of my most interesting. Function parameter in
example is a TeX macro \printaction which not expanded, respectively
expanded only when I printing it to TeX. Parameter of function is string
"\printaction" in which it is futile to look for a comma separator.
Comma not be found, although the content of macro face that is so.
\ctxlua{pars('\\printaction')}
Is there a possibility for this case, as in some way to save to Lua
variable content of macro (of course expanded)?
I note that this example is important for me and I would like there to
be a Lua function (eg "expandtostring"), which expanded a TeX macro into
variable until inside function Lua.
I hope the my example (with comments) will be comprehensible and I
apologize if the solution is too trivial. I searched dozens of examples,
but I come across something similar.
Thanx very much - Jaroslav
Here is example:
\startluacode
function pars(inppar)
strpar=tostring(inppar) -- here I need a function "expandtostring(inppar)"
gsubstr=string.gsub(strpar, ',', ';')
tex.print("Input parametr (string or macro): ")
tex.write(inppar)
tex.print("\\par")
tex.print("Content of string (macro): "..strpar) -- There will always be
expansion
tex.print("\\par")
tex.print("Length string (macro): "..string.len(inppar).."\\par")
tex.print("Length of content : "..string.len(strpar).."\\par")
tex.print("Occurrence of the commma separator: "..gsubstr.."\\par")
end
\stopluacode
\def\printaction{x,y,z}
\starttext
Example 1)
Function parameter in first example is a text string. Everything works as
expected - comma separator is found and replaced:
\ctxlua{pars('a,b,c,d,e')}
\blank[big]
Example 2)
Function parameter in second example is a TeX macro \backslash printaction
which expanded before entering the function. Everything works as
expected too - comma separator is found
and replaced:
\ctxlua{pars('\printaction')}
\blank[big]
Example 3)
The third example of my most interesting. Function parameter in example is
a TeX macro \backslash printaction which not expanded, respectively
expanded
only when I printing it to TeX. Parameter of function is still string
"\backslash printaction" in which it is futile to look for a comma
separator.
Comma not be found, although the content of macro face that is so. Is
there a
possibility for this case, as in some way to save to Lua variable
content of
macro (of course expanded)?
\ctxlua{pars('\\printaction')}
\stoptext
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the
Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage : http://www.pragma-ade.nl / http://tex.aanhet.net
archive : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___________________________________________________________________________________