[NTG-context] \startuseMPgraphic

Alan BRASLAU alan.braslau at cea.fr
Tue Apr 12 00:30:56 CEST 2016

Thank you Wolfgang, this is a very good explanation.

One can simplify one's code, perhaps, by defining MP colors from
ConTeXt colors, as in:
	color orange ; orange := \MPcolor{orange} ;
Then,  one can use orange. There is not much point in redefining the
other colors (red, green, blue, cyan, magenta, yellow, black, white) as
they are defined using the same rgb values.

In fact, \MPcolor{} simply injects "(r,g,b)" or "(c,m,y,k)" with
explicit values into the MP code.

Defining new MP colors is less general than explicitly using
\MPcolor{...}, for it is limiting, and it would be somewhat silly to
add definitions for all of the wonderful colors found in colo-imp-x11,
for example.

By the way, we added colo-imp-crayola having some funky, hallucinogenic
names (according to Hans) as well as colo-imp-ral.
(The first might be of interest to Americans and the second to
Europeans ;-)

Other collections, such as colo-imp-pantone and colo-imp-rosco are not
distributed due to copyright restrictions (but I have made private
copies, shhh!)


On Mon, 11 Apr 2016 22:27:06 +0200
Wolfgang Schuster <schuster.wolfgang at gmail.com> wrote:

> 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}}".

More information about the ntg-context mailing list