summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/emp/emp.dtx
blob: b502e62f7ce131f898a275e7801d9a06f089a85d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
% \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: