Difference between revisions of "MetaFun - MetaPost in ConTeXt"

From Wiki
Jump to navigation Jump to search
(Details about MPenvironment, MPinclusions, MPpage and staticMPfigure)
m (fix pragma links & typos)
 
(33 intermediate revisions by 9 users not shown)
Line 1: Line 1:
< [[Graphics]]|[[Metafun]]|[[Metapost]]>
+
__TOC__
  
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
 
  
 +
MetaFun is ConTeXt’s extension of the [[MetaPost]] language. It provides a tight integration of both 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 a document.
  
==<cmd>startMPenvironment</cmd>==
+
'''The [[manual:metafun-p.pdf|MetaFun manual]]''', also available in a [[manual:metafun-s.pdf|screen version]].
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>==
+
Don’t miss the illustrations at 100% MetaFun page [https://art-aleatoire.com art-aleatoire].
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 page is a brief overview of some of the commonly used commands.
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>
+
= ConTeXt System Overview =
\starttext
 
\startMPpage
 
draw fullcircle scaled 2cm ;
 
dotlabel.bot(textext("(0,0)"),origin) ;
 
\stopMPpage
 
  
\startMPpage
+
[[File:ConTeXt-System.png|700px]]
draw fullcircle scaled 2cm ;
 
drawarrow (0,0)--(1cm,0) ;
 
label.bot(textext("$r$"),(5mm,0)) ;
 
\stopMPpage
 
  
\stoptext
+
= Commonly used commands =
</texcode>
 
  
Processing this file using
+
; {{cmd|defineMPinstance}}, {{cmd|setupMPinstance}}: used to set up MetaPost invocations with particular features. One use case could be to select a sans serif font for all MetaPost labels.
<texcode>
+
: {{cmd|startMPenvironment}} '''is DEPRECATED''' in which one could place settings that one only wanted to apply in the MetaPost environment, but not in the document itself. One should use {{cmd|defineMPinstance}} and {{cmd|setupMPinstance}}, instead.
texmfstart texexec --pdf filename
 
</texcode>
 
gives a pdf with two pages of graphics.
 
  
==<cmd>startstaticMPfigure</cmd>==
+
; {{cmd|startMPinclusions}}: Inside, one can specify MetaPost files to ''input'', and also define MetaPost functions.
<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,
+
; {{cmd|startuseMPgraphic}}, {{cmd|useMPgraphic}}: defines a piece of graphics code that is processed anew every time the graphic is placed with {{cmd|useMPgraphic}}.
<texcode>
 
\startstaticMPfigure{center}
 
draw fullcircle scaled 2cm ;
 
dotlabel.bot(textext("(0,0)"),origin) ;
 
\stopstaticMPfigure
 
  
\startstaticMPfigure{radius}
+
; {{cmd|startreusableMPgraphic}}, {{cmd|reuseMPgraphic}}: 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}}.
draw fullcircle scaled 2cm ;
 
drawarrow (0,0)--(1cm,0) ;
 
label.bot(textext("$r$"),(5mm,0)) ;
 
\stopstaticMPfigure
 
  
\starttext
+
; {{cmd|startMPcode}}: When reusing a graphic is not important, you can simply use {{cmd|startMPcode}}.
  
Circle centered \usestaticMPfigure[center][width=1cm] at origin with radius
+
; {{cmd|startMPpage}}: produces a page a containing MetaPost graphic. The page is just large enough to contain the 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.  
\usestaticMPfigure[radius][width=1cm] $r=1\,\text{cm}$.
 
  
\stoptext
+
; {{cmd|startstaticMPfigure}}, {{cmd|usestaticMPfigure}}: 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}}. ConTeXt is clever enough to recompile the resulting MetaPost file only if something inside the {{cmd|startstaticMPfigure}} has changed.
</texcode>
 
  
* '''center''' and '''radius''' above are ''labels'' that are used to access the figure.
+
= Documentation and links =
* <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.
 
  
 +
* [[manual:mmakempy.pdf|MakeMPY]]: create MetaPost outlines (by Pragma)
 +
* [[Flow Charts|FlowCharts]]: encapsulated application, demonstration of MetaPost/MetaFun
 +
* [http://www.pragma-ade.nl/general/sources/mptopdf.pdf MPtoPDF]: create PDF from MetaPost (by Pragma)
 +
* [http://www.pragma-ade.nl/show-gra.pdf a few examples of MetaPost graphics]
 +
* [http://www.pragma-ade.nl/articles/art-puzz.pdf Puzzling graphics in MetaPost] (article)
 +
* [http://www.ntg.nl/maps/25/15.pdf metapost metafun. Hans Hagen at MAPS]
 +
* [[Fill Patterns|FillPatterns]]: Fill pattern examples using MetaPost/MetaFun
 +
 +
 +
----
 
[[Category:Graphics]]
 
[[Category:Graphics]]
 
[[Category:Metapost]]
 
[[Category:Metapost]]
 +
 +
 +
{{MetaPost see also}}
 +
{{Metapost navbox}}

Latest revision as of 08:16, 1 July 2022


MetaFun is ConTeXt’s extension of the MetaPost language. It provides a tight integration of both 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 a document.

The MetaFun manual, also available in a screen version.


Don’t miss the illustrations at 100% MetaFun page art-aleatoire.


This page is a brief overview of some of the commonly used commands.

ConTeXt System Overview

ConTeXt-System.png

Commonly used commands

\defineMPinstance, \setupMPinstance
used to set up MetaPost invocations with particular features. One use case could be to select a sans serif font for all MetaPost labels.
\startMPenvironment is DEPRECATED in which one could place settings that one only wanted to apply in the MetaPost environment, but not in the document itself. One should use \defineMPinstance and \setupMPinstance, instead.
\startMPinclusions
Inside, one can specify MetaPost files to input, and also define MetaPost functions.
\startuseMPgraphic, \useMPgraphic
defines a piece of graphics code that is processed anew every time the graphic is placed with \useMPgraphic.
\startreusableMPgraphic, \reuseMPgraphic
For graphics that are the same every time, it is better to use \startreusableMPgraphic: the graphic is compiled only once, and the one resulting picture can be placed at various points with \reuseMPgraphic.
\startMPcode
When reusing a graphic is not important, you can simply use \startMPcode.
\startMPpage
produces a page a containing MetaPost graphic. The page is just large enough to contain the 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.
\startstaticMPfigure, \usestaticMPfigure
The \startuseMPgraphic series of commands were designed for using MetaPost for drawing fancy frames and backgrounds and not for using stand-alone graphics for a document. \startstaticMPfigure creates a separate pdf file containing the graphic. This pdf can be included in the document using \usestaticMPfigure. ConTeXt is clever enough to recompile the resulting MetaPost file only if something inside the \startstaticMPfigure has changed.

Documentation and links