'empty string' test in MP
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. Peter
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) 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
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@ntg.nl http://www.ntg.nl/mailman/listinfo/ntg-context
participants (2)
-
Hans Hagen
-
Peter Rolf