Meer, Hans van der
11. April 2016 um 21:50
But why should typing \MPcolor{\MPvar{color}}be necessary or useful when \MPvar(color) obviously is sufficient?
Or is there a special reason for the nested macros?
Let’s separate your question in two separate things, the first is colors.

There are two way to define colors for a metapost graphics, the first is to define it with metapost itself.

%% begin example
\startMPpage
color myred ; myred := (1,0,0) ;
fill fullcircle scaled 3cm withcolor myred ;
\stopMPpage
%% end example

The disadvantage is that you can use this color only in your graphics but not in your tex code.

Now comes the second method where I define the color in tex with the \definecolor command and access it in metapost with the color \MPcolor command.

%% begin example
\definecolor[myred][r=1]

\startMPpage
fill fullcircle scaled 3cm withcolor \MPcolor{myred} ;
\stopMPpage
%% end example


The second part of the questions concerns metapost variables.

%% begin example
\startuseMPgraphic{mycircle}{diameter,color}
fill fullcircle scaled \MPvariable{diameter} withcolor \MPvariable{color} ;
\stopuseMPgraphic

\startTEXpage
\useMPgraphic{mycircle}{diameter=3cm,color=red}
\stopTEXpage
%% end example

The second argument of the \startuseMPgraphic command initializes
the variables of your command and the \MPvariable accesses the value
of the variable. In this case "color" is only the name of the variable
and doesn’t tell if we want a tex defined color or a metapost defined color.

In my example the color has to be defined in metapost because after
expansion we end with "withcolor red" in the example. We you want
a color which has been defined in tex you have put \MPcolor around
the \MPvariable command, i.e. "\MPcolor{\MPvariable{color}}".

Wolfgang