* Expansion of TeX macros inside the Lua function
@ 2010-08-01 9:45 Jaroslav Hajtmar
2010-08-01 15:08 ` Hans Hagen
0 siblings, 1 reply; 3+ messages in thread
From: Jaroslav Hajtmar @ 2010-08-01 9:45 UTC (permalink / raw)
To: mailing list for ConTeXt users
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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Expansion of TeX macros inside the Lua function
2010-08-01 9:45 Expansion of TeX macros inside the Lua function Jaroslav Hajtmar
@ 2010-08-01 15:08 ` Hans Hagen
2010-08-01 16:00 ` Jaroslav Hajtmar
0 siblings, 1 reply; 3+ messages in thread
From: Hans Hagen @ 2010-08-01 15:08 UTC (permalink / raw)
To: hajtmar, mailing list for ConTeXt users
On 1-8-2010 11:45, Jaroslav Hajtmar wrote:
> \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')}
currently the tex parsing and expansion code is not available in luatex
(future versions might provide some introspection or expansion code, but
it's a hairy topic)
Anyhow, given that \printaction is defined you can use the token library
to see what's in there (you then can sort of reconstruct the content).
Another approach is a two-step:
function step_1(str) -- str = \whatever
tex.print("\ctxlua{step_2('",str,"')}")
end
It all depends on what you want to do. Why do you want to look into
\whatever?
Hans
-----------------------------------------------------------------
Hans Hagen | PRAGMA ADE
Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com
| www.pragma-pod.nl
-----------------------------------------------------------------
___________________________________________________________________________________
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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Expansion of TeX macros inside the Lua function
2010-08-01 15:08 ` Hans Hagen
@ 2010-08-01 16:00 ` Jaroslav Hajtmar
0 siblings, 0 replies; 3+ messages in thread
From: Jaroslav Hajtmar @ 2010-08-01 16:00 UTC (permalink / raw)
Cc: mailing list for ConTeXt users
Thanx very much to Hans.
I see that you understood what I meant. I expected something like this
probably will not do.
I'll try to experiment according to your advice.
You ask why do I need? It is hard for me to explain in English why I
need it.
Only shortly:
I prepared a series of Lua functions, that accesses data from a CSV file
in very general level.
In fact I can in Luacycle print in ConTeXt (but in LuaLaTeX or LuaPlain
too) any reports, forms, mail merge letters, etc.
The user creates a report (using data of row of the CSV table). The user
can in report use TeX macros, that are automaticaly creating during
browsing of the CSV file. Macro names are derived from Excel table
columns (\ cA, \ cB, \ cC, ...) or are created under the header (first
line) CSV table.
I had it working quite well, but I am trying now output from my
applications to use as an input to the database module of Mojca Miklavec.
The problem is that output of my application appears in the one macro
(printmacro \printacion or maybe better \lineaction because it contains
the row data of the CSV table). Unfortunately, I have a macro in
unexpanded form (as one token), because it constantly changes according
to the contents of the current row of CSV table, but Mojca module
requires several values separated by separators.
I hope at least someone can understand my bad English ... Sorry Taco :-)
...
Thank you all for your patience with amateurs such as myself. I have
great admiration for you all and I am privileged to be helping me.
Thanks Jaroslav
Dne 1.8.2010 17:08, Hans Hagen napsal(a):
> On 1-8-2010 11:45, Jaroslav Hajtmar wrote:
>
>> \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')}
>
> currently the tex parsing and expansion code is not available in
> luatex (future versions might provide some introspection or expansion
> code, but it's a hairy topic)
>
> Anyhow, given that \printaction is defined you can use the token
> library to see what's in there (you then can sort of reconstruct the
> content).
>
> Another approach is a two-step:
>
> function step_1(str) -- str = \whatever
> tex.print("\ctxlua{step_2('",str,"')}")
> end
>
> It all depends on what you want to do. Why do you want to look into
> \whatever?
>
> Hans
>
> -----------------------------------------------------------------
> Hans Hagen | PRAGMA ADE
> Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
> tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com
> | www.pragma-pod.nl
> -----------------------------------------------------------------
>
___________________________________________________________________________________
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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2010-08-01 16:00 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-08-01 9:45 Expansion of TeX macros inside the Lua function Jaroslav Hajtmar
2010-08-01 15:08 ` Hans Hagen
2010-08-01 16:00 ` Jaroslav Hajtmar
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).