Changes

Jump to navigation Jump to search
m
Adding {{Metapost navbox}}
< [[Graphics]]|[[Metafun]]|[[Metapost]]>
ConTeXT provides a tight integration of TeX and [[MetapostMetaPost]]. Metapost MetaPost can used behind the scenes for some graphic trickery. This integration is also helpful for drawing figures in metapost MetaPost and use them in the document. Some This page is a brief overview of some of the commonly used commands for this are.
== \defineMPinstance and \setupMPinstance ==
==<{{cmd>startMPenvironment</|defineMPinstance}} and {{cmd>==This is |setupMPinstance}} can be used to change the body set up MetaPost invocations with particular features. One use case could be to select a sans serif font for metapost graphicsall MetaPostlabels. For example, to get the text in metapost graphics in times, use
<texcode>=== \startMPenvironment\usetypescript[times][texnansi]\switchtobodyfont[times,10pt]\stopMPenvironment</texcode>===
==<{{cmd>startMPinclusions</cmd>==This can be used for specifying metapost files to |startMPenvironment}} is a '''deprecated'input'' and also evironment in which one could place settings that one only wanted to define metapost functions.For example<texcode>\startMPinclusions input boxes ; vardef my_metapost_fun(expr var)= .apply in the MetaPost environment, but not in the document itself.One should use {{cmd|defineMPinstance}} and {{cmd|setupMPinstance}}, instead. enddef ;\stopMPinclusions</texcode>
== \startMPinclusions ==
==<Inside {{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 |startMPinclusions}} one can specify MetaPost files to send the figure to a coauthor or a journal''input'', and also define MetaPost functions. For example, one can have
<texcode>== \starttextstartuseMPgraphic and \startMPpage draw fullcircle scaled 2cm ; dotlabel.bot(textext("(0,0)"),origin) ;\stopMPpageuseMPgraphic ==
\startMPpage draw fullcircle scaled 2cm ; drawarrow (0,0)--(1cm,0) ; label{{cmd|startuseMPgraphic}}defines a piece of graphics code that is processed anew every time the graphic is placed with {{cmd|useMPgraphic}}.bot(textext("$r$"),(5mm,0)) ;\stopMPpage
== \stoptextstartreusableMPgraphic and \reuseMPgraphic ==</texcode>For graphics that are the same every time, it is better to use {{cmd|startreusableMPgraphic}}: the graphic is compiled only once, and the one resulting picture can be placed at various points with {{cmd|reuseMPgraphic}}.
Processing this file using<texcode> texmfstart texexec --pdf filename</texcode>gives a pdf with two pages of graphics.== \startMPcode ==
==<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 When reusing a separate pdf file containing the graphic. This pdf is not important, you can be included in the document using <simply use {{cmd>usestaticMPfigure</cmd>. Context is clever enough to recompile the resulting metapost file, only if something inside the start stop staticMPgraphic has changed|startMPcode}}.
For example,<texcode>== \startstaticMPfigure{center} draw fullcircle scaled 2cm ; dotlabel.bot(textext("(0,0)"),origin) ;\stopstaticMPfigurestartMPpage ==
\startstaticMPfigure{radius{cmd|startMPpage}} draw fullcircle scaled 2cm ; drawarrow (0,0)-produces a page a containing MetaPost graphic. The page is just large enough to contain the graphic. The resulting pdf is self-contained (1cm,0it has all the fonts embedded) ; labelThis is useful if you want to send the figure to a coauthor or a journal.bot(textext("$r$"),(5mm,0)) ;\stopstaticMPfigure
== \starttextstartstaticMPfigure ==
Circle centered \The {{cmd|startuseMPgraphic}} 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}} creates a separate pdf file containing the graphic. This pdf can be included in the document using {{cmd|usestaticMPfigure[center][width=1cm] at origin with radius\usestaticMPfigure[radius][width=1cm] $r=1\,\text}}. ConTeXt is clever enough to recompile the resulting MetaPost file only if something inside the {{cmcmd|startstaticMPfigure}}$has changed.
\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.==Transparent colors in figures== You can use transparent colors! For example[[Category:Graphics]] <texcode>\runMPgraphicstrue\setupcolors[state=start[Category:Metapost]\starttext\startreusableMPgraphic{a}fill unitsquare scaled 1cm withcolor yellow;fill unitsquare shifted (0.5,0.5) scaled 1cm withcolor transparent(1,0.5,red);\stopreusableMPgraphic \placefigure[force,none]{}{\reuseMPgraphic{a}}\stoptext</texcode> If you see black squares rather than a yellow one underneath a partially transparent red one, then you probably hit the 'missing specials' problem diagnosed by Taco (ntg-context list, 23 Sep 2006 22:00:42 +0200):
<pre>== See also ==This all sounds like {{MetaPost see also}}* section 3.3 of the 'missing specials' problem that is causedby conflicting [[manual:metafun-progname= arguments when using the web2c versionof metaposts.pdf|MetaFun manual]].
Make sure you do not have conflicting memory settings for both main_memory.mpostas well as main_memory.metafun The best is to remove all trace of '.mpost' and '.metafun' memorysettings from your texmf.cnf, but at least make sure all the'.mpost' and 'metafun' values are the same . Then regenerate metafun using texexec --make, and all should bewell again.</pre> And indeed it fixed it for me (Sanjoy). These were the memory setting in the ''/etc/texmf/texmf.d/95NonPath.cnf''configlet that is part of Debian and Ubuntu distributions of TeX: <pre>main_memory = 1000000 % words of inimemory available; also applies to inimf&mpmain_memory.context = 1500000main_memory.mpost = 1500000</pre> I commented out the .mpost line (there was no separate metafun line,which I guess instead used the main_memory value of 1000000),regenerated ''/etc/texmf/texmf.cnf'' with ''update-texmf'' (as root), then regenerated metafun with ''texexec --make metafun'' (as me) and transparency worked. [[Category:Graphics]][[Category:{{Metapost]]navbox}}

Navigation menu