[metapost] Automatic labeling (fwd)

Mojca Miklavec mojca.miklavec.lists at gmail.com
Wed Nov 15 14:44:52 CET 2006


On 11/14/06, Boguslaw Jackowski wrote:
>
> I wrote:
> >> \starttext
> >> \startMPcode
> >> pair v[];
> >> v[1]=origin;
> >> v[2]=(1cm,2cm);
> >>
> >> for i=1 upto 2:
> >>    label(textext(decimal i), v[i]); % could be label(textext("abc"))
> >> endfor;
> >> \stopMPcode
> >> \stoptext
>
> >If you remove backslashed commands and add the command
> >
> >  end.
> >
> >at the end, the script should work with mpost.
>
> I was too quick, sorry. You should drop also textext function. Moreover,
> you shoud enclose the code with beginfig ... endfig pair:
>
>    beginfig(100)
>      pair v[];
>      v[1]=origin;
>      v[2]=(1cm,2cm);
>
>      for i=1 upto 2: label(decimal i, v[i]); endfor;
>    endfig;
>
>    end.
>
> A bit more tricky is the placement of the value of the running variable
> (in this case `i') as a part of math formula, say, as a lower or upper
> index.

That's why the first example inside ConTeXt is useful:
   label(textext("$v_" & decimal i & "$"), v[i]);

(But yes, there are also other tools apart from ConTeXt which can do that.)

Mojca


More information about the metapost mailing list