[NTG-context] 'empty string' test in MP

Peter Rolf indiego at gmx.net
Wed Nov 30 13:36:59 CET 2005


Hans Hagen wrote:
> Peter Rolf wrote:
> 
>> Hi all,
>>
>> I pass a string to a MP graphic using \setMPtext{LABEL}{TEXT}. The
>> string can also be empty, and then no action (for the text) is taken.
>> How can I test in MP, if the given \MPstring{LABEL} is empty?
>>
>> I have tried everything I can imagine in the last one hour, but no
>> success. Not my day...
>>
>> This is the old, not working version
>>
>> if not(\MPstring{LABEL}="") : % is always true.
>>
>>  
>>
> unless to set it to nothign (currently you don't assign it at all)
>
yes and no. I had an older macro

\XXmacro[#1]#2{%
 ...
\ifsecondargument\setMPtext{XX}{\SomeFontsettings\strut#2}\else\setMPtext{XX}{}\fi

which is naturally always true. I replaced it with a \doiftextelse and
now everything is working as expected.
Thanks for the enlightenment and the nice example :)

Peter

> take this:
> 
> \setupcolors[state=start]
> 
> \starttext
> 
> \startuseMPgraphic{test}
>    fill fullcircle
>        scaled 1cm
>        withcolor if not(\MPstring{XX}="") : red else : green fi ;
> \stopuseMPgraphic
> 
> \useMPgraphic{test} \start \setMPtext{XX}{} \useMPgraphic{test} \stop
> 
> \unprotect
> 
> \def\MPtext       #1{\executeifdefined{\@@MPT#1}\empty}
> \def\MPstring    #1{"\executeifdefined{\@@MPT#1}\empty"}
> \def\MPbetex #1{btex \executeifdefined{\@@MPT#1}\empty etex}
> 
> \protect
> 
> \useMPgraphic{test} \start \setMPtext{XX}{} \useMPgraphic{test} \stop
> 
> \stoptext
> 
> the current definitions return "\relax" when a text is not defined; i'll
> change the definitions
> 
> Hans
> _______________________________________________
> ntg-context mailing list
> ntg-context at ntg.nl
> http://www.ntg.nl/mailman/listinfo/ntg-context
> 
> 



More information about the ntg-context mailing list