summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/mpgraphics/mpgraphics.dtx
blob: 43d061784901ca9339fea757d27c7f6b1be52a86 (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
% \iffalse 
%<*internal>
\iffalse
%</internal>
%<*readme>
_________________
The mpgraphics package
v0.3

mpgraphics allows users to typeset metapost inline and display
figures in their LaTeX documents with only and only one run of 
LaTeX, or PDFLaTeX, or XelaTeX (no separate runs of mpost). 
mpgraphics achieves this by using shell scape or write 18 
feature so the whole process is automatic and the 
end user do not need to carry out the long process.

If you want to report any bugs or typos and corrections in the documentation,
or ask for any new features, or suggest any improvements, or ask any questions
about the package, then please do not send any direct emails to us; we will not 
answer any direct emails. Instead please use the issue tracker:
  <https://github.com/persian-tex/mpgraphics/issues>
In doing so, please always explain your issue well enough, always include
a minimal working examples showing the issue, and always choose the appropriate
label for your query (i.e. if you are reporting any bugs, choose `bug' label). 

Current version release date: 2013/04/04

______________
Persian TeX Group
persian-tex@tug.org

Copyright © 2011-2013
Distributed under the LaTeX Project Public License
It may be distributed and/or modified under the LaTeX Project Public License,
version 1.3c or higher (your choice). The latest version of
this license is at: http://www.latex-project.org/lppl.txt

This work is “maintained” (as per LPPL maintenance status) 
by Persian TeX Group.
%</readme>
%<*internal>
\fi
\begingroup
%</internal>
%<*batchfile>
\input docstrip.tex
\keepsilent
\preamble

  ______________________________________
  Copyright © 2011-2013  Persian TeX Group

  License information appended.


\endpreamble
\postamble

Copyright © 2011-2013  Persian TeX Group <persian-tex@tug.org>

It may be distributed and/or modified under the LaTeX Project Public License,
version 1.3c or higher (your choice). The latest version of
this license is at: http://www.latex-project.org/lppl.txt

This work is “maintained” (as per LPPL maintenance status) 
by Persian TeX Group.



\endpostamble
\askforoverwritefalse
\generate{\file{mpgraphics.sty}{\from{\jobname.dtx}{mpgraphics.sty}}}
%</batchfile>
%<batchfile>\endbatchfile
%<*internal>
\generate{\file{\jobname.ins}{\from{\jobname.dtx}{batchfile}}}
\nopreamble\nopostamble
\generate{\file{README.txt}{\from{\jobname.dtx}{readme}}}
\generate{\file{mpgraphics-example.ltx}{\from{\jobname.dtx}{mpgraphics-example.ltx}}}
\endgroup
\immediate\write18{mv README.txt README}
\immediate\write18{makeindex -s gind.ist -o \jobname.ind  \jobname.idx}
\immediate\write18{makeindex -s gglo.ist -o \jobname.gls  \jobname.glo}
%</internal>
%
%<*driver>
\documentclass{ltxdoc}
\usepackage{url,wrapfig,graphicx}
\usepackage{fontspec}
\usepackage{calc}
\usepackage{pifont}
\usepackage{bbding}
\usepackage{bidicode}
\usepackage[numbered]{hypdoc}
\definecolor{bidiblue}{rgb}{0.1,0.2,0.8}
\definecolor{myred}{rgb}{0.65,0.04,0.07}
\hypersetup{linkcolor=bidiblue,urlcolor=bidiblue,citecolor=bidiblue}
\usepackage{bidi}
\setlength\columnseprule{.4pt}
\newcommand\cmdtype[1]{\textcolor{myred}{\texttt{#1}}}
\def\mpg{\textsf{mpgraphics} package}
\def\mpost{\textsf{MetaPost}}
\lstset{backgroundcolor=\color{hellgelb},numbers=left,frame=single,escapeinside=~~,morekeywords={includegraphics,
textFR}
}
\makeatletter
\@addtoreset{CodelineNo}{subsection}
\pdfstringdefDisableCommands{%
\renewcommand\Lcs[1]{\textbackslash#1}
}
\renewcommand\tableofcontents{\relax
  \begin{multicols}{2}[\section*{\contentsname}]\small
    \@starttoc{toc}\relax
  \end{multicols}}
\makeatother
\newcounter{local}
\renewcommand\theenumi{\protect\setcounter{local}%
  {201+\the\value{enumi}}\protect\ding{\value{local}}}
\renewcommand\labelenumi{\theenumi}
\renewcommand\labelitemi{\HandRight}
\renewcommand\labelitemii{\HandRightUp}
\renewcommand\labelitemiii{\HandCuffRight}
\renewcommand\labelitemiv{\HandPencilLeft}
\EnableCrossrefs
\CodelineIndex
\RecordChanges
%\OnlyDescription
\begin{document}
  \DocInput{\jobname.dtx}
  \PrintIndex
  \PrintChanges
\end{document}
%</driver>
%
%
% \fi
%
% \GetFileInfo{\jobname.sty}
% \CheckSum{0}
% \makeatletter
%\title{The \textsf{mpgraphics} Package\\ \href{https://github.com/persian-tex/mpgraphics}{\texttt{https://github.com/persian-tex/mpgraphics}}}
%\author{Persian TeX Group\\ \href{mailto:persian-tex@tug.org}{\texttt{persian-tex@tug.org}}}
%\date{Version 0.3\qquad\today}
%\maketitle
%\begin{abstract}
%It is not possible to include \mpost{} graphics directly into your \LaTeX{} documents; you have got to process your \mpost{} code first with \mpost{} and then include the images in your \LaTeX{} document. This is difficult and time consuming and the situation even becomes worser when you have many \mpost{} graphics.
%
%\medskip
%The \mpg{} allows you to have all your \mpost{} codes directly into your \LaTeX{} document and if you run \LaTeX{}, or PDF\LaTeX{}, or \XeLaTeX{} with the \cmdtype{-shell-escape} option only once, then you can see your \mpost{} graphics in your \LaTeX{} output.
%
%\medskip
%This package works with PDF\LaTeX{} (both PDF and DVI modes) and \XeLaTeX{} formats.
%\end{abstract}
%\tableofcontents
%\section{Dedication}
%We dedicate the \mpg{} to the \textbf{Iranian mathematician}, \textbf{Jamshid Kashani}. Al-Kashi was one of the best mathematicians in the Islamic world. He was born in 1380, in Kashan, in central Iran. This region was controlled by Tamurlane, better known as Timur, who was more interested in invading other areas than taking care of what he had. Due to this, al-Kashi lived in poverty during his childhood and the beginning years of his adulthood.
%
%\begin{wrapfigure}{r}{0.6\textwidth}
%\centering
%\fbox{\includegraphics{jamshid_kashani}}
% \caption{Ghyath al-Din Jamshid Kashani}
%\end{wrapfigure}
%
%\medskip
%The situation changed for the better when Timur died in 1405, and his son, Shah Rokh, ascended into power. Shah Rokh and his wife, Goharshad, a Persian princess, were very interested in the sciences, and they encouraged their court to study the various fields in great depth. Their son, Ulugh Beg, was enthusiastic about science as well, and made some noted contributions in mathematics and astronomy himself. Consequently, the period of their power became one of many scholarly accomplishments. This was the perfect environment for al-Kashi to begin his career as one of the world’s greatest mathematicians.
%
%\medskip
%Eight years after he came into power in 1409, Ulugh Beg founded an institute in Samarkand which soon became a prominent university. Students from all over the Middle East, and beyond, flocked to this academy in the capital city of Ulugh Beg’s empire. Consequently, Ulugh Beg harvested many great mathematicians and scientists of the Muslim world. In 1414, al-Kashi took this opportunity to contribute vast amounts of knowledge to his people. His best work was done in the court of Ulugh Beg, and it is said that he was the king’s favourite student.
%
%\medskip
%Al-Kashi was still working on his book, called “Risala al-watar wa’l-jaib” meaning “The Treatise on the Chord and Sine”, when he died in 1429. Some scholars believe that Ulugh Beg may have ordered his murder, while others say he died a natural death. The details are unclear. 
%\section{Requirements}
%\begin{itemize}
%\item A \texttt{web2c} \TeX{} implementation such as \TeX Live or MiK\TeX{} is needed; the package does not work with commercial \TeX{} implementations such as PC\TeX.
%\item \LaTeX{}, or PDF\LaTeX{}, or \XeLaTeX{} (depending on which one you use) must be called with the \cmdtype{-shell-escape} option.
%\item A recent and working version of \textsf{epstopdf} program (available in \TeX Live and MiK\TeX) is needed.
%\item A recent version of \textsf{color}, \textsf{graphicx}, \textsf{ifpdf}, \textsf{ifplatform}, \textsf{iftex}, \textsf{moreverb}, and \textsf{xkeyval} packages are required.
%\end{itemize}
%\section{Basic Usage}
%\subsection{Placing \mpost{} graphics at the center}
%\begin{BDef}
%\LBEG{mpdisplay}\\
%\Larga{\mpost{} codes between \texttt{beginfig();} and \texttt{endfig;}}\\
%\LEND{mpdisplay}
%\end{BDef}
%\begin{itemize}
%\item \texttt{mpdisplay} environment places \mpost{} graphics in  display mode (at the center).
%\end{itemize}
%If your \mpost{}  code is something like this:
%
%\begin{lstlisting}[language=MetaPost,caption={\mpost{} code}]
%beginfig(1);
%u=1cm;
%draw (2u,2u)--(0,0)--(0,3u)--(3u,0)--(0,0);
%pickup pencircle scaled 4pt;
%for i=0 upto 2:
%for j=0 upto 2: drawdot (i*u,j*u); endfor
%endfor
%endfig;
%end;
%\end{lstlisting}
%
%Then the equivalent \LaTeX{} document should be like this:
%
%\begin{lstlisting}
%\documentclass{article}
%\usepackage{mpgraphics}
%\begin{document}
%\begin{mpdisplay}
%u=1cm;
%draw (2u,2u)--(0,0)--(0,3u)--(3u,0)--(0,0);
%pickup pencircle scaled 4pt;
%for i=0 upto 2:
%for j=0 upto 2: drawdot (i*u,j*u); endfor
%endfor
%\end{mpdisplay}
%\end{document}
%\end{lstlisting}
%
%\subsection{Placing \mpost{} graphics in inline mode}
%\begin{BDef}
%\LBEG{mpinline}\\
%\Larga{\mpost{} codes between \texttt{beginfig();} and \texttt{endfig;}}\\
%\LEND{mpinline}
%\end{BDef}
%\begin{itemize}
%\item \texttt{mpinline} environment places \mpost{} graphics in inline mode (just like inline maths).
%\end{itemize}
%If your \mpost{}  code is something like this:
%
%\begin{lstlisting}[language=MetaPost,caption={\mpost{} code}]
%beginfig(2);
%draw (20,20)--(0,0)--(0,30)--(30,0)--(0,0);
%endfig;
%end;
%\end{lstlisting}
%Then the equivalent \LaTeX{} document should be like this:
%
%\begin{lstlisting}
%\documentclass{article}
%\usepackage{mpgraphics}
%\begin{document}
%\begin{mpinline}
%draw (20,20)--(0,0)--(0,30)--(30,0)--(0,0)
%\end{mpinline}
%\end{document}
%\end{lstlisting}
%\section{Your Global \mpost{} definitions and inputs}
%\begin{BDef}
%\LBEG{mpdefs}\\
%\Larga{your global \mpost{} definitions and inputs}\\
%\LEND{mpdefs}
%\end{BDef}
%\begin{itemize}
%\item You can put your global \mpost{} definitions and inputs inside \texttt{mpdefs} environment.
%\end{itemize}
%If your \mpost{}  code is something like this:
%
%\begin{lstlisting}[language=MetaPost,caption={\mpost{} code}]
%input metaobj
%defaultfont:="ptmr8r";
%warningcheck:=0;
%beginfig(1)
%newDEllipse.a(btex some text etex);
%scaleObj(a,1.7);
%rotateObj(a,45);
%a.c=origin;
%drawObj(a);
%endfig;
%end;
%\end{lstlisting}
%Then the equivalent \LaTeX{} document should be like this:
%
%\begin{lstlisting}
%\documentclass{article}
%\usepackage{mpgraphics}
%\begin{document}
%\begin{mpdefs}
%input metaobj
%defaultfont:="ptmr8r";
%warningcheck:=0;
%\end{mpdefs}
%\begin{mpdisplay}
%newDEllipse.a(btex some text etex);
%scaleObj(a,1.7);
%rotateObj(a,45);
%a.c=origin;
%drawObj(a);
%\end{mpdisplay}
%\end{document}
%\end{lstlisting}
%\section{Your \LaTeX{} packages and macros used within \mpost{} graphics}
%\begin{BDef}
%\LBEG{ltxpreamble}\\
%\Larga{Your \LaTeX{} packages and macros used within \mpost{} graphics}\\
%\LEND{ltxpreamble}
%\end{BDef}
%\begin{itemize}
%\item You can put your \LaTeX{} packages and macros that needs to be used within \mpost{} graphics, in \texttt{ltxpreamble} environment.
%\end{itemize}
%If you want to use the previous \mpost{} code but you want that your labels to be typeset with fonts from \textsf{fourier} package, then your \LaTeX{} document should look like this:
%
%\begin{lstlisting}
%\documentclass{article}
%\usepackage{mpgraphics}
%\begin{document}
%\begin{mpdefs}
%input metaobj
%defaultfont:="ptmr8r";
%warningcheck:=0;
%\end{mpdefs}
%\begin{ltxpreamble}
%\usepackage{fourier}
%\end{ltxpreamble}
%\begin{mpdisplay}
%newDEllipse.a(btex some text etex);
%scaleObj(a,1.7);
%rotateObj(a,45);
%a.c=origin;
%drawObj(a);
%\end{mpdisplay}
%\end{document}
%\end{lstlisting}
%\section{Options of the package and few related commands}
%There are four options:
%\begin{description}
%\item[\OptArg*{epstopdf=\Largb{\Larga{options}}}:] Options can be appended to the \textsf{epstopdf} program if you wish\footnote{See options of \textsf{epstopdf} program.}. For example, to run \textsf{epstopdf} auxillary compilation with debugging information written to the console, use the following package option:
%\begin{BDef*}
%\Lcs{usepackage}\OptArg{epstopdf=\Largb{-debug}}\Largb{mpgraphics}
%\end{BDef*}
%By default, no option is appended to the \textsf{epstopdf} program.
%\item[\OptArg*{compilation=\Larga{on/off}}:] After your \mpost{} figures have been generated and you no longer wish to re-generate your \mpost{} figures, the package can be given the \OptArg*{compilation=off} option to save compilation time:
%\begin{BDef*}
%\Lcs{usepackage}\OptArg{compilation=off}\Largb{mpgraphics}
%\end{BDef*}
%By default, \OptArg*{compilation=on}. Also the following two commands are provided:
%\begin{BDef}
%\Lcs{mpgOff}\qquad\Lcs{mpgOn}
%\end{BDef}
%\begin{itemize}
%\item \Lcs{mpgOff} turns off compilation.
%\item \Lcs{mpgOn} turn on compilation.
%\end{itemize}
%A command \Lcs{NoProcess} is also available to facilitate suppressing of pdf/eps generation of those
%figures whose pdf/eps’s are already available. This might prove helpful when you have more figures
%to process and many of them are perfected and don’t need recompilation and translation everytime
%you run \LaTeX. The usage is:
%\begin{BDef}
%\Lcs{NoProcess}\Largs{\Larga{comma separated and/or hyphen separated ranges}}
%\end{BDef}
%For example, If you have ten figures and if you want to suppress the processing of the figure numbers 1, 2, 4 to
%8 you can issue the command at the top of the document as:
%\begin{BDef*}
%\Lcs{NoProcess}\Largs{1,2,4-8}
%\end{BDef*}
%\item[\OptArg*{metapost=\Largb{\Larga{options}}}:] The \mpost{} auxiliary compilation has some hard-coded options (\texttt{-tex=latex}, \texttt{-jobname="\Lcs{mpgfigname}"}, and \texttt{-interaction=batchmode}), and further options can be appended if you wish\footnote{See page 89 of \mpost{} manual.}. For example, to run \mpost{} auxillary compilation with more information written to the console, use the following package option:
%\begin{BDef*}
%\Lcs{usepackage}\OptArg{metapost=\Largb{-interaction=nonstopmode}}\Largb{mpgraphics}
%\end{BDef*}
%\item[\OptArg*{runs=\Larga{positive integer}}:] Sometimes with some \mpost{} macros such as \textsf{makecirc}, you find that you need to run \mpost{} more than once. The exact number will vary by exact application, and must
%be set explicitly. For example if you want to run \mpost{} twice, then You can have:
%\begin{BDef*}
%\Lcs{usepackage}\OptArg{runs=2}\Largb{mpgraphics}
%\end{BDef*}
% By default \mpost{} runs only once so we have \OptArg*{runs=1} by default.
%\end{description}
%\section{Controlling different aspects of \mpost{} graphics}
%There are few hooks to control different aspects of \mpost{} graphics:
%\begin{BDef}
%\Lcs{configure}\Largs{mpggraphic}\Largs{width=2in}\\
%\Lcs{configure}\Largs{mpggraphic}\Largs{height=3in}\\
%\Lcs{configure}\Largs{mpggraphic}\Largs{width=2in,height=3in}\\
%\Lcs{configure}\Largs{mpggraphic}\Largs{scale=.5}\\
%\Lcs{configure}\Largs{mpggraphic}\Largs{linecolor=red}\\
%\Lcs{configure}\Largs{mpggraphic}\Largs{linewidth=1pt}\\
%\Lcs{configure}\Largs{mpggraphic}\Largs{background=green}\\
%\Lcs{configure}\Largs{mpggraphic}\Largs{rulesep=6pt}
%\end{BDef}
%The functionality is same as the \texttt{width}, \texttt{height} and \texttt{scale} options as in the \Lcs{includegraphics} command.
%But the graphic will be restricted to aspect ratio. \texttt{linecolor}, \texttt{linewidth}, \texttt{rulesep} and \texttt{background} corresponds to the box surrounding the graphic. The default values are \texttt{white}, \texttt{0pt}, \texttt{0pt} and \texttt{white} respectively.
%\section{Acknowledgements}
%Many thanks to the authors of \textsf{pdftricks} (Radhakrishnan CV, Rajagopal CV, and Antoine Chambert-Loir) and \textsf{auto-pst-pdf} (Will Robertson and Johannes Große) packages. This package could not exist without their combined efforts over many years as \mpg{} borrows some ideas from \textsf{pdftricks} and \textsf{auto-pst-pdf} packages.
%
%Thanks to Enrico Gregorio for suggesting \textsf{epstopdf} program.
%
%Finally, I wish to thank John D. Hobby, Taco Hoekwater, and other \mpost{} developers for developing \mpost.
% \StopEventually{}
%
% \section{\textsf{\jobname} implementation}
%\iffalse
%<*mpgraphics.sty>
%\fi
%
%
%
%    \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}
\newcommand{\mpgraphics@date}{2013/04/04}
\newcommand{\mpgraphics@version}{v0.3}
\ProvidesPackage{mpgraphics}[\mpgraphics@date\space \mpgraphics@version\space
inline and display metapost figures in LaTeX]
\newcommand{\mpg@graphicsextension}{\ifPDFTeX\ifpdf pdf\else eps\fi\else\ifXeTeX pdf\fi\fi}
\newcommand{\mpg@graphicsformatname}{\ifPDFTeX\ifpdf PDF\else EPS\fi\else\ifXeTeX PDF\fi\fi}
\newcommand{\mpg@formatname}{\ifPDFTeX\ifpdf pdflatex\else latex\fi\else\ifXeTeX xelatex\fi\fi}
\RequirePackage{graphicx,color,moreverb,xkeyval,ifplatform,iftex,ifpdf}
\@ifundefined{verbatim@out}{\newwrite\verbatim@out}{}%
\newif\if@mpg@debug\@mpg@debugfalse
\expandafter\newif\csname if@mpg@no@\mpg@graphicsextension\endcsname
\newif\if@mpg@noprocess \@mpg@noprocessfalse
\newif\if@mpg@On
\DeclareOptionX{metapost}{%
  \def\mpg@metapost@opts{%
    -tex=latex
    -jobname="\mpgfigname"
    -interaction=batchmode
    #1}}
\DeclareOptionX{epstopdf}{\def\mpg@epstopdf@opts{#1}}
\define@choicekey{mpgraphics.sty}{compilation}[\@tempa\@tempb]{on,off}{%
  \ifcase\@tempb\relax
    \@mpg@Ontrue
  \or
    \@mpg@Onfalse
  \fi}
\define@choicekey{mpgraphics.sty}{debug}[\@tempa\@tempb]{on,off}{%
  \ifcase\@tempb\relax
    \@mpg@debugtrue
  \or
    \@mpg@debugfalse
  \fi}
\newcounter{mpg@runs}
\DeclareOptionX{runs}{%
  \setcounter{mpg@runs}{#1}% support calc
  \ifnum\c@mpg@runs > \z@
  \else
    \mpg@PackageWarning{The number of runs must be at least one.}%
    \c@mpg@runs\@ne
  \fi}
\newcommand{\mpgOff}{\@mpg@Onfalse}
\newcommand{\mpgOn}{\@mpg@Ontrue}
\ExecuteOptionsX{%
       metapost={},%
       epstopdf={},%
       compilation=on,%
       debug=off,%
       runs=1%
}
\ProcessOptionsX
\def\mpg@exe{\immediate\write18}
\def\OnlyIfFileExists#1#2{\IfFileExists{#1}{#2}{}}
\def\NotIfFileExists#1#2{\IfFileExists{#1}{}{#2}}
\def\mpg@convert#1#2#3{%
  \OnlyIfFileExists{#2}{%
    \mpg@exe{\csname mpg@cmd@#1\endcsname{#2}{#3}}%
    \NotIfFileExists{#3}{\mpg@Warning{Creation of #3 failed.}}}}
\def\mpg@cmd@metapost#1#2{mpost \mpg@metapost@opts\space
  "\unexpanded{\input} #1"}
\def\mpg@cmd@extrametapost#1#2{mpost \mpg@metapost@opts\space
  "\unexpanded{\input} #1"}
\def\mpg@cmd@epstopdf#1#2{epstopdf \mpg@epstopdf@opts\space --outfile "#2" "#1"}
\def\mpg@nl{^^J\space\space\space\space}
\newcommand\mpg@PackageError[2]{%
  \PackageError{mpgraphics}{\mpg@nl #1^^J}{#2}}
\newcommand\mpg@Warning[2]{\if@mpg@debug\PackageWarning{#1}{#2}\fi}
\newcommand\mpg@PackageWarning[1]{%
  \PackageWarning{mpgraphics}{\mpg@nl #1^^JThis warning occured}}
\newcommand\mpg@WarningNoLine[2]{\if@mpg@debug\PackageWarningNoLine{#1}{#2}\fi}
\ifshellescape
  \PackageWarningNoLine{mpgraphics}
   {****************************************\MessageBreak
    Using \csname write\endcsname18 capability \MessageBreak
    for producing \mpg@graphicsformatname-figures.  \MessageBreak
    ****************************************}
\else
  \mpg@PackageError{%
     "shell escape" (or "write18") is not enabled;\mpg@nl
     mpgraphics will not work!}
    {You need to run "\mpg@formatname\space -shell-escape"\mpg@nl
     on your LaTeX document Or turn compilation off}
\fi
\newenvironment{mpdefs}{\MPDEFSverbatimwrite{mpdefs.mp}}
   {\endMPDEFSverbatimwrite}
\newenvironment{ltxpreamble}{\verbatimwrite{ltxpreamble.ltx}}
   {\endverbatimwrite}
\newcommand{\mpgfigname}{\jobname-fig\thempgfig}
\def\MPGverbatimwrite#1{%
  \@bsphack
  \immediate\openout \verbatim@out #1
  \BeforeMPGStream%
  \let\do\@makeother\dospecials
  \catcode`\^^M\active \catcode`\^^I=12
  \def\verbatim@processline{%
    \immediate\write\verbatim@out
      {\the\verbatim@line}}%
  \verbatim@start}
\def\endMPGverbatimwrite{%
  \immediate\write\verbatim@out{endfig;}
  \immediate\write\verbatim@out{end;}
  \immediate\closeout\verbatim@out
  \@esphack}
\def\MPDEFSverbatimwrite#1{%
  \@bsphack
  \immediate\openout \verbatim@out #1
  \BeforeMPDEFSStream%
  \let\do\@makeother\dospecials
  \catcode`\^^M\active \catcode`\^^I=12
  \def\verbatim@processline{%
    \immediate\write\verbatim@out
      {\the\verbatim@line}}%
  \verbatim@start}
\def\endMPDEFSverbatimwrite{%
  \immediate\closeout\verbatim@out
  \@esphack}
\def\BeforeMPGStream
   {\message{Opening MPGStream=\mpgfigname.mp}%
    \ifPDFTeX\ifpdf%
    \immediate\write\verbatim@out{prologues:=3;}\else
    \immediate\write\verbatim@out{prologues:=2;}\fi\else\ifXeTeX
    \immediate\write\verbatim@out{prologues:=3;}\fi\fi
    \immediate\write\verbatim@out{outputtemplate:= "\@percentchar j.eps";}
    \immediate\write\verbatim@out{verbatimtex}
    \immediate\write\verbatim@out{\string\documentclass{article}}
    \IfFileExists{ltxpreamble.ltx}{\immediate\write\verbatim@out{\string\input{ltxpreamble.ltx}}}{}
    \immediate\write\verbatim@out{\string\begin{document}}
    \immediate\write\verbatim@out{etex;}
    \IfFileExists{mpdefs.mp}{\immediate\write\verbatim@out{input mpdefs;}}{}
    \immediate\write\verbatim@out{beginfig(\thempgfig);}
    }
\def\BeforeMPDEFSStream
   {\message{Opening MPGStream=mpdefs.mp}%
    \immediate\write\verbatim@out{verbatimtex}
    \immediate\write\verbatim@out{\string\documentclass{article}}
    \IfFileExists{ltxpreamble.ltx}{\immediate\write\verbatim@out{\string\input{ltxpreamble.ltx}}}{}
    \immediate\write\verbatim@out{\string\begin{document}}
    \immediate\write\verbatim@out{etex;}
    }
\newenvironment{mpdisplay}{\stepcounter{mpgfig}%
  \xdef\MPGCutFile{\mpgfigname.mp}
  \MPGverbatimwrite{\MPGCutFile}}
 {\endMPGverbatimwrite%
  \MPGgraphicsinclude%
   \global\@mpg@noprocessfalse\noindent}
\newenvironment{mpinline}{\stepcounter{mpgfig}%
  \xdef\MPGCutFile{\mpgfigname.mp}
  \MPGverbatimwrite{\MPGCutFile}}
 {\endMPGverbatimwrite%
  \MPGinlinegraphicsinclude%
   \global\@mpg@noprocessfalse\noindent}
\AtEndDocument{\endMPGhook%
      \csname if@mpg@no@\mpg@graphicsextension\endcsname
        \PackageWarningNoLine{mpgraphics}
        {******************************************\MessageBreak
         Some \mpg@graphicsformatname\space files of images were not found.\MessageBreak
         ******************************************}
       \fi
}
\gdef\endMPGhook{}
\newcommand{\mpgnoprocess}{\global\@mpg@noprocesstrue
  \PackageWarning{mpgraphics}
        {******************************************\MessageBreak
           Figure Number: \mpgfigname\space is not processed \MessageBreak
         ******************************************\MessageBreak}
}
\newcounter{mpgfig}
\newif\if@mpgGINwidth
\newif\if@mpgGINheight
\newif\if@mpgGINscale
\long\gdef\MPGgraphicsProcess{%
  \@ifundefined{Fig\thempgfig}
  {\mpg@WarningNoLine{mpgraphics}
    {******************************************\MessageBreak
     ************ Processing Fig: \thempgfig\space**********\MessageBreak
    ******************************************}
  }
  {\mpgnoprocess}
   \ifshellescape\if@mpg@noprocess\relax\else\if@mpg@On
    \IfFileExists{\mpgfigname.mp}{%
    \loop\ifnum\c@mpg@runs > \@ne
    \mpg@convert{extrametapost}{\mpgfigname.mp}{\mpgfigname.eps}%
          \advance\c@mpg@runs\m@ne
    \repeat
    \mpg@convert{metapost}{\mpgfigname.mp}{\mpgfigname.eps}%
  \mpg@WarningNoLine{mpgraphics}
    {******************************************\MessageBreak
     \mpgfigname.mp converted to \mpgfigname.eps\MessageBreak
     ******************************************}
    }{}
   \IfFileExists{\mpgfigname.eps}{%
   \ifPDFTeX\ifpdf%
   \mpg@convert{epstopdf}{\mpgfigname.eps}{\mpgfigname.pdf}%
   \mpg@WarningNoLine{mpgraphics}
    {******************************************\MessageBreak
     \mpgfigname.eps converted to \mpgfigname.pdf\MessageBreak
     ******************************************}\else\fi\else\ifXeTeX%
   \mpg@convert{epstopdf}{\mpgfigname.eps}{\mpgfigname.pdf}%
   \mpg@WarningNoLine{mpgraphics}
    {******************************************\MessageBreak
     \mpgfigname.eps converted to \mpgfigname.pdf\MessageBreak
     ******************************************}\fi\fi
}{%
     \mpg@PackageError{%
      metapost encountered error(s) while compiling your\mpg@nl
      metapost code and so it did not produce the figure!}
      {Fix your metapost code, delete all metapost and\mpg@nl
       LaTeX auxillary files and then run "\mpg@formatname\space -shell-escape"\mpg@nl
       on your document again}
}\else\fi
    \ifwindows%
    \IfFileExists{\mpgfigname.log}{\immediate\write18{del \mpgfigname.log}}{}%
    \IfFileExists{\mpgfigname.mp}{\immediate\write18{del \mpgfigname.mp}}{}%
    \ifPDFTeX\ifpdf%
    \IfFileExists{\mpgfigname.eps}{\immediate\write18{del \mpgfigname.eps}}{}\else\fi\else\ifXeTeX%
    \IfFileExists{\mpgfigname.eps}{\immediate\write18{del \mpgfigname.eps}}{}\fi\fi%
    \IfFileExists{\mpgfigname.mpx}{\immediate\write18{del \mpgfigname.mpx}}{}%
    \IfFileExists{texnum.mpx}{\immediate\write18{del texnum.mpx}}{}% 
    \IfFileExists{makempx.log}{\immediate\write18{del makempx.log}}{}%
    \IfFileExists{mpxerr.log}{\immediate\write18{del mpxerr.log}}{}%
    \IfFileExists{mpxerr.tex}{\immediate\write18{del mpxerr.tex}}{}%  
    \else
    \IfFileExists{\mpgfigname.log}{\immediate\write18{rm \mpgfigname.log}}{}%
    \IfFileExists{\mpgfigname.mp}{\immediate\write18{rm \mpgfigname.mp}}{}%
    \ifPDFTeX\ifpdf%
    \IfFileExists{\mpgfigname.eps}{\immediate\write18{rm \mpgfigname.eps}}{}\else\fi\else\ifXeTeX%
    \IfFileExists{\mpgfigname.eps}{\immediate\write18{rm \mpgfigname.eps}}{}\fi\fi%
    \IfFileExists{\mpgfigname.mpx}{\immediate\write18{rm \mpgfigname.mpx}}{}%
    \IfFileExists{texnum.mpx}{\immediate\write18{rm texnum.mpx}}{}%
    \IfFileExists{makempx.log}{\immediate\write18{rm makempx.log}}{}%
    \IfFileExists{mpxerr.log}{\immediate\write18{rm mpxerr.log}}{}%
    \IfFileExists{mpxerr.tex}{\immediate\write18{rm mpxerr.tex}}{}%
   \fi\fi
   \fi
}
\long\gdef\MPGgraphicsinclude{\MPGgraphicsProcess%
  \IfFileExists{\mpgfigname.\mpg@graphicsextension}%
     {\begin{center}
     \bgroup\fboxsep\@MPGboxsep\fboxrule\@MPGboxrule%
      \color{\@MPGgraphiccolor}%
      \fcolorbox{\@MPGgraphiclinecolor}{\@MPGgraphicbackground}%
     {\if@mpgGINwidth%
       \includegraphics[width=\@MPGgraphicwidth]{\mpgfigname.\mpg@graphicsextension}\else%
      \if@mpgGINheight%
       \includegraphics[height=\@MPGgraphicheight]{\mpgfigname.\mpg@graphicsextension}\else%
      \if@mpgGINscale%
       \includegraphics[scale=\@MPGgraphicscale]{\mpgfigname.\mpg@graphicsextension}\else%
       \includegraphics{\mpgfigname.\mpg@graphicsextension}\fi\fi\fi%
     }\egroup\end{center}%
      \global\@mpgGINwidthfalse\let\@MPGgraphicwidth\relax
      \global\@mpgGINheightfalse\let\@MPGgraphicheight\relax
      \global\@mpgGINscalefalse\let\@MPGgraphicscale\relax
      }{\csname @mpg@no@\mpg@graphicsextension true\endcsname}
   \gdef\@MPGgraphiclinecolor{white}
   \gdef\@MPGgraphicbackground{white}
   \gdef\@MPGboxsep{0pt}
   \gdef\@MPGboxrule{0pt}
}
\long\gdef\MPGinlinegraphicsinclude{%
  \MPGgraphicsProcess%
  \IfFileExists{\mpgfigname.\mpg@graphicsextension}%
     {\bgroup\fboxrule0pt%
       \normalcolor\fbox{\includegraphics{\mpgfigname.\mpg@graphicsextension}}%
       \egroup}%
      {\csname @mpg@no@\mpg@graphicsextension true\endcsname}%
}
\def\configure[#1][#2]{\setkeys{#1}{#2}
  \mpg@Warning{mpgraphics}{Reconfigured #1 parameter(s)\MessageBreak  
   #2\MessageBreak}}
\define@key{mpggraphic}{width}     {\gdef\@MPGgraphicwidth{#1}%
                                    \global\@mpgGINwidthtrue}
\define@key{mpggraphic}{height}    {\gdef\@MPGgraphicheight{#1}%
                                    \global\@mpgGINheighttrue}
\define@key{mpggraphic}{scale}     {\gdef\@MPGgraphicscale{#1}%
                                    \global\@mpgGINscaletrue}
\define@key{mpggraphic}{color}     {\gdef\@MPGgraphiccolor{#1}}
\define@key{mpggraphic}{linecolor} {\gdef\@MPGgraphiclinecolor{#1}}
\define@key{mpggraphic}{background}{\gdef\@MPGgraphicbackground{#1}}
\define@key{mpggraphic}{linewidth} {\gdef\@MPGboxrule{#1}}
\define@key{mpggraphic}{rulesep}   {\gdef\@MPGboxsep{#1}}
\gdef\@MPGgraphiccolor{black}
\gdef\@MPGgraphiclinecolor{white}
\gdef\@MPGgraphicbackground{white}
\gdef\@MPGboxrule{0pt}
\gdef\@MPGboxsep{0pt}
\@ifundefined{c@arraylength}{\newcounter{arraylength}}{}%
\@ifundefined{c@ArrayIndex}{\newcounter{ArrayIndex}}{}%
\@ifundefined{c@zeroCtr}{\newcounter{zeroCtr}}{}%
\@ifundefined{c@recordCtr}{\newcounter{recordCtr}}{}
\setcounter{recordCtr}{1}
\@ifundefined{c@Ctr}{\newcounter{Ctr}}{}
\def\DeclareArray#1{\Array{#1}[0]{}}%
\def\Array#1[#2]#3{%
      \expandafter\gdef\csname #1#2\endcsname{#3}%
      \expandafter\gdef\csname #1\endcsname[##1]{\csname #1##1\endcsname}}%
\def\getArraylength#1{\setcounter{arraylength}{0}%
   \loop\expandafter\ifx\csname #1\thearraylength\endcsname\relax%
   \else\stepcounter{arraylength}\repeat}%
\def\addToArray#1#2{\setcounter{arraylength}{0}%
   \loop\expandafter\ifx\csname #1\thearraylength\endcsname\relax%
   \else\stepcounter{arraylength}\repeat%
   \Array{#1}[\thearraylength]{#2}}%
\def\clearArray#1{\getArraylength{#1}%
   \loop\ifnum\c@arraylength >0%
   \global\expandafter\let\csname #1\thearraylength\endcsname\relax%
   \addtocounter{arraylength}{-1}\repeat}%
\long\def\ArrayIterator#1#2{%
   \setcounter{ArrayIndex}{1}\getArraylength{#1}%
   \setcounter{zeroCtr}{\c@arraylength}%
   \loop\ifnum\c@ArrayIndex<\c@zeroCtr{#2}%
   \stepcounter{ArrayIndex}\repeat%
}%
\def\@nnil{\@nil}
\def\@empty{}
\def\@cvrstop#1\@@#2{}
\long\def\cvr@delimfor#1#2#3{\DeclareArray{#1}\clearArray{#1}%
   \long\def\@icvrloop##1#2##2\@@##3{\def##3{##1}\ifx ##3\@nnil%
   \expandafter\@cvrstop \else\addToArray{#1}{##1}%
    \relax\expandafter\@icvrloop\fi##2\@@##3}%
   \long\def\@cvrloop##1#2##2#2##3\@@##4{\addToArray{#1}{##1}%
   \def##4{##1}\ifx ##4\@nnil \else%
    \def##4{##2}\def\y@y{##2}\ifx\y@y\@nnil\else%
         \addToArray{#1}{##2}\fi\ifx ##4\@nnil \else%
      \@icvrloop ##3\@@##4\fi\fi}%
  \expandafter\def\expandafter\@fortmp\expandafter{#3}%
  \ifx\@fortmp\@empty \else%
    \expandafter\@cvrloop#3#2\@nil#2\@nil\@@\@ee@\fi}%
\@ifundefined{c@f@irstCtr}{\newcounter{f@irstCtr}}{}%
\@ifundefined{c@s@econdCtr}{\newcounter{s@econdCtr}}{}%
\long\gdef\NoProcess[#1]{%
   \long\def\@i@@noprocess##1,##2\@@##3{\def##3{##1}\ifx ##3\@nnil%
   \expandafter\@cvrstop \else
      \expandafter\hyphencheck##1-@-*[*]
    \relax\expandafter\@i@@noprocess\fi##2\@@##3}%
   \long\def\@@@noprocess##1,##2,##3\@@##4{
      \expandafter\hyphencheck##1-@-*[*]
   \def##4{##1}\ifx ##4\@nnil \else%
    \def##4{##2}\def\y@y{##2}\ifx\y@y\@nnil\else%
      \expandafter\hyphencheck##2-@-*[*]
         \fi\ifx ##4\@nnil \else%
      \@i@@noprocess ##3\@@##4\fi\fi}%
  \expandafter\def\expandafter\@fortmp\expandafter{#1}%
  \ifx\@fortmp\@empty \else%
    \expandafter\@@@noprocess#1,\@nil,\@nil\@@\@ee@\fi}%
\def\d@d#1[*]{}
\def\hyphencheck#1-#2-#3{\def\r@r{@}\def\s@s{*}\edef\c@c{#3}
   \ifx\c@c\r@r
   \setcounter{f@irstCtr}{#1}
   \setcounter{s@econdCtr}{#2}
   \stepcounter{s@econdCtr}
   \loop\ifnum\thes@econdCtr > \thef@irstCtr% 
      \expandafter\edef\csname Fig\thef@irstCtr\endcsname{TRUE}
      \stepcounter{f@irstCtr}
   \repeat%
   \else\ifx\c@c\s@s% 
      \expandafter\edef\csname Fig#1\endcsname{TRUE}
   \fi\fi\d@d}
%    \end{macrocode}
% \iffalse
%</mpgraphics.sty>
%\fi
%
% \Finale
%
%
%\iffalse
%<*mpgraphics-example.ltx>
\documentclass{article}
\usepackage{mpgraphics}
\begin{document}
\begin{mpdisplay}
LaTeX_unitlength := 1.0pt;
w := 60*LaTeX_unitlength;
h := 40*LaTeX_unitlength;
numeric xmin, xmax, ymin, ymax;
xmin := 1/4; xmax := 6; ymax := 1/xmin; u := 1cm;
vardef f(expr x) = 1/x enddef;
xinc := 0.1;
path pts_f;
pts_f := (xmin,f(xmin))*u
for x=xmin+xinc step xinc until xmax:
.. (x,f(x))*u
endfor;
path hline[], vline[];
hline0 = (0,0)*u -- (xmax,0)*u;
vline0 = (0,0)*u -- (0,ymax)*u;
vline0.5 = (0.5,0)*u -- (0.5,ymax)*u;
vline4 = (4,0)*u -- (4,ymax)*u;
fill buildcycle(hline0, vline0.5, pts_f, vline4)
withcolor 0.8[blue,white];
draw hline0; draw vline0; % draw axes
draw (0.5,0)*u -- vline0.5 intersectionpoint pts_f;
draw (4,0)*u -- vline4 intersectionpoint pts_f;
draw pts_f withpen pencircle scaled 2;
label.bot(btex $x$ etex, (0.9xmax,0)*u);
label.lft(btex $y$ etex, (0,0.9ymax)*u);
label.urt(btex Hello $f(x)$ etex, (0.5,f(0.5))*u);
\end{mpdisplay}
\end{document}
%</mpgraphics-example.ltx>
%\fi
%
% \typeout{*************************************************************}
% \typeout{*}
% \typeout{* To finish the installation you have to move the following}
% \typeout{* file into a directory searched by TeX:}
% \typeout{*}
% \typeout{* \space\space\space mpgraphics.sty  file}
% \typeout{*}
% \typeout{*************************************************************}
%
\endinput