[metapost] `withprescript' writing order

Dan&Jan Luecking luecking at uark.edu
Thu Dec 27 10:03:36 CET 2007


At 06:58 AM 12/26/2007, you wrote:
>Dear List,
>
>When several `withprescript' drawing options are specified
>for a given object, the order in which the strings are
>written to the output file is the opposite of the order in
>which they appear in the input file.  This does not happen
>with `withpostscript'.  Example:
>
>         beginfig(1)
>           fill fullcircle scaled 2cm withcolor blue
>             withprescript "gsave"
>             withprescript ".3 .setopacityalpha"

Couldn't you write
   withprescript "gsave .3 .setopacityalpha"
?

>             withpostscript "grestore";
>           fill fullcircle scaled 2cm shifted (1cm, 0)
>             withcolor blue;
>         endfig;
>
>The `.setopacityalpha' operator comes before `gsave' in the
>output file, but my intention is the other way round (just
>to alter the graphics state for the first circle).  I wonder
>whether this is a deliberate behaviour as intended by the
>developers: because it is a "prescript", it may make sense
>that LIFO writing order.

I believe all the "with..." operators are left associative.
Thus,
   addto currentpicture contour P % = fill
     withcolor c withpen p withprescript "whatever";
Means
   addto currentpicture
   ((((contour P) withcolor c) withpen p) withprescript "whatever");

So each with-operator applies itself to the picture previously
created, producing a new picture upon which later with-operators
will act. If that means prefixing something and then prefixing
to that, etc., then so be it. It is probably better than trying
to work out a special set of syntax rules for withprescript.

Clipping has a similar effect: If one makes a picture, P, and then
says "clip P to c", the PS code sets up the clipping path c before
the building of picture P.

Adding an explanation to the manual is probably a good idea.
Or it might suggest there should be just one "withprescript".

Dan


Dan Luecking
Fayetteville, Arkansas 



More information about the metapost mailing list