Debian Codegraph @

texmf-dist/source/latex/emp/emp.dtx

raw
1 % \iffalse % emp.dtx - Encapsulated MetaPost for LaTeX(2e)
2 % Copyright (C) 1997 by [email protected]
3 % $Id: emp.dtx,v 1.10 1997/11/12 21:14:41 ohl Exp $
4 %
5 % Emp is free software; you can redistribute it and/or modify it
6 % under the terms of the GNU General Public License as published by
7 % the Free Software Foundation; either version 2, or (at your option)
8 % any later version.
9 %
10 % Emp is distributed in the hope that it will be useful, but
11 % WITHOUT ANY WARRANTY; without even the implied warranty of
12 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 % GNU General Public License for more details.
14 %
15 % You should have received a copy of the GNU General Public License
16 % along with this program; if not, write to the Free Software
17 % Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 %
19 % \fi
20 %
21 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
22 %
23 %% \CheckSum{291}
24 %% \CharacterTable
25 %% {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
26 %% 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
27 %% Digits \0\1\2\3\4\5\6\7\8\9
28 %% Exclamation \! Double quote \" Hash (number) \#
29 %% Dollar \$ Percent \% Ampersand \&
30 %% Acute accent \' Left paren \( Right paren \)
31 %% Asterisk \* Plus \+ Comma \,
32 %% Minus \- Point \. Solidus \/
33 %% Colon \: Semicolon \; Less than \<
34 %% Equals \= Greater than \> Question mark \?
35 %% Commercial at \@ Left bracket \[ Backslash \\
36 %% Right bracket \] Circumflex \^ Underscore \_
37 %% Grave accent \` Left brace \{ Vertical bar \|
38 %% Right brace \} Tilde \~}
39 %%
40 %
41 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
42 %
43 % \MakeShortVerb{\|}
44 %
45 % \title{%
46 % \EMP: \\
47 % Encapsulated \MP{} for \LaTeX\thanks{%
48 % This is \texttt{\filename}, version \fileversion,
49 % revision \filerevision, date \filedate.}}
50 %
51 % \author{%
52 % Thorsten Ohl\thanks{e-mail:
53 % \texttt{[email protected]}}\\
54 % \hfil \\
55 % Technische Hochschule Darmstadt \\
56 % Schlo\ss gartenstr. 9 \\
57 % D-64289 Darmstadt \\
58 % Germany}
59 %
60 % \maketitle
61 % \begin{abstract}
62 % The \EMP{} package allows to encapsulate \MP{} files in \LaTeX{}
63 % sources. This is very useful for keeping illustrations in sync
64 % with the text. It also frees the user from inventing descriptive
65 % names for PostScript files that fit into the confines of file
66 % system conventions.
67 % \end{abstract}
68 %
69 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
70 % \vfill
71 % \section*{Copying}
72 %
73 % \EMP{} is free software; you can redistribute it and/or modify it
74 % under the terms of the GNU General Public License as published by
75 % the Free Software Foundation; either version 2, or (at your option)
76 % any later version.
77 %
78 % \EMP{} is distributed in the hope that it will be useful, but
79 % \emph{without any warranty}; without even the implied warranty of
80 % \emph{merchantability} or \emph{fitness for a particular purpose}.
81 % See the GNU General Public License for more details.
82 %
83 % You should have received a copy of the GNU General Public License
84 % along with this program; if not, write to the Free Software
85 % Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
86 %
87 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
88 % \newpage
89 % \unitlength=1mm
90 % \def\topfraction{0.9}
91 % \def\bottomfraction{0.9}
92 % \def\textfraction{0.1}
93 % \empaddtoTeX{\usepackage{amsmath}}
94 % \empprelude{input graph}
95 % \begin{empfile}
96 %
97 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
98 % \section{Introduction}
99 %
100 % When adding illustrations to documents, one faces two bookkeeping
101 % problems:
102 % \begin{enumerate}
103 % \item How to encourage oneself to keep the illustrations in sync
104 % with the text, when the document is updated?
105 % \item How to make sure that the illustrations appear on the right
106 % spot?
107 % \end{enumerate}
108 % For both problems, the best solution is to encapsulate the figures
109 % in the \LaTeX{} source:
110 % \begin{enumerate}
111 % \item It is much easier to remember to update an illustration if
112 % one doesn't have to switch files in the editor.
113 % \item One does not have to invent illustrative file names, if
114 % the computer keeps track of them.
115 % \end{enumerate}
116 % Therefore \EMP{} was written to allow to encapsulate
117 % \MP~\cite{MP,LaTeX-Graphics-Companion} into
118 % \LaTeX~\cite{LaTeX-Graphics-Companion,LaTeX,LaTeX-Companion}.
119 %
120 % These macros have some overlap with
121 % \FMF~\cite{LaTeX-Graphics-Companion,FeynMF},
122 % |axodraw|~\cite{axodraw} and
123 % |mfpic|~\cite{LaTeX-Graphics-Companion,mfpic}. In fact, most of the
124 % functionality of \EMP{} is available from \FMF. Longer pieces of
125 % \MP{} code are however not very conveniently typed in \FMF, because
126 % there is no facility for multi line input (using |\fmfcmd| with long
127 % arguments can overflow \MP's input buffers because of the missing
128 % line breaks). Since \FMF{} provides much syntax that is superfluous
129 % for \EMP's purpose (the \EMP{} package exports only five new
130 % environments and five commands), it is more appropriate to create a
131 % separate small package than to add this functionality to \FMF.
132 % Similar comments apply to |mfpic|.
133 %
134 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
135 % \section{Usage}
136 %
137 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
138 % \subsection{Commands and Environments}
139 % \label{sec:commands}
140 %
141 % \DescribeEnv{empfile}
142 % All descriptions that should go into one \MP{} file are placed
143 % inside a |empfile| environment which takes the name of the \MP{}
144 % file as an optional argument:
145 % \begin{quote}
146 % \begin{flushleft}
147 % |\begin{empfile}[|\meta{\MP-file}|]|\\
148 % \qquad\ldots\\
149 % |\end{empfile}|
150 % \end{flushleft}
151 % \end{quote}
152 % The default \MP-filename is |\jobname.mp|.
153 %
154 % \DescribeEnv{emp}
155 % The |emp| environment contains the description of a single
156 % figure that will be placed at the location of the environment.
157 % Required arguments are the width and the height of the figure, in
158 % units of |\unitlength|. They will be available as the \MP{}
159 % variables~|w| and~|h|. The optional argument assigns a name to be
160 % used with |\empuse{|\meta{name}|}|.
161 % \begin{quote}
162 % \begin{flushleft}
163 % |\begin{emp}[|\meta{name}|](|\meta{width}|,|\meta{height}|)|\\
164 % \qquad\meta{\MP-commands}\\
165 % |\end{emp}|
166 % \end{flushleft}
167 % \end{quote}
168 % Note that this environment uses the |verbatim| package to process
169 % the input lines and can therefore \emph{not} be used as an argument
170 % to another macros. To work around this problem, you can first use
171 % the |empdef| environment and |\empuse| it later.
172 %
173 % \DescribeMacro{\empuse}
174 % Reuse a previously defined figure.
175 %
176 % \DescribeEnv{empdef}
177 % The |empdef| environment is similar to |emp|, but the figure is not
178 % drawn. This is useful, because these environments use the
179 % |verbatim| package and can therefore \emph{not} be used as an
180 % argument to another macros.
181 % \begin{quote}
182 % \begin{flushleft}
183 % |\begin{empdef}[|\meta{name}|](|\meta{width}|,|\meta{height}|)|\\
184 % \qquad\meta{\MP-commands}\\
185 % |\end{empdef}|
186 % \end{flushleft}
187 % \end{quote}
188 %
189 % \DescribeEnv{empcmds}
190 % Write \MP{} commands to the current file outside of a figure.
191 % \begin{quote}
192 % \begin{flushleft}
193 % |\begin{empcmds}|\\
194 % \qquad\meta{\MP-commands}\\
195 % |\end{empcmds}|
196 % \end{flushleft}
197 % \end{quote}
198 %
199 % \DescribeEnv{empgraph}
200 % The |empgraph| environment contains the description of a graph
201 % that will be placed a the location of the environment.
202 % The user is responsible for including the |graph| package by the
203 % using the command |\empprelude{input graph}| in the preamble.
204 % Required arguments are the width and
205 % the height of the graph, in units of |\unitlength|. They will be
206 % available as the \MP{} variables~|w| and~|h|. The optional argument
207 % assigns a name to be used with |\empuse{|\meta{name}|}|.
208 % \begin{quote}
209 % \begin{flushleft}
210 % |\begin{empgraph}[|\meta{name}|](|\meta{width}|,|\meta{height}|)|\\
211 % \qquad\meta{\MP-commands}\\
212 % |\end{empgraph}|
213 % \end{flushleft}
214 % \end{quote}
215 %
216 % \DescribeMacro{\empTeX}
217 % Define a \LaTeX{} prelude to be written to the top of every \MP{}
218 % file. The default is |\documentclass[|\meta{ptsize}|]{article}|.
219 % If the prelude is not empty, |\begin{document}| will be added. Note
220 % that you have to run \MP{} as |TEX=latex mpost| \meta{filename} if the
221 % prelude calls \LaTeX.
222 %
223 % \DescribeMacro{\empaddtoTeX}
224 % Add to the \LaTeX{} prelude.
225 % E.g.~|\empaddtoTeX{\usepackage{euler}}| makes sure that \MP{} will
226 % use the Euler fonts for the labels.
227 %
228 % \DescribeMacro{\empprelude}
229 % \DescribeMacro{\empaddtoprelude}
230 % Define and add to a \MP{} prelude to the top of every \MP{} file.
231 % The default is empty.
232 %
233 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
234 % \subsection{Examples}
235 % \label{sec:examples}
236 %
237 % For a simple example, let's draw a smiling and a frowning face.
238 % Since they are identical except for the mouth, we prepare a macro
239 % for the common parts:
240 % \begin{macrocode}
241 %<*sample>
242 \begin{empcmds}
243 vardef draw_face =
244 pair lefteye, righteye, nose[];
245 lefteye = c + (-0.25w,0.15h); righteye = c + (0.25w,0.15h);
246 nose1 = c - (0,0.05h); nose2 = c + (0,0.15h);
247 pickup pencircle scaled 1;
248 draw fullcircle xscaled w yscaled h shifted c;
249 draw fullcircle scaled 2 shifted lefteye;
250 draw fullcircle scaled 2 shifted righteye;
251 draw nose1--nose2; draw mouth1..mouth2..mouth3;
252 setbounds currentpicture to unitsquare xscaled w yscaled .5h;
253 enddef;
254 \end{empcmds}
255 % \end{macrocode}
256 % \begin{empcmds}
257 vardef draw_face =
258 pair lefteye, righteye, nose[];
259 lefteye = c + (-0.25w,0.15h); righteye = c + (0.25w,0.15h);
260 nose1 = c - (0,0.05h); nose2 = c + (0,0.15h);
261 pickup pencircle scaled 1;
262 draw fullcircle xscaled w yscaled h shifted c;
263 draw fullcircle scaled 2 shifted lefteye;
264 draw fullcircle scaled 2 shifted righteye;
265 draw nose1--nose2; draw mouth1..mouth2..mouth3;
266 setbounds currentpicture to unitsquare xscaled w yscaled .5h;
267 enddef;
268 \end{empcmds}
269 % This can now be used for the frowning
270 % \begin{emp}[frown](5,5)
271 pair mouth[], c; c = (0.5w,0);
272 mouth1 = c + (-0.2w,-0.25h);
273 mouth2 = c + (0,-0.2h);
274 mouth3 = c + (0.2w,-0.25h);
275 draw_face;
276 \end{emp}
277 % \begin{macrocode}
278 \begin{emp}(5,5)
279 pair mouth[], c; c = (0.5w,0);
280 mouth1 = c + (-0.2w,-0.25h);
281 mouth2 = c + (0,-0.2h);
282 mouth3 = c + (0.2w,-0.25h);
283 draw_face;
284 \end{emp}
285 % \end{macrocode}
286 % and the smiling
287 % \begin{emp}[smile](5,5)
288 pair mouth[], c; c = (0.5w,0);
289 mouth1 = c + (-0.2w,-0.2h);
290 mouth2 = c + (0,-0.25h);
291 mouth3 = c + (0.2w,-0.2h);
292 draw_face;
293 \end{emp}
294 % face
295 % \begin{macrocode}
296 \begin{emp}[smile](5,5)
297 pair mouth[], c; c = (0.5w,0);
298 mouth1 = c + (-0.2w,-0.2h);
299 mouth2 = c + (0,-0.25h);
300 mouth3 = c + (0.2w,-0.2h);
301 draw_face;
302 \end{emp}
303 % \end{macrocode}
304 % Since we have given a name to |smile|, we can now use it with
305 % |\empuse{smile}|:
306 % \begin{itemize}
307 % \item[\empuse{smile}] Note that the reference point has been set
308 % up such that it works best as replacement for |\bullet| in
309 % |itemize| environments.
310 % \item[\empuse{smile}] This is very useful for slides.
311 % \end{itemize}
312 %
313 % \begin{figure}
314 % \begin{center}
315 % \begin{empgraph}(60,40)
316 pickup pencircle scaled 1pt;
317 path p;
318 for x = -20 step 0.2 until -0.2:
319 augment.p (x, sind(x*180/3.14159)/x);
320 endfor
321 augment.p (0, 1);
322 for x = 0.2 step 0.2 until 20:
323 augment.p (x, sind(x*180/3.14159)/x);
324 endfor
325 gdraw p;
326 glabel.lrt (btex $\displaystyle\frac{\sin(x)}{x}$ etex, (-20,1));
327 \end{empgraph}
328 % \vspace*{-1.5\baselineskip}
329 % \end{center}
330 % \caption{\label{fig:graph}%
331 % \texttt{graph} example.}
332 % \end{figure}
333 % As a second example, the simple plot of
334 % \begin{equation}
335 % j_0 = \frac{\sin(x)}{x}
336 % \end{equation}
337 % is shown in figure~\ref{fig:graph}:
338 % \begin{macrocode}
339 \begin{empgraph}(60,40)
340 pickup pencircle scaled 1pt;
341 path p;
342 for x = -20 step 0.2 until -0.2:
343 augment.p (x, sind(x*180/3.14159)/x);
344 endfor
345 augment.p (0, 1);
346 for x = 0.2 step 0.2 until 20:
347 augment.p (x, sind(x*180/3.14159)/x);
348 endfor
349 glabel.lrt (btex $$\displaystyle\frac{\sin(x)}{x}$$ etex, (-20,1));
350 gdraw p;
351 \end{empgraph}
352 % \end{macrocode}
353 % The command |\empprelude{input graph}| must have been put in the
354 % preamble to make the |graph| package available.
355 %
356 % \begin{figure}
357 % \begin{center}
358 % \begin{empgraph}(60,40)
359 pi = 3.14159; beta0 = 11 - 2/3*4;
360 lambda1 = 0.15; lambda2 = 0.25;
361 vardef ln expr x = (mlog x) / 256 enddef;
362 vardef alphas (expr x, l) = 4*pi/(beta0*2ln(x/l)) enddef;
363 setcoords (log,linear);
364 pickup pencircle scaled 1pt;
365 path p[];
366 for x = 0.5 step 0.1 until 10:
367 augment.p1 (x, alphas (x, lambda1));
368 augment.p2 (x, alphas (x, lambda2));
369 endfor
370 gfill p1--(reverse p2)--cycle withcolor .5white;
371 glabel.lft (btex $\alpha_s(Q^2)$ etex rotated 90, OUT);
372 glabel.bot (btex $Q^2/\text{GeV}$ etex, OUT);
373 \end{empgraph}
374 % \vspace*{-1.5\baselineskip}
375 % \end{center}
376 % \caption{\label{fig:alphas}%
377 % Another \texttt{graph} example.}
378 % \end{figure}
379 % Finally, another application of the |graph| package:
380 % \begin{equation}
381 % \alpha_s(Q^2) = \frac{4\pi}{\beta_0\ln(Q^2/\Lambda_{\text{QCD}}^2)}
382 % \end{equation}
383 % with $\Lambda_{\text{QCD}}\in[0.15\,\text{GeV},0.25\,\text{GeV}]$
384 % and $\beta_0=11-2N_f/3$ is shown in figure~\ref{fig:alphas}:
385 % \begin{macrocode}
386 \begin{empgraph}(60,40)
387 pi = 3.14159; beta0 = 11 - 2/3*4;
388 lambda1 = 0.15; lambda2 = 0.25;
389 vardef ln expr x = (mlog x) / 256 enddef;
390 vardef alphas (expr x, l) = 4*pi/(beta0*2ln(x/l)) enddef;
391 setcoords (log,linear);
392 pickup pencircle scaled 1pt;
393 path p[];
394 for x = 0.5 step 0.1 until 10:
395 augment.p1 (x, alphas (x, lambda1));
396 augment.p2 (x, alphas (x, lambda2));
397 endfor
398 gfill p1--(reverse p2)--cycle withcolor .5white;
399 glabel.lft (btex $\alpha_s(Q^2)$ etex rotated 90, OUT);
400 glabel.bot (btex $Q^2/\text{GeV}$ etex, OUT);
401 \end{empgraph}
402 %</sample>
403 % \end{macrocode}
404 % Note that the |\text| macro of AMS-\LaTeX{} has been used,
405 % therefore, the command |\empaddtoTeX{\usepackage{amsmath}}| must
406 % have been put in the preamble for this example to work.
407 %
408 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
409 % \begin{thebibliography}{99}
410 % \bibitem{MP} John D.~Hobby, \textit{A User's Manual for
411 % \MP}, Computer Science Report \#162, AT\&T Bell
412 % Laboratories, April 1992.
413 % \bibitem{LaTeX-Graphics-Companion} Michel Goossens, Sebastian
414 % Rahtz, and Frank Mittelbach, \textit{The \LaTeX{} Graphics
415 % Companion}, Addison-Wesley, Reading MA, 1997.
416 % \bibitem{LaTeX} Leslie Lamport, \textit{\LaTeX{} --- A
417 % Documentation Preparation System},
418 % Addison-Wesley, Reading MA, 1985.
419 % \bibitem{LaTeX-Companion} Michel Goossens, Frank Mittelbach, and
420 % Alexander Samarin, \textit{The \LaTeX{} Companion},
421 % Addison-Wesley, Reading MA, 1994.
422 % \bibitem{FeynMF} Thorsten Ohl,
423 % Comp.~Phys.~Comm.~\textbf{90} (1995) 340;
424 % CERN Computer Newsletter~\textbf{220} (1995) 22;
425 % \textbf{221} (1995) 46; \textbf{222} (1996) 24.
426 % \texttt{axodraw} is available from CTAN
427 % (cf.~p.~\pageref{pg:CTAN}), in the
428 % \texttt{latex/contrib/supported} directory.
429 % \bibitem{axodraw} Jos Vermaseren,
430 % Comp.~Phys.~Comm.~\textbf{83} (1994) 45.
431 % \texttt{axodraw} is available from CTAN
432 % (cf.~p.~\pageref{pg:CTAN}), in the \texttt{graphics} directory.
433 % \bibitem{mfpic} Thomas E.~Leathrum, \texttt{mfpic}, available from
434 % CTAN (cf.~p.~\pageref{pg:CTAN}), in the \texttt{graphics}
435 % directory.
436 % \end{thebibliography}
437 %
438 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
439 % \section*{Distribution}
440 % \label{sec:distribution}
441 %
442 % \EMP{} is available by anonymous internet ftp from any of the
443 % Comprehensive \TeX{} Archive Network (CTAN) hosts
444 % \label{pg:CTAN}
445 % \begin{quote}
446 % |ftp.tex.ac.uk|, |ftp.dante.de|
447 % \end{quote}
448 % in the directory
449 % \begin{quote}
450 % |macros/latex/contrib/supported/emp|
451 % \end{quote}
452 % It is also available from the host
453 % \begin{quote}
454 % |crunch.ikp.physik.tu-darmstadt.de|
455 % \end{quote}
456 % in the directory
457 % \begin{quote}
458 % |pub/ohl/emp|
459 % \end{quote}
460 % Unsupported snapshots of work in progress are provided as
461 % \begin{quote}
462 % |pub/ohl/emp.versions/emp-current.tar.gz|
463 % \end{quote}
464 % ^^A There are two mailing lists
465 % ^^A \begin{quote}
466 % ^^A \begin{flushleft}
467 % ^^A |[email protected]|\\
468 % ^^A |[email protected]|
469 % ^^A \end{flushleft}
470 % ^^A \end{quote}
471 % ^^A open for subscription. The former should carry only important
472 % ^^A announcements, of new versions in particular. To subscribe, send
473 % ^^A mail to the (electronic) mailing list manager
474 % ^^A \begin{quote}
475 % ^^A |[email protected]|
476 % ^^A \end{quote}
477 % ^^A and \emph{not} to the lists itself. The following commands (on a
478 % ^^A line in the body of the mail, not in the subject) are useful:
479 % ^^A \begin{quote}
480 % ^^A \begin{flushleft}
481 % ^^A |subscribe emp-announce|\\
482 % ^^A |unsubscribe emp-announce|\\
483 % ^^A |help|
484 % ^^A \end{flushleft}
485 % ^^A \end{quote}
486 %
487 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
488 % \end{empfile}
489 % \StopEventually{\PrintIndex\PrintChanges}
490 %
491 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
492 % \section{Implementation}
493 % \changes{v1.00}{1997/11/12}{Version 1.00 frozen.}
494 %
495 % It's is good practice to identify this version of the document style
496 % option. We do this by parsing an RCS |Id| string and storing the
497 % result in the conventional \TeX{} control sequences:
498 % \begin{macrocode}
499 %<*style>
500 \def\fileversion{v1.00}
501 \NeedsTeXFormat{LaTeX2e}
502 {\def\RCS#1#2\endRCS{%
503 \ifx$#1%
504 \@RCS $#2 \endRCS
505 \else
506 \@RCS $*: #1#2$ \endRCS
507 \fi}%
508 \def\@RCS $#1: #2,v #3 #4 #5 #6 #7$ \endRCS{%
509 \gdef\filename{#2}%
510 \gdef\filerevision{#3}%
511 \gdef\filedate{#4}%
512 \gdef\filemaintainer{#6}}%
513 \RCS $Id: emp.dtx,v 1.10 1997/11/12 21:14:41 ohl Exp $ \endRCS}%
514 % \end{macrocode}
515 %
516 % And now the standard procedure:
517 % \begin{macrocode}
518 \ProvidesPackage{emp}[\filedate\space\fileversion\space
519 Encapsulated MetaPost LaTeX Package (\filemaintainer)]
520 % \end{macrocode}
521 % Every option we don't understand is sent down to |graphics|:
522 % \begin{macrocode}
523 \DeclareOption*{\PassOptionsToPackage{\CurrentOption}{graphics}}
524 \ProcessOptions
525 \RequirePackage{graphics}[1994/12/15]
526 \RequirePackage{verbatim}
527 % \end{macrocode}
528 %
529 % \begin{macro}{\empwrite}
530 % \begin{macrocode}
531 {\catcode`\%=11\gdef\p@rcent{%}}
532 \def\empwrite#1{%
533 \if@empio
534 \immediate\write\@outemp{#1}%
535 \fi
536 \ignorespaces}
537 \newif\if@empio
538 \@empiotrue
539 \newwrite\@outemp
540 % \end{macrocode}
541 % \end{macro}
542 %
543 % \begin{macro}{\empfile}
544 % This environment encloses each \MP{} input file. The single optional
545 % argument gives the name of the file.
546 % \begin{macrocode}
547 \newcommand{\empfile}[1][\jobname]{%
548 \def\theempfile{#1}%
549 % \end{macrocode}
550 % Open the \MP{} file. If we're running under AMS-\LaTeX, turn off
551 % I/O during the first pass over equation environments.
552 % \begin{macrocode}
553 \if@empio
554 \@ifundefined{ifmeasuring@}%
555 {}%
556 {\def\if@empio{\ifmeasuring@\else}}%
557 \immediate\openout\@outemp=\theempfile.mp\relax
558 \empwrite{\p@rcent\p@rcent\p@rcent\space \theempfile.mp -- %
559 do not edit, generated automatically by \jobname.tex}%
560 % \end{macrocode}
561 % append |\begin{document}| to a non-empty |\LaTeX| prelude and write
562 % it out:
563 % \begin{macrocode}
564 \expandafter\ifx\expandafter*\the\emp@TeX*\else
565 \emp@TeX=\expandafter{\the\emp@TeX^^J\begin{document}}%
566 \empwrite{verbatimtex^^J\the\emp@TeX^^Jetex;}%
567 \fi
568 \expandafter\ifx\expandafter*\the\emp@prelude*\else
569 \empwrite{\the\emp@prelude;}%
570 \fi
571 \fi
572 % \end{macrocode}
573 % Count the figures
574 % \begin{macrocode}
575 \setcounter{empfig}{0}}
576 \let\theempfile\relax
577 \newcounter{empfig}
578 % \end{macrocode}
579 % Standard preludes:
580 % \begin{macrocode}
581 \newtoks\emp@TeX
582 \ifcase\@ptsize
583 \emp@TeX={\documentclass[10pt]{article}}
584 \or
585 \emp@TeX={\documentclass[11pt]{article}}
586 \or
587 \emp@TeX={\documentclass[12pt]{article}}
588 \else
589 \emp@TeX={\documentclass{article}}
590 \fi
591 \newtoks\emp@prelude
592 % \end{macrocode}
593 % \end{macro}
594 %
595 % \begin{macro}{\empTeX}
596 % \begin{macro}{\empaddtoTeX}
597 % \begin{macro}{\empprelude}
598 % \begin{macro}{\empaddtoprelude}
599 % \begin{macrocode}
600 \def\empTeX#1{\emp@TeX={#1}}
601 \def\empaddtoTeX#1{\emp@TeX=\expandafter{\the\emp@TeX^^J#1}}
602 \def\empprelude#1{\emp@prelude={#1}}
603 \def\empaddtoprelude#1{\emp@prelude=\expandafter{\the\emp@prelude^^J#1}}
604 % \end{macrocode}
605 % \end{macro}
606 % \end{macro}
607 % \end{macro}
608 % \end{macro}
609 %
610 % \begin{macro}{\endempfile}
611 % And here is how we close the |empfile| environment:
612 % \begin{macrocode}
613 \def\endempfile{%
614 \expandafter\ifx\expandafter*\the\emp@TeX*\else
615 \empwrite{verbatimtex^^J\string\end{document}^^Jetex;}%
616 \fi
617 \empwrite{\p@rcent\p@rcent\p@rcent\space the end.^^J%
618 end.^^J%
619 endinput;}%
620 \let\theempfile\relax
621 \if@empio
622 \immediate\closeout\@outemp
623 \fi}
624 % \end{macrocode}
625 % \end{macro}
626 %
627 % \begin{macro}{\emp}
628 % \begin{macrocode}
629 \newcommand{\emp}[1][*]{%
630 \def\emp@@name{#1}%
631 \emp@}
632 % \end{macrocode}
633 % \end{macro}
634 %
635 % \begin{macro}{\emp@}
636 % \begin{macrocode}
637 \def\emp@(#1,#2){%
638 \emp@start{#1}{#2}%
639 \emp@includegraphics{\theempfile}{\theempfig}%
640 \empcmds}
641 % \end{macrocode}
642 % \end{macro}
643 %
644 % \begin{macro}{\emp@start}
645 % \begin{macrocode}
646 \def\emp@start#1#2{%
647 \emp@checkfile
648 % \end{macrocode}
649 % We can't use |\stepcounter| because of the |amstext| option of
650 % AMS-\LaTeX{} disables it sometimes.
651 % \begin{macrocode}
652 \global\expandafter\advance\csname c@empfig\endcsname \@ne
653 \emp@@def{\emp@@name}%
654 % \end{macrocode}
655 % Start the \MP{} figure:
656 % \begin{macrocode}
657 \empwrite{beginfig(\theempfig);^^J%
658 LaTeX_unitlength := \the\unitlength;^^J%
659 w := #1*LaTeX_unitlength;^^J%
660 h := #2*LaTeX_unitlength;}}
661 % \end{macrocode}
662 % \end{macro}
663 %
664 % \begin{macro}{\emp@checkfile}
665 % Make sure that a \MP{} file is open, otherwise \emph{really}
666 % obscure error messages are possible:
667 % \begin{macrocode}
668 \def\emp@checkfile{%
669 \ifx\theempfile\relax
670 \errhelp={Outside a empfile environment, I have no clue as to where^^J%
671 the MetaPost commands should go. I will use empdefault.mp^^J%
672 for this graph, but you'd better fix your code!}%
673 \errmessage{I detected a emp environment outside of empfile}%
674 \empfile[empdefault]
675 \fi}
676 % \end{macrocode}
677 % \end{macro}
678 %
679 % \begin{macro}{\emp@includegraphics}
680 % \begin{macrocode}
681 \def\emp@includegraphics#1#2{%
682 \leavevmode
683 \IfFileExists{#1.#2}%
684 {\includegraphics{#1.#2}}%
685 {\typeout{%
686 emp: File #1.#2\space not found:^^J%
687 emp: Process #1.mp with MetaPost and then %
688 reprocess this file.}}}
689 % \end{macrocode}
690 % \end{macro}
691 %
692 % \begin{macro}{\empcmds}
693 % Write to the file:
694 % \begin{macrocode}
695 \def\empcmds{%
696 \begingroup
697 \@bsphack
698 \let\do\@makeother\dospecials
699 \catcode`\^^M\active
700 \def\verbatim@processline{\empwrite{\the\verbatim@line}}%
701 \verbatim@start}%
702 % \end{macrocode}
703 % \end{macro}
704 %
705 % \begin{macro}{\endempcmds}
706 % \begin{macrocode}
707 \def\endempcmds{%
708 \@esphack
709 \endgroup}
710 % \end{macrocode}
711 % \end{macro}
712 %
713 % \begin{macro}{\endemp}
714 % \begin{macrocode}
715 \def\endemp{%
716 \endempcmds
717 \empwrite{endfig;}}
718 % \end{macrocode}
719 % \end{macro}
720 %
721 % \begin{macro}{\empdef}
722 % \begin{macrocode}
723 \newcommand{\empdef}[1][\relax]{%
724 \def\emp@@name{#1}%
725 \emp@def}
726 % \end{macrocode}
727 % \end{macro}
728 %
729 % \begin{macro}{\emp@def}
730 % \begin{macrocode}
731 \def\emp@def(#1,#2){%
732 \emp@start{#1}{#2}%
733 \empcmds}
734 % \end{macrocode}
735 % \end{macro}
736 %
737 % \begin{macro}{\endempdef}
738 % \begin{macrocode}
739 \def\endempdef{\endemp}
740 % \end{macrocode}
741 % \end{macro}
742 %
743 % \begin{macro}{\emp@@def}
744 % \begin{macrocode}
745 \def\emp@@def#1{%
746 \global\e@namedef{emp@k:f:#1}{\theempfile}%
747 \global\e@namedef{emp@k:c:#1}{\theempfig}}
748 \def\e@namedef#1{\expandafter\edef\csname #1\endcsname}
749 % \end{macrocode}
750 % \end{macro}
751 %
752 % \begin{macro}{\empgraph}
753 % \begin{macrocode}
754 \newcommand{\empgraph}[1][*]{%
755 \def\emp@@name{#1}%
756 \emp@graph}
757 % \end{macrocode}
758 % \end{macro}
759 %
760 % \begin{macro}{\emp@graph}
761 % \begin{macrocode}
762 \def\emp@graph(#1,#2){%
763 \emp@start{#1}{#2}%
764 \empwrite{draw begingraph (w, h);}%
765 \emp@includegraphics{\theempfile}{\theempfig}%
766 \empcmds}
767 % \end{macrocode}
768 % \end{macro}
769 %
770 % \begin{macro}{\endempgraph}
771 % \begin{macrocode}
772 \def\endempgraph{%
773 \endempcmds
774 \empwrite{endgraph;^^Jendfig;}}
775 % \end{macrocode}
776 % \end{macro}
777 %
778 % \begin{macro}{\empuse}
779 % \begin{macrocode}
780 \def\empuse#1{%
781 \@ifundefined{emp@k:f:#1}%
782 {\typeout{emp: \string\empuse: `#1' undefined!}}%
783 {\emp@includegraphics{\@nameuse{emp@k:f:#1}}{\@nameuse{emp@k:c:#1}}}}
784 %</style>
785 % \end{macrocode}
786 % \end{macro}
787 %
788 % \Finale
789 %
790 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
791 % \appendix
792 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
793 % \section{Driver File}
794 %
795 % \begin{macrocode}
796 %<*driver>
797 \documentclass[a4paper]{article}
798 \usepackage{doc}
799 \usepackage{amsmath}
800 % \end{macrocode}
801 % The \MF{} and \MP{} logos come out much nicer if you have |mflogo|
802 % installed:
803 % \begin{macrocode}
804 \IfFileExists{mflogo.sty}%
805 {\usepackage{mflogo}%
806 \def\FMF{\texttt{feyn}\textlogo{MF}}%
807 \def\EMP{\textlogo{EMP}}}%
808 {\def\MF{\textsf{META}\-\textsf{FONT}}%
809 \def\MP{\textsf{META}\-\textsf{POST}}%
810 \def\FMF{\texttt{feyn}\textsf{MF}}%
811 \def\EMP{\textsf{EMF}}}
812 % \end{macrocode}
813 % Protect against certain obsolete versions of the |graphics| package:
814 % \begin{macrocode}
815 \usepackage{graphics}[1994/12/15]
816 \usepackage{emp}
817 % \end{macrocode}
818 % \begin{macrocode}
819 \setlength{\parindent}{0pt}
820 \def\manindex#1{\SortIndex{#1}{#1}}
821 %<manual>\OnlyDescription
822 \EnableCrossrefs
823 \RecordChanges
824 \CodelineIndex
825 \DoNotIndex{\def,\gdef,\long,\let,\begin,\end,\if,\ifx,\else,\fi}
826 \DoNotIndex{\immediate,\write,\newwrite,\openout,\closeout,\typeout}
827 \DoNotIndex{\font,\jobname,\documentclass,\char,\catcode,\ }
828 \DoNotIndex{\CodelineIndex,\DocInput,\DoNotIndex,\EnableCrossrefs}
829 \DoNotIndex{\filedate,\filename,\fileversion,\logo,\manfnt}
830 \DoNotIndex{\NeedsTeXFormat,\ProvidesPackage,\RecordChanges,\space}
831 \DoNotIndex{\begingroup,\csname,\edef,\endcsname,\expandafter}
832 \DoNotIndex{\usepackage,\@ifundefined,\ignorespaces,\item,\leavevmode}
833 \DoNotIndex{\newcounter,\newif,\par,\parindent}
834 \DoNotIndex{\relax,\setcounter,\stepcounter,\the,\advance}
835 \DoNotIndex{\CurrentOption,\DeclareOption,\documentstyle}
836 \DoNotIndex{\endgroup,\global,\hfuzz,\LaTeX,\LaTeXe}
837 \DoNotIndex{\macrocode,\OnlyDescription,\PassOptionsToPackage}
838 \DoNotIndex{\ProcessOptions,\RequirePackage,\string,\textsf,\unitlength}
839 \DoNotIndex{\@bsphack,\@esphack,\@nameuse,\@ne,\active,\do,\dospecials}
840 \DoNotIndex{\errhelp,\errmessage,\ifcase,\IfFileExists,\includegraphics}
841 \DoNotIndex{\manindex,\SortIndex,\newcommand,\newtoks,\or,\origmacrocode}
842 \DoNotIndex{\alpha,\displaystyle,\frac,\sin,\texttt}
843 % \end{macrocode}
844 % Cut the line breaking some slack for macro code which might contain
845 % long lines (it doesn't really hurt if they stick out a bit).
846 % \begin{macrocode}
847 \let\origmacrocode\macrocode
848 \def\macrocode{\hfuzz 5em\origmacrocode}
849 \begin{document}
850 \DocInput{emp.dtx}
851 \end{document}
852 %</driver>
853 % \end{macrocode}
854 %
855 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
856 \endinput
857 Local Variables:
858 mode:LaTeX
859 fill-prefix:"% "
860 indent-tabs-mode:nil
861 change-log-default-name:"TODO"
862 page-delimiter:"^% %%%%%%%%%*\n"
863 End: