[metapost] Variables inside btex etex
Dan T. Abell
dabell at bikerider.com
Wed Feb 2 00:01:06 CET 2011
What version of MetaPost are you using?
On later versions this fails because of some timing
issues related to the temporary files used by Metapost.
(At least that's my understanding.)
I tend to do something like the following:
%%%%%%%%% this block contains all the labels for the current
%%%%%%%%% .mp file, not just the ones I've shown here
%%%%%%%%% put this in the preamble
%:labels for this set of graphics
%% convert latex strings to pictures
string tick.x[]; picture tlbl.x[]; numeric tick.x.n;
tick.x[1] := "0.0"; % set these explicitly to
tick.x[2] := "0.2"; % avoid MP round-off errors
tick.x[3] := "0.4";
tick.x[4] := "0.6";
tick.x[5] := "0.8";
tick.x[6] := "1.0";
tick.x.n := 6;
%% process these through latex via file mptex
string mptex; mptex = "mptextemp.mp";
%% latex header
write "verbatimtex" to mptex;
write "%&latex" to mptex;
write "\documentclass{revtex4-1}" to mptex; %% use same documentclass as your article/book
write "\usepackage{amsmath}" to mptex;
write "\begin{document}" to mptex;
write "etex" to mptex;
%% for each label
%% write pic.var := btex str.var etex to mptex;
for i = 1 upto tick.x.n:
write "tlbl.x[" & decimal i & "] := btex {$"
& tick.x[i] & "$} etex;" to mptex;
endfor;
%% latex trailer
write "verbatimtex" to mptex;
write "\end{document}" to mptex;
write "etex" to mptex;
write EOF to mptex;
%% read those labels (pictures)
input mptextemp.mp;
%%%%%%%%% inside your beginfig-endfig block
for i = 1 upto tick.x.n:
label.bot(tlbl.x[i], (scantokens tick.x[i], vmin)); endfor;
%%% but you may have to adjust the above for your needs
On 1 Feb 2011, at 12:58, Maurício CA wrote:
> Hi, all,
>
> 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?
>
> Thanks,
> Maurício
>
>
> --
> http://tug.org/metapost/
More information about the metapost
mailing list