Am 08.11.2011 um 04:45 schrieb Syed N Haider:
Hi All I am new to the Metapost and Context world, and need some help regarding the inclusion of Metapost graphics in ConTeXt documents. I am trying a very simple approach, using a graphic as a background. Here's my sample (using a very basic metapost graphic as a page background in a document):
Metapost: ======== beginfig(0); theta := 360/7; radius := 1in; z0 = origin; z1 = z0 + dir(90)*radius; z2 = z0 + dir(90 + theta)*radius; z3 = z0 + dir(90 + 2*theta)*radius; z4 = z0 + dir(90 + 3*theta)*radius; z5 = z0 + dir(90 + 4*theta)*radius; z6 = z0 + dir(90 + 5*theta)*radius; z7 = z0 + dir(90 + 6*theta)*radius; draw z1 -- z2 -- z3 -- z4 -- z5 -- z6 -- z7 -- cycle; endfig; end;
ConTeXt (after running mpost on the metapost graphic to generate the hexagon.0 file): =====================================================================
\defineoverlay [backg] [{\externalfigure[hexagon.0][width=\overlaywidth,height=\overlayheight]}]
\starttext \noheaderandfooterlines \setupbackgrounds[page][background=backg] %\placefigure %{none} %{\externalfigure[hexagon.0][width=12cm]} \stoptext
With ConTeXt you can include your MetaPost code in the document and the graphic is generated at runtime. \startuseMPgraphic{hexagon} theta := 360/7; radius := 1in; z0 = origin; z1 = z0 + dir(90)*radius; z2 = z0 + dir(90 + theta)*radius; z3 = z0 + dir(90 + 2*theta)*radius; z4 = z0 + dir(90 + 3*theta)*radius; z5 = z0 + dir(90 + 4*theta)*radius; z6 = z0 + dir(90 + 5*theta)*radius; z7 = z0 + dir(90 + 6*theta)*radius; draw (z1 -- z2 -- z3 -- z4 -- z5 -- z6 -- z7 -- cycle) xysized(OverlayWidth,OverlayHeight) ; \stopuseMPgraphic \defineoverlay[hexagon][\useMPgraphic{hexagon}] \setupbackgrounds[page][background=hexagon] \starttext \page[empty] \stoptext For more information about MetaPost graphics take a look into the MetaFun manual (http://pragma-ade.com/show-man-7.htm) which provides many examples. Wolfgang