mån 2008-11-24 klockan 09:08 -0500 skrev Aditya Mahajan:
> On Mon, 24 Nov 2008, Jan-Erik Hägglöf wrote:
> 
> > Hi All!
> >
> > I'm in beginning to write a thesis in physics(undergraduate level) and
> > one of many things I wanna do is, cause I create much illustrations in
> > DIA http://www.gnome.org/projects/dia/
> > and the program can export to figure.mp, to include these in my
> > document.
> >
> > I've read the instructions on http://wiki.contextgarden.net/Mpgraphic
> >
> > I do not get this working. How is the best way to accomplish this?
> 
> See the attached file. Dia exports the figure with
> verbatimtex
> &latex
> etex
> 
> which tells metapost to run labels through latex. I guess that this is 
> what causes the errors. If you simply remove some of the boiler plate, the 
> figure compiles fine (see attached file)
> 
> > The reason is why I want to do in this way is to input tex code in the
> > figure (especially math and symbol definitions) and optionally place
> > them in specific places inside the figure. By this method I can even do
> > better illustrations, hopefully.
> >
> > My workflow has been like this:
> >
> > 1. Create the desired figure in DIA and choose the export option. TeX
> > metapost *.mp(see attached file ).
> >
> > 2. Tryed to do inclusion in a TeX-document like this
> >
> > \startstaticMPfigure{magflux}
> >  the code in the attached file
> > \stopstaticMPfigure
> >
> > \starttext
> >
> > Here is my figure \usestaticMPfigure[magflux][width=0.8\textwidth]
> >
> > \stoptext
> >
> > But it fails with errormessage:
> >
> > !Paragraph ended before \startstaticMPfigure was complete .....
> >
> > Should I place part of the code in some definitions?
> 
> I do not get this error, but staticMPfigure is not working for me. I would 
> recomment not to use staticMPfigure, rather use useMPfigure.
> 
> (I had asked Hans for staticMPfigure a few years ago when TeX-MP 
> interaction was slow. Now, with MPLib I do not think that we need the 
> staticMPfigure mechanism. Personally, I haven't used it for a while)
> 
> I also had to add
> 
> save x, y, t, p ; %%%% Added this line
> 
> to include the figure multiple times (or to include multiple figures, I 
> would imagine).
> 
> Aditya
Thanks to all answers. I got it work, though a minor problem left, it
seems that "calligraphy" is not working.

 line 108 draw btex { $ \vec{\cal B }$} etex.....

see the new attached file.

Janneman
\usetypescriptfile[type-gyr]
\usetypescript[Adventor] % leave out 'ec' when using XeTeX/luaTeX
\setupbodyfont[Adventor,14.4pt,ss]
\startMPenvironment
\usetypescript[Adventor] % leave out 'ec' when using XeTeX/luaTeX
\setupbodyfont[Adventor,14.4pt,ss]
\stopMPenvironment



\startuseMPgraphic{mag2}
% Define macro for horizontal centering.
vardef hcentered primary P =
  P shifted -(xpart center P, 0)
enddef;
% Define macro for right justification.
vardef rjust primary P =
  P shifted -(xpart (lrcorner P - llcorner P), 0)
enddef;
save x, y, t, p ;
  % picture(3.436250,-29.212500)(46.421315,9.246250)
  x = 1.000000cm; y = -1.000000cm;

  t = 1.000000;

% set_line_color 0.000000, 0.000000, 0.000000
% set_line_color 1.000000, 1.000000, 1.000000
% set_linewidth 0.100000
  path p;
  p = (15.400000x,5.150000y)--(15.400000x,22.900000y)--(46.100000x,22.900000y)--(46.100000x,5.150000y)--cycle;
  fill p withcolor (1.000000,1.000000,1.000000);
%metapost_arc
% center->x = 15.400000% center->y = 5.150000% width = 0.000000% height = 0.000000% angle1 = 90.000000% angle2 = 180.000000% set_line_color 1.000000, 1.000000, 1.000000
  draw (15.400000x,5.150000y)..(15.400000x,5.150000y)..(15.400000x,5.150000y)
    withpen pencircle scaled 0.1000x
    withcolor (1.0000, 1.0000, 1.0000);
%metapost_arc
% center->x = 46.100000% center->y = 5.150000% width = 0.000000% height = 0.000000% angle1 = 0.000000% angle2 = 90.000000% set_line_color 1.000000, 1.000000, 1.000000
  draw (46.100000x,5.150000y)..(46.100000x,5.150000y)..(46.100000x,5.150000y)
    withpen pencircle scaled 0.1000x
    withcolor (1.0000, 1.0000, 1.0000);
  path p;
  p = (15.400000x,5.150000y)--(15.400000x,22.900000y)--(46.100000x,22.900000y)--(46.100000x,5.150000y)--cycle;
  fill p withcolor (1.000000,1.000000,1.000000);
%metapost_arc
% center->x = 15.400000% center->y = 22.900000% width = 0.000000% height = 0.000000% angle1 = 180.000000% angle2 = 270.000000% set_line_color 1.000000, 1.000000, 1.000000
  draw (15.400000x,22.900000y)..(15.400000x,22.900000y)..(15.400000x,22.900000y)
    withpen pencircle scaled 0.1000x
    withcolor (1.0000, 1.0000, 1.0000);
%metapost_arc
% center->x = 46.100000% center->y = 22.900000% width = 0.000000% height = 0.000000% angle1 = 270.000000% angle2 = 360.000000% set_line_color 1.000000, 1.000000, 1.000000
  draw (46.100000x,22.900000y)..(46.100000x,22.900000y)..(46.100000x,22.900000y)
    withpen pencircle scaled 0.1000x
    withcolor (1.0000, 1.0000, 1.0000);
% set_line_color 0.000000, 0.000000, 0.000000
  draw (15.400000x,5.150000y)--(46.100000x,5.150000y)
    withpen pencircle scaled 0.1000x;
% set_line_color 0.000000, 0.000000, 0.000000
  draw (15.400000x,22.900000y)--(46.100000x,22.900000y)
    withpen pencircle scaled 0.1000x;
%metapost_arc
% center->x = 15.400000% center->y = 5.150000% width = 0.000000% height = 0.000000% angle1 = 90.000000% angle2 = 180.000000% set_line_color 0.000000, 0.000000, 0.000000
  draw (15.400000x,5.150000y)..(15.400000x,5.150000y)..(15.400000x,5.150000y)
    withpen pencircle scaled 0.1000x;
%metapost_arc
% center->x = 46.100000% center->y = 5.150000% width = 0.000000% height = 0.000000% angle1 = 0.000000% angle2 = 90.000000% set_line_color 0.000000, 0.000000, 0.000000
  draw (46.100000x,5.150000y)..(46.100000x,5.150000y)..(46.100000x,5.150000y)
    withpen pencircle scaled 0.1000x;
% set_line_color 0.000000, 0.000000, 0.000000
  draw (15.400000x,5.150000y)--(15.400000x,22.900000y)
    withpen pencircle scaled 0.1000x;
% set_line_color 0.000000, 0.000000, 0.000000
  draw (46.100000x,5.150000y)--(46.100000x,22.900000y)
    withpen pencircle scaled 0.1000x;
%metapost_arc
% center->x = 15.400000% center->y = 22.900000% width = 0.000000% height = 0.000000% angle1 = 180.000000% angle2 = 270.000000% set_line_color 0.000000, 0.000000, 0.000000
  draw (15.400000x,22.900000y)..(15.400000x,22.900000y)..(15.400000x,22.900000y)
    withpen pencircle scaled 0.1000x;
%metapost_arc
% center->x = 46.100000% center->y = 22.900000% width = 0.000000% height = 0.000000% angle1 = 270.000000% angle2 = 360.000000% set_line_color 0.000000, 0.000000, 0.000000
  draw (46.100000x,22.900000y)..(46.100000x,22.900000y)..(46.100000x,22.900000y)
    withpen pencircle scaled 0.1000x;
% set_linewidth 0.100000
% set_line_color 1.000000, 1.000000, 1.000000
% fill_polygon
  path p;
  p = (9.950000x,1.150000y)--(40.000000x,1.050000y)--(46.250000x,5.050000y)--(15.450000x,5.000000y)--cycle;
  fill p 
    withpen pencircle scaled 0.1000x
    withcolor (1.0000, 1.0000, 1.0000);
% set_line_color 0.000000, 0.000000, 0.000000
  draw (9.950000x,1.150000y)--(40.000000x,1.050000y)--(46.250000x,5.050000y)--(15.450000x,5.000000y)--cycle
    withpen pencircle scaled 0.1000x;
% set_linewidth 0.100000
% set_line_color 0.749020, 0.749020, 0.749020
% fill_polygon
  path p;
  p = (10.000000x,1.100000y)--(15.350000x,4.950000y)--(15.450000x,22.850000y)--(10.050000x,18.800000y)--cycle;
  fill p 
    withpen pencircle scaled 0.1000x
    withcolor (0.7490, 0.7490, 0.7490);
% set_line_color 0.000000, 0.000000, 0.000000
  draw (10.000000x,1.100000y)--(15.350000x,4.950000y)--(15.450000x,22.850000y)--(10.050000x,18.800000y)--cycle
    withpen pencircle scaled 0.1000x;
% set_line_color 0.000000, 0.000000, 0.000000
  draw btex {$n$} etex scaled 6.15t shifted (40.550000x,-7.150000y);
% set_line_color 0.000000, 0.000000, 0.000000
  draw btex { $ \vec{\cal B }$} etex scaled 6.15t shifted (21.400000x,-3.375000y);
% set_line_color 0.000000, 0.000000, 0.000000
  draw btex {$ A $} etex scaled 6.15t shifted (3.500000x,21.825000y);
% set_line_color 0.000000, 0.000000, 0.000000
  draw btex {${\vec{u}}$} etex scaled 6.15t shifted (5.950000x,10.325000y);
% set_line_color 0.000000, 0.000000, 0.000000
  draw btex {$ \vec{l}$}  etex scaled 6.15t shifted (10.400000x,26.400000y);
% set_line_color 0.000000, 0.000000, 0.000000
  draw btex {$ dl $} etex scaled 6.15t shifted (30.000000x,27.600000y);
% set_linewidth 0.100000
% set_line_color 0.000000, 0.000000, 0.000000
  draw (10.000000x,18.800000y)--(40.000000x,18.850000y)
    withpen pencircle scaled 0.1000x
    dashed dashpattern (on 0.050000x off 0.050000x);
% set_linewidth 0.100000
% set_line_color 0.000000, 0.000000, 0.000000
  draw (40.000000x,1.200000y)--(39.950000x,18.700000y)
    withpen pencircle scaled 0.1000x
    dashed dashpattern (on 0.050000x off 0.050000x);
% set_linewidth 0.100000
% set_line_color 0.000000, 0.000000, 0.000000
  draw (39.950000x,18.800000y)--(46.100000x,22.800000y)
    withpen pencircle scaled 0.1000x
    dashed dashpattern (on 0.050000x off 0.050000x);
  path p;
  p = (19.100000x,20.000000y)..(18.600000x,20.500000y)..(18.100000x,20.000000y)..(18.600000x,19.500000y)..cycle;
  fill p withcolor (1.000000,1.000000,1.000000);
% set_linewidth 0.100000
% set_line_color 0.000000, 0.000000, 0.000000
  draw (19.100000x,20.000000y)..(18.600000x,20.500000y)..(18.100000x,20.000000y)..(18.600000x,19.500000y)..cycle
    withpen pencircle scaled 0.1000x;
  path p;
  p = (17.000000x,3.150000y)..(16.500000x,3.650000y)..(16.000000x,3.150000y)..(16.500000x,2.650000y)..cycle;
  fill p withcolor (1.000000,1.000000,1.000000);
% set_linewidth 0.100000
% set_line_color 0.000000, 0.000000, 0.000000
  draw (17.000000x,3.150000y)..(16.500000x,3.650000y)..(16.000000x,3.150000y)..(16.500000x,2.650000y)..cycle
    withpen pencircle scaled 0.1000x;
  path p;
  p = (34.500000x,4.100000y)..(34.000000x,4.600000y)..(33.500000x,4.100000y)..(34.000000x,3.600000y)..cycle;
  fill p withcolor (1.000000,1.000000,1.000000);
% set_linewidth 0.100000
% set_line_color 0.000000, 0.000000, 0.000000
  draw (34.500000x,4.100000y)..(34.000000x,4.600000y)..(33.500000x,4.100000y)..(34.000000x,3.600000y)..cycle
    withpen pencircle scaled 0.1000x;
  path p;
  p = (23.600100x,6.975000y)..(23.100100x,7.475000y)..(22.600100x,6.975000y)..(23.100100x,6.475000y)..cycle;
  fill p withcolor (1.000000,1.000000,1.000000);
% set_linewidth 0.100000
% set_line_color 0.000000, 0.000000, 0.000000
  draw (23.600100x,6.975000y)..(23.100100x,7.475000y)..(22.600100x,6.975000y)..(23.100100x,6.475000y)..cycle
    withpen pencircle scaled 0.1000x;
  path p;
  p = (20.590000x,12.350000y)..(20.090000x,12.850000y)..(19.590000x,12.350000y)..(20.090000x,11.850000y)..cycle;
  fill p withcolor (1.000000,1.000000,1.000000);
% set_linewidth 0.100000
% set_line_color 0.000000, 0.000000, 0.000000
  draw (20.590000x,12.350000y)..(20.090000x,12.850000y)..(19.590000x,12.350000y)..(20.090000x,11.850000y)..cycle
    withpen pencircle scaled 0.1000x;
  path p;
  p = (28.225000x,12.000000y)..(27.725000x,12.500000y)..(27.225000x,12.000000y)..(27.725000x,11.500000y)..cycle;
  fill p withcolor (1.000000,1.000000,1.000000);
% set_linewidth 0.100000
% set_line_color 0.000000, 0.000000, 0.000000
  draw (28.225000x,12.000000y)..(27.725000x,12.500000y)..(27.225000x,12.000000y)..(27.725000x,11.500000y)..cycle
    withpen pencircle scaled 0.1000x;
  path p;
  p = (27.850000x,16.250000y)..(27.350000x,16.750000y)..(26.850000x,16.250000y)..(27.350000x,15.750000y)..cycle;
  fill p withcolor (1.000000,1.000000,1.000000);
% set_linewidth 0.100000
% set_line_color 0.000000, 0.000000, 0.000000
  draw (27.850000x,16.250000y)..(27.350000x,16.750000y)..(26.850000x,16.250000y)..(27.350000x,15.750000y)..cycle
    withpen pencircle scaled 0.1000x;
  path p;
  p = (35.245000x,21.200000y)..(34.745000x,21.700000y)..(34.245000x,21.200000y)..(34.745000x,20.700000y)..cycle;
  fill p withcolor (1.000000,1.000000,1.000000);
% set_linewidth 0.100000
% set_line_color 0.000000, 0.000000, 0.000000
  draw (35.245000x,21.200000y)..(34.745000x,21.700000y)..(34.245000x,21.200000y)..(34.745000x,20.700000y)..cycle
    withpen pencircle scaled 0.1000x;
  path p;
  p = (39.300000x,16.050000y)..(38.800000x,16.550000y)..(38.300000x,16.050000y)..(38.800000x,15.550000y)..cycle;
  fill p withcolor (1.000000,1.000000,1.000000);
% set_linewidth 0.100000
% set_line_color 0.000000, 0.000000, 0.000000
  draw (39.300000x,16.050000y)..(38.800000x,16.550000y)..(38.300000x,16.050000y)..(38.800000x,15.550000y)..cycle
    withpen pencircle scaled 0.1000x;
  path p;
  p = (44.550000x,16.500000y)..(44.050000x,17.000000y)..(43.550000x,16.500000y)..(44.050000x,16.000000y)..cycle;
  fill p withcolor (1.000000,1.000000,1.000000);
% set_linewidth 0.100000
% set_line_color 0.000000, 0.000000, 0.000000
  draw (44.550000x,16.500000y)..(44.050000x,17.000000y)..(43.550000x,16.500000y)..(44.050000x,16.000000y)..cycle
    withpen pencircle scaled 0.1000x;
  path p;
  p = (35.250100x,9.625000y)..(34.750100x,10.125000y)..(34.250100x,9.625000y)..(34.750100x,9.125000y)..cycle;
  fill p withcolor (1.000000,1.000000,1.000000);
% set_linewidth 0.100000
% set_line_color 0.000000, 0.000000, 0.000000
  draw (35.250100x,9.625000y)..(34.750100x,10.125000y)..(34.250100x,9.625000y)..(34.750100x,9.125000y)..cycle
    withpen pencircle scaled 0.1000x;
% set_linewidth 0.100000
% set_line_color 0.000000, 0.000000, 0.000000
  draw (33.600100x,22.850000y)--(21.805237x,-2.533529y)
    withpen pencircle scaled 0.1000x;
% set_line_color 0.000000, 0.000000, 0.000000
% fill_polygon
  path p;
  p = (21.647213x,-2.873608y)--(22.084630x,-2.525518y)--(21.805237x,-2.533529y)--(21.631192x,-2.314821y)--cycle;
  fill p 
    withpen pencircle scaled 0.1000x;
% set_line_color 0.000000, 0.000000, 0.000000
  draw (21.647213x,-2.873608y)--(22.084630x,-2.525518y)--(21.805237x,-2.533529y)--(21.631192x,-2.314821y)--cycle
    withpen pencircle scaled 0.1000x;
% set_linewidth 0.100000
% set_line_color 0.000000, 0.000000, 0.000000
  draw (45.900100x,25.500000y)--(15.936903x,25.450799y)
    withpen pencircle scaled 0.1000x;
% set_line_color 0.000000, 0.000000, 0.000000
% fill_polygon
  path p;
  p = (15.561903x,25.450184y)--(16.062313x,25.201005y)--(15.936903x,25.450799y)--(16.061492x,25.701004y)--cycle;
  fill p 
    withpen pencircle scaled 0.1000x;
% set_line_color 0.000000, 0.000000, 0.000000
  draw (15.561903x,25.450184y)--(16.062313x,25.201005y)--(15.936903x,25.450799y)--(16.061492x,25.701004y)--cycle
    withpen pencircle scaled 0.1000x;
% set_linewidth 0.100000
% set_line_color 0.000000, 0.000000, 0.000000
  draw (15.350100x,23.300000y)--(15.350100x,25.550000y)
    withpen pencircle scaled 0.1000x;
% set_linewidth 0.100000
% set_line_color 0.000000, 0.000000, 0.000000
  draw (46.035100x,23.150000y)--(46.035100x,25.400000y)
    withpen pencircle scaled 0.1000x;
% set_linewidth 0.100000
% set_line_color 0.000000, 0.000000, 0.000000
  draw (12.700100x,12.175000y)--(5.036903x,12.175000y)
    withpen pencircle scaled 0.1000x;
% set_line_color 0.000000, 0.000000, 0.000000
% fill_polygon
  path p;
  p = (4.661903x,12.175000y)--(5.161903x,11.925000y)--(5.036903x,12.175000y)--(5.161903x,12.425000y)--cycle;
  fill p 
    withpen pencircle scaled 0.1000x;
% set_line_color 0.000000, 0.000000, 0.000000
  draw (4.661903x,12.175000y)--(5.161903x,11.925000y)--(5.036903x,12.175000y)--(5.161903x,12.425000y)--cycle
    withpen pencircle scaled 0.1000x;
% set_linewidth 0.050000
%metapost_arc
% center->x = 16.044451% center->y = 29.643274% width = 29.161250% height = 29.161250% angle1 = 104.068771% angle2 = 146.755563% set_line_color 0.000000, 0.000000, 0.000000
  draw (12.500100x,15.500000y)..(7.595646x,17.759995y)..(3.850100x,21.650000y)
    withpen pencircle scaled 0.0500x;
% set_linewidth 0.050000
%metapost_arc
% center->x = 46.858720% center->y = 3.886073% width = 25.384589% height = 25.384589% angle1 = 121.377854% angle2 = 178.640130% set_line_color 0.000000, 0.000000, 0.000000
  draw (40.250100x,-6.950000y)..(35.865875x,-2.458349y)..(34.170000x,3.584860y)
    withpen pencircle scaled 0.0500x;
% set_linewidth 0.100000
% set_line_color 0.000000, 0.000000, 0.000000
  draw (14.350100x,24.250000y)--(7.786891x,24.203452y)
    withpen pencircle scaled 0.1000x;
% set_line_color 0.000000, 0.000000, 0.000000
% fill_polygon
  path p;
  p = (7.411901x,24.200793y)--(7.913661x,23.954345y)--(7.786891x,24.203452y)--(7.910115x,24.454333y)--cycle;
  fill p 
    withpen pencircle scaled 0.1000x;
% set_line_color 0.000000, 0.000000, 0.000000
  draw (7.411901x,24.200793y)--(7.913661x,23.954345y)--(7.786891x,24.203452y)--(7.910115x,24.454333y)--cycle
    withpen pencircle scaled 0.1000x;
\stopuseMPgraphic
\starttext

\scale[width=\textwidth]{\useMPgraphic{mag2}}
\scale[width=\textwidth]{\useMPgraphic{mag2}}

\stoptext

___________________________________________________________________________________
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  : https://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

Reply via email to