ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* \doifelse inside MP(code|graphic)
@ 2008-11-18  6:33 Aditya Mahajan
  2008-11-18  8:47 ` Taco Hoekwater
  0 siblings, 1 reply; 4+ messages in thread
From: Aditya Mahajan @ 2008-11-18  6:33 UTC (permalink / raw)
  To: mailing list for ConTeXt users

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

___________________________________________________________________________________
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  : https://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: \doifelse inside MP(code|graphic)
  2008-11-18  6:33 \doifelse inside MP(code|graphic) Aditya Mahajan
@ 2008-11-18  8:47 ` Taco Hoekwater
  2008-11-18  9:06   ` Hans Hagen
  0 siblings, 1 reply; 4+ messages in thread
From: Taco Hoekwater @ 2008-11-18  8:47 UTC (permalink / raw)
  To: mailing list for ConTeXt users



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

___________________________________________________________________________________
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  : https://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: \doifelse inside MP(code|graphic)
  2008-11-18  8:47 ` Taco Hoekwater
@ 2008-11-18  9:06   ` Hans Hagen
  2008-11-18 15:45     ` Aditya Mahajan
  0 siblings, 1 reply; 4+ messages in thread
From: Hans Hagen @ 2008-11-18  9:06 UTC (permalink / raw)
  To: mailing list for ConTeXt users

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
-----------------------------------------------------------------
___________________________________________________________________________________
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  : https://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: \doifelse inside MP(code|graphic)
  2008-11-18  9:06   ` Hans Hagen
@ 2008-11-18 15:45     ` Aditya Mahajan
  0 siblings, 0 replies; 4+ messages in thread
From: Aditya Mahajan @ 2008-11-18 15:45 UTC (permalink / raw)
  To: mailing list for ConTeXt users

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
___________________________________________________________________________________
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  : https://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2008-11-18 15:45 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-11-18  6:33 \doifelse inside MP(code|graphic) Aditya Mahajan
2008-11-18  8:47 ` Taco Hoekwater
2008-11-18  9:06   ` Hans Hagen
2008-11-18 15:45     ` Aditya Mahajan

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).