[NTG-context] Using metapost figures in context

Aditya Mahajan adityam at umich.edu
Tue Jun 13 02:16:33 CEST 2006


On Mon, 12 Jun 2006, Aditya Mahajan wrote:
> 2. How to get textext to work?

startMPrun not check for textext. Consider

% \forceMPTEXgraphictrue
% Does not make a difference!

\starttext
\startMPrun{testmp}
   beginfig(1)
   drawarrow (0,0)--(1cm,0) ;
   drawarrow (0,0)--(0,1cm) ;
   label.llft(textext("(0,0)"),origin) ;
   endfig;
\stopMPrun
\externalfigure[testmp.1]
\stoptext

which gives the dreaded "unknown" string, while

\starttext
\startMPgraphic
   beginfig(1)
   drawarrow (0,0)--(1cm,0) ;
   drawarrow (0,0)--(0,1cm) ;
   label.llft(textext("(0,0)"),origin) ;
   endfig;
\stopMPgraphic
\externalfigure[\jobname-mpgraph.1]
\stoptext

works.

I can get my previous macro to work for textext using startMPgraphic.

\def\startMPfigure#1#2\stopMPfigure
   {\bgroup
     \setMPrandomseedfalse
     %Otherwise randomseed := number line always differ
     \def\executeMPOST##1%
     {texmfstart --verbose --ifchanged=##1.mp bin:mpost

\ifcase\interactionmode\MPOSTbatchswitch\or\MPOSTnonstopswitch\fi
       \space\ifuseMETAFUNformat \MPOSTformatswitch metafun \fi ##1}
    \def\executeMPTEX##1% slower, due to nested texexec call
    {texmfstart --verbose --ifchanged=##1.mp texexec
        --batch \ifcase\interactionmode --logfile='mptex.log' \fi
        --output=\MPOSTdriver\space
        \ifuseMETAFUNformat --mpformat=metafun \fi --mptex --nomp 
--once ##1}
     \def\MPgraphicfile{\jobname-#1}
     \newcount\currentMPgraphic
     \startMPgraphic
       #2
     \stopMPgraphic\egroup\deallocateMPslot\currentMPgraphic}

\def\useMPfigure{\dosingleempty\douseMPfigure}

\def\douseMPfigure[#1]%
   {\externalfigure[\jobname-#1.1]}


\starttext

\startMPfigure{circle}
   fill fullcircle scaled 10cm;
\stopMPfigure

\startMPfigure{axis}
   drawarrow (0,0)--(1cm,0) ;
   drawarrow (0,0)--(0,1cm) ;
   label.llft(textext("(0,0)") ,origin) ;
\stopMPfigure

\hbox to \hsize  \bgroup
\hss \useMPfigure[circle][width=1cm] \hss \useMPfigure[axis] \hss 
\egroup
\stoptext

Right now I have a big speed improvement as metapost is not executed 
each time. I only need to convert the mps files to pdf to save a bit 
on pdf conversion.

Aditya




More information about the ntg-context mailing list