23.10.2014 Views

mfpic-doc.pdf.

mfpic-doc.pdf.

mfpic-doc.pdf.

SHOW MORE
SHOW LESS

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. 74<br />

\assignmfvalue{〈TEX-macro〉}{〈MF-expr〉}<br />

\assignmpvalue{〈TEX-macro〉}{〈MF-expr〉}<br />

\globalassignmfvalue{〈TEX-macro〉}{〈MF-expr〉}<br />

\globalassignmpvalue{〈TEX-macro〉}{〈MF-expr〉}<br />

The command names spelled with ‘mp’ are no different than the ones spelled with ‘mf’. You can<br />

use either spelling with either the metafont or metapost option.<br />

These commands causes the 〈MF-expr〉 to be written to the output file for METAFONT to evaluate.<br />

The resulting value is then written to the .log file of that METAFONT run. On the next TEX run,<br />

if mfpreadlog (see section 2.11) is in effect, the macro 〈TEX-macro〉 will be defined to produce the<br />

resulting value. For example:<br />

\setmfnumeric{s}{2}<br />

\assignmfvalue{\val}{exp s}<br />

\tlabel(1,2){$e^s = \val$}<br />

After METAFONT is run and then TEX run a second time, \val will acquire the definition ‘7.38905’,<br />

the value of exp s when s=2 (i.e., e 2 , correct to at least the fourth decimal place). If mplabels is<br />

in effect, the correct label is written to the figure file only during this second run, and a second<br />

METAPOST run will be required. In many cases (when using <strong>pdf</strong>TEX, for example, or when the label<br />

changes the figure dimensions), a third TEX run will be required to make the figure correct when it<br />

is included in the <strong>doc</strong>ument.<br />

Before METAFONT is run to evaluate the expression, the macro produces ‘???’. Thus, it cannot<br />

be used in places where a number is needed (as in the position arguments of a \tlabel command).<br />

Note also that if a command defined by \assignmfvalue is used in a tlabel with mplabels in effect,<br />

then mplabels must be in effect during the \assignmfvalue command as well.<br />

The ‘global’ version makes the definition of the 〈TEX-macro〉 global, surviving the current<br />

group. In particular, it can be used in other pictures. The plain versions create commands that are<br />

only locally defined. Past versions of this manual stated that you can say<br />

\global\assignmfvalue<br />

to define the macro globally. This turns out not to be true in all cases. If a global definition is needed,<br />

use the global versions above.<br />

Because of the asynchronous nature of the definition process, using \assignmfvalue with the<br />

same macro name more than once in the same <strong>mfpic</strong> environment will not work. The macro becomes<br />

defined upon reading the logfile during the execution of \opengraphsfile, and it will end<br />

up with the last definition encountered. (The same is true for uses outside <strong>mfpic</strong> environments: the<br />

macro acquires the last such definition.) Moreover, the definition is associated to a picture by number.<br />

Which means that reordering the environments or changing the numbering by any means will<br />

require the TEX-METAFONT-TEX sequence (or more) to be repeated.<br />

If the 〈TEX-macro〉 is already defined, no warning will be issued and the command will be redefined,<br />

so be careful in the name chosen. If mplabels is turned off when \assignmfvalue is used,<br />

but turned on before the 〈TEX-macro〉 is used in a \tlabel command, the macro definition will not<br />

be written to the .mp file, and either an error message, or incorrect label will result when METAPOST<br />

tries to make the tlabel.<br />

The concept and much of the code for \assignmfvalue came from Werner Lemberg. However,<br />

I have rewritten it substantially to conform to MFPIC conventions and so any errors are my<br />

responsibility.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!