[NTG-context] MetaFun: MetaPost example works with `mpost` but not embedded in ConTeXt: `! Redundant equation.`

2011-12-11 Thread Paul Menzel
Dear ConTeXt folks,


looking for graphics example and therefore searching the list I found
the answer from David Arnold in the ntg-context list thread »OT: looking
for metapost/fun examples« [1].

It is for plain MetaPost and works fine with `mpost` after making sure
to remove the line breaks inserted by the mail program.

I then copied it into `\{start,stop}useMPgraphic`, removed the `end ;`
and `{begin,end}fig` and replaced `{e,b}tex` by `textext()` but still
get the following error.

! terminal: ! Redundant equation.
to be read again 
   ;
* ...500; dt:=(tstop-tstart)/N; (b-a)*ux=1.75in;
   (d-c)*uy=1.75in; 
q=(a,c)-...

! Redundant equation.
to be read again 
   ;
* ...start)/N; (b-a)*ux=1.75in; (d-c)*uy=1.75in;
   
q=(a,c)--(b,c)--(b,d)--(a...


.

system   tex  error on line 39 in file arnold-2005.tex: 
terminal: ! Redundant equation.
to be read again 
   ;
* ...500; dt:=(tstop-tstart)/N; (b-a)*ux=1.75in;
   (d-c)*uy=1.75in; 
q=(a,c)-...

! Redundant equation.
to be read again 
   ;
* ...start)/N; (b-a)*ux=1.75in; (d-c)*uy=1.75in;
   
q=(a,c)--(b,c)--(b,d)--(a...

Does someone have an idea why this fails and how to fix it?


Thanks,

Paul


[1] http://www.ntg.nl/pipermail/ntg-context/2005/009928.html
%This file creates two figures associated with the
%system x'=f(x,y), y'=g(x,y)
%1. Plots the graphs of x(t) and y(t)
%2. Plots the graph of (x(t),y(t)) in the phase plane.

%verbatimtex
%\input mtplain
%etex

%Generate standard eps
prologues:=2;

beginfig(0);

%Place RHS of x'=f(t,x,y) here
  def fxy(expr t, x, y)=
   (0.4-0.01*y)*x
  enddef;

%Place RHS of y'=g(t,x,y) here
  def gxy(expr t, x, y)=
   (-0.3+0.005*x)*y
  enddef;

%Declare some variables
  path q, trajx, trajy;
  pair L, R, B, T, xt, yt;
  numeric sx[], sy[];

%Initialize clipping window
  a:=0; b:=40;   %left and right of viewing rectangle
  c:=0; d:=150;  %bottom and top of viewing rectangle

%Initialize timespan
  tstart:=a;
  tstop:=b;

%Initialize number of points to be plotted
  N:=500;

%Calculate time increment dt for Euler's method
  dt:=(tstop-tstart)/N;

%Scaling factors for horizontal and vertical axes. Note that this produces
%an image that is 2 inches by 2 inches.
  (b-a)*ux=1.75in;
  (d-c)*uy=1.75in;

%Clipping boundary
  q=(a,c)--(b,c)--(b,d)--(a,d)--cycle;

%Use Runge-Kutta4 to create path (t,x(t))

%Choose initial condition
  t:=tstart;
  x:=40;
  y:=20;
  trajx:=(t,x);
  forever:
   sx1:=fxy(t,x,y);
   sy1:=gxy(t,x,y);
   sx2:=fxy((t+dt/2),(x+dt*sx1/2),(y+dt*sy1/2));
   sy2:=gxy((t+dt/2),(x+dt*sx1/2),(y+dt*sy1/2));
   sx3:=fxy((t+dt/2),(x+dt*sx2/2),(y+dt*sy2/2));
   sy3:=gxy((t+dt/2),(x+dt*sx2/2),(y+dt*sy2/2));
   sx4:=fxy((t+dt),(x+dt*sx3),(y+dt*sy3));
   sy4:=gxy((t+dt),(x+dt*sx3),(y+dt*sy3));
   x:=x+dt*(sx1+2*sx2+2*sx3+sx4)/6;
   y:=y+dt*(sy1+2*sy2+2*sy3+sy4)/6;
   t:=t+dt;
   trajx:=trajx..(t,x);
   exitif ((ttstop) or (tb) or (xc) or (xd));
  endfor;

%Use Runge-Kutta4 to create path (t,y(t))

%Choose initial condition
  t:=tstart;
  x:=40;
  y:=20;
  trajy:=(t,y);
  forever:
   sx1:=fxy(t,x,y);
   sy1:=gxy(t,x,y);
   sx2:=fxy((t+dt/2),(x+dt*sx1/2),(y+dt*sy1/2));
   sy2:=gxy((t+dt/2),(x+dt*sx1/2),(y+dt*sy1/2));
   sx3:=fxy((t+dt/2),(x+dt*sx2/2),(y+dt*sy2/2));
   sy3:=gxy((t+dt/2),(x+dt*sx2/2),(y+dt*sy2/2));
   sx4:=fxy((t+dt),(x+dt*sx3),(y+dt*sy3));
   sy4:=gxy((t+dt),(x+dt*sx3),(y+dt*sy3));
   x:=x+dt*(sx1+2*sx2+2*sx3+sx4)/6;
   y:=y+dt*(sy1+2*sy2+2*sy3+sy4)/6;
   t:=t+dt;
   trajy:=trajy..(t,y);
   exitif ((ttstop) or (tb) or (yc) or (yd));
  endfor;

%Draw the paths x(t) and y(t) and clip them to bounding box
  draw trajx xscaled ux yscaled uy withcolor red;
  draw trajy xscaled ux yscaled uy withcolor red dashed evenly;
  clip currentpicture to (q xscaled ux yscaled uy);

%Label graph x(t) and initial condition
  len:= 0.65*(length trajx);
  xt:=point len of trajx;
  label.urt(btex $\scriptstyle x(t)$ etex, (xt xscaled ux yscaled uy));

%Label graph y(t) and initial condition
  len:= 0.5*(length trajy);
  yt:=point len of trajy;
  label.lrt(btex $\scriptstyle y(t)$ etex, (yt xscaled ux yscaled uy));


%Initialize left and right endpoints on time-axis
  L=(a*ux,0);R=(b*ux,0);

%Draw and label t-axis
  drawarrow L--R;
  label.rt(btex $\scriptstyle t$ etex,(b*ux,0));

%Initialize bottom and top endpoints on time-axis
  B=(0,c*uy);T=(0,d*uy);

%Draw and label vertical axis
  drawarrow B--T;
  label.lft(btex $\scriptstyle 0$ etex, B);
  label.lft(btex $\scriptstyle 150$ etex, T);

endfig;


beginfig(2);

%Make some variables local
  save ux, uy;


Re: [NTG-context] MetaFun: MetaPost example works with `mpost` but not embedded in ConTeXt: `! Redundant equation.`

2011-12-11 Thread Marco
On 2011-12-11 Paul Menzel paulepan...@users.sourceforge.net wrote:

 […]

 I  then  copied   it  into  `\{start,stop}useMPgraphic`,
 removed the  `end ;`  and `{begin,end}fig`  and replaced
 `{e,b}tex` by  `textext()` but  still get  the following
 error.

I didn't  check you  code (try to  make a  minimal example
next time), but the problem seems to be the combination of
equations and labels. When labels are present, the file is
processed twice and the equations  are also read twice (in
MkIV). It hasn't been fixed  for ages, that probably means
it will stay.

One  workaround  is  to   substitute  the  equations  with
assignments or to “save” the values beforehand.

See also:
http://archive.contextgarden.net/message/20101205.035356.1b7bfb72.en.html

Marco


___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___