[metapost] Processing comma separated values
Nicola
nvitacolonna at gmail.com
Sat Feb 27 09:29:02 CET 2010
In article <alpine.LNX.2.01.1002241522510.9029 at ybpnyubfg.ybpnyqbznva>,
Aditya Mahajan <adityam at umich.edu> wrote:
> Hi,
>
> What is the canonical way of processing a list of comma separated values
> in metapost. I want to write a helper macro for the boxes package so that
>
> boxsep(a,b,c) = p ;
>
> expands to
>
> b.w - a.e = c.w - b.e = p ;
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