On Wed, Dec 3, 2008 at 4:25 PM, Hans Hagen <[EMAIL PROTECTED]> 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/mp-gnuplot.mp
>> 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
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the
Wiki!
maillist : [email protected] / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage : http://www.pragma-ade.nl / http://tex.aanhet.net
archive : https://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___________________________________________________________________________________