metapost code fails to work in mkiv
Hello, A while back I wrote this dirty code (read as: hack) in attachment that allows multiple optional parameters in metapost functions, for example: draw_text("text"); draw_text(angle(30),"text"); draw_text(angle(30),align(right),"text"); draw_text(align(center),"text"); The code compiles fine with mkii, but not with mkiv. I would be grateful for any hints about how to fix this. I get the error: mplib | mp terminal: ! Missing `,' has been inserted. <to be read again> , textext->...etextext(SUFFIX2)(rawtextext((EXPR3)), origin)else:thetextext(SUF... dummy->begingroup(TEXT2) endgroup gp_put_text->...tt)=tt.enddef;pict:=dummy((TEXT1)) ;let,=@;endgroup;draw(gp_t... <*> ...m, 1cm), angle(30), textext.drt("rotated")) ; ; ! An expression can't begin with `;'. <inserted text> 0 <to be read again> , textext->...etextext(SUFFIX2)(rawtextext((EXPR3)), origin)else:thetextext(SUF... Thanks a lot, Mojca (The code is taken out of http://dl.contextgarden.net/modules/t-gnuplot/metapost/context/third/gnuplot... and I'm slowly plucking up my courage to port the code to mkiv.)
Mojca Miklavec wrote:
Hello,
A while back I wrote this dirty code (read as: hack) in attachment that allows multiple optional parameters in metapost functions, for example:
draw_text("text"); draw_text(angle(30),"text"); draw_text(angle(30),align(right),"text"); draw_text(align(center),"text");
The code compiles fine with mkii, but not with mkiv. I would be grateful for any hints about how to fix this.
I get the error:
mplib | mp terminal: ! Missing `,' has been inserted. <to be read again> , textext->...etextext(SUFFIX2)(rawtextext((EXPR3)), origin)else:thetextext(SUF...
dummy->begingroup(TEXT2) endgroup gp_put_text->...tt)=tt.enddef;pict:=dummy((TEXT1)) ;let,=@;endgroup;draw(gp_t... <*> ...m, 1cm), angle(30), textext.drt("rotated")) ; ; ! An expression can't begin with `;'. <inserted text> 0 <to be read again> , textext->...etextext(SUFFIX2)(rawtextext((EXPR3)), origin)else:thetextext(SUF...
Thanks a lot, Mojca
(The code is taken out of http://dl.contextgarden.net/modules/t-gnuplot/metapost/context/third/gnuplot... and I'm slowly plucking up my courage to port the code to mkiv.)
\startMPcode def fuzzy(expr a, b, c) = draw image( draw textext(c) ; currentpicture := currentpicture rotatedaround(center currentpicture,b) shifted a ; ) ; enddef ; fuzzy((1cm,1cm), 30, "rotated") ; \stopMPcode ----------------------------------------------------------------- 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 -----------------------------------------------------------------
On Wed, Dec 3, 2008 at 4:25 PM, Hans Hagen
Mojca Miklavec wrote:
Hello,
A while back I wrote this dirty code (read as: hack) in attachment that allows multiple optional parameters in metapost functions, for example:
draw_text("text"); draw_text(angle(30),"text"); draw_text(angle(30),align(right),"text"); draw_text(align(center),"text");
The code compiles fine with mkii, but not with mkiv. I would be grateful for any hints about how to fix this.
I get the error:
mplib | mp terminal: ! Missing `,' has been inserted. <to be read again> , textext->...etextext(SUFFIX2)(rawtextext((EXPR3)), origin)else:thetextext(SUF...
dummy->begingroup(TEXT2) endgroup gp_put_text->...tt)=tt.enddef;pict:=dummy((TEXT1)) ;let,=@;endgroup;draw(gp_t... <*> ...m, 1cm), angle(30), textext.drt("rotated")) ; ; ! An expression can't begin with `;'. <inserted text> 0 <to be read again> , textext->...etextext(SUFFIX2)(rawtextext((EXPR3)), origin)else:thetextext(SUF...
Thanks a lot, Mojca
(The code is taken out of http://dl.contextgarden.net/modules/t-gnuplot/metapost/context/third/gnuplot... and I'm slowly plucking up my courage to port the code to mkiv.)
\startMPcode def fuzzy(expr a, b, c) = draw image( draw textext(c) ; currentpicture := currentpicture rotatedaround(center currentpicture,b) shifted a ; ) ; enddef ;
fuzzy((1cm,1cm), 30, "rotated") ; \stopMPcode
But what if I wanted the angle to be an optional parameter? (More in the sense that if I decide to add some more parameters later, the old code would still work.) Is there any special reason why the old code doesn't work on mkiv? I have found one possible explanation, though I'm not sure about that: This works: picture a; a := \sometxt{rotated}; gp_put_text((1cm, 1cm), angle(30), a); but this doesn't: gp_put_text((1cm, 1cm), angle(30), \sometxt{rotated}); What does metapost see in mkiv when one puts \sometxt there? Maybe that explains the problem. Mojca
Mojca Miklavec wrote:
On Wed, Dec 3, 2008 at 4:25 PM, Hans Hagen
wrote: Mojca Miklavec wrote:
Hello,
A while back I wrote this dirty code (read as: hack) in attachment that allows multiple optional parameters in metapost functions, for example:
draw_text("text"); draw_text(angle(30),"text"); draw_text(angle(30),align(right),"text"); draw_text(align(center),"text");
The code compiles fine with mkii, but not with mkiv. I would be grateful for any hints about how to fix this.
I get the error:
mplib | mp terminal: ! Missing `,' has been inserted. <to be read again> , textext->...etextext(SUFFIX2)(rawtextext((EXPR3)), origin)else:thetextext(SUF...
dummy->begingroup(TEXT2) endgroup gp_put_text->...tt)=tt.enddef;pict:=dummy((TEXT1)) ;let,=@;endgroup;draw(gp_t... <*> ...m, 1cm), angle(30), textext.drt("rotated")) ; ; ! An expression can't begin with `;'. <inserted text> 0 <to be read again> , textext->...etextext(SUFFIX2)(rawtextext((EXPR3)), origin)else:thetextext(SUF...
Thanks a lot, Mojca
(The code is taken out of http://dl.contextgarden.net/modules/t-gnuplot/metapost/context/third/gnuplot... and I'm slowly plucking up my courage to port the code to mkiv.) \startMPcode def fuzzy(expr a, b, c) = draw image( draw textext(c) ; currentpicture := currentpicture rotatedaround(center currentpicture,b) shifted a ; ) ; enddef ;
fuzzy((1cm,1cm), 30, "rotated") ; \stopMPcode
But what if I wanted the angle to be an optional parameter? (More in the sense that if I decide to add some more parameters later, the old code would still work.)
Is there any special reason why the old code doesn't work on mkiv? I have found one possible explanation, though I'm not sure about that:
This works:
picture a; a := \sometxt{rotated}; gp_put_text((1cm, 1cm), angle(30), a);
but this doesn't:
gp_put_text((1cm, 1cm), angle(30), \sometxt{rotated});
What does metapost see in mkiv when one puts \sometxt there? Maybe that explains the problem.
\long\def\sometxt#1#{\dosometxt{#1}} % grab optional [args] \long\def\dosometxt#1#2% {textext.drt("\ifcsname @@st@@#1\endcsname\csname @@st@@#1\endcsname{#2}\else#2\fi")} so, it sees textext.drt("somestring") ----------------------------------------------------------------- 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 -----------------------------------------------------------------
On Wed, Dec 3, 2008 at 5:00 PM, Hans Hagen wrote:
Mojca Miklavec wrote:
Is there any special reason why the old code doesn't work on mkiv? I have found one possible explanation, though I'm not sure about that:
This works:
picture a; a := \sometxt{rotated}; gp_put_text((1cm, 1cm), angle(30), a);
but this doesn't:
gp_put_text((1cm, 1cm), angle(30), \sometxt{rotated});
What does metapost see in mkiv when one puts \sometxt there? Maybe that explains the problem.
\long\def\sometxt#1#{\dosometxt{#1}} % grab optional [args]
\long\def\dosometxt#1#2% {textext.drt("\ifcsname @@st@@#1\endcsname\csname @@st@@#1\endcsname{#2}\else#2\fi")}
so, it sees textext.drt("somestring")
Thanks a lot! I have found a workaround in that case. I can redefine textext to catch it, revert the weird changes done earlier and finally call the original function: vardef textext@#(expr txt) = let,=@; % this line is needed to annulate earlier hacks thetextext(rawtextext(txt),origin) enddef ; I don't clam that this is a nice thing to do, but it's still better than non-functional code. Another option would be (in the language of TeX, but probably possible to translate to metapost): \let\originaltextext=\textext \def\textext#1{\sometrickeryreversal\originaltextext{#1}} Thanks again, Mojca
Mojca Miklavec wrote:
vardef textext@#(expr txt) = let,=@; % this line is needed to annulate earlier hacks thetextext(rawtextext(txt),origin) enddef ;
brrr, no guarantees Hans ----------------------------------------------------------------- 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 -----------------------------------------------------------------
On Wed, Dec 3, 2008 at 6:28 PM, Hans Hagen wrote:
Mojca Miklavec wrote:
vardef textext@#(expr txt) = let,=@; % this line is needed to annulate earlier hacks thetextext(rawtextext(txt),origin) enddef ;
brrr, no guarantees
I guess I will just change the code when ConTeXt internals change. This trick/hack has a potential to solve a couple of other problems. So I'll keep it for a while. Mojca
Mojca Miklavec wrote:
On Wed, Dec 3, 2008 at 6:28 PM, Hans Hagen wrote:
Mojca Miklavec wrote:
vardef textext@#(expr txt) = let,=@; % this line is needed to annulate earlier hacks thetextext(rawtextext(txt),origin) enddef ;
brrr, no guarantees
I guess I will just change the code when ConTeXt internals change. This trick/hack has a potential to solve a couple of other problems. So I'll keep it for a while.
we can make a context-gnuplot.mem file with its own definition (or maybe even just plain mp and the definition done runtime); but for that i first need to implement multiple instances associated with MPcode cum suis; not that hard but it can wait for a while Hans ----------------------------------------------------------------- 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