From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/60578 Path: news.gmane.org!not-for-mail From: Jaroslav Hajtmar Newsgroups: gmane.comp.tex.context Subject: Expansion of TeX macros inside the Lua function Date: Sun, 01 Aug 2010 11:45:54 +0200 Message-ID: <4C554252.7000903@gyza.cz> Reply-To: hajtmar@gyza.cz, mailing list for ConTeXt users NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; Format="flowed" Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1280655969 27942 80.91.229.12 (1 Aug 2010 09:46:09 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sun, 1 Aug 2010 09:46:09 +0000 (UTC) To: mailing list for ConTeXt users Original-X-From: ntg-context-bounces@ntg.nl Sun Aug 01 11:46:08 2010 Return-path: Envelope-to: gctc-ntg-context-518@m.gmane.org Original-Received: from balder.ntg.nl ([195.12.62.10]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1OfV7M-00073W-OJ for gctc-ntg-context-518@m.gmane.org; Sun, 01 Aug 2010 11:46:04 +0200 Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 1F161C9DCD; Sun, 1 Aug 2010 11:46:04 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at balder.ntg.nl Original-Received: from balder.ntg.nl ([127.0.0.1]) by localhost (balder.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with LMTP id mjYOkJYHjMzE; Sun, 1 Aug 2010 11:46:03 +0200 (CEST) Original-Received: from balder.ntg.nl (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id C0FCBC9E01; Sun, 1 Aug 2010 11:46:00 +0200 (CEST) Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 13E82C9DCD for ; Sun, 1 Aug 2010 11:46:00 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at balder.ntg.nl Original-Received: from balder.ntg.nl ([127.0.0.1]) by localhost (balder.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with LMTP id QYdg54FwOf5v for ; Sun, 1 Aug 2010 11:45:57 +0200 (CEST) Original-Received: from psi4.forpsi.com (smtpa.forpsi.com [81.2.195.204]) by balder.ntg.nl (Postfix) with SMTP id 4BD62C9E02 for ; Sun, 1 Aug 2010 11:45:57 +0200 (CEST) Original-Received: (qmail 7011 invoked by uid 89); 1 Aug 2010 09:45:54 -0000 Original-Received: from unknown (HELO ?192.168.1.2?) (hajtmar@gyza.cz@88.103.230.14) by psi04 with ESMTPA; 1 Aug 2010 09:45:54 -0000 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; cs; rv:1.9.1.8) Gecko/20100216 Thunderbird/3.0.2 X-BeenThere: ntg-context@ntg.nl X-Mailman-Version: 2.1.12 Precedence: list List-Id: mailing list for ConTeXt users List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: ntg-context-bounces@ntg.nl Errors-To: ntg-context-bounces@ntg.nl Xref: news.gmane.org gmane.comp.tex.context:60578 Archived-At: 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 ___________________________________________________________________________________