Difference between revisions of "Command/startMPinclusions"

From Wiki
Jump to navigation Jump to search
(Created page with "{{Reference |name={{subst:SUBPAGENAME}} |attributes= }} == Syntax == <table cellspacing="4" cellpadding="2" class="cmd"> <tr> <td colspan="2" class="cmd...")
 
m (Taco moved page Environment/MPinclusions to Command/startMPinclusions over a redirect without leaving a redirect)
 
(11 intermediate revisions by 4 users not shown)
Line 3: Line 3:
 
|attributes=
 
|attributes=
 
}}
 
}}
 +
 +
== [[Help:Reference|Syntax]] (autogenerated) ==
 +
<syntax>startMPinclusions</syntax>
  
 
== [[Help:Reference|Syntax]] ==
 
== [[Help:Reference|Syntax]] ==
Line 31: Line 34:
  
 
== Example ==
 
== Example ==
 +
 +
The following example defines a create_wave macro that is then used for the page background.
  
 
<texcode>
 
<texcode>
 
\startMPinclusions
 
\startMPinclusions
input boxes ;
+
  vardef create_wave =
+
    path wave;
vardef my_metapost_fun(expr var)=
+
    wave := (0, 0);
...
+
 
enddef ;
+
    % Number of bezier points along the wave.
 +
    wave_resolution := 20;
 +
 
 +
    % Number of full wave cycles.
 +
    wave_cycles := 2;
 +
 
 +
    for x = 0 step (1 / wave_resolution) until 2 wave_cycles:
 +
      wave := wave .. (x, sin( x * pi ));
 +
    endfor;
 +
 
 +
    % Return the path
 +
    wave
 +
  enddef;
 
\stopMPinclusions
 
\stopMPinclusions
 +
 +
\startuseMPgraphic{page:ThemeBackground}
 +
  path wave;
 +
  wave := create_wave;
 +
  draw wave xyscaled( 60, 20 ) withpen pencircle scaled 1mm;
 +
\stopuseMPgraphic
 +
 +
\defineoverlay[page:ThemeBackground][\uniqueMPgraphic{page:ThemeBackground}]
 +
 +
\starttext
 +
  \setupbackgrounds[page][background={page:ThemeBackground}]
 +
  \startchapter
 +
  \input knuth
 +
  \input zapf
 +
  \input knuth
 +
  \stopchapter
 +
\stoptext
 
</texcode>
 
</texcode>
 +
 +
== Multiple Inclusions ==
 +
 +
To use multiple {{cmd|startMPinclusions}} that should be combined, use ''[+]''. For example, the following code will fail because the second inclusion overwrites the first:
 +
 +
<pre>
 +
\startMPinclusions
 +
  path a ;
 +
\stopMPinclusions
 +
 +
\startMPinclusions
 +
  a := (0,0) -- (1cm,0) ;
 +
\stopMPinclusions
 +
</pre>
 +
 +
Use ''[+]'' to appended the second inclusion after the first:
 +
 +
<pre>
 +
\startMPinclusions
 +
  path a ;
 +
\stopMPinclusions
 +
 +
\startMPinclusions[+]
 +
  a := (0,0) -- (1cm,0) ;
 +
\stopMPinclusions
 +
</pre>
 +
  
 
== See also ==
 
== See also ==
 +
{{MetaPost see also}}
  
 
== Help from ConTeXt-Mailinglist/Forum ==
 
== Help from ConTeXt-Mailinglist/Forum ==
Line 48: Line 110:
 
{{Forum|startMPinclusions}}
 
{{Forum|startMPinclusions}}
  
[[Category:Commands|startMPinclusions]]
+
[[Category:Command/MetaPost|startMPinclusions]]

Latest revision as of 09:34, 7 August 2020

\startMPinclusions

Syntax (autogenerated)

\startMPinclusions[...]{...} ... \stopMPinclusions
[...]+
{...}metafun minifun extrafun lessfun doublefun binaryfun decimalfun mprun metapost nofun doublepost binarypost decimalpost simplefun


Syntax

\startMPinclusions[...][...][...]
[...] text
[...] text
[...] text

Description

Inside \startMPinclusions one can specify MetaFun code that you would like to be present in your MetaPost instance. It is generally used to define MetaPost functions, or to input files that contain them.

Example

The following example defines a create_wave macro that is then used for the page background.

\startMPinclusions
  vardef create_wave =
    path wave;
    wave := (0, 0); 

    % Number of bezier points along the wave.
    wave_resolution := 20;

    % Number of full wave cycles.
    wave_cycles := 2;

    for x = 0 step (1 / wave_resolution) until 2 wave_cycles:
      wave := wave .. (x, sin( x * pi ));
    endfor;

    % Return the path
    wave
  enddef;
\stopMPinclusions

\startuseMPgraphic{page:ThemeBackground}
  path wave;
  wave := create_wave;
  draw wave xyscaled( 60, 20 ) withpen pencircle scaled 1mm;
\stopuseMPgraphic

\defineoverlay[page:ThemeBackground][\uniqueMPgraphic{page:ThemeBackground}]

\starttext
  \setupbackgrounds[page][background={page:ThemeBackground}]
  \startchapter
  \input knuth
  \input zapf
  \input knuth
  \stopchapter
\stoptext

Multiple Inclusions

To use multiple \startMPinclusions that should be combined, use [+]. For example, the following code will fail because the second inclusion overwrites the first:

\startMPinclusions
   path a ;
\stopMPinclusions

\startMPinclusions
   a := (0,0) -- (1cm,0) ;
\stopMPinclusions

Use [+] to appended the second inclusion after the first:

\startMPinclusions
   path a ;
\stopMPinclusions

\startMPinclusions[+]
   a := (0,0) -- (1cm,0) ;
\stopMPinclusions


See also

Help from ConTeXt-Mailinglist/Forum

All issues with: