\ifx\arc\undefined\usepackage{curves}\fi
\newcommand{\drawing}[4][*]{
\ifx*#1\addtocounter{drawing}{1}\def\drawname{\jobname\thedrawing}
\else\def\drawname{#1}\fi
\newread\Drawing\openin\Drawing=\drawname.lfg\relax
\ifeof\Drawing\closein\Drawing\newwrite\Drawing
\openout\Drawing=\drawname.mfg\relax
\write\Drawings{drawing('#1',[#2;#3]);}
\write\Drawing{#4}
\closeout\Drawing
\else\closein\Drawing{\input \drawname.lfg\relax}\fi}

\newcommand\makedrawings{\global\newwrite\Drawings
\openout\Drawings=\jobname.mfg\relax
\write\Drawings{global JOBNAME DRAWNUMBER}
\write\Drawings{JOBNAME='\jobname'; DRAWNUMBER=0;}}

\let\enddoc=\enddocument
\def\enddocument{\closeout\Drawings\enddoc}
\newcounter{drawing}\setcounter{drawing}{0}

