[metapost] test for empty text?

Colin Fraizer metapost at cfraizer.com
Tue May 28 16:28:46 CEST 2013


A great tip. Thanks, Daniel!

 

I had found a workaround for my immediate need using a mixture of delimited
and undelimited text params and some special delimiters, but this is a
better general solution.

 

From: Daniel H. Luecking [mailto:luecking at uark.edu] 
Sent: Tuesday, May 28, 2013 9:55 AM
To: Colin Fraizer; metapost at tug.org
Subject: RE: [metapost] test for empty text?

 

Colin Fraizer [metapost at cfraizer.com] wrote:

> -          Is there a way to test if the replacement text of a macro 
>is empty? 

 

>I have a macro which expands to a color or to empty (0 tokens), 
>in which case I want to use "background". 

I might make use of the fact that a for-loop ignores empty 
items in a list. For example:
 def getmycolor (text clr) = 
   for c = clr,background:
     mycolor := c;
     exitif true;
   endfor
   ...
 enddef;

When the parameter clr is empty, one should get 
  mycolor := background 
on the first (only) iteration of the loop, but when clr 
is an actual color one should get 
  mycolor:=clr;
on the first iteration, and then immediately exit the
loop.


I did not test this, but I have done similar things before.

Dan
-- 

Daniel H. Luecking
Department of Mathematical Sciences
University of Arkansas
Fayetteville, Arkansas

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://tug.org/pipermail/metapost/attachments/20130528/2e99a3c1/attachment.html>


More information about the metapost mailing list