% \iffalse % emp.dtx - Encapsulated MetaPost for LaTeX(2e)
% Copyright (C) 1997 by Thorsten.Ohl@Physik.TU-Darmstadt.de
% $Id: emp.dtx,v 1.10 1997/11/12 21:14:41 ohl Exp $
%
% Emp is free software; you can redistribute it and/or modify it
% under the terms of the GNU General Public License as published by 
% the Free Software Foundation; either version 2, or (at your option)
% any later version.
%
% Emp is distributed in the hope that it will be useful, but
% WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program; if not, write to the Free Software
% Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
%
% \fi
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%% \CheckSum{291}
%% \CharacterTable
%%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%%   Digits        \0\1\2\3\4\5\6\7\8\9
%%   Exclamation   \!     Double quote  \"     Hash (number) \#
%%   Dollar        \$     Percent       \%     Ampersand     \&
%%   Acute accent  \'     Left paren    \(     Right paren   \)
%%   Asterisk      \*     Plus          \+     Comma         \,
%%   Minus         \-     Point         \.     Solidus       \/
%%   Colon         \:     Semicolon     \;     Less than     \<
%%   Equals        \=     Greater than  \>     Question mark \?
%%   Commercial at \@     Left bracket  \[     Backslash     \\
%%   Right bracket \]     Circumflex    \^     Underscore    \_
%%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%%   Right brace   \}     Tilde         \~}
%%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% \MakeShortVerb{\|}
%
% \title{%
%   \EMP: \\
%   Encapsulated \MP{} for \LaTeX\thanks{%
%      This is \texttt{\filename}, version \fileversion,
%      revision \filerevision, date \filedate.}}
%
% \author{%
%   Thorsten Ohl\thanks{e-mail:
%     \texttt{Thorsten.Ohl@Physik.TU-Darmstadt.de}}\\
%   \hfil \\
%   Technische Hochschule Darmstadt \\
%   Schlo\ss gartenstr. 9 \\
%   D-64289 Darmstadt \\
%   Germany}
%
% \maketitle
% \begin{abstract}
%   The \EMP{} package allows to encapsulate \MP{} files in \LaTeX{}
%   sources.  This is very useful for keeping illustrations in sync
%   with the text.  It also frees the user from inventing descriptive
%   names for PostScript files that fit into the confines of file
%   system conventions.
% \end{abstract}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \vfill
% \section*{Copying}
%
% \EMP{} is free software; you can redistribute it and/or modify it
% under the terms of the GNU General Public License as published by 
% the Free Software Foundation; either version 2, or (at your option)
% any later version.
%
% \EMP{} is distributed in the hope that it will be useful, but
% \emph{without any warranty}; without even the implied warranty of
% \emph{merchantability} or \emph{fitness for a particular purpose}.
% See the GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program; if not, write to the Free Software
% Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \newpage
% \unitlength=1mm
% \def\topfraction{0.9}
% \def\bottomfraction{0.9}
% \def\textfraction{0.1}
% \empaddtoTeX{\usepackage{amsmath}}
% \empprelude{input graph}
% \begin{empfile}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \section{Introduction}
%
% When adding illustrations to documents, one faces two bookkeeping
% problems:
% \begin{enumerate}
%   \item How to encourage oneself to keep the illustrations in sync
%     with the text, when the document is updated?
%   \item How to make sure that the illustrations appear on the right
%     spot? 
% \end{enumerate}
% For both problems, the best solution is to encapsulate the figures
% in the \LaTeX{} source:
% \begin{enumerate}
%   \item It is much easier to remember to update an illustration if
%     one doesn't have to switch files in the editor.
%   \item One does not have to invent illustrative file names, if
%     the computer keeps track of them.
% \end{enumerate}
% Therefore \EMP{} was written to allow to encapsulate
% \MP~\cite{MP,LaTeX-Graphics-Companion} into
% \LaTeX~\cite{LaTeX-Graphics-Companion,LaTeX,LaTeX-Companion}.
%
% These macros have some overlap with
% \FMF~\cite{LaTeX-Graphics-Companion,FeynMF},
% |axodraw|~\cite{axodraw} and
% |mfpic|~\cite{LaTeX-Graphics-Companion,mfpic}.  In fact, most of the
% functionality of \EMP{} is available from \FMF.  Longer pieces of
% \MP{} code are however not very conveniently typed in \FMF, because
% there is no facility for multi line input (using |\fmfcmd| with long
% arguments can overflow \MP's input buffers because of the missing
% line breaks).  Since \FMF{} provides much syntax that is superfluous
% for \EMP's purpose (the \EMP{} package exports only five new
% environments and five commands), it is more appropriate to create a
% separate small package than to add this functionality to \FMF.
% Similar comments apply to |mfpic|.
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \section{Usage}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Commands and Environments}
% \label{sec:commands}
%
% \DescribeEnv{empfile}
% All descriptions that should go into one \MP{} file are placed
% inside a |empfile| environment which takes the name of the \MP{}
% file as an optional argument:
% \begin{quote}
% \begin{flushleft}
%   |\begin{empfile}[|\meta{\MP-file}|]|\\
%   \qquad\ldots\\
%   |\end{empfile}|
% \end{flushleft}
% \end{quote}
% The default \MP-filename is |\jobname.mp|.
%
% \DescribeEnv{emp}
% The |emp| environment contains the description of a single
% figure that will be placed at the location of the environment.
% Required arguments are the width and the height of the figure, in
% units of |\unitlength|.  They will be available as the \MP{}
% variables~|w| and~|h|.  The optional argument assigns a name to be
% used with |\empuse{|\meta{name}|}|.
% \begin{quote}
% \begin{flushleft}
%   |\begin{emp}[|\meta{name}|](|\meta{width}|,|\meta{height}|)|\\
%     \qquad\meta{\MP-commands}\\
%   |\end{emp}|
% \end{flushleft}
% \end{quote}
% Note that this environment uses the |verbatim| package to process
% the input lines and can therefore \emph{not} be used as an argument
% to another macros.  To work around this problem, you can first use
% the |empdef| environment and |\empuse| it later.
%
% \DescribeMacro{\empuse}
% Reuse a previously defined figure.
%
% \DescribeEnv{empdef}
% The |empdef| environment is similar to |emp|, but the figure is not
% drawn.  This is useful, because these environments use the
% |verbatim| package and can therefore \emph{not} be used as an
% argument to another macros.
% \begin{quote}
% \begin{flushleft}
%   |\begin{empdef}[|\meta{name}|](|\meta{width}|,|\meta{height}|)|\\
%     \qquad\meta{\MP-commands}\\
%   |\end{empdef}|
% \end{flushleft}
% \end{quote}
%
% \DescribeEnv{empcmds}
% Write \MP{} commands to the current file outside of a figure.
% \begin{quote}
% \begin{flushleft}
%   |\begin{empcmds}|\\
%     \qquad\meta{\MP-commands}\\
%   |\end{empcmds}|
% \end{flushleft}
% \end{quote}
%
% \DescribeEnv{empgraph}
% The |empgraph| environment contains the description of a graph
% that will be placed a the location of the environment.
% The user is responsible for including the |graph| package by the
% using the command |\empprelude{input graph}| in the preamble.
% Required arguments are the width and
% the height of the graph, in units of |\unitlength|.  They will be
% available as the \MP{} variables~|w| and~|h|.  The optional argument
% assigns a name to be used with |\empuse{|\meta{name}|}|.
% \begin{quote}
% \begin{flushleft}
%   |\begin{empgraph}[|\meta{name}|](|\meta{width}|,|\meta{height}|)|\\
%     \qquad\meta{\MP-commands}\\
%   |\end{empgraph}|
% \end{flushleft}
% \end{quote}
%
% \DescribeMacro{\empTeX}
% Define a \LaTeX{} prelude to be written to the top of every \MP{}
% file.  The default is |\documentclass[|\meta{ptsize}|]{article}|.
% If the prelude is not empty, |\begin{document}| will be added.  Note
% that you have to run \MP{} as |TEX=latex mpost| \meta{filename} if the
% prelude calls \LaTeX.
%
% \DescribeMacro{\empaddtoTeX}
% Add to the \LaTeX{} prelude.
% E.g.~|\empaddtoTeX{\usepackage{euler}}| makes sure that \MP{} will
% use the Euler fonts for the labels.
%
% \DescribeMacro{\empprelude}
% \DescribeMacro{\empaddtoprelude}
% Define and add to a \MP{} prelude to the top of every \MP{} file.
% The default is empty.
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Examples}
% \label{sec:examples}
%
% For a simple example, let's draw a smiling and a frowning face.
% Since they are identical except for the mouth, we prepare a macro
% for the common parts:
%    \begin{macrocode}
%<*sample>
\begin{empcmds}
  vardef draw_face =
    pair lefteye, righteye, nose[];
    lefteye = c + (-0.25w,0.15h);  righteye = c + (0.25w,0.15h);
    nose1 = c - (0,0.05h);  nose2 = c + (0,0.15h);
    pickup pencircle scaled 1;
    draw fullcircle xscaled w yscaled h shifted c;
    draw fullcircle scaled 2 shifted lefteye;
    draw fullcircle scaled 2 shifted righteye;
    draw nose1--nose2;  draw mouth1..mouth2..mouth3;
    setbounds currentpicture to unitsquare xscaled w yscaled .5h;
  enddef;
\end{empcmds}
%    \end{macrocode}
% \begin{empcmds}
    vardef draw_face =
      pair lefteye, righteye, nose[];
      lefteye = c + (-0.25w,0.15h);  righteye = c + (0.25w,0.15h);
      nose1 = c - (0,0.05h);  nose2 = c + (0,0.15h);
      pickup pencircle scaled 1;
      draw fullcircle xscaled w yscaled h shifted c;
      draw fullcircle scaled 2 shifted lefteye;
      draw fullcircle scaled 2 shifted righteye;
      draw nose1--nose2;  draw mouth1..mouth2..mouth3;
      setbounds currentpicture to unitsquare xscaled w yscaled .5h;
    enddef;
\end{empcmds}
% This can now be used for the frowning
% \begin{emp}[frown](5,5)
    pair mouth[], c;  c = (0.5w,0);
    mouth1 = c + (-0.2w,-0.25h);
    mouth2 = c + (0,-0.2h);
    mouth3 = c + (0.2w,-0.25h);
    draw_face;
\end{emp}
%    \begin{macrocode}
\begin{emp}(5,5)
  pair mouth[], c;  c = (0.5w,0);
  mouth1 = c + (-0.2w,-0.25h);
  mouth2 = c + (0,-0.2h);
  mouth3 = c + (0.2w,-0.25h);
  draw_face;
\end{emp}
%    \end{macrocode}
% and the smiling
% \begin{emp}[smile](5,5)
    pair mouth[], c;  c = (0.5w,0);
    mouth1 = c + (-0.2w,-0.2h);
    mouth2 = c + (0,-0.25h);
    mouth3 = c + (0.2w,-0.2h);
    draw_face;
\end{emp}
% face
%    \begin{macrocode}
\begin{emp}[smile](5,5)
  pair mouth[], c;  c = (0.5w,0);
  mouth1 = c + (-0.2w,-0.2h);
  mouth2 = c + (0,-0.25h);
  mouth3 = c + (0.2w,-0.2h);
  draw_face;
\end{emp}
%    \end{macrocode}
% Since we have given a name to |smile|, we can now use it with
% |\empuse{smile}|:
% \begin{itemize}
%   \item[\empuse{smile}] Note that the reference point has been set
%     up such that it works best as replacement for |\bullet| in
%     |itemize| environments.
%   \item[\empuse{smile}] This is very useful for slides.
% \end{itemize}
%
% \begin{figure}
%   \begin{center}
%     \begin{empgraph}(60,40)
        pickup pencircle scaled 1pt;
        path p;
        for x = -20 step 0.2 until -0.2:
          augment.p (x, sind(x*180/3.14159)/x);
        endfor
        augment.p (0, 1);
        for x = 0.2 step 0.2 until 20:
          augment.p (x, sind(x*180/3.14159)/x);
        endfor
        gdraw p;
        glabel.lrt (btex $\displaystyle\frac{\sin(x)}{x}$ etex, (-20,1));
\end{empgraph}
%     \vspace*{-1.5\baselineskip}
%   \end{center}
%   \caption{\label{fig:graph}%
%     \texttt{graph} example.}
% \end{figure}
% As a second example, the simple plot of
% \begin{equation}
%    j_0 = \frac{\sin(x)}{x}
% \end{equation}
% is shown in figure~\ref{fig:graph}:
%    \begin{macrocode}
\begin{empgraph}(60,40)
  pickup pencircle scaled 1pt;
  path p;
  for x = -20 step 0.2 until -0.2:
    augment.p (x, sind(x*180/3.14159)/x);
  endfor
  augment.p (0, 1);
  for x = 0.2 step 0.2 until 20:
    augment.p (x, sind(x*180/3.14159)/x);
  endfor
  glabel.lrt (btex $$\displaystyle\frac{\sin(x)}{x}$$ etex, (-20,1));
  gdraw p;
\end{empgraph}
%    \end{macrocode}
% The command |\empprelude{input graph}| must have been put in the
% preamble to make the |graph| package available.
%
% \begin{figure}
%   \begin{center}
%     \begin{empgraph}(60,40)
        pi = 3.14159; beta0 = 11 - 2/3*4;
        lambda1 = 0.15; lambda2 = 0.25;
        vardef ln expr x = (mlog x) / 256 enddef;
        vardef alphas (expr x, l) = 4*pi/(beta0*2ln(x/l)) enddef;
        setcoords (log,linear);
        pickup pencircle scaled 1pt;
        path p[];
        for x = 0.5 step 0.1 until 10:
          augment.p1 (x, alphas (x, lambda1));
          augment.p2 (x, alphas (x, lambda2));
        endfor
        gfill p1--(reverse p2)--cycle withcolor .5white;
        glabel.lft (btex $\alpha_s(Q^2)$ etex rotated 90, OUT);
        glabel.bot (btex $Q^2/\text{GeV}$ etex, OUT);
\end{empgraph}
%     \vspace*{-1.5\baselineskip}
%   \end{center}
%   \caption{\label{fig:alphas}%
%     Another \texttt{graph} example.}
% \end{figure}
% Finally, another application of the |graph| package:
% \begin{equation}
%    \alpha_s(Q^2) = \frac{4\pi}{\beta_0\ln(Q^2/\Lambda_{\text{QCD}}^2)}
% \end{equation}
% with $\Lambda_{\text{QCD}}\in[0.15\,\text{GeV},0.25\,\text{GeV}]$
% and $\beta_0=11-2N_f/3$ is shown in figure~\ref{fig:alphas}:
%    \begin{macrocode}
\begin{empgraph}(60,40)
  pi = 3.14159; beta0 = 11 - 2/3*4;
  lambda1 = 0.15; lambda2 = 0.25;
  vardef ln expr x = (mlog x) / 256 enddef;
  vardef alphas (expr x, l) = 4*pi/(beta0*2ln(x/l)) enddef;
  setcoords (log,linear);
  pickup pencircle scaled 1pt;
  path p[];
  for x = 0.5 step 0.1 until 10:
    augment.p1 (x, alphas (x, lambda1));
    augment.p2 (x, alphas (x, lambda2));
  endfor
  gfill p1--(reverse p2)--cycle withcolor .5white;
  glabel.lft (btex $\alpha_s(Q^2)$ etex rotated 90, OUT);
  glabel.bot (btex $Q^2/\text{GeV}$ etex, OUT);
\end{empgraph}
%</sample>
%    \end{macrocode}
% Note that the |\text| macro of AMS-\LaTeX{} has been used,
% therefore, the command |\empaddtoTeX{\usepackage{amsmath}}| must
% have been put in the preamble for this example to work.
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \begin{thebibliography}{99}
%   \bibitem{MP} John D.~Hobby, \textit{A User's Manual for
%     \MP}, Computer Science Report \#162, AT\&T Bell
%     Laboratories, April 1992.
%   \bibitem{LaTeX-Graphics-Companion} Michel Goossens, Sebastian
%     Rahtz, and Frank Mittelbach, \textit{The \LaTeX{} Graphics
%     Companion}, Addison-Wesley, Reading MA, 1997.
%   \bibitem{LaTeX} Leslie Lamport, \textit{\LaTeX{} --- A
%     Documentation Preparation System},
%     Addison-Wesley, Reading MA, 1985.
%   \bibitem{LaTeX-Companion} Michel Goossens, Frank Mittelbach, and
%     Alexander Samarin, \textit{The \LaTeX{} Companion},
%     Addison-Wesley, Reading MA, 1994.
%   \bibitem{FeynMF} Thorsten Ohl, 
%     Comp.~Phys.~Comm.~\textbf{90} (1995) 340;
%     CERN Computer Newsletter~\textbf{220} (1995) 22;
%     \textbf{221} (1995) 46; \textbf{222} (1996) 24.
%     \texttt{axodraw} is available from CTAN
%     (cf.~p.~\pageref{pg:CTAN}), in the
%     \texttt{latex/contrib/supported} directory.
%   \bibitem{axodraw} Jos Vermaseren,
%     Comp.~Phys.~Comm.~\textbf{83} (1994) 45.
%     \texttt{axodraw} is available from CTAN
%     (cf.~p.~\pageref{pg:CTAN}), in the  \texttt{graphics} directory.
%   \bibitem{mfpic} Thomas E.~Leathrum, \texttt{mfpic}, available from
%     CTAN (cf.~p.~\pageref{pg:CTAN}), in the \texttt{graphics}
%     directory.
% \end{thebibliography}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \section*{Distribution}
% \label{sec:distribution}
%
% \EMP{} is available by anonymous internet ftp from any of the
% Comprehensive \TeX{} Archive Network (CTAN) hosts 
% \label{pg:CTAN}
% \begin{quote}
%   |ftp.tex.ac.uk|, |ftp.dante.de|
% \end{quote}
% in the directory
% \begin{quote}
%   |macros/latex/contrib/supported/emp|
% \end{quote}
% It is also available from the host
% \begin{quote}
%   |crunch.ikp.physik.tu-darmstadt.de|
% \end{quote}
% in the directory
% \begin{quote}
%   |pub/ohl/emp|
% \end{quote}
% Unsupported snapshots of work in progress are provided as
% \begin{quote}
%   |pub/ohl/emp.versions/emp-current.tar.gz|
% \end{quote}
% ^^A There are two mailing lists
% ^^A \begin{quote}
% ^^A \begin{flushleft}
% ^^A   |emp-announce@crunch.ikp.physik.tu-darmstadt.de|\\
% ^^A   |emp-bugs@crunch.ikp.physik.tu-darmstadt.de|
% ^^A \end{flushleft}
% ^^A \end{quote}
% ^^A open for subscription.  The former should carry only important
% ^^A announcements, of new versions in particular.  To subscribe, send
% ^^A mail to the (electronic) mailing list manager
% ^^A \begin{quote}
% ^^A   |majordomo@crunch.ikp.physik.tu-darmstadt.de|
% ^^A \end{quote}
% ^^A and \emph{not} to the lists itself.  The following commands (on a
% ^^A line in the body of the mail, not in the subject) are useful:
% ^^A \begin{quote}
% ^^A \begin{flushleft}
% ^^A   |subscribe emp-announce|\\
% ^^A   |unsubscribe emp-announce|\\
% ^^A   |help|
% ^^A \end{flushleft}
% ^^A \end{quote}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \end{empfile}
% \StopEventually{\PrintIndex\PrintChanges}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \section{Implementation}
% \changes{v1.00}{1997/11/12}{Version 1.00 frozen.}
%
% It's is good practice to identify this version of the document style
% option.  We do this by parsing an RCS |Id| string and storing the
% result in the conventional \TeX{} control sequences:
%    \begin{macrocode}
%<*style>
\def\fileversion{v1.00}
\NeedsTeXFormat{LaTeX2e}
{\def\RCS#1#2\endRCS{%
  \ifx$#1%
    \@RCS $#2 \endRCS
  \else
    \@RCS $*: #1#2$ \endRCS
  \fi}%
 \def\@RCS $#1: #2,v #3 #4 #5 #6 #7$ \endRCS{%
   \gdef\filename{#2}%
   \gdef\filerevision{#3}%
   \gdef\filedate{#4}%
   \gdef\filemaintainer{#6}}%
\RCS $Id: emp.dtx,v 1.10 1997/11/12 21:14:41 ohl Exp $ \endRCS}%
%    \end{macrocode}
%
% And now the standard procedure:
%    \begin{macrocode}
\ProvidesPackage{emp}[\filedate\space\fileversion\space
  Encapsulated MetaPost LaTeX Package (\filemaintainer)]
%    \end{macrocode}
% Every option we don't understand is sent down to |graphics|:
%    \begin{macrocode}
\DeclareOption*{\PassOptionsToPackage{\CurrentOption}{graphics}}
\ProcessOptions
\RequirePackage{graphics}[1994/12/15]
\RequirePackage{verbatim}
%    \end{macrocode}
%
% \begin{macro}{\empwrite}
%    \begin{macrocode}
{\catcode`\%=11\gdef\p@rcent{%}}
\def\empwrite#1{%
  \if@empio
    \immediate\write\@outemp{#1}%
  \fi
  \ignorespaces}
\newif\if@empio
\@empiotrue
\newwrite\@outemp
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\empfile}
% This environment encloses each \MP{} input file.  The single optional
% argument gives the name of the file.
%    \begin{macrocode}
\newcommand{\empfile}[1][\jobname]{%
  \def\theempfile{#1}%
%    \end{macrocode}
% Open the \MP{} file.  If we're running under AMS-\LaTeX, turn off
% I/O during the first pass over equation environments.
%    \begin{macrocode}
  \if@empio
    \@ifundefined{ifmeasuring@}%
      {}%
      {\def\if@empio{\ifmeasuring@\else}}%
    \immediate\openout\@outemp=\theempfile.mp\relax
    \empwrite{\p@rcent\p@rcent\p@rcent\space \theempfile.mp -- %
              do not edit, generated automatically by \jobname.tex}%
%    \end{macrocode}
% append |\begin{document}| to a non-empty |\LaTeX| prelude and write
% it out:
%    \begin{macrocode}
    \expandafter\ifx\expandafter*\the\emp@TeX*\else
      \emp@TeX=\expandafter{\the\emp@TeX^^J\begin{document}}%
      \empwrite{verbatimtex^^J\the\emp@TeX^^Jetex;}%
    \fi
    \expandafter\ifx\expandafter*\the\emp@prelude*\else
      \empwrite{\the\emp@prelude;}%
    \fi
  \fi
%    \end{macrocode}
% Count the figures
%    \begin{macrocode}
  \setcounter{empfig}{0}}
\let\theempfile\relax
\newcounter{empfig}
%    \end{macrocode}
% Standard preludes:
%    \begin{macrocode}
\newtoks\emp@TeX
\ifcase\@ptsize
  \emp@TeX={\documentclass[10pt]{article}}
\or
  \emp@TeX={\documentclass[11pt]{article}}
\or
  \emp@TeX={\documentclass[12pt]{article}}
\else
  \emp@TeX={\documentclass{article}}
\fi
\newtoks\emp@prelude
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\empTeX}
%   \begin{macro}{\empaddtoTeX}
%     \begin{macro}{\empprelude}
%       \begin{macro}{\empaddtoprelude}
%    \begin{macrocode}
\def\empTeX#1{\emp@TeX={#1}}
\def\empaddtoTeX#1{\emp@TeX=\expandafter{\the\emp@TeX^^J#1}}
\def\empprelude#1{\emp@prelude={#1}}
\def\empaddtoprelude#1{\emp@prelude=\expandafter{\the\emp@prelude^^J#1}}
%    \end{macrocode}
%       \end{macro}
%     \end{macro}
%   \end{macro}
% \end{macro}
%
% \begin{macro}{\endempfile}
% And here is how we close the |empfile| environment:
%    \begin{macrocode}
\def\endempfile{%
  \expandafter\ifx\expandafter*\the\emp@TeX*\else
    \empwrite{verbatimtex^^J\string\end{document}^^Jetex;}%
  \fi
  \empwrite{\p@rcent\p@rcent\p@rcent\space the end.^^J%
            end.^^J%
            endinput;}%
  \let\theempfile\relax
  \if@empio
    \immediate\closeout\@outemp
  \fi}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\emp}
%    \begin{macrocode}
\newcommand{\emp}[1][*]{%
  \def\emp@@name{#1}%
  \emp@}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\emp@}
%    \begin{macrocode}
\def\emp@(#1,#2){%
  \emp@start{#1}{#2}%
  \emp@includegraphics{\theempfile}{\theempfig}%
  \empcmds}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\emp@start}
%    \begin{macrocode}
\def\emp@start#1#2{%
  \emp@checkfile
%    \end{macrocode}
% We can't use |\stepcounter| because of the |amstext| option of
% AMS-\LaTeX{} disables it sometimes.
%    \begin{macrocode}
  \global\expandafter\advance\csname c@empfig\endcsname \@ne
  \emp@@def{\emp@@name}%
%    \end{macrocode}
% Start the \MP{} figure:
%    \begin{macrocode}
  \empwrite{beginfig(\theempfig);^^J%
                     LaTeX_unitlength := \the\unitlength;^^J%
                     w := #1*LaTeX_unitlength;^^J%
                     h := #2*LaTeX_unitlength;}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\emp@checkfile}
% Make sure that a \MP{} file is open, otherwise \emph{really}
% obscure error messages are possible:
%    \begin{macrocode}
\def\emp@checkfile{%
  \ifx\theempfile\relax
    \errhelp={Outside a empfile environment, I have no clue as to where^^J%
              the MetaPost commands should go.   I will use empdefault.mp^^J%
              for this graph, but you'd better fix your code!}%
    \errmessage{I detected a emp environment outside of empfile}%
    \empfile[empdefault]
  \fi}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\emp@includegraphics}
%    \begin{macrocode}
\def\emp@includegraphics#1#2{%
  \leavevmode
  \IfFileExists{#1.#2}%
    {\includegraphics{#1.#2}}%
    {\typeout{%
      emp: File #1.#2\space not found:^^J%
      emp: Process #1.mp with MetaPost and then %
           reprocess this file.}}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\empcmds}
% Write to the file:
%    \begin{macrocode}
\def\empcmds{%
  \begingroup
    \@bsphack
    \let\do\@makeother\dospecials
    \catcode`\^^M\active
    \def\verbatim@processline{\empwrite{\the\verbatim@line}}%
    \verbatim@start}%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\endempcmds}
%    \begin{macrocode}
\def\endempcmds{%
    \@esphack
  \endgroup}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\endemp}
%    \begin{macrocode}
\def\endemp{%
  \endempcmds
  \empwrite{endfig;}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\empdef}
%    \begin{macrocode}
\newcommand{\empdef}[1][\relax]{%
  \def\emp@@name{#1}%
  \emp@def}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\emp@def}
%    \begin{macrocode}
\def\emp@def(#1,#2){%
  \emp@start{#1}{#2}%
  \empcmds}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\endempdef}
%    \begin{macrocode}
\def\endempdef{\endemp}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\emp@@def}
%    \begin{macrocode}
\def\emp@@def#1{%
  \global\e@namedef{emp@k:f:#1}{\theempfile}%
  \global\e@namedef{emp@k:c:#1}{\theempfig}}
\def\e@namedef#1{\expandafter\edef\csname #1\endcsname}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\empgraph}
%    \begin{macrocode}
\newcommand{\empgraph}[1][*]{%
  \def\emp@@name{#1}%
  \emp@graph}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\emp@graph}
%    \begin{macrocode}
\def\emp@graph(#1,#2){%
  \emp@start{#1}{#2}%
  \empwrite{draw begingraph (w, h);}%
  \emp@includegraphics{\theempfile}{\theempfig}%
  \empcmds}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\endempgraph}
%    \begin{macrocode}
\def\endempgraph{%
  \endempcmds
  \empwrite{endgraph;^^Jendfig;}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\empuse}
%    \begin{macrocode}
\def\empuse#1{%
  \@ifundefined{emp@k:f:#1}%
   {\typeout{emp: \string\empuse: `#1' undefined!}}%
   {\emp@includegraphics{\@nameuse{emp@k:f:#1}}{\@nameuse{emp@k:c:#1}}}}
%</style>
%    \end{macrocode}
% \end{macro}
%
% \Finale
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \appendix
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \section{Driver File}
%
%    \begin{macrocode}
%<*driver>
\documentclass[a4paper]{article}
\usepackage{doc}
\usepackage{amsmath}
%    \end{macrocode}
% The \MF{} and \MP{} logos come out much nicer if you have |mflogo|
% installed:
%    \begin{macrocode}
\IfFileExists{mflogo.sty}%
  {\usepackage{mflogo}%
   \def\FMF{\texttt{feyn}\textlogo{MF}}%
   \def\EMP{\textlogo{EMP}}}%
  {\def\MF{\textsf{META}\-\textsf{FONT}}%
   \def\MP{\textsf{META}\-\textsf{POST}}%
   \def\FMF{\texttt{feyn}\textsf{MF}}%
   \def\EMP{\textsf{EMF}}}
%    \end{macrocode}
% Protect against certain obsolete versions of the |graphics| package:
%    \begin{macrocode}
\usepackage{graphics}[1994/12/15]
\usepackage{emp}
%    \end{macrocode}
%    \begin{macrocode}
\setlength{\parindent}{0pt}
\def\manindex#1{\SortIndex{#1}{#1}}
%<manual>\OnlyDescription
\EnableCrossrefs
\RecordChanges
\CodelineIndex
\DoNotIndex{\def,\gdef,\long,\let,\begin,\end,\if,\ifx,\else,\fi}
\DoNotIndex{\immediate,\write,\newwrite,\openout,\closeout,\typeout}
\DoNotIndex{\font,\jobname,\documentclass,\char,\catcode,\ }
\DoNotIndex{\CodelineIndex,\DocInput,\DoNotIndex,\EnableCrossrefs}
\DoNotIndex{\filedate,\filename,\fileversion,\logo,\manfnt}
\DoNotIndex{\NeedsTeXFormat,\ProvidesPackage,\RecordChanges,\space}
\DoNotIndex{\begingroup,\csname,\edef,\endcsname,\expandafter}
\DoNotIndex{\usepackage,\@ifundefined,\ignorespaces,\item,\leavevmode}
\DoNotIndex{\newcounter,\newif,\par,\parindent}
\DoNotIndex{\relax,\setcounter,\stepcounter,\the,\advance}
\DoNotIndex{\CurrentOption,\DeclareOption,\documentstyle}
\DoNotIndex{\endgroup,\global,\hfuzz,\LaTeX,\LaTeXe}
\DoNotIndex{\macrocode,\OnlyDescription,\PassOptionsToPackage}
\DoNotIndex{\ProcessOptions,\RequirePackage,\string,\textsf,\unitlength}
\DoNotIndex{\@bsphack,\@esphack,\@nameuse,\@ne,\active,\do,\dospecials}
\DoNotIndex{\errhelp,\errmessage,\ifcase,\IfFileExists,\includegraphics}
\DoNotIndex{\manindex,\SortIndex,\newcommand,\newtoks,\or,\origmacrocode}
\DoNotIndex{\alpha,\displaystyle,\frac,\sin,\texttt}
%    \end{macrocode}
% Cut the line breaking some slack for macro code which might contain
% long lines (it doesn't really hurt if they stick out a bit).
%    \begin{macrocode}
\let\origmacrocode\macrocode
\def\macrocode{\hfuzz 5em\origmacrocode}
\begin{document}
  \DocInput{emp.dtx}
\end{document}
%</driver>
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\endinput
Local Variables:
mode:LaTeX
fill-prefix:"% "
indent-tabs-mode:nil
change-log-default-name:"TODO"
page-delimiter:"^% %%%%%%%%%*\n"
End:
