<div dir="ltr">I have something very simple like:<br><br>
<style type="text/css">p, li { white-space: pre-wrap; }</style>
<p style="margin: 0px; text-indent: 0px;">\documentclass{minimal}</p>
<p style="margin: 0px; text-indent: 0px;">\usepackage{moreverb}</p>
<p style="margin: 0px; text-indent: 0px;">\newenvironment{vafa}{\verbatimwrite{<a href="http://vafa.mp">vafa.mp</a>}}{\endverbatimwrite%</p>
<p style="margin: 0px; text-indent: 0px;">\immediate\write18{mpost -tex=latex <a href="http://vafa.mp">vafa.mp</a>}}</p>
<p style="margin: 0px; text-indent: 0px;">\begin{document}</p>
<p style="margin: 0px; text-indent: 0px;">\begin{equation}</p>
<p style="margin: 0px; text-indent: 0px;">1+2=3\label{eq1}</p>
<p style="margin: 0px; text-indent: 0px;">\end{equation}</p>
<p style="margin: 0px; text-indent: 0px;">\begin{vafa}</p>
<p style="margin: 0px; text-indent: 0px;">prologues:=3;</p>
<p style="margin: 0px; text-indent: 0px;">verbatimtex</p>
<p style="margin: 0px; text-indent: 0px;">\documentclass{article}</p>
<p style="margin: 0px; text-indent: 0px;">\input{test.aux}</p>
<p style="margin: 0px; text-indent: 0px;">\begin{document}</p>
<p style="margin: 0px; text-indent: 0px;">etex</p>
<p style="margin: 0px; text-indent: 0px;">beginfig(1);</p>
<p style="margin: 0px; text-indent: 0px;">numeric u;</p>
<p style="margin: 0px; text-indent: 0px;">u = 1cm;</p>
<p style="margin: 0px; text-indent: 0px;">draw (0,2u)--(0,0)--(4u,0);</p>
<p style="margin: 0px; text-indent: 0px;">pickup pencircle scaled 1pt;</p>
<p style="margin: 0px; text-indent: 0px;">draw (0,0){up}</p>
<p style="margin: 0px; text-indent: 0px;">for i=1 upto 8: ..(i/2,sqrt(i/2))*u endfor;</p>
<p style="margin: 0px; text-indent: 0px;">label.lrt(btex $\sqrt x$ etex, (3,sqrt 3)*u);</p>
<p style="margin: 0px; text-indent: 0px;">label.bot(btex $x$ Equation \ref{eq1} etex, (2u,0));</p>
<p style="margin: 0px; text-indent: 0px;">label.lft(btex $y$ etex, (0,u));</p>
<p style="margin: 0px; text-indent: 0px;">endfig</p>
<p style="margin: 0px; text-indent: 0px;">end</p>
<p style="margin: 0px; text-indent: 0px;">\end{vafa}</p>
<p style="margin: 0px; text-indent: 0px;">\end{document}</p><br>but I do not know why in the output (vafa.1), instead "Equation 1", I get "Equation ??" on the x-axis. I tried putting \immediate\write18{...} outside of vafa environment, that fixed the problem but it is not what I want. How can I fix this?<br>
<br>Thanks<br clear="all"><br>-- <br><div dir="ltr">If some one say: "You divide ten into two parts: multiply the one by 
itself; it will be equal to the other taken eighty-one times." 
Computation: You say, ten less thing, multiplied by itself, is a hundred
 plus a square less twenty things, and this is equal to eighty-one 
things. Separate the twenty things from a hundred and a square, and add 
them to eighty-one. It will then be a hundred plus a square, which is 
equal to a hundred and one roots. Halve the roots; the moiety is fifty 
and a half. Multiply this by itself, it is two thousand five hundred and
 fifty and a quarter. Subtract from this one hundred; the remainder is 
two thousand four hundred and fifty and a quarter. Extract the root from
 this; it is forty-nine and a half. Subtract this from the moiety of the
 roots, which is fifty and a half. There remains one, and this is one of
 the two parts.<br><br><b>Muḥammad ibn Mūsā al-Khwārizmī</b></div><br>
</div>