Changes

Jump to navigation Jump to search
4,342 bytes added ,  07:52, 24 June 2020
m
→‎Documentation & Tutorials: delete link to deleted wiki page
< [[Math]], [[MetaFun]], [[Graphics]]__TOC__
MetaPost is a graphical programming language, based on Donald Knuth's MetaFont. Normally MP graphics are converted to PostScript and used with dvips, but ConTeXt can use it directly with PDF (see the
[http://www.pragma-ade.com/general/sources/mptopdf.pdf MP to PDF] manual).
MetaPost is ConTeXt's native graphics language. [[MetaFun- MetaPost in ConTeXt]] is a MetaPost module by Hans Hagen that adds a lot of extra features; it is enabled by default, so one could say that MetaFun is ConTeXt's default dialect of MetaPost.
== Documentation & Tutorials ==
* [http://www.tug.org/docs/metapost/mpman.pdf A User's Manual for MetaPost] <!-- http://cm.bell-labs.com/who/hobby/cstr_162.pdf has its pages reversed -->
* [http://remote.science.uva.nl/~heck/Courses/mptut.pdf Learning METAPOST by doing] ([http://maps.aanhet.net/maps/pdf/32_14.pdf this] and [http://maps.aanhet.net/maps/pdf/32_15.pdf this link] are not working)
* [[manual:metafun-s.pdf|MetaFun]]
* [http://tex.loria.fr/prod-graph/zoonekynd/metapost/metapost.html Lots of examples]
* [[Color in MetaPost]] describes how to get color mixtures, TeX colors, and transparent effects in MetaPost graphics.
= Using MetaPost in ConTeXt =
With {{cmd|startuseMPgraphic}}, you define a piece of graphics code that is processed anew every time the graphic is placed with {{cmd|useMPgraphic}}. Further commands are described at [[MetaFun - MetaPost in ConTeXt]]. <context source=yes>\def\mycolor{.625red} \startuseMPgraphic{name} fill fullcircle scaled 20pt withcolor \mycolor;\stopuseMPgraphic red: \useMPgraphic{name} \def\mycolor{.625blue}blue: \useMPgraphic{name}</context> = Different Packages, Extensions & Applications of Metapost =* [http://www.ctan.org/tex-archive/graphics/metaplot/ MetaPlot] - graph drawing* [http://www.ctan.org/tex-archive/graphics/metapost/contrib/macros/metaobj/ MetaObj] - object-oriented drawing, see also the page about [[MetaObj and Labels]] * [http://stud4.tuwien.ac.at/~e0225855/finomaton/finomaton.html finomaton] - drawing finite state automata* [http://www-math.univ-poitiers.fr/~phan/statsmac.html statsmac] - metapost macros for statistics graphs* [http://metauml.sourceforge.net/ MetaUML] - MetaPost library for typesetting UML diagrams* [http://vigna.dsi.unimi.it/metagraph/ METAGRAPH] - drawing (un)directed graphs == Troubleshooting plain 3D support ==* [http://matagalatlante.org/nobre/featpost/doc/featexamples.html FeatPost]* [http://www.gnu.org/software/3dldf/LDF.html 3DLDF]* [http://www-math.univ-poitiers.fr/~phan/m3Dplain.html m3D] {{todo|needs major review}} = MetaPost relatives === Font Creation ==* [[MetaType1]], see [http://www.ctan.org/tex-archive/fonts/utilities/metatype1/ CTAN] == 3D drawing ==* Test if [http://asymptote.sourceforge.net/ Asymptote] - inspired by MetaPost & fully generalizes MetaPost path construction algorithms to three-dimensions = Testing plain MetaPost =To test whether MetaPost is installed on your system. * , create a file called {{code|test.mp containing this}}:
beginfig(1)
* that should create a postscript file test.1
* open test.1 with a postscript viewer like ghostviewGhostview, okularOkular, … You should see a circle.
== Troubleshooting Testing MetaPost embedded in ConTeXt ==
* create test.tex containing this:If MetaPost is installed on your system and working correctly, you can
\starttext
* that should create a pdf file test.pdf
* open test.pdf with a pdf viewer like acroreadAdobe Acrobat, okularOkular... You should see a circle. = Text in MetaPost = Text that is typeset using `textext` or `btex … etex` adapts to the body font. However, when `label("Foo", pair)` or `"Foo" infont defaultfont` is used, which is not the recommended way, the text is typeset using the font `MetafunDefault`, which can be changed if desired. Example: <context mode="mkiv" source="yes" text="Gives:">\starttext \startMPcode label("Foo", origin); draw textext("Bar") yshifted -LineHeight; \stopMPcode  \definefontsynonym [MetafunDefault] [Bold*default]  \switchtobodyfont [pagella, 18pt]  \startMPcode label("Foo", origin); draw textext("Foo") yshifted -LineHeight; \stopMPcode\stoptext</context>
The recommended way to typeset text is to use the `textext` macro and change the font using {{cmd |setupMPinstance}}. =Repetition of a Text Element to Fill a Bar Using textext = Different Packages Imagine you want to create a frame which consists out of one glyph or a combination of different glyphs in order to make a decorative border. For this purpose a series of such elements should be placed on the bar as pictures, Extensions & Applications evenly spaced. Probably you want to have at the end of Metapost the bar a different glyph inserted as a picture too. The following code is working but the last picture is not the expected glyph. One would expect 14 times the "?" and at the end of the bar a "*": <context mode="mkiv" source="yes" text="Gives:">\starttext \startMPpage picture PicA ; PicA := textext("* [http"); picture PicB ; PicB := textext("?");  numeric Step ; Step := 2cm div bbwidth(PicB) ;  for i = 1 upto Step : draw PicB shifted (i*5mm,0) ; endfor ; draw PicA ; \stopMPpage\stoptext<//www.ctancontext> What you get is 15 "?" but no "*"! In order to get this corrected one needs to calculate the boundingbox of the "?" on beforehand.org/texHans Hagen provided this solution on 14-archive/graphics/metaplot/ MetaPlot] 10- graph drawing2014. <context mode="mkiv" source="yes" text="Gives:">\starttext \startMPcalculation path PicX ; PicX := boundingbox textext("?") ; \stopMPcalculation  \startMPpage picture PicA ; PicA := textext("* [http"); picture PicB ; PicB ://www.ctan.org/tex-archive/graphics/metapost/contrib/macros/metaobj/ MetaObj] - object-oriented drawing= textext("?");  numeric Step ; Step := 2cm div bbwidth(PicX) ; % numeric Step ; Step := 2cm div bbwidth(PicB) ;  for i = 1 upto Step : draw PicB shifted (i*5mm, see also the page about [[MetaObj and Labels]]0) ; endfor ; draw PicA ; \stopMPpage\stoptext
* [http:<//stud4.tuwien.ac.at/~e0225855/finomaton/finomaton.html finomaton] - drawing finite state automata* [http://www-math.univ-poitiers.fr/~phan/statsmac.html statsmac] - metapost macros for statistics graphs* [http://metauml.sourceforge.net/ MetaUML] - MetaPost library for typesetting UML diagrams* [http://vigna.dsi.unimi.it/metagraph/ METAGRAPH] - drawing (un)directed graphscontext>
=== 3D support ===Now you get 14 "?" and the "* [http://matagalatlante".org/nobre/featpost/doc/featexamples.html FeatPost]* [http://www.gnu.org/software/3dldf/LDF.html 3DLDF]* [http://www-math.univ-poitiers.fr/~phan/m3Dplain.html m3D]
{{todo|needs major review}}== A Full Example ==
<context mode="mkiv" source= MetaPost relatives ===== Font Creation =="yes" text="Gives:">* [\setupbodyfont [MetaType1]], see [http://www.ctan.org/tex-archive/fonts/utilities/metatype1/ CTAN8pt]
=== 3D drawing ===* \defineoverlay[http://asymptote.sourceforge.net/ AsymptoteMyframe][\reuseMPgraphic{Frame}] - inspired by MetaPost & fully generalizes MetaPost path construction algorithms to three-dimensions
== Using MP in ConTeXt ==The first way is a usable graphic. Such a graphic is calculated anew each time it is used. An example:\setuppapersize[A8][A8]
<texcode>\setuplayout [topspace=5mm, backspace=5mm, height=middle,\startuseMPgraphic{name} width=middle, fill fullcircle scaled 5cm withcolor red; header=0pt,\stopuseMPgraphic footer=0pt]
\useMPgraphic{name}</texcode>starttext
As said% ======== Definition of the frame in Metafun ==========\startMPcalculation path PicX ; PicX := boundingbox textext("= : =") ;\stopMPcalculation \startreusableMPgraphic{Frame} numeric u, this graphic is calculated each time it is placedv, which can be time consuming. Apart from the time aspectxshift,yshift, this also means that the graphic itself is incorporated many times. Thereforepicwidth, for graphics that don’t changeremnant, CONTEXT provides reusable graphics:nelements;
<texcode> u := OverlayWidth; v := OverlayHeight; path p,w;\startreusableMPgraphic{name} p := unitsquare xscaled u yscaled v; fill w := fullcircle scaled 200pt withcolor .625yellow8pt; picture Edgepic,Linepic[]; color edgedotcolor,linelementcolorA;\stopreusableMPgraphic edgedotcolor := blue; linelementcolorA := red;
Linepic[1] := textext("\reuseMPgraphicrotate[rotation=90]{name= : =}");< Linepic[2] := textext("= : ="); Edgepic := textext("o"); %Calculations for the horizontal frame-element placement: % In order to make this work, the width of the line element needs to be calculated on beforehand. % path PicX; PicX := textext(")("); picwidth := bbwidth(PicX); nelements := u div picwidth; remnant := u mod picwidth; xshift := picwidth + remnant/texcode>nelements;
When reusing a graphic is not so important and you just want to include something inline Linepic[3] := Linepic[2] shifted (0.5*picwidth, you can also use the following:0);
<texcode> for a = llcorner p, ulcorner p :\startMPcode for i = 1 upto nelements : draw Linepic[3] shifted ((xpart a + (i-1)*xshift),ypart a) withcolor linelementcolorA; endfor; endfor; %Calculations for the vertical frame-element placement: picheight fill fullcircle scaled 200pt := bbwidth(PicX); nelements := v div picheight; remnant := v mod picheight; yshift := picheight + remnant/nelements; Linepic[4]:= Linepic[1] shifted (0,0.5*picheight); for a = llcorner p, lrcorner p : for i = 1 upto nelements: draw Linepic[4] shifted (xpart a,ypart a + (i-1)*yshift) withcolor .625yellowlinelementcolorA;\stopMPcode endfor;</texcode> endfor;
See also section 3.3 of [[manual for i = llcorner p, lrcorner p,ulcorner p,urcorner p :metafun-s.pdf|MetaFun manual]]. fill w shifted (xpart i,ypart i) withcolor white; draw Edgepic shifted (xpart i,ypart i) withcolor edgedotcolor; endfor;
=== Examples ===% For frame-element positioning checking:% draw p;%\stopreusableMPgraphic
{{todo|Enable support for Metapost code when running ConTeXt online. This will allow easy creation of Metapost examples, including both source code and resulted figure.}}% ==========
Currently\startframedtext [width=0.8\textwidth, running online Metapost codeheight=0.8\textheight, like this exampleframe=off, does background=Myframe, align={middle,lohi}] The butterfly counts not return anythingmonths but moments, and has time enough. \blank {\tfx Rabindranath Tagore}\stopframedtext\stoptext
<pre>
<context source="yes" text="produces">
\startMPcode
fill fullcircle scaled 200pt withcolor .625yellow;
\stopMPcode
</context>
</pre>
=There is one important remark: The MPcalculation and the drawing itself must be inside \starttext ... \stoptext. = Other Links ==
* Metapost home page: http://tug.org/metapost

Navigation menu