Changes

Jump to navigation Jump to search
Details about MPenvironment, MPinclusions, MPpage and staticMPfigure
< [[Graphics]]|[[Metafun]]|[[Metapost]]>
ConTeXT provides a tight integration of TeX and [[Metapost]]. Metapost can used behind the scenes for some graphic trickery. This integration is also helpful for drawing figures in metapost and use them in the document. Some of the commonly used commands for this are
==<cmd>startMPenvironment</cmd>==
This is used to change the body font for metapost graphics. For example, to get the text in metapost graphics in times, use
 
<texcode>
\usetypescript[times][texnansi]
\switchtobodyfont[times,10pt]
</texcode>
 
==<cmd>startMPinclusions</cmd>==
This can be used for specifying metapost files to ''input'' and also to define metapost functions.
For example
<texcode>
\startMPinclusions
input boxes ;
vardef my_metapost_fun(expr var)=
...
enddef ;
\stopMPinclusions
</texcode>
 
 
==<cmd>startMPpage</cmd>==
This produces a page containing containing metapost graphic. The resulting pdf is self contained (it has all the fonts embedded) This is useful if you want to send the figure to a coauthor or a journal. For example, one can have
 
<texcode>
\starttext
\startMPpage
draw fullcircle scaled 2cm ;
dotlabel.bot(textext("(0,0)"),origin) ;
\stopMPpage
 
\startMPpage
draw fullcircle scaled 2cm ;
drawarrow (0,0)--(1cm,0) ;
label.bot(textext("$r$"),(5mm,0)) ;
\stopMPpage
 
\stoptext
</texcode>
 
Processing this file using
<texcode>
texmfstart texexec --pdf filename
</texcode>
gives a pdf with two pages of graphics.
 
==<cmd>startstaticMPfigure</cmd>==
<cmd>startuseMPgraphic</cmd> series of commands were designed for using metapost for drawing fancy frames and backgrounds and not for using <i>stand-alone</i> graphics for a document. <cmd>startstaticMPfigure</cmd> creates a separate pdf file containing the graphic. This pdf can be included in the document using <cmd>usestaticMPfigure</cmd>. Context is clever enough to recompile the resulting metapost file, only if something inside the start stop staticMPgraphic has changed.
 
For example,
<texcode>
\startstaticMPfigure{center}
draw fullcircle scaled 2cm ;
dotlabel.bot(textext("(0,0)"),origin) ;
\stopstaticMPfigure
 
\startstaticMPfigure{radius}
draw fullcircle scaled 2cm ;
drawarrow (0,0)--(1cm,0) ;
label.bot(textext("$r$"),(5mm,0)) ;
\stopstaticMPfigure
 
\starttext
 
Circle centered \usestaticMPfigure[center][width=1cm] at origin with radius
\usestaticMPfigure[radius][width=1cm] $r=1\,\text{cm}$.
 
\stoptext
</texcode>
 
* '''center''' and '''radius''' above are ''labels'' that are used to access the figure.
* <cmd>usestaticMPfigure</cmd> takes the first argument as the ''label'' of the figure to be inserted. The second argument has the same options as the second argument of <cmd>externalfigure</cmd>
* To force the figure files to be regenerated, remove all the <code>*.mp.md5</code> files from the current directory.
[[Category:Graphics]]
[[Category:Metapost]]

Navigation menu