Debian Codegraph @

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

raw
1 % \iffalse
2 %<*internal>
3 \iffalse
4 %</internal>
5 %<*readme>
6 _________________
7 The mpgraphics package
8 v0.3
9
10 mpgraphics allows users to typeset metapost inline and display
11 figures in their LaTeX documents with only and only one run of
12 LaTeX, or PDFLaTeX, or XelaTeX (no separate runs of mpost).
13 mpgraphics achieves this by using shell scape or write 18
14 feature so the whole process is automatic and the
15 end user do not need to carry out the long process.
16
17 If you want to report any bugs or typos and corrections in the documentation,
18 or ask for any new features, or suggest any improvements, or ask any questions
19 about the package, then please do not send any direct emails to us; we will not
20 answer any direct emails. Instead please use the issue tracker:
21 <https://github.com/persian-tex/mpgraphics/issues>
22 In doing so, please always explain your issue well enough, always include
23 a minimal working examples showing the issue, and always choose the appropriate
24 label for your query (i.e. if you are reporting any bugs, choose `bug' label).
25
26 Current version release date: 2013/04/04
27
28 ______________
29 Persian TeX Group
30 [email protected]
31
32 Copyright © 2011-2013
33 Distributed under the LaTeX Project Public License
34 It may be distributed and/or modified under the LaTeX Project Public License,
35 version 1.3c or higher (your choice). The latest version of
36 this license is at: http://www.latex-project.org/lppl.txt
37
38 This work is “maintained” (as per LPPL maintenance status)
39 by Persian TeX Group.
40 %</readme>
41 %<*internal>
42 \fi
43 \begingroup
44 %</internal>
45 %<*batchfile>
46 \input docstrip.tex
47 \keepsilent
48 \preamble
49
50 ______________________________________
51 Copyright © 2011-2013 Persian TeX Group
52
53 License information appended.
54
55
56 \endpreamble
57 \postamble
58
59 Copyright © 2011-2013 Persian TeX Group <[email protected]>
60
61 It may be distributed and/or modified under the LaTeX Project Public License,
62 version 1.3c or higher (your choice). The latest version of
63 this license is at: http://www.latex-project.org/lppl.txt
64
65 This work is “maintained” (as per LPPL maintenance status)
66 by Persian TeX Group.
67
68
69
70 \endpostamble
71 \askforoverwritefalse
72 \generate{\file{mpgraphics.sty}{\from{\jobname.dtx}{mpgraphics.sty}}}
73 %</batchfile>
74 %<batchfile>\endbatchfile
75 %<*internal>
76 \generate{\file{\jobname.ins}{\from{\jobname.dtx}{batchfile}}}
77 \nopreamble\nopostamble
78 \generate{\file{README.txt}{\from{\jobname.dtx}{readme}}}
79 \generate{\file{mpgraphics-example.ltx}{\from{\jobname.dtx}{mpgraphics-example.ltx}}}
80 \endgroup
81 \immediate\write18{mv README.txt README}
82 \immediate\write18{makeindex -s gind.ist -o \jobname.ind \jobname.idx}
83 \immediate\write18{makeindex -s gglo.ist -o \jobname.gls \jobname.glo}
84 %</internal>
85 %
86 %<*driver>
87 \documentclass{ltxdoc}
88 \usepackage{url,wrapfig,graphicx}
89 \usepackage{fontspec}
90 \usepackage{calc}
91 \usepackage{pifont}
92 \usepackage{bbding}
93 \usepackage{bidicode}
94 \usepackage[numbered]{hypdoc}
95 \definecolor{bidiblue}{rgb}{0.1,0.2,0.8}
96 \definecolor{myred}{rgb}{0.65,0.04,0.07}
97 \hypersetup{linkcolor=bidiblue,urlcolor=bidiblue,citecolor=bidiblue}
98 \usepackage{bidi}
99 \setlength\columnseprule{.4pt}
100 \newcommand\cmdtype[1]{\textcolor{myred}{\texttt{#1}}}
101 \def\mpg{\textsf{mpgraphics} package}
102 \def\mpost{\textsf{MetaPost}}
103 \lstset{backgroundcolor=\color{hellgelb},numbers=left,frame=single,escapeinside=~~,morekeywords={includegraphics,
104 textFR}
105 }
106 \makeatletter
107 \@addtoreset{CodelineNo}{subsection}
108 \pdfstringdefDisableCommands{%
109 \renewcommand\Lcs[1]{\textbackslash#1}
110 }
111 \renewcommand\tableofcontents{\relax
112 \begin{multicols}{2}[\section*{\contentsname}]\small
113 \@starttoc{toc}\relax
114 \end{multicols}}
115 \makeatother
116 \newcounter{local}
117 \renewcommand\theenumi{\protect\setcounter{local}%
118 {201+\the\value{enumi}}\protect\ding{\value{local}}}
119 \renewcommand\labelenumi{\theenumi}
120 \renewcommand\labelitemi{\HandRight}
121 \renewcommand\labelitemii{\HandRightUp}
122 \renewcommand\labelitemiii{\HandCuffRight}
123 \renewcommand\labelitemiv{\HandPencilLeft}
124 \EnableCrossrefs
125 \CodelineIndex
126 \RecordChanges
127 %\OnlyDescription
128 \begin{document}
129 \DocInput{\jobname.dtx}
130 \PrintIndex
131 \PrintChanges
132 \end{document}
133 %</driver>
134 %
135 %
136 % \fi
137 %
138 % \GetFileInfo{\jobname.sty}
139 % \CheckSum{0}
140 % \makeatletter
141 %\title{The \textsf{mpgraphics} Package\\ \href{https://github.com/persian-tex/mpgraphics}{\texttt{https://github.com/persian-tex/mpgraphics}}}
142 %\author{Persian TeX Group\\ \href{mailto:[email protected]}{\texttt{[email protected]}}}
143 %\date{Version 0.3\qquad\today}
144 %\maketitle
145 %\begin{abstract}
146 %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.
147 %
148 %\medskip
149 %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.
150 %
151 %\medskip
152 %This package works with PDF\LaTeX{} (both PDF and DVI modes) and \XeLaTeX{} formats.
153 %\end{abstract}
154 %\tableofcontents
155 %\section{Dedication}
156 %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.
157 %
158 %\begin{wrapfigure}{r}{0.6\textwidth}
159 %\centering
160 %\fbox{\includegraphics{jamshid_kashani}}
161 % \caption{Ghyath al-Din Jamshid Kashani}
162 %\end{wrapfigure}
163 %
164 %\medskip
165 %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.
166 %
167 %\medskip
168 %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.
169 %
170 %\medskip
171 %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.
172 %\section{Requirements}
173 %\begin{itemize}
174 %\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.
175 %\item \LaTeX{}, or PDF\LaTeX{}, or \XeLaTeX{} (depending on which one you use) must be called with the \cmdtype{-shell-escape} option.
176 %\item A recent and working version of \textsf{epstopdf} program (available in \TeX Live and MiK\TeX) is needed.
177 %\item A recent version of \textsf{color}, \textsf{graphicx}, \textsf{ifpdf}, \textsf{ifplatform}, \textsf{iftex}, \textsf{moreverb}, and \textsf{xkeyval} packages are required.
178 %\end{itemize}
179 %\section{Basic Usage}
180 %\subsection{Placing \mpost{} graphics at the center}
181 %\begin{BDef}
182 %\LBEG{mpdisplay}\\
183 %\Larga{\mpost{} codes between \texttt{beginfig();} and \texttt{endfig;}}\\
184 %\LEND{mpdisplay}
185 %\end{BDef}
186 %\begin{itemize}
187 %\item \texttt{mpdisplay} environment places \mpost{} graphics in display mode (at the center).
188 %\end{itemize}
189 %If your \mpost{} code is something like this:
190 %
191 %\begin{lstlisting}[language=MetaPost,caption={\mpost{} code}]
192 %beginfig(1);
193 %u=1cm;
194 %draw (2u,2u)--(0,0)--(0,3u)--(3u,0)--(0,0);
195 %pickup pencircle scaled 4pt;
196 %for i=0 upto 2:
197 %for j=0 upto 2: drawdot (i*u,j*u); endfor
198 %endfor
199 %endfig;
200 %end;
201 %\end{lstlisting}
202 %
203 %Then the equivalent \LaTeX{} document should be like this:
204 %
205 %\begin{lstlisting}
206 %\documentclass{article}
207 %\usepackage{mpgraphics}
208 %\begin{document}
209 %\begin{mpdisplay}
210 %u=1cm;
211 %draw (2u,2u)--(0,0)--(0,3u)--(3u,0)--(0,0);
212 %pickup pencircle scaled 4pt;
213 %for i=0 upto 2:
214 %for j=0 upto 2: drawdot (i*u,j*u); endfor
215 %endfor
216 %\end{mpdisplay}
217 %\end{document}
218 %\end{lstlisting}
219 %
220 %\subsection{Placing \mpost{} graphics in inline mode}
221 %\begin{BDef}
222 %\LBEG{mpinline}\\
223 %\Larga{\mpost{} codes between \texttt{beginfig();} and \texttt{endfig;}}\\
224 %\LEND{mpinline}
225 %\end{BDef}
226 %\begin{itemize}
227 %\item \texttt{mpinline} environment places \mpost{} graphics in inline mode (just like inline maths).
228 %\end{itemize}
229 %If your \mpost{} code is something like this:
230 %
231 %\begin{lstlisting}[language=MetaPost,caption={\mpost{} code}]
232 %beginfig(2);
233 %draw (20,20)--(0,0)--(0,30)--(30,0)--(0,0);
234 %endfig;
235 %end;
236 %\end{lstlisting}
237 %Then the equivalent \LaTeX{} document should be like this:
238 %
239 %\begin{lstlisting}
240 %\documentclass{article}
241 %\usepackage{mpgraphics}
242 %\begin{document}
243 %\begin{mpinline}
244 %draw (20,20)--(0,0)--(0,30)--(30,0)--(0,0)
245 %\end{mpinline}
246 %\end{document}
247 %\end{lstlisting}
248 %\section{Your Global \mpost{} definitions and inputs}
249 %\begin{BDef}
250 %\LBEG{mpdefs}\\
251 %\Larga{your global \mpost{} definitions and inputs}\\
252 %\LEND{mpdefs}
253 %\end{BDef}
254 %\begin{itemize}
255 %\item You can put your global \mpost{} definitions and inputs inside \texttt{mpdefs} environment.
256 %\end{itemize}
257 %If your \mpost{} code is something like this:
258 %
259 %\begin{lstlisting}[language=MetaPost,caption={\mpost{} code}]
260 %input metaobj
261 %defaultfont:="ptmr8r";
262 %warningcheck:=0;
263 %beginfig(1)
264 %newDEllipse.a(btex some text etex);
265 %scaleObj(a,1.7);
266 %rotateObj(a,45);
267 %a.c=origin;
268 %drawObj(a);
269 %endfig;
270 %end;
271 %\end{lstlisting}
272 %Then the equivalent \LaTeX{} document should be like this:
273 %
274 %\begin{lstlisting}
275 %\documentclass{article}
276 %\usepackage{mpgraphics}
277 %\begin{document}
278 %\begin{mpdefs}
279 %input metaobj
280 %defaultfont:="ptmr8r";
281 %warningcheck:=0;
282 %\end{mpdefs}
283 %\begin{mpdisplay}
284 %newDEllipse.a(btex some text etex);
285 %scaleObj(a,1.7);
286 %rotateObj(a,45);
287 %a.c=origin;
288 %drawObj(a);
289 %\end{mpdisplay}
290 %\end{document}
291 %\end{lstlisting}
292 %\section{Your \LaTeX{} packages and macros used within \mpost{} graphics}
293 %\begin{BDef}
294 %\LBEG{ltxpreamble}\\
295 %\Larga{Your \LaTeX{} packages and macros used within \mpost{} graphics}\\
296 %\LEND{ltxpreamble}
297 %\end{BDef}
298 %\begin{itemize}
299 %\item You can put your \LaTeX{} packages and macros that needs to be used within \mpost{} graphics, in \texttt{ltxpreamble} environment.
300 %\end{itemize}
301 %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:
302 %
303 %\begin{lstlisting}
304 %\documentclass{article}
305 %\usepackage{mpgraphics}
306 %\begin{document}
307 %\begin{mpdefs}
308 %input metaobj
309 %defaultfont:="ptmr8r";
310 %warningcheck:=0;
311 %\end{mpdefs}
312 %\begin{ltxpreamble}
313 %\usepackage{fourier}
314 %\end{ltxpreamble}
315 %\begin{mpdisplay}
316 %newDEllipse.a(btex some text etex);
317 %scaleObj(a,1.7);
318 %rotateObj(a,45);
319 %a.c=origin;
320 %drawObj(a);
321 %\end{mpdisplay}
322 %\end{document}
323 %\end{lstlisting}
324 %\section{Options of the package and few related commands}
325 %There are four options:
326 %\begin{description}
327 %\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:
328 %\begin{BDef*}
329 %\Lcs{usepackage}\OptArg{epstopdf=\Largb{-debug}}\Largb{mpgraphics}
330 %\end{BDef*}
331 %By default, no option is appended to the \textsf{epstopdf} program.
332 %\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:
333 %\begin{BDef*}
334 %\Lcs{usepackage}\OptArg{compilation=off}\Largb{mpgraphics}
335 %\end{BDef*}
336 %By default, \OptArg*{compilation=on}. Also the following two commands are provided:
337 %\begin{BDef}
338 %\Lcs{mpgOff}\qquad\Lcs{mpgOn}
339 %\end{BDef}
340 %\begin{itemize}
341 %\item \Lcs{mpgOff} turns off compilation.
342 %\item \Lcs{mpgOn} turn on compilation.
343 %\end{itemize}
344 %A command \Lcs{NoProcess} is also available to facilitate suppressing of pdf/eps generation of those
345 %figures whose pdf/eps’s are already available. This might prove helpful when you have more figures
346 %to process and many of them are perfected and don’t need recompilation and translation everytime
347 %you run \LaTeX. The usage is:
348 %\begin{BDef}
349 %\Lcs{NoProcess}\Largs{\Larga{comma separated and/or hyphen separated ranges}}
350 %\end{BDef}
351 %For example, If you have ten figures and if you want to suppress the processing of the figure numbers 1, 2, 4 to
352 %8 you can issue the command at the top of the document as:
353 %\begin{BDef*}
354 %\Lcs{NoProcess}\Largs{1,2,4-8}
355 %\end{BDef*}
356 %\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:
357 %\begin{BDef*}
358 %\Lcs{usepackage}\OptArg{metapost=\Largb{-interaction=nonstopmode}}\Largb{mpgraphics}
359 %\end{BDef*}
360 %\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
361 %be set explicitly. For example if you want to run \mpost{} twice, then You can have:
362 %\begin{BDef*}
363 %\Lcs{usepackage}\OptArg{runs=2}\Largb{mpgraphics}
364 %\end{BDef*}
365 % By default \mpost{} runs only once so we have \OptArg*{runs=1} by default.
366 %\end{description}
367 %\section{Controlling different aspects of \mpost{} graphics}
368 %There are few hooks to control different aspects of \mpost{} graphics:
369 %\begin{BDef}
370 %\Lcs{configure}\Largs{mpggraphic}\Largs{width=2in}\\
371 %\Lcs{configure}\Largs{mpggraphic}\Largs{height=3in}\\
372 %\Lcs{configure}\Largs{mpggraphic}\Largs{width=2in,height=3in}\\
373 %\Lcs{configure}\Largs{mpggraphic}\Largs{scale=.5}\\
374 %\Lcs{configure}\Largs{mpggraphic}\Largs{linecolor=red}\\
375 %\Lcs{configure}\Largs{mpggraphic}\Largs{linewidth=1pt}\\
376 %\Lcs{configure}\Largs{mpggraphic}\Largs{background=green}\\
377 %\Lcs{configure}\Largs{mpggraphic}\Largs{rulesep=6pt}
378 %\end{BDef}
379 %The functionality is same as the \texttt{width}, \texttt{height} and \texttt{scale} options as in the \Lcs{includegraphics} command.
380 %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.
381 %\section{Acknowledgements}
382 %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.
383 %
384 %Thanks to Enrico Gregorio for suggesting \textsf{epstopdf} program.
385 %
386 %Finally, I wish to thank John D. Hobby, Taco Hoekwater, and other \mpost{} developers for developing \mpost.
387 % \StopEventually{}
388 %
389 % \section{\textsf{\jobname} implementation}
390 %\iffalse
391 %<*mpgraphics.sty>
392 %\fi
393 %
394 %
395 %
396 % \begin{macrocode}
397 \NeedsTeXFormat{LaTeX2e}
398 \newcommand{\mpgraphics@date}{2013/04/04}
399 \newcommand{\mpgraphics@version}{v0.3}
400 \ProvidesPackage{mpgraphics}[\mpgraphics@date\space \mpgraphics@version\space
401 inline and display metapost figures in LaTeX]
402 \newcommand{\mpg@graphicsextension}{\ifPDFTeX\ifpdf pdf\else eps\fi\else\ifXeTeX pdf\fi\fi}
403 \newcommand{\mpg@graphicsformatname}{\ifPDFTeX\ifpdf PDF\else EPS\fi\else\ifXeTeX PDF\fi\fi}
404 \newcommand{\mpg@formatname}{\ifPDFTeX\ifpdf pdflatex\else latex\fi\else\ifXeTeX xelatex\fi\fi}
405 \RequirePackage{graphicx,color,moreverb,xkeyval,ifplatform,iftex,ifpdf}
406 \@ifundefined{verbatim@out}{\newwrite\verbatim@out}{}%
407 \newif\if@mpg@debug\@mpg@debugfalse
408 \expandafter\newif\csname if@mpg@no@\mpg@graphicsextension\endcsname
409 \newif\if@mpg@noprocess \@mpg@noprocessfalse
410 \newif\if@mpg@On
411 \DeclareOptionX{metapost}{%
412 \def\mpg@metapost@opts{%
413 -tex=latex
414 -jobname="\mpgfigname"
415 -interaction=batchmode
416 #1}}
417 \DeclareOptionX{epstopdf}{\def\mpg@epstopdf@opts{#1}}
418 \define@choicekey{mpgraphics.sty}{compilation}[\@tempa\@tempb]{on,off}{%
419 \ifcase\@tempb\relax
420 \@mpg@Ontrue
421 \or
422 \@mpg@Onfalse
423 \fi}
424 \define@choicekey{mpgraphics.sty}{debug}[\@tempa\@tempb]{on,off}{%
425 \ifcase\@tempb\relax
426 \@mpg@debugtrue
427 \or
428 \@mpg@debugfalse
429 \fi}
430 \newcounter{mpg@runs}
431 \DeclareOptionX{runs}{%
432 \setcounter{mpg@runs}{#1}% support calc
433 \ifnum\c@mpg@runs > \z@
434 \else
435 \mpg@PackageWarning{The number of runs must be at least one.}%
436 \c@mpg@runs\@ne
437 \fi}
438 \newcommand{\mpgOff}{\@mpg@Onfalse}
439 \newcommand{\mpgOn}{\@mpg@Ontrue}
440 \ExecuteOptionsX{%
441 metapost={},%
442 epstopdf={},%
443 compilation=on,%
444 debug=off,%
445 runs=1%
446 }
447 \ProcessOptionsX
448 \def\mpg@exe{\immediate\write18}
449 \def\OnlyIfFileExists#1#2{\IfFileExists{#1}{#2}{}}
450 \def\NotIfFileExists#1#2{\IfFileExists{#1}{}{#2}}
451 \def\mpg@convert#1#2#3{%
452 \OnlyIfFileExists{#2}{%
453 \mpg@exe{\csname mpg@cmd@#1\endcsname{#2}{#3}}%
454 \NotIfFileExists{#3}{\mpg@Warning{Creation of #3 failed.}}}}
455 \def\mpg@cmd@metapost#1#2{mpost \mpg@metapost@opts\space
456 "\unexpanded{\input} #1"}
457 \def\mpg@cmd@extrametapost#1#2{mpost \mpg@metapost@opts\space
458 "\unexpanded{\input} #1"}
459 \def\mpg@cmd@epstopdf#1#2{epstopdf \mpg@epstopdf@opts\space --outfile "#2" "#1"}
460 \def\mpg@nl{^^J\space\space\space\space}
461 \newcommand\mpg@PackageError[2]{%
462 \PackageError{mpgraphics}{\mpg@nl #1^^J}{#2}}
463 \newcommand\mpg@Warning[2]{\if@mpg@debug\PackageWarning{#1}{#2}\fi}
464 \newcommand\mpg@PackageWarning[1]{%
465 \PackageWarning{mpgraphics}{\mpg@nl #1^^JThis warning occured}}
466 \newcommand\mpg@WarningNoLine[2]{\if@mpg@debug\PackageWarningNoLine{#1}{#2}\fi}
467 \ifshellescape
468 \PackageWarningNoLine{mpgraphics}
469 {****************************************\MessageBreak
470 Using \csname write\endcsname18 capability \MessageBreak
471 for producing \mpg@graphicsformatname-figures. \MessageBreak
472 ****************************************}
473 \else
474 \mpg@PackageError{%
475 "shell escape" (or "write18") is not enabled;\mpg@nl
476 mpgraphics will not work!}
477 {You need to run "\mpg@formatname\space -shell-escape"\mpg@nl
478 on your LaTeX document Or turn compilation off}
479 \fi
480 \newenvironment{mpdefs}{\MPDEFSverbatimwrite{mpdefs.mp}}
481 {\endMPDEFSverbatimwrite}
482 \newenvironment{ltxpreamble}{\verbatimwrite{ltxpreamble.ltx}}
483 {\endverbatimwrite}
484 \newcommand{\mpgfigname}{\jobname-fig\thempgfig}
485 \def\MPGverbatimwrite#1{%
486 \@bsphack
487 \immediate\openout \verbatim@out #1
488 \BeforeMPGStream%
489 \let\do\@makeother\dospecials
490 \catcode`\^^M\active \catcode`\^^I=12
491 \def\verbatim@processline{%
492 \immediate\write\verbatim@out
493 {\the\verbatim@line}}%
494 \verbatim@start}
495 \def\endMPGverbatimwrite{%
496 \immediate\write\verbatim@out{endfig;}
497 \immediate\write\verbatim@out{end;}
498 \immediate\closeout\verbatim@out
499 \@esphack}
500 \def\MPDEFSverbatimwrite#1{%
501 \@bsphack
502 \immediate\openout \verbatim@out #1
503 \BeforeMPDEFSStream%
504 \let\do\@makeother\dospecials
505 \catcode`\^^M\active \catcode`\^^I=12
506 \def\verbatim@processline{%
507 \immediate\write\verbatim@out
508 {\the\verbatim@line}}%
509 \verbatim@start}
510 \def\endMPDEFSverbatimwrite{%
511 \immediate\closeout\verbatim@out
512 \@esphack}
513 \def\BeforeMPGStream
514 {\message{Opening MPGStream=\mpgfigname.mp}%
515 \ifPDFTeX\ifpdf%
516 \immediate\write\verbatim@out{prologues:=3;}\else
517 \immediate\write\verbatim@out{prologues:=2;}\fi\else\ifXeTeX
518 \immediate\write\verbatim@out{prologues:=3;}\fi\fi
519 \immediate\write\verbatim@out{outputtemplate:= "\@percentchar j.eps";}
520 \immediate\write\verbatim@out{verbatimtex}
521 \immediate\write\verbatim@out{\string\documentclass{article}}
522 \IfFileExists{ltxpreamble.ltx}{\immediate\write\verbatim@out{\string\input{ltxpreamble.ltx}}}{}
523 \immediate\write\verbatim@out{\string\begin{document}}
524 \immediate\write\verbatim@out{etex;}
525 \IfFileExists{mpdefs.mp}{\immediate\write\verbatim@out{input mpdefs;}}{}
526 \immediate\write\verbatim@out{beginfig(\thempgfig);}
527 }
528 \def\BeforeMPDEFSStream
529 {\message{Opening MPGStream=mpdefs.mp}%
530 \immediate\write\verbatim@out{verbatimtex}
531 \immediate\write\verbatim@out{\string\documentclass{article}}
532 \IfFileExists{ltxpreamble.ltx}{\immediate\write\verbatim@out{\string\input{ltxpreamble.ltx}}}{}
533 \immediate\write\verbatim@out{\string\begin{document}}
534 \immediate\write\verbatim@out{etex;}
535 }
536 \newenvironment{mpdisplay}{\stepcounter{mpgfig}%
537 \xdef\MPGCutFile{\mpgfigname.mp}
538 \MPGverbatimwrite{\MPGCutFile}}
539 {\endMPGverbatimwrite%
540 \MPGgraphicsinclude%
541 \global\@mpg@noprocessfalse\noindent}
542 \newenvironment{mpinline}{\stepcounter{mpgfig}%
543 \xdef\MPGCutFile{\mpgfigname.mp}
544 \MPGverbatimwrite{\MPGCutFile}}
545 {\endMPGverbatimwrite%
546 \MPGinlinegraphicsinclude%
547 \global\@mpg@noprocessfalse\noindent}
548 \AtEndDocument{\endMPGhook%
549 \csname if@mpg@no@\mpg@graphicsextension\endcsname
550 \PackageWarningNoLine{mpgraphics}
551 {******************************************\MessageBreak
552 Some \mpg@graphicsformatname\space files of images were not found.\MessageBreak
553 ******************************************}
554 \fi
555 }
556 \gdef\endMPGhook{}
557 \newcommand{\mpgnoprocess}{\global\@mpg@noprocesstrue
558 \PackageWarning{mpgraphics}
559 {******************************************\MessageBreak
560 Figure Number: \mpgfigname\space is not processed \MessageBreak
561 ******************************************\MessageBreak}
562 }
563 \newcounter{mpgfig}
564 \newif\if@mpgGINwidth
565 \newif\if@mpgGINheight
566 \newif\if@mpgGINscale
567 \long\gdef\MPGgraphicsProcess{%
568 \@ifundefined{Fig\thempgfig}
569 {\mpg@WarningNoLine{mpgraphics}
570 {******************************************\MessageBreak
571 ************ Processing Fig: \thempgfig\space**********\MessageBreak
572 ******************************************}
573 }
574 {\mpgnoprocess}
575 \ifshellescape\if@mpg@noprocess\relax\else\if@mpg@On
576 \IfFileExists{\mpgfigname.mp}{%
577 \loop\ifnum\c@mpg@runs > \@ne
578 \mpg@convert{extrametapost}{\mpgfigname.mp}{\mpgfigname.eps}%
579 \advance\c@mpg@runs\m@ne
580 \repeat
581 \mpg@convert{metapost}{\mpgfigname.mp}{\mpgfigname.eps}%
582 \mpg@WarningNoLine{mpgraphics}
583 {******************************************\MessageBreak
584 \mpgfigname.mp converted to \mpgfigname.eps\MessageBreak
585 ******************************************}
586 }{}
587 \IfFileExists{\mpgfigname.eps}{%
588 \ifPDFTeX\ifpdf%
589 \mpg@convert{epstopdf}{\mpgfigname.eps}{\mpgfigname.pdf}%
590 \mpg@WarningNoLine{mpgraphics}
591 {******************************************\MessageBreak
592 \mpgfigname.eps converted to \mpgfigname.pdf\MessageBreak
593 ******************************************}\else\fi\else\ifXeTeX%
594 \mpg@convert{epstopdf}{\mpgfigname.eps}{\mpgfigname.pdf}%
595 \mpg@WarningNoLine{mpgraphics}
596 {******************************************\MessageBreak
597 \mpgfigname.eps converted to \mpgfigname.pdf\MessageBreak
598 ******************************************}\fi\fi
599 }{%
600 \mpg@PackageError{%
601 metapost encountered error(s) while compiling your\mpg@nl
602 metapost code and so it did not produce the figure!}
603 {Fix your metapost code, delete all metapost and\mpg@nl
604 LaTeX auxillary files and then run "\mpg@formatname\space -shell-escape"\mpg@nl
605 on your document again}
606 }\else\fi
607 \ifwindows%
608 \IfFileExists{\mpgfigname.log}{\immediate\write18{del \mpgfigname.log}}{}%
609 \IfFileExists{\mpgfigname.mp}{\immediate\write18{del \mpgfigname.mp}}{}%
610 \ifPDFTeX\ifpdf%
611 \IfFileExists{\mpgfigname.eps}{\immediate\write18{del \mpgfigname.eps}}{}\else\fi\else\ifXeTeX%
612 \IfFileExists{\mpgfigname.eps}{\immediate\write18{del \mpgfigname.eps}}{}\fi\fi%
613 \IfFileExists{\mpgfigname.mpx}{\immediate\write18{del \mpgfigname.mpx}}{}%
614 \IfFileExists{texnum.mpx}{\immediate\write18{del texnum.mpx}}{}%
615 \IfFileExists{makempx.log}{\immediate\write18{del makempx.log}}{}%
616 \IfFileExists{mpxerr.log}{\immediate\write18{del mpxerr.log}}{}%
617 \IfFileExists{mpxerr.tex}{\immediate\write18{del mpxerr.tex}}{}%
618 \else
619 \IfFileExists{\mpgfigname.log}{\immediate\write18{rm \mpgfigname.log}}{}%
620 \IfFileExists{\mpgfigname.mp}{\immediate\write18{rm \mpgfigname.mp}}{}%
621 \ifPDFTeX\ifpdf%
622 \IfFileExists{\mpgfigname.eps}{\immediate\write18{rm \mpgfigname.eps}}{}\else\fi\else\ifXeTeX%
623 \IfFileExists{\mpgfigname.eps}{\immediate\write18{rm \mpgfigname.eps}}{}\fi\fi%
624 \IfFileExists{\mpgfigname.mpx}{\immediate\write18{rm \mpgfigname.mpx}}{}%
625 \IfFileExists{texnum.mpx}{\immediate\write18{rm texnum.mpx}}{}%
626 \IfFileExists{makempx.log}{\immediate\write18{rm makempx.log}}{}%
627 \IfFileExists{mpxerr.log}{\immediate\write18{rm mpxerr.log}}{}%
628 \IfFileExists{mpxerr.tex}{\immediate\write18{rm mpxerr.tex}}{}%
629 \fi\fi
630 \fi
631 }
632 \long\gdef\MPGgraphicsinclude{\MPGgraphicsProcess%
633 \IfFileExists{\mpgfigname.\mpg@graphicsextension}%
634 {\begin{center}
635 \bgroup\fboxsep\@MPGboxsep\fboxrule\@MPGboxrule%
636 \color{\@MPGgraphiccolor}%
637 \fcolorbox{\@MPGgraphiclinecolor}{\@MPGgraphicbackground}%
638 {\if@mpgGINwidth%
639 \includegraphics[width=\@MPGgraphicwidth]{\mpgfigname.\mpg@graphicsextension}\else%
640 \if@mpgGINheight%
641 \includegraphics[height=\@MPGgraphicheight]{\mpgfigname.\mpg@graphicsextension}\else%
642 \if@mpgGINscale%
643 \includegraphics[scale=\@MPGgraphicscale]{\mpgfigname.\mpg@graphicsextension}\else%
644 \includegraphics{\mpgfigname.\mpg@graphicsextension}\fi\fi\fi%
645 }\egroup\end{center}%
646 \global\@mpgGINwidthfalse\let\@MPGgraphicwidth\relax
647 \global\@mpgGINheightfalse\let\@MPGgraphicheight\relax
648 \global\@mpgGINscalefalse\let\@MPGgraphicscale\relax
649 }{\csname @mpg@no@\mpg@graphicsextension true\endcsname}
650 \gdef\@MPGgraphiclinecolor{white}
651 \gdef\@MPGgraphicbackground{white}
652 \gdef\@MPGboxsep{0pt}
653 \gdef\@MPGboxrule{0pt}
654 }
655 \long\gdef\MPGinlinegraphicsinclude{%
656 \MPGgraphicsProcess%
657 \IfFileExists{\mpgfigname.\mpg@graphicsextension}%
658 {\bgroup\fboxrule0pt%
659 \normalcolor\fbox{\includegraphics{\mpgfigname.\mpg@graphicsextension}}%
660 \egroup}%
661 {\csname @mpg@no@\mpg@graphicsextension true\endcsname}%
662 }
663 \def\configure[#1][#2]{\setkeys{#1}{#2}
664 \mpg@Warning{mpgraphics}{Reconfigured #1 parameter(s)\MessageBreak
665 #2\MessageBreak}}
666 \define@key{mpggraphic}{width} {\gdef\@MPGgraphicwidth{#1}%
667 \global\@mpgGINwidthtrue}
668 \define@key{mpggraphic}{height} {\gdef\@MPGgraphicheight{#1}%
669 \global\@mpgGINheighttrue}
670 \define@key{mpggraphic}{scale} {\gdef\@MPGgraphicscale{#1}%
671 \global\@mpgGINscaletrue}
672 \define@key{mpggraphic}{color} {\gdef\@MPGgraphiccolor{#1}}
673 \define@key{mpggraphic}{linecolor} {\gdef\@MPGgraphiclinecolor{#1}}
674 \define@key{mpggraphic}{background}{\gdef\@MPGgraphicbackground{#1}}
675 \define@key{mpggraphic}{linewidth} {\gdef\@MPGboxrule{#1}}
676 \define@key{mpggraphic}{rulesep} {\gdef\@MPGboxsep{#1}}
677 \gdef\@MPGgraphiccolor{black}
678 \gdef\@MPGgraphiclinecolor{white}
679 \gdef\@MPGgraphicbackground{white}
680 \gdef\@MPGboxrule{0pt}
681 \gdef\@MPGboxsep{0pt}
682 \@ifundefined{c@arraylength}{\newcounter{arraylength}}{}%
683 \@ifundefined{c@ArrayIndex}{\newcounter{ArrayIndex}}{}%
684 \@ifundefined{c@zeroCtr}{\newcounter{zeroCtr}}{}%
685 \@ifundefined{c@recordCtr}{\newcounter{recordCtr}}{}
686 \setcounter{recordCtr}{1}
687 \@ifundefined{c@Ctr}{\newcounter{Ctr}}{}
688 \def\DeclareArray#1{\Array{#1}[0]{}}%
689 \def\Array#1[#2]#3{%
690 \expandafter\gdef\csname #1#2\endcsname{#3}%
691 \expandafter\gdef\csname #1\endcsname[##1]{\csname #1##1\endcsname}}%
692 \def\getArraylength#1{\setcounter{arraylength}{0}%
693 \loop\expandafter\ifx\csname #1\thearraylength\endcsname\relax%
694 \else\stepcounter{arraylength}\repeat}%
695 \def\addToArray#1#2{\setcounter{arraylength}{0}%
696 \loop\expandafter\ifx\csname #1\thearraylength\endcsname\relax%
697 \else\stepcounter{arraylength}\repeat%
698 \Array{#1}[\thearraylength]{#2}}%
699 \def\clearArray#1{\getArraylength{#1}%
700 \loop\ifnum\c@arraylength >0%
701 \global\expandafter\let\csname #1\thearraylength\endcsname\relax%
702 \addtocounter{arraylength}{-1}\repeat}%
703 \long\def\ArrayIterator#1#2{%
704 \setcounter{ArrayIndex}{1}\getArraylength{#1}%
705 \setcounter{zeroCtr}{\c@arraylength}%
706 \loop\ifnum\c@ArrayIndex<\c@zeroCtr{#2}%
707 \stepcounter{ArrayIndex}\repeat%
708 }%
709 \def\@nnil{\@nil}
710 \def\@empty{}
711 \def\@cvrstop#1\@@#2{}
712 \long\def\cvr@delimfor#1#2#3{\DeclareArray{#1}\clearArray{#1}%
713 \long\def\@icvrloop##1#2##2\@@##3{\def##3{##1}\ifx ##3\@nnil%
714 \expandafter\@cvrstop \else\addToArray{#1}{##1}%
715 \relax\expandafter\@icvrloop\fi##2\@@##3}%
716 \long\def\@cvrloop##1#2##2#2##3\@@##4{\addToArray{#1}{##1}%
717 \def##4{##1}\ifx ##4\@nnil \else%
718 \def##4{##2}\def\y@y{##2}\ifx\y@y\@nnil\else%
719 \addToArray{#1}{##2}\fi\ifx ##4\@nnil \else%
720 \@icvrloop ##3\@@##4\fi\fi}%
721 \expandafter\def\expandafter\@fortmp\expandafter{#3}%
722 \ifx\@fortmp\@empty \else%
723 \expandafter\@cvrloop#3#2\@nil#2\@nil\@@\@ee@\fi}%
724 \@ifundefined{c@f@irstCtr}{\newcounter{f@irstCtr}}{}%
725 \@ifundefined{c@s@econdCtr}{\newcounter{s@econdCtr}}{}%
726 \long\gdef\NoProcess[#1]{%
727 \long\def\@i@@noprocess##1,##2\@@##3{\def##3{##1}\ifx ##3\@nnil%
728 \expandafter\@cvrstop \else
729 \expandafter\hyphencheck##1-@-*[*]
730 \relax\expandafter\@i@@noprocess\fi##2\@@##3}%
731 \long\def\@@@noprocess##1,##2,##3\@@##4{
732 \expandafter\hyphencheck##1-@-*[*]
733 \def##4{##1}\ifx ##4\@nnil \else%
734 \def##4{##2}\def\y@y{##2}\ifx\y@y\@nnil\else%
735 \expandafter\hyphencheck##2-@-*[*]
736 \fi\ifx ##4\@nnil \else%
737 \@i@@noprocess ##3\@@##4\fi\fi}%
738 \expandafter\def\expandafter\@fortmp\expandafter{#1}%
739 \ifx\@fortmp\@empty \else%
740 \expandafter\@@@noprocess#1,\@nil,\@nil\@@\@ee@\fi}%
741 \def\d@d#1[*]{}
742 \def\hyphencheck#1-#2-#3{\def\r@r{@}\def\s@s{*}\edef\c@c{#3}
743 \ifx\c@c\r@r
744 \setcounter{f@irstCtr}{#1}
745 \setcounter{s@econdCtr}{#2}
746 \stepcounter{s@econdCtr}
747 \loop\ifnum\thes@econdCtr > \thef@irstCtr%
748 \expandafter\edef\csname Fig\thef@irstCtr\endcsname{TRUE}
749 \stepcounter{f@irstCtr}
750 \repeat%
751 \else\ifx\c@c\s@s%
752 \expandafter\edef\csname Fig#1\endcsname{TRUE}
753 \fi\fi\d@d}
754 % \end{macrocode}
755 % \iffalse
756 %</mpgraphics.sty>
757 %\fi
758 %
759 % \Finale
760 %
761 %
762 %\iffalse
763 %<*mpgraphics-example.ltx>
764 \documentclass{article}
765 \usepackage{mpgraphics}
766 \begin{document}
767 \begin{mpdisplay}
768 LaTeX_unitlength := 1.0pt;
769 w := 60*LaTeX_unitlength;
770 h := 40*LaTeX_unitlength;
771 numeric xmin, xmax, ymin, ymax;
772 xmin := 1/4; xmax := 6; ymax := 1/xmin; u := 1cm;
773 vardef f(expr x) = 1/x enddef;
774 xinc := 0.1;
775 path pts_f;
776 pts_f := (xmin,f(xmin))*u
777 for x=xmin+xinc step xinc until xmax:
778 .. (x,f(x))*u
779 endfor;
780 path hline[], vline[];
781 hline0 = (0,0)*u -- (xmax,0)*u;
782 vline0 = (0,0)*u -- (0,ymax)*u;
783 vline0.5 = (0.5,0)*u -- (0.5,ymax)*u;
784 vline4 = (4,0)*u -- (4,ymax)*u;
785 fill buildcycle(hline0, vline0.5, pts_f, vline4)
786 withcolor 0.8[blue,white];
787 draw hline0; draw vline0; % draw axes
788 draw (0.5,0)*u -- vline0.5 intersectionpoint pts_f;
789 draw (4,0)*u -- vline4 intersectionpoint pts_f;
790 draw pts_f withpen pencircle scaled 2;
791 label.bot(btex $x$ etex, (0.9xmax,0)*u);
792 label.lft(btex $y$ etex, (0,0.9ymax)*u);
793 label.urt(btex Hello $f(x)$ etex, (0.5,f(0.5))*u);
794 \end{mpdisplay}
795 \end{document}
796 %</mpgraphics-example.ltx>
797 %\fi
798 %
799 % \typeout{*************************************************************}
800 % \typeout{*}
801 % \typeout{* To finish the installation you have to move the following}
802 % \typeout{* file into a directory searched by TeX:}
803 % \typeout{*}
804 % \typeout{* \space\space\space mpgraphics.sty file}
805 % \typeout{*}
806 % \typeout{*************************************************************}
807 %
808 \endinput