From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/78110 Path: news.gmane.org!not-for-mail From: Aditya Mahajan Newsgroups: gmane.comp.tex.context Subject: Re: TeX expansion within lua Date: Tue, 4 Sep 2012 11:28:56 -0400 (EDT) Message-ID: References: <20120904171243.3f70b4a6@homerow> Reply-To: mailing list for ConTeXt users NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; Format="flowed" Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1346772548 10383 80.91.229.3 (4 Sep 2012 15:29:08 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 4 Sep 2012 15:29:08 +0000 (UTC) To: mailing list for ConTeXt users Original-X-From: ntg-context-bounces@ntg.nl Tue Sep 04 17:29:10 2012 Return-path: Envelope-to: gctc-ntg-context-518@m.gmane.org Original-Received: from balder.ntg.nl ([195.12.62.10]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1T8v3s-00076J-A2 for gctc-ntg-context-518@m.gmane.org; Tue, 04 Sep 2012 17:29:08 +0200 Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 4B80C10200; Tue, 4 Sep 2012 17:29:05 +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 VDhMlealIpe4; Tue, 4 Sep 2012 17:29:03 +0200 (CEST) Original-Received: from balder.ntg.nl (localhost [IPv6:::1]) by balder.ntg.nl (Postfix) with ESMTP id 5215E101F8; Tue, 4 Sep 2012 17:29:03 +0200 (CEST) Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 77874101F8 for ; Tue, 4 Sep 2012 17:29:01 +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 DBsDOsjyHoMa for ; Tue, 4 Sep 2012 17:29:00 +0200 (CEST) Original-Received: from filter3-utr.mf.surf.net (filter3-utr.mf.surf.net [195.169.124.154]) by balder.ntg.nl (Postfix) with ESMTP id 9DEE3101EB for ; Tue, 4 Sep 2012 17:29:00 +0200 (CEST) Original-Received: from tombraider.mr.itd.umich.edu (smtp.mail.umich.edu [141.211.12.86]) by filter3-utr.mf.surf.net (8.14.3/8.14.3/Debian-9.4) with ESMTP id q84FSvpD015375 for ; Tue, 4 Sep 2012 17:28:59 +0200 Original-Received: FROM adi-netbook (bas3-montreal02-1096679445.dsl.bell.ca [65.94.0.21]) By tombraider.mr.itd.umich.edu ID 50461E38.641DE.6168 ; Authuser adityam; 4 Sep 2012 11:28:56 EDT In-Reply-To: <20120904171243.3f70b4a6@homerow> User-Agent: Alpine 2.02 (LNX 1266 2009-07-14) X-Bayes-Prob: 0.0001 (Score 0, tokens from: @@RPTN) X-CanIt-Geo: ip=141.211.12.86; country=US; region=MI; city=Ann Arbor; postalcode=48109; latitude=42.2923; longitude=-83.7145; metrocode=505; areacode=734; http://maps.google.com/maps?q=42.2923,-83.7145&z=6 X-CanItPRO-Stream: uu:ntg-context@ntg.nl (inherits from uu:default, base:default) X-Canit-Stats-ID: 08HT3sW31 - e4e495bc5c5a - 20120904 (trained as not-spam) X-Scanned-By: CanIt (www . roaringpenguin . com) on 195.169.124.154 X-BeenThere: ntg-context@ntg.nl X-Mailman-Version: 2.1.14 Precedence: list List-Id: mailing list for ConTeXt users List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ntg-context-bounces@ntg.nl Original-Sender: ntg-context-bounces@ntg.nl Xref: news.gmane.org gmane.comp.tex.context:78110 Archived-At: On Tue, 4 Sep 2012, Marco Patzer wrote: > Hi, > > please have a look at the following example: > > \starttext > > \def\cmd{% > \def\mymacro{Foobar} > \newtoks\mytoks > \mytoks={mytoks}} > > \startluacode > context.cmd() > context.mymacro() > -- this fails > -- context(tex.toks.mytoks) > \stopluacode > > -- this works > \startluacode > context(tex.toks.mytoks) > \stopluacode > > \stoptext > > Why does the first call to tex.toks.mytoks fail? > > Apparently the luacode environment has to be closed for cmd to be > expanded. I guess that the call to mymacro() succeeds is a quirk due > to the face that the macro is expanded later, in contrast to tokens, > dimens and counters. > > Is there a command I can use within Lua to expand a macro > immediately or to expand the pending macros to be able to access the > values like the token register in the example? Instead of context(tex.toks.mytoks) use context(function () context(tex.toks.mytoks) end) See the ConTeXt Lua Document manual for explanation. > > Another question which is related: > > Is there a way to access the contents of the macro from within Lua > like counters and token registers? > > \starttext > > \newtoks\mytoks > \mytoks={Foobar} > > \startluacode > local tok = tex.toks.mytoks > > -- something like this is what I have in mind > -- local mac = tex.macros.somemacro > \stopluacode > > \stoptext > > I am just interested in a text string, not a box with typeset > material. I guess that's more difficult, since macros are expanded > and not just simply read. AFAIK, this is not possible. Aditya ___________________________________________________________________________________ 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 ___________________________________________________________________________________