\doifelse inside MP(code|graphic)
Hi, \doifelse does not work inside any MP environment. Something really strange happens if you try to use it. \loggingall tells me what exactly is happening, but I do not know enough low-level TeX to understand why this is happening. Conside this test file %---------------------- \def\test{string} \starttext \doifelse{\test}{string}{test is a string}{or not} \loggingall \startMPcode draw \doifelse{\test}{string}{fullcircle}{fullsquare} scaled 5cm ; \stopMPcode \stoptext %------------------------ It does not compile correctly. Intesting pieces from the log file (actually the MKII log, since that is more interesting) \dostartMPcode #1\stopMPcode ->\startuseMPgraphic {@@}#1\stopuseMPgraphic \useMPgraphic {@@}\endgroup #1<-draw \doifelse {\test }{string}{fullcircle}{fullsquare} scaled 5cm ; ... \doifelse #1#2->\edef \!!stringa {#1}\edef \!!stringb {#2}\ifx \!!stringa \!!stringb \expandafter \firstoftwoarguments \else \expandafter \secondoftwoargument s \fi #1<-\test #2<-string \!!stringa ->currentcolor \test ->string \!!stringb ->black {no mode: \ifx: (level 5) entered on line 11} {false} {\else: \ifx (level 5) entered on line 11} {\expandafter} {\fi: \ifx (level 5) entered on line 11} ..... \ascii -> draw \edef currentcolor{string}\edef black{string}fullsquare scaled 5cm ; {changing \MPascii=undefined} {into \MPascii=macro:-> draw \edef currentcolor{string\ETC.} {\the} Notice the first line of \ascii, and compare that with the definition of \doifelse. The command \!!stringa inside the definition of \doifelse gets expanded too soon. Is there any way to get this work, other than doing the comparison outside the MP code. Aditya
Aditya Mahajan wrote:
Notice the first line of \ascii, and compare that with the definition of \doifelse. The command \!!stringa inside the definition of \doifelse gets expanded too soon. Is there any way to get this work, other than doing the comparison outside the MP code.
Not with \doifelse. If the control sequences are as simple as in the example, you could do the comparison in MP code: def doifelse (expr a, b)(text c)(text d) = if a=b: c else: d fi enddef; draw doifelse("test")("string")(fullcircle)(fullsquare) scaled 5cm ; Best wishes, Taco
Taco Hoekwater wrote:
Aditya Mahajan wrote:
Notice the first line of \ascii, and compare that with the definition of \doifelse. The command \!!stringa inside the definition of \doifelse gets expanded too soon. Is there any way to get this work, other than doing the comparison outside the MP code.
Not with \doifelse. If the control sequences are as simple as in the example, you could do the comparison in MP code:
def doifelse (expr a, b)(text c)(text d) = if a=b: c else: d fi enddef; draw doifelse("test")("string")(fullcircle)(fullsquare) scaled 5cm ;
alternatively, in mkiv there is a fully expandable \expdoifelse but at the cost of lua call (\doifelse uses intermediate macros which is why it is not fully expandable) Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
On Tue, 18 Nov 2008, Hans Hagen wrote:
Taco Hoekwater wrote:
Aditya Mahajan wrote:
Notice the first line of \ascii, and compare that with the definition of \doifelse. The command \!!stringa inside the definition of \doifelse gets expanded too soon. Is there any way to get this work, other than doing the comparison outside the MP code.
Not with \doifelse. If the control sequences are as simple as in the example, you could do the comparison in MP code:
def doifelse (expr a, b)(text c)(text d) = if a=b: c else: d fi enddef; draw doifelse("test")("string")(fullcircle)(fullsquare) scaled 5cm ;
alternatively, in mkiv there is a fully expandable \expdoifelse but at the cost of lua call (\doifelse uses intermediate macros which is why it is not fully expandable)
I just did an expanded comparison outside metapost. It was much easier that way. Thanks, Aditya
participants (3)
-
Aditya Mahajan
-
Hans Hagen
-
Taco Hoekwater