You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
4.12 FOR ADVANCED USERS. 66<br />
The 〈value〉 must be a constant of the appropriate type or a METAFONT expression returning the<br />
appropriate type. It can also be (or include) other variables previously defined. The \setmfcolor<br />
command has been enhanced so that in recent METAPOST the 〈value〉 can be any of the three types<br />
of colors METAPOST allows: numeric (for grayscale color), rgbcolor or cmykcolor. The data type of<br />
〈value〉 will be examined, and the variable 〈name〉 will be declared to be a variable of the appropriate<br />
type. The same is true of \setmfvariable{color}.<br />
As an example of their use, since dimensions are numeric data types in METAFONT, the command<br />
\setmfnumeric{my_spc}{5pt}<br />
\setmfnumeric{my_dia}{.8pt}<br />
would set the METAFONT variables my_spc and my_dia to the values 5pt and .8pt, respectively.<br />
After that, these variables can be used in any drawing command where a dimension is required:<br />
\plot[my_dia,my_spc]{Triangle}\rect{(0,0),(1,1)}<br />
will plot the rectangle with small triangles of diameter .8pt, spaced 5pt apart.<br />
The knowledgeable user may realize that path and picture are METAFONT data types, and<br />
may want use them in \setmfvariable. It is also true that at some level, MFPIC figure macros<br />
produce a path and \mfpimage produces a picture. However, MFPIC commands cannot be used in<br />
the value portion of \setmfvariable. The TEX code that most MFPIC commands produce would<br />
be meaningless to METAFONT. You can store the path produced by figure macros with \store, and<br />
store pictures in variables with \mfpimage or even \tile.<br />
With the obvious exception of the \globalsetmfvariable command, these commands define<br />
the variable locally. That is, the variable will revert to any previous definition (or become undefined)<br />
at the end of the <strong>mfpic</strong> environment it is defined in. It is in fact local to any METAFONT<br />
group. In MFPIC, only \connect . . . \endconnect, \mfpimage . . . \endmfpimage, and \<strong>mfpic</strong><br />
. . . \end<strong>mfpic</strong> create METAFONT groups in the graph file.<br />
A warning about variable names. METAFONT and METAPOST allow multi-part variable names<br />
like ‘arrowhead length’ or ‘X.r’ The part after the first space or ‘.’ is called a suffix. In META-<br />
FONT, variable settings are global unless explicitly made local. The code of the \set... commands<br />
does make the variable setting local. However, METAFONT syntax forbids this localization when a<br />
variable name has a suffix. Moreover, if you localize a variable, METAFONT will localize all variables<br />
with that name plus any suffix. Even more, localizing a variable renders all variables with the<br />
same name plus suffix locally undefined. The command \globalsetmfvariable simply omits the<br />
localization part, so suffixes are permitted, but it cannot ‘globalize’ something that has previously<br />
been localized within the same group.<br />
For example, suppose you use the example code in subsection 4.4.3 and define a custom arrowhead<br />
path myAH and the corresponding clearing path myAH.clear. Suppose now you try to make<br />
this head the default for the \arrow command by doing the following.<br />
\setmfvariable{path}{Arrowhead}{myAH}<br />
Then this assignments is local and makes Arrowhead.clear undefined (locally). You cannot use<br />
\setmfvariable to define Arrowhead.clear; that will produce an error from METAFONT. You<br />
need to do<br />
\setmfvariable{path}{Arrowhead}{myAH}<br />
\globalsetmfvariable{path}{Arrowhead.clear}{myAH.clear}<br />
and both assignments will be local. To make both assignments global, use the global version in both.