Mojca Miklavec wrote:
Hello,
I'm a bit "out" of programming at the moment (and not following mkiv as deep as I should), but here's one of the old sins that keeps preventing my module to be used in MKIV.
How can I get rid of \startTeXtexts in the following code, so that the code will be usable by both mkii and mkiv? (Metapost code is probably [almost] OK, but the TeX part needs some minor polishing. One could definitely rewrite metapost code into lua, but then I would need to take care for two paralel versions - I do not want to go there since metapost does all the work at the moment.)
Any hinst most welcome, Mojca
\defineconversion [hans and taco] [H,a,n,s,\ ,\&,\ ,T,a,c,o,\ ]
\setupcolors [state=start] \chardef\TeXtextcolormode\zerocount
\startTeXtexts \doloop{\doifelseconversionnumber{hans and taco}{\recurselevel}% % +500 is a hack (hopefully the plot doesn't contain more than 500 labels) % otherwise the points would be overwritten by labels with another \TeXtext: % it might need a fix in ConTeXt core {\TeXtext{\numexpr\recurselevel+500\relax}{\strut{\convertnumber{hans and taco}{\recurselevel}}}}% {\exitloop}}% \stopTeXtexts
\edef\numberofsymbols{1}% \doloop{\doifelseconversionnumber{hans and taco}{\recurselevel}% {\edef\numberofsymbols{\recurselevel}}% {\exitloop}}%
\starttext \startMPcode
color c[]; for i=1 upto \numberofsymbols: c[i] = ((i-1)/(\numberofsymbols-1))[red,blue]; endfor;
vardef the_number(expr n) = ((n mod \numberofsymbols) + 1) enddef;
vardef the_symbol(expr n) = picture pict; pict := sometxt(the_number(n) + 500); pict shifted -.5[llcorner pict,lrcorner pict] enddef;
def draw_point(expr x, y, n) = draw (the_symbol(n) shifted (x,y)) withcolor c[the_number(n)]; enddef;
for i=0 upto 23: draw_point(0,-i*3mm,i); endfor; \stopMPcode
\stoptext
just make a proper tex string ... here 's' \setupcolors[state=start] \unexpanded\def\colored[#1]% {\groupedcommand {\definecolor[@colored@][#1]\doactivatecolor{@colored@}} {}} \starttext \startMPcode vardef draw_point(expr x, y, n) = save s ; string s ; s := "\colored[r=" & decimal (n/25) & "]{" & decimal n & "}" ; draw (textext(s) shifted (x,y)) ; enddef; for i=0 upto 23: draw_point(-i*2mm,-i*3mm,i); endfor; \stopMPcode \stoptext i'll add \colored to the core (this is the mkiv definition) ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------