[metapost] Processing comma separated values
adityam at umich.edu
Sat Feb 27 23:27:59 CET 2010
On Fri, 26 Feb 2010, Nicola wrote:
> 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)
> 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
Ah! All this while I was thinking how to get the first two arguments.
> Another possibility is the following:
> def boxsep(text T) =
> forsuffixes B = T : + B.w = -B.e endfor
> + (whatever,whatever)
> 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;
Thanks. This may be useful in the future.
Is the METAFONTbook the only source to learn such tricks?
More information about the metapost