[metapost] Automatic labeling

Mojca Miklavec mojca.miklavec.lists at gmail.com
Tue Nov 14 18:42:09 CET 2006


On 11/14/06, Peng Yu wrote:
> Hi,
>
> Suppose I have 100 vertexes, I want to label all of them with the vertex index.
>
> I'm wondering if it is possible to do it with a for loop in metapost.
>
> pair v[];
> v1 := ...;
> v2 := ...
> ...
> v100 = ...;
>
> label(btex $1$ etex, v1);
> label(btex $2$ etex, v2);
> ...
> label(btex $100$ etex, v100);

You can compile the following code with "texexec filename.tex" if you
have ConTeXt installed:

% filename.tex:

\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 don't have ConTeXt, you can first try that on
http://live.contextgarden.net and ask in case of problems with
installation)

Mojca


More information about the metapost mailing list