[metapost] Dynamic TeX labels in functions
Hartmut Henkel
hartmut_henkel at gmx.de
Thu Nov 11 00:39:59 CET 2004
On Wed, 10 Nov 2004, John S. Walker wrote:
> There is an error message about using btex etex from a file
>
> Here is a file with the macro included.
it seems to work when you include the verbatimtex etex stanza into the
string and use scantokens, otherwise the latex head is missing during
scan. I have tried it with "export TEX=latex".
%%%Begin sparklinef.mp file
input graph;
prologues:=1;
vardef sparkline(text gname)(expr fname,w,h,upper,lower)=
draw begingraph(w,h);
string s,ip ;
numeric endx, endy, gupper, glower;
path p,q;
pair ly, by;
gdata(fname, s, augment.p(i, scantokens s1); );
by:=point 0 of p;
ly:= point infinity of p;
endx:=xpart(ly);
endy:=ypart(ly);
gupper:=upper;
glower:=lower;
q:= (0,gupper)--(endx,gupper)--(endx,glower)--(0,glower)--cycle;
gfill q withcolor 0.8white;
gdraw p withcolor 0.3white;
pickup pencircle scaled 2pt;
gdraw ly withcolor red;
s:= "glabel.rt( verbatimtex \documentclass{article}"
& "\usepackage{color} \begin{document} etex "
& "btex\scriptsize\textsf{"
& decimal endy
& "} etex , ly) withcolor red; glabel.lft(btex \scriptsize \textsf{"
& gname
& "} etex, OUT);";
write s to "sparklabels.tmp";
write EOF to "sparklabels.tmp";
scantokens "input sparklabels.tmp";
Gneedgr_ := false;
Gneedfr_ := false;
endgraph;
enddef;
beginfig(1);
sparkline("glucose")("newdata.d", 36pt, 12pt, 70, 40)
endfig;
bye;
%%%end sparklinef.mp
Regards, Hartmut
More information about the metapost
mailing list