[do we need TeXtexts in MkIV]: how to rewrite \startTeXtexts?
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
On Sat, Oct 4, 2008 at 2:50 AM, 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?
It must be something trivial, but this one (bad try) eats backslashes: vardef sometxtm(expr n) = textext("\\convertnumber{hans and taco}{2}") enddef; ... pict := sometxtm(n); Mojca
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 -----------------------------------------------------------------
\unexpanded\def\colored[#1]% {\groupedcommand {\definecolor[@colored@][#1]\doactivatecolor{@colored@}} {}}
i'll add \colored to the core (this is the mkiv definition)
Concerning this specific issue: I often miss \color[r=.5,g=.5]{something orange} in mkii as well. Is the "command space" in the definition of \color command itself already polluted, so that this is not possible? \color is very complex command, so there's probably a chance that "if argument are assignments, then define the color first and then use it, if it's not assignment, use the already known color" would not work. Is there any specific reason why only mark iv (apart from the fact that you consider mkii "frozen")? Mojca (I have some more questions concerning this thread.)
Mojca Miklavec wrote:
Concerning this specific issue: I often miss \color[r=.5,g=.5]{something orange} in mkii as well. Is the "command space" in the definition of \color command itself already polluted, so that this is not possible? \color
permitting this in \color would slow down thsi command too much so best use a dedicated one
is very complex command, so there's probably a chance that "if argument are assignments, then define the color first and then use it, if it's not assignment, use the already known color" would not work.
Is there any specific reason why only mark iv (apart from the fact that you consider mkii "frozen")?
i added it to both ----------------------------------------------------------------- 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 -----------------------------------------------------------------
participants (2)
-
Hans Hagen
-
Mojca Miklavec