[metapost] Processing comma separated values

Nicola nvitacolonna at gmail.com
Fri Feb 26 22:15:59 CET 2010


In article <alpine.LNX.2.01.1002261133470.25584 at ybpnyubfg.ybpnyqbznva>,
 Aditya Mahajan <adityam at umich.edu> wrote:

> On Fri, 26 Feb 2010, Taco Hoekwater wrote:
> 
> > Aditya Mahajan wrote:
> >> What is the canonical way of processing a list of comma separated values 
> >> in 
> >> metapost.

A similar problem is dealt with in Appendix D of The METAFONTbook. The 
“dirty trick” in your case (working only for pairs) becomes:

def boxsep(suffix A)(text T) =
   -A.e forsuffixes B = T : + B.w = -B.e endfor + (whatever,whatever)
enddef;

having noticed that

b.w - a.e = c.w - b.e = d.w - c.e

can be re-written as

-a.e + b.w = -b.e + c.w = -c.e + d.w

Another possibility is the following:

def boxsep(text T) =
   (whatever,whatever)
   forsuffixes B = T : + B.w = -B.e endfor
   + (whatever,whatever)
enddef;

which has the advantage of permitting for loops in the argument, e.g., 
you may write:

boxsep(a0 for i = 1 upto 100: ,a[i] endfor) = p;

instead of

boxsep(a0, a1, a2, ..., a100) = p;

Nicola



More information about the metapost mailing list