* Passing text to Metapost functions @ 2005-12-26 3:34 David Arnold 2005-12-26 11:44 ` Hans Hagen 0 siblings, 1 reply; 8+ messages in thread From: David Arnold @ 2005-12-26 3:34 UTC (permalink / raw) All, I'd like to do something like this: create_axes(xmin,xmax,ymin,ymax,ux,uy)(x); Where x will be a label for my x-axis. But once in a while it might be t or u or some other thing such as "Days." I want to use it like this: beginfig(0); %initialize window parameters numeric xmin, xmax, xscl, ymin, ymax, yscl; xmin:=-5; xmax:=5; xscl:=1; ymin:=-5; ymax:=5; yscl:=1; %initialize scale numeric ux, uy; (xmax-xmin)*ux=4in; (ymax-ymin)*uy=3in; %create-axes function vardef create_axes(expr xxmin, xxmax, yymin, yymax, uux, uuy)(text xlbl)= drawdblarrow (1.05*xxmin*uux,0)--(1.05*xxmax*uux,0); label.rt(btex $xlbl$, (1.05*xxmax*uux,0)); drawdblarrow (0,1.05*yymin*uuy)--(0,1.05*yymax*uuy); enddef; create_axes(xmin,xmax,ymin,ymax,ux,uy)(x); endfig; end. Two questions: 1. How can I do this in plain metapost? 2. What would be the "Context Way?" ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Passing text to Metapost functions 2005-12-26 3:34 Passing text to Metapost functions David Arnold @ 2005-12-26 11:44 ` Hans Hagen 2005-12-26 18:04 ` David Arnold 0 siblings, 1 reply; 8+ messages in thread From: Hans Hagen @ 2005-12-26 11:44 UTC (permalink / raw) David Arnold wrote: > 1. How can I do this in plain metapost? > > 2. What would be the "Context Way?" btex ... etex is parsed as-is and therefore cannot be uses this is what the macro textext("...") is for, it writes the (expanded) string to a file and then applies tex to it between runs Hans ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Passing text to Metapost functions 2005-12-26 11:44 ` Hans Hagen @ 2005-12-26 18:04 ` David Arnold 2005-12-26 20:03 ` Willi Egger 2005-12-27 8:09 ` Taco Hoekwater 0 siblings, 2 replies; 8+ messages in thread From: David Arnold @ 2005-12-26 18:04 UTC (permalink / raw) Hans, I've tried various things without much success. I cannot seem to access the contents of xlbl below. Is this approach ever going to work? Note: I am trying to pass the string "x" to the parameter xlbl. %output=pdf \setupcolors[state=start] \definecolor[gridlines][s=0.7] \startMPinclusions color gridlines; gridlines:=\MPcolor{gridlines}; vardef create_grid(expr xxmin,xxmax,xxscl,yymin,yymax,yyscl,uux,uuy)= for k=xxmin step xxscl until xxmax: draw (xmin*uux,k*uuy)--(xmax*uux,k*uuy) withcolor \MPcolor {gridlines}; draw (k*uux,ymin*uuy)--(k*uux,ymax*uuy) withcolor \MPcolor {gridlines}; endfor; enddef; vardef create_axes (expr xxmin,xxmax,yymin,yymax,uux,uuy) (text xlbl) = drawdblarrow (1.05*xxmin*uux,0)--(1.05*xxmax*uux,0); draw textext.origin(\MPstring{xlbl}); drawdblarrow (0,1.05*yymin*uuy)--(0,1.05*yymax*uuy); enddef; \stopMPinclusions \starttext \startMPpage %initialize window parameters numeric xmin, xmax, xscl, ymin, ymax, yscl; xmin:=-5; xmax:=5; xscl:=1; ymin:=-5; ymax:=5; yscl:=1; %initialize scale numeric ux, uy; (xmax-xmin)*ux=4in; (ymax-ymin)*uy=3in; %create the grid create_grid(xmin,xmax,xscl,ymin,ymax,yscl,ux,uy); %create the axes create_axes(xmin,xmax,ymin,ymax,ux,uy)(x); \stopMPpage \stoptext %%% Local Variables: %%% mode: conTeXt-en %%% End: ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Passing text to Metapost functions 2005-12-26 18:04 ` David Arnold @ 2005-12-26 20:03 ` Willi Egger 2005-12-26 21:17 ` David Arnold 2005-12-27 8:09 ` Taco Hoekwater 1 sibling, 1 reply; 8+ messages in thread From: Willi Egger @ 2005-12-26 20:03 UTC (permalink / raw) Hi David, Put the "x" into a variable: \setMPtext{1}{x} you can define the \stetMPtext within the \starttext \stoptext or outside Call create_axes(xmin,xmax,ymin,ymax,ux,uy)(\MPbetex{1}); Willi David Arnold wrote: > Hans, > > I've tried various things without much success. I cannot seem to > access the contents of xlbl below. > > Is this approach ever going to work? > > Note: I am trying to pass the string "x" to the parameter xlbl. > > %output=pdf > > \setupcolors[state=start] > > \definecolor[gridlines][s=0.7] > > \startMPinclusions > > color gridlines; gridlines:=\MPcolor{gridlines}; > > vardef create_grid(expr xxmin,xxmax,xxscl,yymin,yymax,yyscl,uux,uuy)= > for k=xxmin step xxscl until xxmax: > draw (xmin*uux,k*uuy)--(xmax*uux,k*uuy) withcolor \MPcolor > {gridlines}; > draw (k*uux,ymin*uuy)--(k*uux,ymax*uuy) withcolor \MPcolor > {gridlines}; > endfor; > enddef; > > vardef create_axes (expr xxmin,xxmax,yymin,yymax,uux,uuy) (text xlbl) = > drawdblarrow (1.05*xxmin*uux,0)--(1.05*xxmax*uux,0); > draw textext.origin(\MPstring{xlbl}); > drawdblarrow (0,1.05*yymin*uuy)--(0,1.05*yymax*uuy); > enddef; > > \stopMPinclusions > > > \starttext > > \startMPpage > > %initialize window parameters > numeric xmin, xmax, xscl, ymin, ymax, yscl; > xmin:=-5; > xmax:=5; > xscl:=1; > ymin:=-5; > ymax:=5; > yscl:=1; > > %initialize scale > numeric ux, uy; > (xmax-xmin)*ux=4in; (ymax-ymin)*uy=3in; > > %create the grid > create_grid(xmin,xmax,xscl,ymin,ymax,yscl,ux,uy); > > %create the axes > create_axes(xmin,xmax,ymin,ymax,ux,uy)(x); > > \stopMPpage > > \stoptext > > %%% Local Variables: > %%% mode: conTeXt-en > %%% End: > _______________________________________________ > ntg-context mailing list > ntg-context@ntg.nl > http://www.ntg.nl/mailman/listinfo/ntg-context ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Passing text to Metapost functions 2005-12-26 20:03 ` Willi Egger @ 2005-12-26 21:17 ` David Arnold 0 siblings, 0 replies; 8+ messages in thread From: David Arnold @ 2005-12-26 21:17 UTC (permalink / raw) Willi et al, No luck. I can't get any text to show up. I've spent about three days on this, reading, etc., and I'm no closer than I was three days ago. %output=pdf \setupcolors[state=start] \definecolor[gridlines][s=0.7] \startMPinclusions color gridlines; gridlines:=\MPcolor{gridlines}; vardef create_grid(expr xxmin,xxmax,xxscl,yymin,yymax,yyscl,uux,uuy)= for k=xxmin step xxscl until xxmax: draw (xmin*uux,k*uuy)--(xmax*uux,k*uuy) withcolor \MPcolor {gridlines}; draw (k*uux,ymin*uuy)--(k*uux,ymax*uuy) withcolor \MPcolor {gridlines}; endfor; enddef; vardef create_axes (expr xxmin,xxmax,yymin,yymax,uux,uuy) (text xlbl) = drawdblarrow (1.05*xxmin*uux,0)--(1.05*xxmax*uux,0); draw textext.origin(\MPbetex{xlbl}); drawdblarrow (0,1.05*yymin*uuy)--(0,1.05*yymax*uuy); enddef; \stopMPinclusions \starttext \startMPpage %initialize window parameters numeric xmin, xmax, xscl, ymin, ymax, yscl; xmin:=-5; xmax:=5; xscl:=1; ymin:=-5; ymax:=5; yscl:=1; %initialize scale numeric ux, uy; (xmax-xmin)*ux=4in; (ymax-ymin)*uy=3in; %create the grid create_grid(xmin,xmax,xscl,ymin,ymax,yscl,ux,uy); %create the axes \setMPtext{1}{x}; create_axes(xmin,xmax,ymin,ymax,ux,uy)(\MPbetex{1}); \stopMPpage \stoptext %%% Local Variables: %%% mode: conTeXt-en %%% End: ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Passing text to Metapost functions 2005-12-26 18:04 ` David Arnold 2005-12-26 20:03 ` Willi Egger @ 2005-12-27 8:09 ` Taco Hoekwater 2005-12-27 8:24 ` David Arnold 1 sibling, 1 reply; 8+ messages in thread From: Taco Hoekwater @ 2005-12-27 8:09 UTC (permalink / raw) David Arnold wrote: > Hans, > > I've tried various things without much success. I cannot seem to access > the contents of xlbl below. > > Is this approach ever going to work? I can make your example work by passing the argument as a true metapost string: * remove the \MPstring command: draw textext.origin(xlbl); * create_axes(xmin,xmax,ymin,ymax,ux,uy)("x"); But it is out of sync: you always have to call texexec twice whenever you make changes. Cheers, Taco ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Passing text to Metapost functions 2005-12-27 8:09 ` Taco Hoekwater @ 2005-12-27 8:24 ` David Arnold 2005-12-27 8:58 ` Taco Hoekwater 0 siblings, 1 reply; 8+ messages in thread From: David Arnold @ 2005-12-27 8:24 UTC (permalink / raw) OK. But I need it set as btex $x$ etex at the right end of the horizontal axis. On Dec 27, 2005, at 12:09 AM, Taco Hoekwater wrote: > David Arnold wrote: >> Hans, >> I've tried various things without much success. I cannot seem to >> access the contents of xlbl below. >> Is this approach ever going to work? > > I can make your example work by passing the argument as > a true metapost string: > > * remove the \MPstring command: draw textext.origin(xlbl); > * create_axes(xmin,xmax,ymin,ymax,ux,uy)("x"); > > But it is out of sync: you always have to call texexec twice > whenever you make changes. > > Cheers, > Taco > _______________________________________________ > ntg-context mailing list > ntg-context@ntg.nl > http://www.ntg.nl/mailman/listinfo/ntg-context ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Passing text to Metapost functions 2005-12-27 8:24 ` David Arnold @ 2005-12-27 8:58 ` Taco Hoekwater 0 siblings, 0 replies; 8+ messages in thread From: Taco Hoekwater @ 2005-12-27 8:58 UTC (permalink / raw) David Arnold wrote: > OK. But I need it set as btex $x$ etex at the right end of the > horizontal axis. I'm not going to fiddle with the "right end" for you, but You can make it $x$ by: create_axes(xmin,xmax,ymin,ymax,ux,uy)("$x$"); Cheers, Taco ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2005-12-27 8:58 UTC | newest] Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2005-12-26 3:34 Passing text to Metapost functions David Arnold 2005-12-26 11:44 ` Hans Hagen 2005-12-26 18:04 ` David Arnold 2005-12-26 20:03 ` Willi Egger 2005-12-26 21:17 ` David Arnold 2005-12-27 8:09 ` Taco Hoekwater 2005-12-27 8:24 ` David Arnold 2005-12-27 8:58 ` Taco Hoekwater
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).