From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/91959 Path: news.gmane.org!not-for-mail From: luigi scarso Newsgroups: gmane.comp.tex.context Subject: Re: TeX capacity exceeded - in Lua block - why? Date: Thu, 16 Jul 2015 15:29:10 +0200 Message-ID: References: <55A76B04.9080608@wxs.nl> Reply-To: mailing list for ConTeXt users NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============0445192029==" X-Trace: ger.gmane.org 1437053408 28753 80.91.229.3 (16 Jul 2015 13:30:08 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 16 Jul 2015 13:30:08 +0000 (UTC) To: mailing list for ConTeXt users Original-X-From: ntg-context-bounces@ntg.nl Thu Jul 16 15:29:57 2015 Return-path: Envelope-to: gctc-ntg-context-518@m.gmane.org Original-Received: from balder.ntg.nl ([5.39.185.229]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1ZFjEY-0006Ji-AX for gctc-ntg-context-518@m.gmane.org; Thu, 16 Jul 2015 15:29:54 +0200 Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 7346D1021C for ; Thu, 16 Jul 2015 15:29:53 +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 ev0RiLXYCA7k for ; Thu, 16 Jul 2015 15:29:52 +0200 (CEST) Original-Received: from balder.ntg.nl (localhost [IPv6:::1]) by balder.ntg.nl (Postfix) with ESMTP id 05C2F1022F for ; Thu, 16 Jul 2015 15:29:18 +0200 (CEST) Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 79CB0101F6 for ; Thu, 16 Jul 2015 15:29:13 +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 H9Mgm6NWAxEH for ; Thu, 16 Jul 2015 15:29:12 +0200 (CEST) Original-Received: from filter4-ams.mf.surf.net (filter4-ams.mf.surf.net [192.87.102.72]) by balder.ntg.nl (Postfix) with ESMTP id 92B10101E6 for ; Thu, 16 Jul 2015 15:29:12 +0200 (CEST) Original-Received: from mail-wg0-x230.google.com (mail-wg0-x230.google.com [IPv6:2a00:1450:400c:c00::230]) by filter4-ams.mf.surf.net (8.14.4/8.14.4/Debian-4) with ESMTP id t6GDTAnO002216 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=NOT) for ; Thu, 16 Jul 2015 15:29:11 +0200 Original-Received: by wgxm20 with SMTP id m20so58530612wgx.3 for ; Thu, 16 Jul 2015 06:29:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=5dwzNIFBempK41rp0vsOIGY0Fv2DSvL0nzvCR74GgdA=; b=Ccz+VKFmZfKRqaIYZAAEWyMIjC3OKC+WWJnxcGGXHL9YLueQ3Yk1wkTVuqLIzCIYV3 yHV9VSJFCU5BlTXkTscka7pKCGDDUWbsi6A4CRd0ZUzmjydLjno5Riwz2qSuK1BZ9Qjr tQXzbI3eJr6xDGjBUig1tLF6e4+KNbRUg76GaJyIoDPBLE48RssaCpGyE1u56AUSB2Mn /vQGVHLYK9LYozH48rnAcEGlg4fa5L/yrIozgb7V/ldqRs2PxnJcm+Sjmv7A9F7qtn2q gZXRCFpdFatXBImZLOkp1ulYkNUjUuVNbvFeD7he1ZE7CqtLDNY9JYX+f/LMEYah7PyF DRQA== X-Received: by 10.194.97.196 with SMTP id ec4mr19224876wjb.3.1437053350792; Thu, 16 Jul 2015 06:29:10 -0700 (PDT) Original-Received: by 10.194.200.106 with HTTP; Thu, 16 Jul 2015 06:29:10 -0700 (PDT) In-Reply-To: X-Bayes-Prob: 0.0001 (Score 0, tokens from: ntg-context@ntg.nl, base:default, @@RPTN) X-CanIt-Geo: ip=2a00:1450:400c:c00::230; country=BE; region=Brussels Capital; city=Brussels; latitude=50.8466; longitude=4.3528; http://maps.google.com/maps?q=50.8466,4.3528&z=6 X-CanItPRO-Stream: uu:ntg-context@ntg.nl (inherits from uu:default, base:default) X-Canit-Stats-ID: 01OR1tb8g - b38894211df6 - 20150716 (trained as not-spam) Received-SPF: pass (filter4-ams.mf.surf.net: domain of luigi.scarso@gmail.com designates 2a00:1450:400c:c00::230 as permitted sender) receiver=filter4-ams.mf.surf.net; client-ip=2a00:1450:400c:c00::230; envelope-from=; helo=mail-wg0-x230.google.com; identity=mailfrom X-Scanned-By: CanIt (www . roaringpenguin . com) X-BeenThere: ntg-context@ntg.nl X-Mailman-Version: 2.1.16 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" Xref: news.gmane.org gmane.comp.tex.context:91959 Archived-At: --===============0445192029== Content-Type: multipart/alternative; boundary=047d7bf0ef187f52e5051afe0e87 --047d7bf0ef187f52e5051afe0e87 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Thu, Jul 16, 2015 at 12:13 PM, Proch=C3=A1zka Luk=C3=A1=C5=A1 Ing. - Pon= tex s. r. o. < LPr@pontex.cz> wrote: > Hello, > > On Thu, 16 Jul 2015 11:03:05 +0200, luigi scarso > wrote: > > \def\GG{\ifmmode G_G\else$\GG$\fi} >> means "define the macro \GG as G_G if mmmod is true, >> else as \GG " >> It's clear that you always are in a situation where mmod is true, then >> \GG >> is replaced with G_G >> > > Well, I intended "replaced with $G_G$", > not "replaced with G_G"; > so I thought this would force/ensure math mode and thus prevent infinite > recursion. > > but as soon as you fall into "mmod not true" then you have infinite >> recursion. >> > > Also, my observation was that my original macro worked well when called > for TeX code (at various places of use: > \GG $\GG$ > \startitemize[][] > \sym{\GG} \GG > \sym{$\GG$} $\GG$ > \sym{\m{\GG}} \m{\GG} > \item End > \stopitemize > ) > but stopped working when called from Lua (?!). > > \def\GG{\ifmmode G_G\else$\GG$\fi} define a macro \GG with replacement text \ifmmode G_G\else$\GG$\fi In your use in TeX, \if is expanded: if we are in mmode then we have the expansion of G ,then _ and then G. If we are not in mmode, then we have the expansion of $ , so we enter in mmode and then we have the expansion of \GG again. In this second level of expansion, we are in mmod for sure and so we end again with G, _ and G. We cannot know what happen in other situations. For example, in \edef\x{\GG} as shown by Hans, at definition time the replacement text is expanded until possible. If at definition time we are not in mmode, this gives the endless sequence \GG ->\ifmmode G_G\else $\GG $\fi {\ifmmode: (level 1) entered on line 9} {false} {\else: \ifmmode (level 1) entered on line 9} \GG ->\ifmmode G_G\else $\GG $\fi {\ifmmode: (level 2) entered on line 9} {false} {\else: \ifmmode (level 2) entered on line 9} \GG ->\ifmmode G_G\else $\GG $\fi {\ifmmode: (level 3) entered on line 9} {false} {\else: \ifmmode (level 3) entered on line 9} \GG ->\ifmmode G_G\else $\GG $\fi .... because in this case the first $ is just accumulated, not interpretated --- i.e. doesn't trig the change of state to math mode. To avoid expansion we can say \edef\x{\noexpand\GG} which means that the replacement text of \x is \GG . Perhaps we can see better here: \def\HH{\ifmmode H_H\else$H_H$\fi} \edef\x{\HH} means, if we are not in mmode when \x is defined, \HH ->\ifmmode H_H\else $H_H$\fi {\ifmmode: (level 1) entered on line 10} {false} {\else: \ifmmode (level 1) entered on line 10} {\fi: \ifmmode (level 1) entered on line 10} {changing \x=3Dundefined} {into \x=3Dmacro:->$H_H$} so the replacement text of \x is $H_H$ --=20 luigi --047d7bf0ef187f52e5051afe0e87 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable


On Thu, Jul 16, 2015 at 12:13 PM, Proch=C3=A1zka Luk=C3=A1=C5=A1 Ing. -= Pontex s. r. o. <LPr@pontex.cz> wrote:
Hell= o,

On Thu, 16 Jul 2015 11:03:05 +0200, luigi scarso <luigi.scarso@gmail.com> wrote:=

=C2=A0\def\GG{\ifmmode G_G\else$\GG$\fi}
means "define the macro \GG as G_G if mmmod is true,
else as \GG "
It's clear that you=C2=A0 always are in a situation where mmod is true,= then \GG
is replaced with=C2=A0 G_G

Well, I intended "replaced with $G_G$",
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0not "replaced with=C2= =A0 G_G";
so I thought this would force/ensure math mode and thus prevent infinite re= cursion.

but as soon as you fall into "mmod not true" then you have infini= te
recursion.

Also, my observation was that my original macro worked well when called for= TeX code (at various places of use:
=C2=A0 \GG $\GG$
=C2=A0 \startitemize[][]
=C2=A0 =C2=A0 \sym{\GG} \GG
=C2=A0 =C2=A0 \sym{$\GG$} $\GG$
=C2=A0 =C2=A0 \sym{\m{\GG}} \m{\GG}
=C2=A0 =C2=A0 \item End
=C2=A0 \stopitemize
)
but stopped working when called from Lua (?!).






\def\GG{\ifmmode G_G\else$\GG$\fi}
defi= ne a macro \GG with replacement text=C2=A0
\ifmmode G_G\else$\GG$= \fi

In your use in TeX, \if is expanded:
=
if we =C2=A0are in mmode then we have the expansion of G ,then =C2=A0_= =C2=A0and then G.
If we are not in mmode, then we have the expan= sion of $ , so we enter in mmode and then we have the expansion of \GG agai= n.
In this second level of expansion, we are in mmod for sure and= =C2=A0so we end again with G, _ =C2=A0and G.

We c= annot know what happen in other situations.

For ex= ample, in=C2=A0
\edef\x{\GG} as shown by Hans,

=
at definition time the replacement text is expanded until possib= le.=C2=A0

If at definition time we are not in mmod= e,
this gives the endless sequence
=C2=A0
\GG ->\ifmmode G_G\else $\GG $\fi=C2=A0
{\ifmmode: (level 1)= entered on line 9}
{false}
{\else: \ifmmode (level 1) = entered on line 9}

\GG ->\ifmmode G_G\else $\GG= $\fi=C2=A0
{\ifmmode: (level 2) entered on line 9}
{fa= lse}
{\else: \ifmmode (level 2) entered on line 9}

\GG ->\ifmmode G_G\else $\GG $\fi=C2=A0
{\ifm= mode: (level 3) entered on line 9}
{false}
{\else: \ifm= mode (level 3) entered on line 9}

\GG ->\ifmmod= e G_G\else $\GG $\fi ....

because in this case the= first $ is just accumulated, not interpretated --- i.e. doesn't trig t= he change of state to math mode.
To avoid expansion we can say
\edef\x{\noexpand\GG}
which means that the= replacement text of \x =C2=A0is \GG .


<= div>Perhaps we can see better here:
\def\HH{\ifmmode H_H\els= e$H_H$\fi}

\edef\x{\HH}
=
means,=C2=A0
if we are not in mmode when \x is defined,<= br>

\HH ->\ifmmode H_H\else $H_H$\fi=C2=A0=
{\ifmmode: (level 1) entered on line 10}
{false}
=
{\else: \ifmmode (level 1) entered on line 10}
{\fi: \ifmmod= e (level 1) entered on line 10}
{changing \x=3Dundefined}
{into \x=3Dmacro:->$H_H$}

so the repla= cement text of \x is $H_H$=C2=A0




--
luigi
--047d7bf0ef187f52e5051afe0e87-- --===============0445192029== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19f X19fX19fX19fX19fX19fX19fX19fX19fX18KSWYgeW91ciBxdWVzdGlvbiBpcyBvZiBpbnRlcmVz dCB0byBvdGhlcnMgYXMgd2VsbCwgcGxlYXNlIGFkZCBhbiBlbnRyeSB0byB0aGUgV2lraSEKCm1h aWxsaXN0IDogbnRnLWNvbnRleHRAbnRnLm5sIC8gaHR0cDovL3d3dy5udGcubmwvbWFpbG1hbi9s aXN0aW5mby9udGctY29udGV4dAp3ZWJwYWdlICA6IGh0dHA6Ly93d3cucHJhZ21hLWFkZS5ubCAv IGh0dHA6Ly90ZXguYWFuaGV0Lm5ldAphcmNoaXZlICA6IGh0dHA6Ly9mb3VuZHJ5LnN1cGVsZWMu ZnIvcHJvamVjdHMvY29udGV4dHJldi8Kd2lraSAgICAgOiBodHRwOi8vY29udGV4dGdhcmRlbi5u ZXQKX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19f X19fX19fX19fX19fX19fX19fX19fX19fX19fX18= --===============0445192029==--