[metapost] Variables inside btex etex

Hartmut Henkel hartmut_henkel at gmx.de
Wed Feb 2 00:28:11 CET 2011


On Tue, 1 Feb 2011, Maurício CA wrote:

> I'm tring to use TeX to typeset labels for points x1 to x10. I've just
> realized my naive approach doesn't work:
>
>     for i = 1 step 1 until 10:
>         pair p;
>         p := ((i-1)/9)[(0,h),(0,0)];
>         label(btex "$x_" & decimal(i) & "$" etex, p);
>     endfor;
>
> Is it possible to do that?

that's what the TEX.mp macros are for:

prologues:=3;
input TEX;
beginfig(1)
    h := 20mm;
    for i = 1 step 1 until 10:
        pair p;
        p := ((i-1)/9)[(0,h),(0,0)];
        label(TEX("$x_{" & decimal(i) & "}$"), p);
    endfor;
endfig;
end

Regards, Hartmut


More information about the metapost mailing list