Changes

Jump to navigation Jump to search
\stopMPenvironment
</texcode>
 
An MPenvironment is sort of like <b>verbatimtex..etex</b> in regular (standalone) MetaPost figures. Here is an example of using verbatimtex in a regular MetaPost figure:
<texcode>
verbatimtex
% center-align and stack the two arguments
\def\2#1#2{\vbox{\halign{\hfil##\hfil\cr #1\cr #2\cr}}}
etex
 
beginfig(1)
z0 = (2in,0);
draw fullcircle scaled 3cm;
label(btex \2{sun}{mass $M$} etex, origin);
draw fullcircle scaled 1.5cm shifted z0;
label(btex \2{earth}{mass $m$} etex, z0);
endfig;
end
</texcode>
 
To integrate such a graphic into a ConTeXt source file, there are several choices.
 
1. Place the definition of <b>\2</b> in the MPenvironment. However, that fails (as of the 2006.09.28 beta but it's likely to work soon, knowing Hans) because the definition is stored as a macro itself, and then the parameters #1 and #2 become ##1 and ##2, alas. There is a <b>\startbuffer</b> trick that Hans posted on the mailing list. But perhaps the easiest is:
 
2. Place the definition of <b>\2</b> in the ConTeXt environment, and change <b>btex..etex</b> to <b>\sometxt</b>. Here's an example:
 
<texcode>
% in a large document, put this def in an environment
\def\2#1#2{\vbox{\halign{\hfil##\hfil\cr #1\cr #2\cr}}}
 
\starttext
 
% earth and sun
\startreusableMPgraphic{fig}
z0 = (2in,0);
draw fullcircle scaled 3cm;
label(\sometxt{\2{sun}{mass $M$}}, origin);
draw fullcircle scaled 1.5cm shifted z0;
label(\sometxt{\2{earth}{mass $m$}}, z0);
\stopreusableMPgraphic
 
\reuseMPgraphic{fig}
 
\stoptext
</texcode>
 
Warning: <b>\sometxt</b> cannot be used in loops. Instead use <b>\textext</b>. [Someone who understands why should expand this statement!]
==<cmd>startMPinclusions</cmd>==
127

edits

Navigation menu