Debian Codegraph @

texmf-dist/source/generic/mfpic/mfpic.dtx

raw
1 % \iffalse
2 % File: mfpic.dtx
3 % A part of mfpic 1.10 2012/12/03
4 %
5 % -------------------------------------------------------------------
6 %
7 % Copyright 2002--2012, Daniel H. Luecking
8 %
9 % Mfpic may be distributed and/or modified under the conditions of the
10 % LaTeX Project Public License, either version 1.3c of this license or (at
11 % your option) any later version. The latest version of this license is in
12 % <http://www.latex-project.org/lppl.txt>
13 % and version 1.3c or later is part of all distributions of LaTeX version
14 % 2008/12/01 or later.
15 %
16 % Mfpic has maintenance status "author-maintained". The Current Maintainer
17 % is Daniel H. Luecking. There are several Base Interpreters: plain TeX, LaTeX,
18 % plain Metafont and plain MetaPost.
19 %
20 %<*driver>
21 \ProvidesFile{mfpic.dtx}
22 %</driver>
23 %<sty>\ProvidesPackage{mfpic}
24 %<*sty>
25 [2012/12/03 v1.10. Macros for drawing with Metafont/MetaPost.]%
26 %</sty>
27 %<*driver>
28 \documentclass{ltxdoc}
29
30 \addtolength{\textwidth}{.5878pt}
31
32 \def\mytt{\upshape\mdseries\ttfamily}
33 \renewcommand\marg[1]{{\mytt\{#1\}}}
34 \renewcommand\oarg[1]{{\mytt [#1]}}
35 \renewcommand\parg[1]{{\mytt (#1)}}
36 \renewcommand \arg[1]{{\mytt \##1}}
37 \renewcommand\#{\char`\#\relax}
38 \renewcommand{\meta}[1]{{$\langle$\rmfamily\itshape#1\/$\rangle$}}
39 \newcommand{\mmarg}[1]{\marg{\meta{#1}}}
40 \DeclareRobustCommand\cs[1]{{\mytt\char`\\#1}}
41 \def\prog#1{{\mdseries\scshape #1}}
42 \def\grafbase{\prog{grafbase}}
43 \def\Grafbase{\prog{Grafbase}}
44 \def\mfpic{\prog{mfpic}}
45 \def\Mfpic{\prog{Mfpic}}
46 \def\MF{\prog{meta\-font}}
47 \def\MP{\prog{meta\-post}}
48 \def\CMF{\prog{Meta\-font}}
49 \def\CMP{\prog{Meta\-post}}
50 \def\opt#1{{\sffamily\upshape#1}}
51 \def\mfc#1{{\mytt#1}}
52 \let\env\mfc
53 \let\file\mfc
54 \let\gbc \mfc
55 \catcode`\_=12
56 \renewcommand\{{\char`\{}
57 \renewcommand\}{\char`\}}
58 \renewcommand\|{${}\mathrel{|}{}$}
59
60 \makeatletter
61 \let\HD@SetMacroIndent\@gobble
62 \newcommand\bsl{{\mytt\@backslashchar}}
63 % Stupid lists!
64 \def\@listi{\leftmargin\leftmargini
65 \parsep \z@ \@plus\p@ \@minus\z@
66 \topsep 4\p@ \@plus\p@ \@minus2\p@
67 \itemsep\parsep}
68 \let\@listI\@listi \@listi
69 \renewcommand\labelitemi{\normalfont\bfseries \textendash}
70 \renewcommand\labelitemii{\textasteriskcentered}
71 \renewcommand\labelitemiii{\textperiodcentered}
72 \leftmargini\parindent
73 % Stupid index!
74 \def\usage#1{\textrm{#1}}
75 \def\index@prologue{\section*{Index}\markboth{Index}{Index}%
76 Numbers refer to the page where the corresponding entry is described.
77 }
78 \def\IndexParms{%
79 \parindent \z@ \columnsep 15pt
80 \parskip 0pt plus 1pt
81 \rightskip 5pt plus2em \mathsurround \z@
82 \parfillskip-5pt \small
83 % less hanging:
84 \def\@idxitem{\par\hangindent 20pt}%
85 \def\subitem{\@idxitem\hspace*{15pt}}%
86 \def\subsubitem{\@idxitem\hspace*{25pt}}%
87 \def\indexspace{\par\vspace{10pt plus 2pt minus 3pt}}}
88 \makeatother
89
90 \def\pdfTeX{\textrm{pdf\kern.04em\TeX}}
91 \def\pdfLaTeX{\textrm{pdf\kern.06em\LaTeX}}
92 \def\ConTeXt{\textrm{Con\kern-.16em\TeX\kern-0.06em t}}
93 \def\PiCTeX{\textrm{P\kern-.13em\lower.3ex\hbox{I}C\TeX}}
94
95 \title{The \mfpic{} package\thanks{This file has version number
96 \fileversion, last revised \filedate. The code described here
97 was developed by several people, notably Thomas Leathrum,
98 Geoffrey Tobin and Dan Luecking. Dan wrote this documentation.}}
99 \author{Dan Luecking}
100 \date{\filedate}
101 \DisableCrossrefs
102 \CodelineIndex
103 \AlsoImplementation
104
105 \begin{document}
106 \DeleteShortVerb{\|}
107 \DocInput{mfpic.dtx}
108 \end{document}
109 %</driver>
110 %\fi
111 % \CheckSum{5188}
112 % \CharacterTable
113 % {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
114 % 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
115 % Digits \0\1\2\3\4\5\6\7\8\9
116 % Exclamation \! Double quote \" Hash (number) \#
117 % Dollar \$ Percent \% Ampersand \&
118 % Acute accent \' Left paren \( Right paren \)
119 % Asterisk \* Plus \+ Comma \,
120 % Minus \- Point \. Solidus \/
121 % Colon \: Semicolon \; Less than \<
122 % Equals \= Greater than \> Question mark \?
123 % Commercial at \@ Left bracket \[ Backslash \\
124 % Right bracket \] Circumflex \^ Underscore \_
125 % Grave accent \` Left brace \{ Vertical bar \|
126 % Right brace \} Tilde \~}
127 %
128 % \GetFileInfo{mfpic.dtx}
129 % \maketitle
130 %
131 % \begin{abstract}
132 % An environment, \env{mfpic}, is defined, within which commands can be
133 % used for drawing pictures, especially of mathematical objects and
134 % functions. These commands actually write code to an external file to be
135 % processed through \MF{} or \MP{} (depending on package options) to
136 % produce the picture. The picture is then included on a second pass
137 % through \TeX.
138 %
139 % This file documents the \mfpic{} source code. The user manual for
140 % \mfpic{} is distributed as \file{mfpic-doc.pdf}, produced from
141 % \file{mfpic-doc.tex}. An introductory guide to \mfpic{} is available
142 % in \file{mfpguide.pdf}, produced from \file{mfpguide.tex}
143 % \end{abstract}
144 %
145 % \StopEventually{\PrintIndex}
146 % \tableofcontents
147 %
148 %
149 %
150 % \section{Introductory setup}\label{intro}
151 %
152 % \Mfpic{} is designed to work with plain \TeX, \LaTeX, \pdfTeX, and
153 % \pdfLaTeX. I consistently use it with eplain and AMS\LaTeX{}
154 % without problems. Users have reported succesfully using it with \AmSTeX.
155 % It has \emph{not} been successfully used with \ConTeXt.
156 %
157 % \subsection{Versions numbers, category codes, etc.}\label{category}
158 %
159 % Almost all the various category code settings we do were prompted by
160 % an \mfpic{} user who had sent a bug report and had to send along his
161 % modified version of \file{mfpic.tex}. It had been modified so that
162 % \cs{message}\,s and \cs{write}\,s would do the right thing in latex
163 % files where various punctuation were made active (e.g., with
164 % \file{french.sty}).
165 %
166 % We keep track of version numbers here. We store the version and date
167 % in macros and later we write this version information to the
168 % output file, The \cs{mfpicversion} is 100 times the numeric part of the
169 % version. The output file can compare this number with the corresponding
170 % value in \file{grafbase} and detect installations where there is a
171 % mismatch.
172 % \begin{macrocode}
173 %<*tex>
174 \ifx\mfpfileversion\UndEfInEd\else\expandafter\endinput\fi%
175 {%
176 \catcode\lq\.12 \catcode\lq\/12%
177 \gdef\mfpfileversion{1.10}%
178 \gdef\mfpfiledate{2012/12/03}%
179 \gdef\mfpicversion{110}%
180 }%
181 % \end{macrocode}
182 %
183 % A bug in older versions of some support files is triggered by the macro
184 % \cs{+}, which is an \cs{outer} macro in plain \TeX. Here we save the
185 % current definition and then give it a nonouter meaning.
186 % \begin{macrocode}
187 \let\mfpsaveplus\+%
188 \let\+\tabalign%
189 % \end{macrocode}
190 %
191 % We now get rid of unusually catcoded punctuation, space and EOL.
192 % We assume that letters, numbers, `\texttt\bsl', `\texttt\{', `\texttt\}',
193 % `\texttt\#' and `\texttt\%' have the usual categories. However, styles
194 % (e.g., \prog{french}) that make punctuation active foul up \cs{write}\,s
195 % of MF/MP code. This can still occur in user-generated \cs{write}\,s, so
196 % maybe some of this code should be added in \cs{mfpic} or \cs{mfsrc}
197 % command, too.
198 % \begin{macrocode}
199 {%
200 \catcode61\space12\relax% 61=equal sign
201 \catcode32=10\relax% 32=space
202 \catcode13=5 % 13=EOL
203 \catcode96=12 % 96=left quote
204 \catcode`\@=11
205 \gdef\MFPsavecodes{%
206 \edef\mfp@restoreNLC{\newlinechar\number\newlinechar\relax}%
207 \edef\mfp@restoreELC{\endlinechar\number\endlinechar\relax}%
208 \edef\mfp@restoreSPA{\catcode32=\number\catcode32\relax}%
209 \edef\mfp@restoreEOL{\catcode13=\number\catcode13\relax}%
210 \edef\mfp@restoreALL{\mfp@restorecode{=}\mfp@restorecode{@}%
211 \mfp@restorecode{$}\mfp@restorecode{:}\mfp@restorecode{;}%
212 \mfp@restorecode{.}\mfp@restorecode{,}\mfp@restorecode{!}%
213 \mfp@restorecode{?}\mfp@restorecode{(}\mfp@restorecode{)}%
214 \mfp@restorecode{[}\mfp@restorecode{]}\mfp@restorecode{<}%
215 \mfp@restorecode{>}\mfp@restorecode{*}\mfp@restorecode{/}%
216 \mfp@restorecode{+}\mfp@restorecode{-}\mfp@restorecode{"}%
217 \mfp@restorecode{'}\mfp@restorecode{_}\mfp@restorecode{`}%
218 \mfp@restoreEOL\mfp@restoreSPA\catcode10=\number\catcode10
219 \mfp@restoreNLC\mfp@restoreELC}}%
220 \gdef\mfp@restorecode#1{\catcode`\string#1=\number\catcode`#1\relax}%
221 \ifx\@makeother\UndEfInEd \gdef\@makeother#1{\catcode`#1=12\relax}\fi
222 \gdef\MFPsanitize{\endlinechar13 \newlinechar10
223 \catcode10=12 \catcode13=5 \catcode`\$=3 \catcode`\ =10
224 \@makeother\:\@makeother\;\@makeother\.\@makeother\,%
225 \@makeother\!\@makeother\?\@makeother\(\@makeother\)%
226 \@makeother\[\@makeother\]\@makeother\>\@makeother\<%
227 \@makeother\/\@makeother\*\@makeother\+\@makeother\-%
228 \@makeother\'\@makeother\"\@makeother\_\@makeother\`%
229 \@makeother\=\@makeother\@}%
230 }%
231 \MFPsavecodes\MFPsanitize
232 \catcode`@11
233 \chardef\mfp@ctrlJ 10 \chardef\mfp@ctrlM 13
234 % \end{macrocode}
235 %
236 % \cs{MFPsavecodes} saves a bunch of things that must have (mostly)
237 % normal settings. \cs{mfp@restoreALL} will be invoked at the end of the
238 % file to restore all the values.
239 %
240 % \cs{MFPsanitize} sets (almost) everything to normal. It can be used to
241 % redo these settings inside some other macro, should that ever become
242 % necessary. Characters 10 and 13 are \verb|^^J| and \verb|^^M|,
243 % control-J and control-M.
244 %
245 %
246 % \subsection{Debugging and messages}\label{debug}
247 %
248 % \DescribeMacro{\mfpicdebug}
249 % To turn on debugging before option processing, the user must make sure
250 % \cs{mfpicdebug} is defined. \cs{mfp@DBlog} writes it contents to the
251 % log file only if debugging is on.
252 % \DescribeMacro{\ifmfpicdebug}
253 % The switch \cs {ifmfpicdebug} is normally set to true if the user loads
254 % \mfpic{} with the \opt{debug} option, or sets it directly with
255 % \cs{mfpicdebugtrue} after loading.
256 % \begin{macrocode}
257 \newif\ifmfpicdebug
258 \ifx\mfpicdebug\UndEfInEd \mfpicdebugfalse
259 \else \mfpicdebugtrue
260 \fi
261 \def\mfp@DBlog#1{%
262 \ifmfpicdebug{\let\@msgbreak\mfp@errbrk\wlog{Mfpic debug: #1}}\fi}%
263 % \end{macrocode}
264 %
265 % We need to write various kinds of messages to the screen and log file.
266 % \cs{mfp@msg} is only used in the definition of the others and to write a
267 % blank line. We always use the second, which identifies the source of the
268 % message, or the third, which adds the word `warning'. The fourth is for
269 % errors and provides for help if a user presses `\texttt h' in response
270 % to the message. The bit with the spaces is to get a hanging indentation
271 % with text properly aligned on screen. The basic \cs{mfp@msg} defines
272 % \cs{@nl} to place the \cs{newlinechar}, for multiline messages. We
273 % also define \cs{@nl} in \cs{mfp@write} for new lines in writing to a
274 % file. We do not define it at all at the outer level.
275 % \begin{macrocode}
276 \def\mfp@msg#1{%
277 {\newlinechar\mfp@ctrlJ\def\@nl{^^J}\immediate\write16{#1}}}%
278 \def\mfp@spaces{\space\space\space\space\space\space}%
279 \def\mfp@msgbrk{^^J\mfp@spaces\space}%
280 \def\mfp@errbrk{\mfp@msgbrk\mfp@spaces}%
281 \def\mfp@warnbrk{\mfp@errbrk\space\space}%
282 \def\Mfpic@msg#1{{\let\@msgbreak\mfp@msgbrk\mfp@msg{Mfpic: #1}}}%
283 \def\Mfpic@warn#1{%
284 {\let\@msgbreak\mfp@warnbrk\mfp@msg{\@nl Mfpic warning: #1}}}%
285 \def\mfp@errmsg#1#2{{\newlinechar\mfp@ctrlJ\let\@msgbreak\mfp@errbrk
286 \errhelp{#2}\errmessage{Mfpic error: #1}}}%
287 % \end{macrocode}
288 %
289 % In \TeX{} 3.x we can identify the line being processed when a message is
290 % issued. We do not support \TeX{} 2.x. The command \cs{mfp@lineno} is
291 % for information written into the output file.
292 % \begin{macrocode}
293 \def\mfp@lineno{line \number\inputlineno\space in the TeX source}%
294 % \end{macrocode}
295 %
296 %
297 % \subsection{Detecting the format}\label{format}
298 %
299 % To detect its environment, \mfpic{} needs to test whether certain
300 % commands are defined. We usually use the positive version
301 % \cs{mfp@ifdefined}. The \cs{@xp} in it is used to `expand away' the rest
302 % of a conditional. \cs{@XP} does this from two levels deep in a
303 % conditional. Since our check uses \cs{@firstoftwo} and
304 % \cs{@secondoftwo}, we cannot use it to check \emph{their} existence (but
305 % we could use other means).
306 %
307 % \cs{mfp@ifundefined} checks its argument to see if it is defined.
308 % If so, it gobbles all code up to \cs{mfp@enddef}. Otherwise that code is
309 % executed. This avoids reading code prematurely (category code changes).
310 %
311 % We also copy \LaTeX's \cs{@ifundefined} since we have at least five
312 % places where we need to supply the name without a backslash.
313 % \begin{macrocode}
314 \let\@xp\expandafter
315 \def\@XP{\@xp\@xp\@xp}%
316 \long\def\@firstoftwo#1#2{#1}%
317 \long\def\@secondoftwo#1#2{#2}%
318 \def\mfp@ifdefined#1{%
319 \ifx#1\UndEfInEd \@xp\@secondoftwo
320 \else\ifx#1\relax \@XP\@secondoftwo
321 \else \@XP\@firstoftwo
322 \fi\fi}%
323 \mfp@ifdefined\@empty{}{\def\@empty{}}%
324 \mfp@ifdefined\@gobble{}{\def\@gobble#1{}}%
325 \mfp@ifdefined\@firstofone{}{\long\def\@firstofone#1{#1}}%
326 \mfp@ifdefined\on@line{}%
327 {\def\on@line{ on input line \number\inputlineno}}%
328 \let\mfp@enddef\@empty
329 \long\def\mfp@gobbledef#1\mfp@enddef{}%
330 \def\mfp@ifundefined#1{\mfp@ifdefined#1\mfp@gobbledef\@empty}%
331 \mfp@ifundefined\@ifundefined
332 \def\@ifundefined#1{%
333 \@xp\ifx\csname #1\endcsname\relax \@xp\@firstoftwo
334 \else \@xp\@secondoftwo
335 \fi}%
336 \mfp@enddef
337 % \end{macrocode}
338 %
339 % The following might be useful in patching things or adding to
340 % \cs{mfp@additions}.
341 % \begin{macrocode}
342 \mfp@ifundefined\g@addto@macro
343 \long\def\g@addto@macro#1#2{%
344 \begingroup
345 \toks@\@xp{#1#2}%
346 \xdef#1{\the\toks@}%
347 \endgroup}%
348 \mfp@enddef
349 \mfp@ifundefined\g@prependto@macro
350 \long\def\g@prependto@macro#1#2{%
351 \begingroup
352 \toks@{#2}\toks2\@xp{#1}%
353 \xdef#1{\the\toks@\the\toks2}%
354 \endgroup}%
355 \mfp@enddef
356 % \end{macrocode}
357 %
358 % We test for LaTeX. We assume plain\TeX{}, or something compatible,
359 % except in a few places where LaTeX{} does thing differently. \Mfpic{}
360 % didn't work in \ConTeXt{} the last few times I tried.
361 %
362 % Here we see if \cs{documentstyle} is defined, and then make sure
363 % we are not in \AmSTeX{}. We used to detect \AmSTeX{} by checking
364 % \cs{fmtname}. This leads to problems if some other format inputs
365 % \file{amstex.tex} and redefined \cs{fmtname}. Thus we will now check
366 % \cs{amstexloaded@}. Unfortunately, \file{amstex.tex} sets it equal to
367 % \cs{relax}, which is much too easy to be the result of some other
368 % attempt to check it. Thus, we add an additional check for
369 % \cs{NoBlackBoxes}.
370 % \begin{macrocode}
371 \newif\ifmfp@latex \mfp@latexfalse
372 \mfp@ifdefined\documentstyle
373 {\ifx \amstexloaded@\relax % amstex loaded, or a bad check for it
374 \ifx\NoBlackBoxes\UndEfInEd % amstex not loaded
375 \mfp@DBlog{LaTeX detected.}\mfp@latextrue
376 \else % most likely amstex loaded
377 \mfp@DBlog{AmS-TeX detected.}%
378 \fi
379 \else % amstex not loaded
380 \mfp@DBlog{LaTeX detected.}\mfp@latextrue
381 \fi}%
382 {\mfp@DBlog{Neither LaTeX nor AmS-TeX detected.}}%
383 % \end{macrocode}
384 %
385 % We are in \LaTeXe{}, as opposed to \LaTeX2.09, if \cs{documentclass}
386 % is defined. The \file{mfpic.sty} now assumes \LaTeXe{}. It might still
387 % be possible to use \LaTeX{}2.09 with \cs{input mfpic}, but I don't
388 % care enough to test it.
389 % \begin{macrocode}
390 \newif\ifmfp@latexe \mfp@latexefalse
391 \mfp@ifdefined\documentclass
392 {\mfp@latexetrue \mfp@DBlog{LaTeX2e detected.}}%
393 {\mfp@DBlog{Not LaTeX2e.}}%
394 % \end{macrocode}
395 %
396 % We now test \cs{pdfoutput} to see if pdf support is needed.
397 % \begin{macrocode}
398 \newif\ifmfp@pdf \mfp@pdffalse
399 \mfp@ifdefined\pdfoutput
400 {\mfp@DBlog{PdfTeX detected...}%
401 \ifnum\pdfoutput<1 \mfp@DBlog{...with dvi output.}%
402 \else \mfp@pdftrue \mfp@DBlog{...with PDF output.}%
403 \fi}%
404 {\mfp@DBlog{Not pdfTeX.}}%
405 % \end{macrocode}
406 %
407 %
408 % \subsection{Blank line and spacing hacks}\label{spacing}
409 %
410 % In order for commands to always read their arguments correctly,
411 % we need EOLs to have their normal category codes, but then a
412 % blank line will end a paragraph, and we would like blank lines to be
413 % ignored inside an \env{mfpic} environment. Therefore we turn off
414 % \cs{par} inside that environment, and then need(?) to turn it back on
415 % inside \cs{tlabel} and \cs{tcaption}. \cs{@@par} (in \LaTeX) and
416 % \cs{endgraf} (in plain \TeX) should equal the primitive \cs{par}.
417 % \begin{macrocode}
418 \ifmfp@latex \else \let\@@par\endgraf \fi
419 \def\mfp@restorepar{\let\par\@@par}%
420 % \end{macrocode}
421 %
422 % Some \mfpic{} commands end with \cs{ignorespaces}. For some others a
423 % better choice is the \LaTeX{} strategy of conditionally ignoring spaces.
424 % \begin{macrocode}
425 \mfp@ifdefined\@namedef{}%
426 {\def\@namedef#1{\@xp\def\csname #1\endcsname}}%
427 \mfp@ifdefined\@namelet{}%
428 {\def\@namelet#1{\@xp\let\csname #1\endcsname}}%
429 \mfp@ifdefined\@nameuse{}%
430 {\def\@nameuse#1{\csname #1\endcsname}}%
431 \mfp@ifundefined\@bsphack
432 \@nameuse{newskip}\@savsk
433 \@nameuse{newcount}\@savsf
434 \def\@bsphack{\relax
435 \ifhmode \@savsk\lastskip \@savsf\spacefactor \fi}%
436 \def\@esphack{\relax
437 \ifhmode \spacefactor\@savsf
438 \ifdim\@savsk>\z@ \ignorespaces
439 \fi\fi}%
440 \mfp@enddef
441 % \end{macrocode}
442 %
443 %
444 % \subsection{Warning if commands are already defined}
445 %
446 % We sometimes (either by accident or by choice) redefine things defined
447 % in some formats. For the accidental redefinitions we want to be told,
448 % and since we cannot assume \LaTeX{} with its \cs{newcommand}, we define
449 % a simple check and print a warning when it happens.
450 % \begin{macrocode}
451 \mfp@DBlog{Defining test for previous definitions of macros.}%
452 \def\mfp@testdef#1{%
453 \ifx#1\UndEfInEd
454 \else\ifx#1\relax
455 \Mfpic@warn{\string#1 was previouly defined to be \string\relax.}%
456 \else
457 \Mfpic@warn{\string#1 is already defined.}%
458 \fi\fi}%
459 % \end{macrocode}
460 %
461 % Is the proposed definer of new definitions itself not new? Well,
462 % we'd like a warning, but go ahead and define it anyway. All
463 % \cs{newdef} does is check whether the macro being defined is already
464 % defined, raise a warning (but \emph{not} an error) and define it
465 % anyway. We do something similar with \cs{let}.
466 % \begin{macrocode}
467 \mfp@testdef\newdef
468 \def\newdef#1{\mfp@testdef#1\def#1}%
469 \newdef\newlet#1{\mfp@testdef#1\let#1}%
470 % \end{macrocode}
471 %
472 %
473 % \subsection{Error messages and warnings}
474 %
475 % If one tries to switch on \MP{} support after the output file has been
476 % set up, we issue this error message.
477 % \begin{macrocode}
478 \newdef\mfp@useMP@error{%
479 \mfp@errmsg {Command \mfp@b usemetapost too late}%
480 {It is too late to select the metapost option.^^J%
481 It must be selected before the \opengraphsfile command.^^J%
482 If you proceed, the metafont option will be assumed.}}%
483 % \end{macrocode}
484 %
485 % This one is for macros that need an output file to write to, but are
486 % called before one has been opened.
487 % \begin{macrocode}
488 \def\mfp@nooutput@error#1{%
489 \mfp@errmsg {No output file has been opened}%
490 {You have tried to used a command, #1, that requires an output^^J%
491 file to be opened with the \opengraphsfile command, which^^J%
492 was either not issued or was not successful.}}%
493 % \end{macrocode}
494 %
495 % Some options and commands require the \opt{metapost} option be in
496 % effect. We define an error message for the case where it is not in
497 % effect. Rarely, we need a similar warning for the \opt{metafont}
498 % option.
499 % \begin{macrocode}
500 \newdef\mfp@noMP@error#1{%
501 \mfp@errmsg {Metafont does not support #1, use MetaPost}%
502 {Metafont doesn't support #1. Perhaps you forgot to turn on^^J%
503 MetaPost support by using the metapost option or issuing the^^J%
504 command \usemetapost. For now, I will ignore it.}}%
505 \newdef\mfp@noMF@warn#1{%
506 \Mfpic@warn
507 {Metapost does not support \string#1, it will be ignored.}}%
508 % \end{macrocode}
509 %
510 % This next is like \cs{mfp@useMP@error}, but it is not so specific.
511 % It is for other options that also need to be issued before
512 % \cs{opengraphsfile}.
513 % \begin{macrocode}
514 \def\mfp@afteropen@error#1{%
515 \mfp@errmsg{Improper use of command \string#1\on@line}%
516 {You must issue the command #1 prior to \opengraphsfile.
517 It will be ignored now.}}%
518 % \end{macrocode}
519 %
520 % \cs{mfp@end} is defined to be an error message, but that is for
521 % debugging purposes. It's actual use is to mark the end when we need to
522 % process a list of tokens. The code should simply detect and remove it,
523 % and it should never be expanded, so seeing the error message indicates
524 % a coding error by me, or incorrect syntax by a user.
525 % \begin{macrocode}
526 \newdef\mfp@end{%
527 \mfp@errmsg {Unexpected token \string\mfp@end}%
528 {If you get this message but did not misuse the command^^J%
529 \mfp@end, it could mean you have unbalanced braces.}}%
530 % \end{macrocode}
531 %
532 % The next two are error messages for missing or empty data files.
533 % \begin{macrocode}
534 \newdef\mfp@nofile@error#1{%
535 \mfp@errmsg{No data file: #1}%
536 {The data file you tried to plot was not found.}}%
537 \newdef\mfp@nodata@error#1{%
538 \mfp@errmsg{Empty data file: #1}%
539 {The data file contained only empty lines and comments.}}%
540 % \end{macrocode}
541 %
542 % This message is issued when the \cs{tlabeljustify} command (see
543 % subsection~\ref{labelsettings}) is issued with an invalid parameter.
544 % \begin{macrocode}
545 \newdef\mfp@justify@error{%
546 \mfp@errmsg{Invalid justification parameter for text label}%
547 {The optional argument for an mfpic text label must be^^J%
548 one of B, b, c or t, followed by^^J%
549 one of l, r or c, optionally followed by an angle.}}%
550 % \end{macrocode}
551 %
552 % This is the default meaning assigned to \cs{@nountil} at the
553 % beginning of \cs{mfploop}. Use of \cs{mfpuntil} cancels the
554 % warning, which is otherwise issued by \cs{mfpendloop}.
555 % \begin{macrocode}
556 \newdef\mfp@untilwarn{%
557 \Mfpic@warn{\mfp@b mfploop without \string\mfpuntil!\@nl}}%
558 % \end{macrocode}
559 %
560 %
561 %
562 % \section{Configuring \mfpic{} behavior}\label{configuring}
563 %
564 %
565 % \subsection{Options}\label{options}
566 %
567 % \DescribeMacro{\ifmfpmpost}
568 % I have decided to make this a user-level macro so that a user can
569 % write code that behaves one way for \MP{} and another for \MF. However
570 % the commands to change the setting are private.
571 %
572 % Our switch to turn \MP{} support on or off needs to be global, so it
573 % can't be a normal \cs{newif}.
574 % \begin{macrocode}
575 \newlet\ifmfpmpost\iffalse
576 \newdef\mfp@mposttrue {\global\let\ifmfpmpost\iftrue}%
577 \newdef\mfp@mpostfalse{\global\let\ifmfpmpost\iffalse}%
578 \newdef\mfp@ifmpost{%
579 \ifmfpmpost\@xp\@firstoftwo\else\@xp\@secondoftwo\fi}%
580 % \end{macrocode}
581 %
582 % \DescribeMacro{\usemetafont}
583 % We make user-level commands for switching to the appropriate drawing
584 % program. This is necessary for plain\TeX, but also used internally by
585 % \mfpic. \CMF{} is the default. This command needs to not only clear the
586 % boolean \cs{ifmfpmpost}, but also restore the default graphics inclusion
587 % commands. Actually, it doesn't \emph{need} to unless \cs{usemetapost}
588 % was previously issued to change the default. This would normally not
589 % happen unless the user wanted to close the current graph file and open a
590 % new one for \MF. For similar reasons, we clear the \opt{mplabels}
591 % option.
592 %
593 % \MP{} support requires macros for including EPS graphics. What works
594 % best depends on the format, so we delay the definition of
595 % \cs{usemetapost} until the \LaTeX{} options section.
596 %
597 % Since \cs{mfpicllx} and \cs{mfpiclly} are globally defined by graphic
598 % inclusion, we reset then to 0, in case \opt{metafont} and \opt{metapost}
599 % options are mixed in one file.
600 % \begin{macrocode}
601 \newdef\usemetafont{\mfp@mpostfalse
602 \nomplabels
603 \def\preparemfpicgraphic##1{}%
604 \def\setmfpicgraphic##1{\mfp@graphfont\char\mfp@count}%
605 \def\getmfpicoffset##1{\gdef\mfpicllx{0}\gdef\mfpiclly{0}}}%
606 % \end{macrocode}
607 %
608 % Some options need an open \file{.mf} or \file{.mp} file before they
609 % can do anything. This means the \cs{opengraphsfile} command must have
610 % been issued but not \cs{closegraphsfile}. Since those commands define and
611 % undefine \cs{mfp@filename}, we use that as our test.
612 % \begin{macrocode}
613 \newdef\mfp@ifopengraphsfile{\mfp@ifdefined\mfp@filename}%
614 % \end{macrocode}
615 %
616 % \DescribeMacro{\mfmode}
617 % For use with the \opt{metafont} option, we allow the user to set the
618 % \MF{} mode. Example: \verb$\mfmode{ljfour}$
619 %
620 % \DescribeMacro{\mfresolution}
621 % If modes are too esoteric, the user can at least set the resolution.
622 % This should be a pure number representing dots per inch. Example:
623 % \verb$\mfresolution{600}$
624 % \begin{macrocode}
625 \newdef\mfmode#1{\edef\mfp@mode{#1}%
626 \mfp@ifopengraphsfile%
627 {\mfp@afteropen@error\mfmode}%
628 {\mfp@ifmpost{\mfp@noMF@warn\mfmode}{}}}%
629 \newdef\mfresolution#1{\edef\mfp@resolution{#1}%
630 \mfp@ifopengraphsfile%
631 {\mfp@afteropen@error\mfresolution}%
632 {\mfp@ifmpost{\mfp@noMF@warn\mfresolution}{}}}%
633 % \end{macrocode}
634 %
635 % \DescribeMacro{\setmfvariable}
636 % A useful abbreviation for a common requirement: declaring and setting
637 % a \MF{} variable. I have decided to change it to a user-level macro for
638 % power users.
639 % \DescribeMacro{\setmpvariable}
640 % For consistency, \cs{setmpvariable} is an alternative name for it. It
641 % takes three arguments: the type of variable, the variable itself, and
642 % its value. Example:\\
643 % \indent \cs{setmfvariable}\marg{numeric}\marg{shadewd}\marg{.7pt}.\\
644 % Since the \MF{} code \mfc{save}\,s the variable, there must be no
645 % suffix. This is not a big problem since mostly it is for internal use.
646 % We document that fact for power users and advise ordinary users on the
647 % naming of \MF{} variables.
648 %
649 % Since \MP{} has three (or four) data types for color, we have to write
650 % the command `\gbc{setcolor}' to the output file instead of
651 % `\gbc{setvariable (color)}' so that the datatype can be determined
652 % before declaring the variable. (Unlike the other data types the
653 % \grafbase{} command \gbc{setcolor} is more complicated than
654 % \gbc{setvariable(color)}.) For simplicity, we do this with all data
655 % types. For example \cs{setmfvariable}\marg{numeric} writes
656 % `\gbc{setnumeric}'. This makes spaces significant in the first argument,
657 % so we strip them off the ends with \cs{mfp@sp@def} (defined in
658 % section~\ref{optional}).
659 %
660 % We have abbreviations for the most common internal uses. For example
661 % \SpecialUsageIndex{\setmfboolean}\cs{setmfboolean} is the equivalent of
662 % \cs{setmfvariable} with type \mfc{boolean}. A similar statement is true
663 % For \SpecialUsageIndex{\setmfnumeric}\cs{setmfnumeric},
664 % \SpecialUsageIndex{\setmfpair}\cs{setmfpair}, and
665 % \SpecialUsageIndex{\setmfcolor}\cs{setmfcolor}.
666 %
667 % \DescribeMacro{\globalsetmfvariable}
668 % This is like \cs{setmfvariable}, except it doesn't perform a
669 % \mfc{save} and so the variable is globally defined. Also,
670 % suffixed variables are permitted (but not numeric suffixes).
671 % Here, too, we have to write a different command for setting color.
672 % Thus, me need to test whether the first argument is `color'. Here again,
673 % spaces are significant.
674 % \begin{macrocode}
675 \newdef\setmfvariable#1{%
676 \mfp@sp@def\mfp@tempa{#1}\@setmfvariable\mfp@tempa}%
677 \newdef\@setmfvariable#1#2#3{%
678 \mfp@ifopengraphsfile%
679 {\mfcmd{set#1 (#2) #3}}%
680 {\mfp@nooutput@error\setmfvariable}}%
681 \newdef\setmfboolean{\@setmfvariable{boolean}}%
682 \newdef\setmfnumeric{\@setmfvariable{numeric}}%
683 \newdef\setmfpair {\@setmfvariable{pair}}%
684 \newdef\setmfcolor {\@setmfvariable{color}}%
685 \newdef\globalsetmfvariable#1#2#3{%
686 \mfp@sp@def\mfp@tempa{#1}%
687 \mfp@ifopengraphsfile
688 {\mfcmd{\ifx\mfp@tempa\mfp@C gsetcolor \else gsetvariable (#1) \fi
689 (#2) #3}}%
690 {\mfp@nooutput@error\globalsetmfvariable}}%
691 \newlet\setmpvariable\setmfvariable
692 \newlet\globalsetmpvariable\globalsetmfvariable
693 % \end{macrocode}
694 %
695 % The command \cs{setmfvariable} arranges for the value of
696 % that variable to be localized to each figure if set inside one, but
697 % it is global otherwise. We have to be careful that \TeX{} and \MF{}
698 % stay in synchrony, as they have different understandings as to what is
699 % global and what is not. So we define a switch that will be set at the
700 % start of an \env{mfpic} environment to test if a command is issued
701 % inside one. The command \cs{mfp@local} tests this switch and makes the
702 % following assignment global if it fails. Then we have two shortcuts for
703 % the more commonly occuring cases.
704 %
705 % We also define here \texttt{true}, \texttt{false} and \texttt{color} as
706 % macros. These are strings we need to write to the output frequently.
707 % \begin{macrocode}
708 \newlet\ifin@mfpicenv\iffalse
709 \newdef\mfp@local{\relax\ifin@mfpicenv\else\global\fi}%
710 \newdef\mfp@let{\mfp@local\let}%
711 \newdef\mfp@def{\mfp@local\def}%
712 \newdef\mfp@T{true}%
713 \newdef\mfp@F{false}%
714 \newdef\mfp@C{color}%
715 % \end{macrocode}
716 %
717 % \DescribeMacro{\usecenteredcaptions}
718 % This (\opt{centeredcaptions}) is the simplest option. Other options
719 % follow a similar pattern: a user-level command \cs{usecenteredcaptions}
720 % is defined for turning it on and another,
721 % \DescribeMacro{\nocenteredcaptions}
722 % \cs{nocenteredcaptions}, is defined for turning it off. Selection of
723 % centered captions can be turned on or off at will throughout a document.
724 % \begin{macrocode}
725 \newdef\usecenteredcaptions{\mfp@let\ifmfp@centcapt\iftrue}%
726 \newdef\nocenteredcaptions {\mfp@let\ifmfp@centcapt\iffalse}%
727 \nocenteredcaptions
728 % \end{macrocode}
729 %
730 % \DescribeMacro{\useraggedcaptions}
731 % Here we define the settings for justified and ragged captions.
732 % Justified captions are the default. Ragged captions are normally
733 % raggedright, but are ragged on both sides if \opt{centeredcaptions} is
734 % in effect.
735 % \DescribeMacro{\noraggedcaptions}
736 % For justified captions, lines are justified on both sides, except the
737 % last is centered under \opt{centeredcaptions}.
738 % \begin{macrocode}
739 \newdef\useraggedcaptions{\mfp@let\mfp@capsettings\mfp@raggedcap}%
740 \newdef\noraggedcaptions{\mfp@let\mfp@capsettings\mfp@justifiedcap}%
741 \newdef\mfp@raggedcap{%
742 \ifmfp@latex
743 \ifmfp@centcapt \centering \else \raggedright \fi
744 \else
745 \rightskip 0pt plus 1fil\relax
746 \ifmfp@centcapt
747 \leftskip 0pt plus 1fil
748 \parfillskip 0pt plus 1fil\relax
749 \fi
750 \def\\{\unskip\hbox{}\penalty-\@M\ignorespaces}%
751 \fi}%
752 \def\mfp@justifiedcap{%
753 \ifmfp@centcapt
754 \leftskip 0pt plus 0.5fil
755 \rightskip 0pt plus -0.5fil
756 \parfillskip 0pt plus 1fil\relax
757 \fi
758 \def\\{\unskip\hbox{}\hfil\penalty-\@M\ignorespaces}}%
759 \noraggedcaptions
760 % \end{macrocode}
761 %
762 % This common code is repeated almost verbatim four times, so we define
763 % the following abbreviation. The first two arguments are the commands
764 % to turn the option on and off. The third and fourth are the \MF{} and
765 % \TeX{} booleans to switch. In all cases, the default for the option is
766 % \emph{off}, so we issue the second command after it is defined.
767 %
768 % Since the output file has not been opened while \mfpic{} is loading, the
769 % \MF{} boolean is not set, but the \cs{opengraphsfile} code will check
770 % the \TeX{} boolean and write the appropriate \MF{} code.
771 % \begin{macrocode}
772 \newdef\mfp@makeoption#1#2#3#4{%
773 \newdef#1{\mfp@let#4\iftrue
774 \mfp@ifopengraphsfile{\setmfboolean{#3}\mfp@T}{}}%
775 \newdef#2{\mfp@let#4\iffalse
776 \mfp@ifopengraphsfile{\setmfboolean{#3}\mfp@F}{}}%
777 #2}%
778 % \end{macrocode}
779 %
780 % \DescribeMacro{\clipmfpic}
781 % The \opt{clip} option shows only what's inside the rectangle given in
782 % the \cs{mfpic} command. It can be turned on or off for each figure
783 % independently.
784 % \DescribeMacro{\noclipmfpic}
785 % The default is the old behavior: no clipping.
786 % \begin{macrocode}
787 \mfp@makeoption\clipmfpic\noclipmfpic{clipall}\ifmfp@clip
788 % \end{macrocode}
789 %
790 % \DescribeMacro{\usetruebbox}
791 % The \opt{truebbox} option lets \MP{} set the true bounding box (which
792 % may differ from the numbers defined through \cs{mfpic}).
793 % \DescribeMacro{\notruebbox}
794 % The default is the old behavior, \cs{notruebbox}.
795 %
796 % We don't need to be too careful with the scope of these option
797 % commands. As currently written, \TeX{} never needs to know the setting
798 % except to pass the information on to \cs{opengraphsfile} if the option
799 % is set before then. However, we treat it like most other settings,
800 % turning on or off an appropriate \TeX{} boolean, in case it ever becomes
801 % necessary to know the setting. It is local to any \env{mfpic}, global
802 % otherwise. The default is to have \opt{truebbox} turned off.
803 % \begin{macrocode}
804 \mfp@makeoption\usetruebbox\notruebbox{truebbox}\ifmfp@truebbox
805 % \end{macrocode}
806 %
807 % \DescribeMacro{\usemplabels}
808 % An option to let \MP{} create labels, \opt{mplabels} mostly just
809 % switches between two versions of \cs{tlabel} so no \MP{} booleans
810 % are set and so synchronization of scope is not an issue.
811 % \DescribeMacro{\nomplabels}
812 % The default is the old behavior: labels are placed by \TeX. The actual
813 % setting is delayed until \cs{opengraphsfile} so the order of these
814 % commands and \cs{usemetapost} is not significant (before
815 % \cs{opengraphsfile}).
816 %
817 % Because of the frequent need to check this setting, we define
818 % \cs{@ifmplabels} to execute one of two alternatives based on it.
819 % When writing \TeX{} code to the file we need to make sure \texttt\#
820 % is not doubled. We do this by issuing \cs{mp@mksharpother} before
821 % reading the argument that will be written.
822 % \begin{macrocode}
823 \newdef\usemplabels{\mfp@let\ifmfp@mplabels\iftrue
824 \mfp@ifopengraphsfile
825 {\mfp@ifmpost{}%
826 {\mfp@noMP@error{mplabels}\global\let\ifmfp@mplabels\iffalse}}{}}%
827 \newdef\nomplabels{\mfp@let\ifmfp@mplabels\iffalse}%
828 \newdef\@ifmplabels{%
829 \ifmfp@mplabels\@xp\@firstoftwo\else\@xp\@secondoftwo\fi}%
830 \nomplabels
831 \newdef\mp@mksharpother{\@ifmplabels{\@makeother\#}{}}%
832 % \end{macrocode}
833 %
834 % \DescribeMacro{\overlaylabels}
835 % The option \opt{overlaylabels} instructs \MP{} to defer adding labels
836 % until the end of the picture. That means they don't get clipped or
837 % covered up by any drawing elements.
838 % \DescribeMacro{\nooverlaylabels}
839 % The default is the old behavior, \cs{nooverlaylabels}. Neither of these
840 % commands affect \MF, but they write to the output file anyway if issued
841 % after \cs{opengraphsfile}.
842 % \begin{macrocode}
843 \mfp@makeoption%
844 \overlaylabels\nooverlaylabels{overlaylabels}\ifmfp@overlabels
845 % \end{macrocode}
846 %
847 % \DescribeMacro{\clearsymbols}
848 % The option \opt{clearsymbols} causes the symbols drawn by
849 % \cs{plotsymbol} and \cs{plotnodes} to have their interiors erased before
850 % being drawn.
851 % \DescribeMacro{\noclearsymbols}
852 % The default is the old behavior: \cs{noclearsymbols}.
853 % \begin{macrocode}
854 \mfp@makeoption%
855 \clearsymbols\noclearsymbols{clearsymbols}\ifmfp@clearsym
856 % \end{macrocode}
857 %
858 % \DescribeMacro{\stopshipping}
859 % This is to turn off character shipping for duration of innermost
860 % enclosing \MF{} group (eg, \env{mfpic} environment). As far as I know
861 % it has never been tested with \MP. (It hasn't been tested recently even
862 % in \MF.) The \MF{} code prevents the figure from being added to the font,
863 % the \TeX{} switch \cs{ifmfp@noship} is checked before \cs{endmfpic}
864 % attempts to add the (nonexistent) figure to the document.
865 % \DescribeMacro{\resumeshipping}
866 % The macro \cs{resumeshipping} restores character shipping.
867 %
868 % \DescribeMacro{\noship}
869 % The macro \cs{noship} is the older name for \cs{stopshipping}. Its name
870 % indicated that it was intended for use in one picture. This is not
871 % actually an option (that is, there is no corresponding
872 % \cs{DeclareOption} in \LaTeX), but it is coded the same.
873 % \begin{macrocode}
874 \mfp@makeoption\stopshipping\resumeshipping{noship}\ifmfp@noship
875 \newlet\noship\stopshipping
876 % \end{macrocode}
877 %
878 % \DescribeMacro{\mfpreadlog}
879 % This sets the boolean governing the option to examine the \MF{} or
880 % \MP{} log file for certain information.
881 % \begin{macrocode}
882 \newlet\ifmfp@readlog\iffalse
883 \newdef\mfpreadlog{%
884 \mfp@ifopengraphsfile
885 {\mfp@afteropen@error\mfpreadlog}{\global\let\ifmfp@readlog\iftrue}}%
886 % \end{macrocode}
887 %
888 %
889 % \subsection{Graphic inclusion}\label{graphic}
890 %
891 % \DescribeMacro{\mfpicllx}
892 % The code to include a figure has been divided into three parts. Under
893 % \opt{metapost} we need to both include the figure and save the
894 % \DescribeMacro{\mfpiclly}
895 % bounding box coordinates of the lower left corner. Here we initialize
896 % the macros that hold these coordinates.
897 % \begin{macrocode}
898 \newdef\mfpicllx{0}%
899 \newdef\mfpiclly{0}%
900 % \end{macrocode}
901 %
902 % \DescribeMacro{\preparemfpicgraphic}
903 % Most EPS inclusion macros make the bounding box information available,
904 % and so after the inclusion command we just save it in the above two
905 % macros. However, \LaTeX's \cs{includegraphics} does not, so we have to
906 % issue a command before the inclusion to force it to become available.
907 % That command is \cs{preparemfpicgraphic}. Usually it does nothing,
908 % but in the \LaTeXe{} case it locally redefines one of the graphics
909 % packages internal macros.
910 %
911 % \DescribeMacro{\setmfpicgraphic}
912 % This command includes the graphic. The \mfpic{} default (for the
913 % \opt{metafont} option) is set by running \cs{usemetafont}.
914 %
915 % \DescribeMacro{\getmfpicoffset}
916 % This one saves the lower left corner in the macros \cs{mfpicllx} and
917 % \cs{mfpiclly}. In the case described above, that is accomplished by
918 % the redefined internal command, so this command does nothing.
919 %
920 % The command \cs{@setmfpicgraphic} is a wrapper around the inclusion
921 % code. It takes the name of the graphic file and passes it along to the
922 % above three commands. Those three commands can be redefined by the
923 % user for special circumstances. The user is then responsible to make
924 % sure \cs{mfpicllx} and \cs{mfpiclly} are properly set when necessary.
925 % Redefining one may necessitate redefining one or both of the others.
926 %
927 % The definition of these three is delayed to the option processing
928 % section, except under the \MF{} default: \cs{usemetafont} defines them.
929 %
930 % We actually define two alternative versions of \cs{@setmfpicgraphic}.
931 % The normal one is as described above, and a `nofile' alternative for
932 % when the graphic file somehow doesn't exist. Then we just print the
933 % filename.
934 % \begin{macrocode}
935 \newdef\normal@setmfpgraphic#1{%
936 \preparemfpicgraphic{#1}\setmfpicgraphic{#1}\getmfpicoffset{#1}}%
937 \newdef\nofile@setmfpgraphic#1{%
938 {\edef\mfp@tempa{#1}%
939 \vbox to 0pt{\vss
940 \rlap{\kern2pt \mfpdraftfont \mfp@sanitized\mfp@tempa}\kern 2pt}}}%
941 \mfp@ifdefined\strip@prefix{}{\def\strip@prefix#1>{}}%
942 \newdef\mfp@sanitized{\@xp\strip@prefix\meaning}%
943 \newlet\@setmfpicgraphic\normal@setmfpgraphic
944 \usemetafont
945 % \end{macrocode}
946 %
947 % \DescribeMacro{\setfilename}
948 % The user can also change \cs{setfilename} to modify the assumed
949 % filenames of the graphics output by \MP. The default is the output
950 % file's basename (\arg1) with the picture number as the extension.
951 %
952 % \DescribeMacro{\setfilenametemplate}
953 % The user can also tell \MP{} what kind of filename he wishes it to
954 % produce. one uses \verb$\_$ in the template as a placeholder for the
955 % \file{.mp} filename (the name used in \cs{opengraphsfile}) and \verb$\#$
956 % for the figure number.
957 % \begin{macrocode}
958 \newdef\setfilename#1#2{#1.#2}%
959 \newdef\setfilenametemplate#1{%
960 \begingroup
961 \def\_{\mfp@p j}%
962 \def\#{\mfp@p c}%
963 \let\@nl\relax
964 \xdef\mfp@settemplate{\@nl setoutputtemplate "#1";\@nl}%
965 \let\number\relax
966 \let\mfp@count\relax
967 \let\mfp@filename\relax
968 \def\_{\mfp@filename}%
969 \def\#{\number\mfp@count}%
970 \xdef\setfilename##1##2{#1}%
971 \endgroup
972 }%
973 % \end{macrocode}
974 %
975 % The \opt{draft}, \opt{final} and \opt{nowrite} options override
976 % \mfpic's attempts to automatically detect whether the pictures should
977 % be included. They also work under the \opt{metafont} option, but are
978 % less important then (even unnecessary).
979 %
980 % \DescribeMacro{\mfpicdraft}
981 % The \opt{draft} option (\cs{mfpicdraft} command) causes the pictures
982 % created by \mfpic{} to be omitted.
983 %
984 % \DescribeMacro{\mfpicnowrite}
985 % The \opt{nowrite} option (\cs{mfpicnowrite} command) turns off creation
986 % of the output \file{.mp} file. It is intended to help speed things up
987 % after all figures are completed, so it permits the insertion of pictures.
988 %
989 % \DescribeMacro{\mfpicfinal}
990 % The \opt{final} option (\cs{mfpicfinal} command) can be used to
991 % override a global draft option. It forces \mfpic{} to attempt to
992 % insert the pictures. Under the \opt{metapost} option, missing figures
993 % may cause serious slow-downs as a large number of directories may be
994 % searched.
995 %
996 % Each of these sets the user level if-command
997 % \SpecialUsageIndex{\ifmfpicdraft}\cs{ifmfpicdraft}, which is retained
998 % for backward compatibility. These settings are global since they are
999 % intended to be set for the whole document. The four commands
1000 % \cs{mfp@\{draft\|final\}\{true\|false\}} are used to communicate with
1001 % the \cs{opengraphsfile} command, in case the user-level commands occur
1002 % before then.
1003 % \begin{macrocode}
1004 \newif\ifmfpicdraft
1005 \newlet\ifmfp@draft\iffalse
1006 \newlet\ifmfp@final\iffalse
1007 \newlet\ifmfp@nowrite\iffalse
1008 \newdef\mfpicdraft{%
1009 \mfp@ifopengraphsfile{\global\mfpicdrafttrue}%
1010 {\global\let\ifmfp@draft\iftrue}}%
1011 \newdef\mfpicfinal{%
1012 \mfp@ifopengraphsfile{\global\mfpicdraftfalse}%
1013 {\global\let\ifmfp@final\iftrue}}%
1014 \newdef\mfpicnowrite{%
1015 \mfp@ifopengraphsfile{\mfp@afteropen@error\mfpicnowrite}%
1016 {\global\let\ifmfp@nowrite\iftrue}}%
1017 %</tex>
1018 % \end{macrocode}
1019 %
1020 %
1021 % \subsection{\LaTeX{} options and \MP{} graphics inclusion}\label{latex}
1022 %
1023 % Code dependent on \LaTeXe. Mostly this is the option processing
1024 % facilities. The declaration of options is in the file
1025 % \file{mfpic.sty}, which will input \file{mfpic.tex}.
1026 % \begin{macrocode}
1027 %<*sty>
1028 \DeclareOption{draft}{\mfpicdraft}%
1029 \DeclareOption{final}{%
1030 \mfpicfinal\PassOptionsToPackage{final}{graphics}}%
1031 \DeclareOption{nowrite}{\mfpicnowrite}%
1032 \DeclareOption{metapost}{\mfp@mposttrue}%
1033 \DeclareOption{metafont}{\usemetafont}%
1034 \DeclareOption{centeredcaptions}{\usecenteredcaptions}%
1035 \DeclareOption{justifiedcaptions}{\noraggedcaptions}%
1036 \DeclareOption{raggedcaptions}{\useraggedcaptions}%
1037 \DeclareOption{clip}{\clipmfpic}%
1038 \DeclareOption{truebbox}{\usetruebbox}%
1039 \DeclareOption{mplabels}{\usemplabels}%
1040 \DeclareOption{overlaylabels}{\overlaylabels}%
1041 \DeclareOption{clearsymbols}{\clearsymbols}%
1042 \DeclareOption{debug}{\mfpicdebugtrue}%
1043 \DeclareOption{mfpreadlog}{\mfp@readlogtrue}%
1044 \DeclareOption*{%
1045 \@ifpackageloaded{graphics}%
1046 {\Mfpic@warn{Unrecognized option \CurrentOption.}}%
1047 {\Mfpic@msg{Passing option \CurrentOption\space to %
1048 graphics package.}%
1049 \PassOptionsToPackage{\CurrentOption}{graphics}}}%
1050 \newcommand*\mfpdraftfont{\normalfont\ttfamily}%
1051 % \end{macrocode}
1052 %
1053 % Now we define one of three versions of \cs{@usemetapost}. This command
1054 % will be issued by the user level command \cs{usemetapost}, and consists
1055 % of the format dependent code. The one here is, of course, for \LaTeX{}
1056 % and will be in \file{mfpic.sty}.
1057 %
1058 % Unlike all the other EPS inclusion macros, \cs{includegraphics} does
1059 % not make the bounding box coordinates available: \cs{Gin@llx} and the
1060 % others are defined, but are local to a group surrounding the internals
1061 % of \cs{includegraphics}. We locally modify one graphics package internal
1062 % macro to globally save the information we need. Here we save the
1063 % original definition and define our replacement. For this, we definitely
1064 % need to make sure the \prog{graphics} package is loaded.
1065 % \begin{macrocode}
1066 \def\@usemetapost{%
1067 \mfp@ifdefined\includegraphics{}{\RequirePackage{graphics}}%
1068 \let\mfp@save@parse@bb\Gread@parse@bb
1069 \newdef\mfp@parse@bb##1 ##2 ##3 ##4 ##5\\{%
1070 \mfp@save@parse@bb##1 ##2 ##3 ##4 ##5\\%
1071 \xdef\mfpicllx{\Gin@llx}\xdef\mfpiclly{\Gin@lly}}%
1072 % \end{macrocode}
1073 % The \prog{graphics} package makes decisions about graphic files based on
1074 % the files' extensions. Since we don't want to force our users to rename
1075 % all the graphics output by \MP, we add code to \cs{preparemfpicgraphic}
1076 % to force \cs{includegraphics} to treat the current extension (some
1077 % number) as if it were `{\tt eps}' or `{\tt mps}' according to the
1078 % context. We also use this command to substitute the above BoundingBox
1079 % parsing code for the \prog{graphics} package version.
1080 % \begin{macrocode}
1081 \ifmfp@pdf \gdef\mfp@Gtype{mps}%
1082 \else \gdef\mfp@Gtype{eps}%
1083 \fi
1084 \gdef\preparemfpicgraphic##1{%
1085 \@namedef{Gin@rule@.\number\mfp@count}####1{{\mfp@Gtype}%
1086 {.\number\mfp@count}{####1}}%
1087 \let\Gread@parse@bb\mfp@parse@bb}%
1088 \global\let\setmfpicgraphic\includegraphics
1089 \gdef\getmfpicoffset##1{}}%
1090 % \end{macrocode}
1091 %
1092 % The \LaTeX{} wrapper ends by inputing \file{mfpic.tex}.
1093 % \begin{macrocode}
1094 \input mfpic.tex\relax
1095 %</sty>
1096 % \end{macrocode}
1097 %
1098 % \DescribeMacro{\usemetapost}
1099 % The user level command \cs{usemetapost} starts with a few actions common
1100 % to all formats, then calls \cs{@usemetapost} which is defined
1101 % differently for different formats.
1102 % \begin{macrocode}
1103 %<*tex>
1104 \newdef\usemetapost{%
1105 \mfp@ifopengraphsfile{\mfp@mpostfalse\mfp@useMP@error}%
1106 {\mfp@mposttrue \@usemetapost}}%
1107 % \end{macrocode}
1108 %
1109 % Under \LaTeX, if \file{mfpic.cfg} exists, it will be input at this
1110 % point. Then, we \cs{ProcessOptions}, using the star-form because it allows
1111 % package options to take precedence over global options. Thus \mfpic's
1112 % \opt{final} option can counteract the \mfpic-specific side effects of a
1113 % global \opt{draft} option.
1114 % \begin{macrocode}
1115 \ifmfp@latexe
1116 \InputIfFileExists{mfpic.cfg}{}{}%
1117 \ProcessOptions*\relax
1118 % \end{macrocode}
1119 %
1120 % \cs{ProcessOptions} doesn't allow \cs{RequirePackage}\marg{graphics},
1121 % so the above and the following were not simply put inside
1122 % \cs{DeclareOption}\marg{metapost}. The \cs{AtEndDocument} command will
1123 % close the output file if the user forgot.
1124 % \begin{macrocode}
1125 \mfp@ifmpost{\usemetapost}{}%
1126 \AtEndDocument{\mfp@closegraphsfile}%
1127 % \end{macrocode}
1128 %
1129 % Now those cases outside \LaTeXe{} that we try to support.
1130 % \begin{macrocode}
1131 \else
1132 \mfp@msg{}\Mfpic@msg{\mfpfiledate\space v\mfpfileversion.\@nl}%
1133 % \end{macrocode}
1134 %
1135 % The definition of \cs{@usemetapost} in plain \TeX{} depends on the
1136 % setting of \cs{ifmfp@pdf}. However both cases are so similar that we
1137 % define a helper macro \cs{mfp@useMP} that just needs to have the names
1138 % of three commands and two files fed to it.
1139 % \begin{macrocode}
1140 \newdef\mfp@useMP#1#2#3#4#5{%
1141 \mfp@ifdefined#1{}{%
1142 \InputIfFileExists{#2}{}{%
1143 \InputIfFileExists{#3}{}{%
1144 \mfp@errmsg{Files not found: #1, #2}%
1145 {One of the two named files is necessary
1146 for mfpic, but neither was found.}}}}%
1147 \global\let\setmfpicgraphic\mfp@includeMPS
1148 \gdef\getmfpicoffset##1{\xdef\mfpicllx{#4}\xdef\mfpiclly{#5}}}%
1149 % \end{macrocode}
1150 %
1151 % Under \pdfTeX{}, the graphics inclusion command is \cs{convertMPtoPDF},
1152 % defined in \file{supp-pdf.tex}. This command parses the file's PS
1153 % contents to PDF code, and leaves the bounding box info in macros
1154 % \cs{MPllx} and \cs{MPlly}.
1155 % \begin{macrocode}
1156 \ifmfp@pdf
1157 \newdef\mfp@includeMPS#1{\convertMPtoPDF{#1}{1}{1}}%
1158 \newdef\@usemetapost{%
1159 \mfp@useMP\convertMPtoPDF{supp-pdf.mkii}{supp-pdf.tex}%
1160 \MPllx\MPlly}%
1161 % \end{macrocode}
1162 %
1163 % Under plain\TeX, eplain (still need to test this after recent eplain
1164 % changes), \AmSTeX, or \LaTeX2.09, the graphics inclusion command is
1165 % \cs{epsfbox}, defined in \file{epsf.tex}. This command writes a
1166 % \cs{special} for \prog{dvips} (and other DVI driver programs), and
1167 % leaves the bounding box info in macros \cs{epsfllx} and \cs{epsflly}.
1168 % \begin{macrocode}
1169 \else
1170 \newdef\mfp@includeMPS#1{\epsfbox{#1}}%
1171 \newdef\@usemetapost{%
1172 \mfp@useMP\epsfbox{epsf.tex}{epsf.sty}\epsfllx\epsflly}%
1173 \fi
1174 \fi
1175 % \end{macrocode}
1176 %
1177 %
1178 %
1179 % \section{Optional parameter handling}\label{optional}
1180 %
1181 % We borrow \LaTeX's \cs{@ifnextchar}. The first argument is the token
1182 % being checked. It doesn't have to be a character and we sometimes use
1183 % \cs{@ifnextchar} to check whether a certain command follows.
1184 % The next argument is the code to run if that character is present, the
1185 % last is code to use if the character is not present.
1186 % \begin{macrocode}
1187 \mfp@DBlog{Handlers for optional parameters.}%
1188 \mfp@ifundefined\@ifnextchar
1189 \long\def\@ifnextchar#1#2#3{%
1190 \let\reserved@d#1%
1191 \def\reserved@a{#2}%
1192 \def\reserved@b{#3}%
1193 \futurelet\@let@token\@ifnch}%
1194 \def\@ifnch{%
1195 \ifx\@let@token\@sptoken
1196 \let\reserved@c\@xifnch
1197 \else
1198 \ifx\@let@token\reserved@d
1199 \let\reserved@c\reserved@a
1200 \else
1201 \let\reserved@c\reserved@b
1202 \fi
1203 \fi
1204 \reserved@c}%
1205 {%
1206 \def\:{\global\let\@sptoken= }\: % makes \@sptoken a space token
1207 \def\:{\@xifnch}\@xp\gdef\: {\futurelet\@let@token\@ifnch}%
1208 }%
1209 \mfp@enddef
1210 % \end{macrocode}
1211 %
1212 % Here we borrow from \file{keyval.sty}. We need a command that strips
1213 % spaces off ends of an argument and stores the result in a macro. In
1214 % \file{keyval}, that is \cs{KV@@sp@def}; we copy it here with name
1215 % changes. Defining \cs{mfp@tempa}, and then calling it with a space as
1216 % argument, ensures there will be an actual space token where needed in
1217 % the definition of \cs{mfp@sp@def}. The first argument is the control
1218 % sequence to define and the second is its definition text, with possible
1219 % spaces to be stripped. (I'm wondering now why I didn't just use
1220 % \cs{zap@space} since there shouldn't be \emph{any} significant spaces.
1221 % Well, at least I have the code in place for a future key-value
1222 % interface.)
1223 % \begin{macrocode}
1224 \def\mfp@tempa#1{%
1225 \def\mfp@sp@def##1##2{%
1226 \futurelet\mfp@next\mfp@sp@d##2\@nil\@nil#1\@nil\relax##1}%
1227 \def\mfp@sp@d{%
1228 \ifx\mfp@next\@sptoken \@xp\mfp@sp@b
1229 \else \@xp\mfp@sp@b\@xp#1%
1230 \fi}%
1231 \def\mfp@sp@b#1##1 \@nil{\mfp@sp@c##1}}%
1232 \mfp@tempa{ }%
1233 \def\mfp@sp@c#1\@nil#2\relax#3{\mfp@toks{#1}\edef#3{\the\mfp@toks}}%
1234 % \end{macrocode}
1235 %
1236 % The following save us some typing whenever we need to check if some
1237 % token follows, and then remove it if it does. That's what
1238 % \cs{mfp@iftoken} does, being just a generalized form of \LaTeX{}'s
1239 % \cs{@ifstar}. Almost all our star-form commands differ only in what
1240 % parameter is passed to some other command. Thus \cs{mfp@ifstar} passes
1241 % either \arg{2} or \arg{3} to command \arg{1}.
1242 %
1243 % The \cs{mfp@ifend} is for use in processing lists, which all end with
1244 % the token \cs{mfp@end}. \cs{mfp@ifendorcomma} is useful for processing
1245 % comma-separated lists. If \cs{mfp@end} follows, it is removed and \arg1
1246 % is executed. Otherwise, if a comma follows, it is removed and \arg2 is
1247 % executed. When neither follows, nothing is removed and \arg3 is
1248 % executed. Normally, this last is the main command being applied to each
1249 % element of the list.
1250 %
1251 % We also define \LaTeX's \cs{@ifstar} for the few cases that require it.
1252 % \begin{macrocode}
1253 \def\mfp@iftoken#1#2{\@ifnextchar#1{\@firstoftwo{#2}}}%
1254 \def\mfp@ifstar#1#2#3{\mfp@iftoken*{#1{#2}}{#1{#3}}}%
1255 \def\mfp@ifend{\mfp@iftoken\mfp@end}%
1256 \def\mfp@ifendorcomma#1#2#3{\mfp@ifend{#1}{\mfp@iftoken,{#2}{#3}}}%
1257 \mfp@ifundefined\@ifstar
1258 \def\@ifstar#1{\@ifnextchar*{\@firstoftwo{#1}}}%
1259 \mfp@enddef
1260 % \end{macrocode}
1261 %
1262 % I've taken to making an empty optional argument the default for a lot
1263 % of commands. I wanted to make it possible to have the same result for
1264 % empty brackets (i.e., \texttt{[\,]}) as for omitted brackets.
1265 % \cs{mfp@ifempty} helps check for emptyness. It uses a simple \cs{if} so
1266 % that \arg{1} will be expanded. I use a non-active \texttt\textasciitilde
1267 % (so it won't expand) to test for emptiness because, even if
1268 % a tilde should accidentally occur in a user's \arg1, it will most
1269 % likely be the usual active version which expands to something else.
1270 %
1271 % The shorthand \cs{mfp@ifexist} executes some code if \arg1 is not
1272 % empty, otherwise it does nothing. And \cs{mfp@emptysub} expands to
1273 % \arg1 if it isn't empty, otherwise \arg2.
1274 %
1275 % The \cs{@ifmtarg} macro is borrowed from \file{ifmtarg.sty}.
1276 % It is used when a space should count as empty, but expansion isn't
1277 % needed. It would be nice to have one that counts both as empty, but
1278 % that seems impossible (or impossibly hard).
1279 % \begin{macrocode}
1280 {%
1281 \catcode`Q3 \catcode`\~12
1282 \gdef\mfp@ifempty#1{\if~#1~\@xp\@firstoftwo\else\@xp\@secondoftwo\fi}%
1283 \gdef\mfp@ifexist#1{\if~#1~\@xp\@gobble\else\@xp\@firstofone\fi}%
1284 \gdef\mfp@emptysub#1#2{\if~#1~#2\else#1\fi}%
1285 \long\gdef\@ifmtarg#1{\@xifmtarg#1QQ\@secondoftwo\@firstoftwo\@nil}%
1286 \long\gdef\@xifmtarg#1#2Q#3#4#5\@nil{#4}%
1287 }%
1288 % \end{macrocode}
1289 %
1290 % These are the two most common methods to parse optional arguments. In
1291 % \cs{mfp@defaultopt}, if an optional argument is present, we use
1292 % \cs{mfp@ifemptyopt} to see if it is empty and substitute a default
1293 % (\arg{2}) if it is. Argument \arg{1} is the command to run
1294 % on the resulting argument after this check. It needn't be a single
1295 % command token, but can (and often will) be a series of commands, or a
1296 % command with additional arguments.
1297 %
1298 % \cs{mfp@nullopt} is a convenient abbreviation for a common case: the
1299 % default option is empty. We could define it in terms of
1300 % \cs{mfp@defaultopt}, but then we'd have the redundant step of checking
1301 % for an empty optional argument, only to replace it by an empty argument.
1302 % That might not make a significant difference, but it just feels wrong.
1303 %
1304 % Both commands turn the delimited argument, if present, into an ordinary
1305 % one. This extra step permits us to avoid many bracket pairs in later
1306 % code.
1307 % \begin{macrocode}
1308 \newdef\mfp@defaultopt#1#2{%
1309 \@ifnextchar[{\mfp@ifemptyopt{#1}{#2}}{#1{#2}}}%]
1310 \newdef\mfp@ifemptyopt#1#2[#3]{\mfp@ifempty{#3}{#1{#2}}{#1{#3}}}%
1311 \newdef\mfp@nullopt#1{\@ifnextchar[{\mfp@getopt{#1}}{#1{}}}%
1312 \newdef\mfp@getopt#1[#2]{#1{#2}}%
1313 % \end{macrocode}
1314 %
1315 % Why do we bother to check for an empty optional argument? Because
1316 % quite a few \mfpic{} commands stuff several parameters into a
1317 % single optional argument. All but the last are processed as undelimited
1318 % arguments and the last one as delimited by the right bracket. If only
1319 % the last parameter is missing, TeX{} takes that as an empty argument and
1320 % we can proceed gracefully (substituting a default). However, if more
1321 % than that are missing, \TeX{} takes the closing bracket as the
1322 % \emph{undelimited} argument and produces pretty inscrutable error
1323 % mesages. This decision to add extra information in one optional argument
1324 % was, in retrospect, a bad one. It was made for backward compatibility
1325 % and (originally) to minimize the changes in existing commands.
1326 % Unfortunately we are stuck with it for at least the near future.
1327 %
1328 % Another reason is that multiple optional arguments generally mean that
1329 % the to specify a later one, all the previous ones need to be specified.
1330 % But with the above code, the user can always use an empty bracket pair
1331 % to indicate the default, minimizing the extra typing.
1332 %
1333 %
1334 %
1335 % \section{Writing to the \file{.mf} or \file{.mp} file}\label{writing}
1336 %
1337 %
1338 % \subsection{Preserving linebreaks}\label{linebreaks}
1339 %
1340 % Some macros (the ones we call list macros) can take quite long
1341 % arguments, especially if they are automatically generated by some
1342 % program. While the output file need not ever be looked at, there can be
1343 % a problem with lines too long for the \MF{} executable's line buffer.
1344 % Plus, for debugging, we might want to examine the file \mfpic{} writes.
1345 % We therefore try to get at least the list macros to preserve linebreaks
1346 % on output.
1347 %
1348 % We make use of the \TeX{} property that expandable commands are expanded
1349 % inside \cs{write} commands, but unexpandable commands and characters are
1350 % written verbatim (almost). If this were the only consideration, nothing
1351 % would need to be done. But characters with catagory code 5 (end-of-line)
1352 % are converted to spaces upon reading, so we have to change the category
1353 % of the \cs{endlinechar}, or we have change the \cs{endlinechar} to a
1354 % character of a different category. We do the former, because the line a
1355 % macro starts on will already have the end-of-line character added, but
1356 % it will not yet have been tokenized, so its category can be changed. We
1357 % need a category that \TeX{} will not \emph{ignore}, but that
1358 % nevertheless has no (or minimal) side effects if encountered in a \TeX{}
1359 % file. We therefore make it active, but \cs{let} it equal to \cs{relax}.
1360 % This makes the end-line-character unexpandable since \cs{relax} is not
1361 % expandable.
1362 % \begin{macrocode}
1363 \mfp@DBlog{Direct output to Metafont/Post file.}%
1364 {%
1365 \catcode\mfp@ctrlM\active%
1366 \gdef\@activectrlM{^^M}%
1367 \gdef\mfp@obeylines{\catcode\mfp@ctrlM\active\let^^M\relax}%
1368 }%
1369 % \end{macrocode}
1370 %
1371 % The choice \cs{relax} seems to be actually a slightly better choice
1372 % than \cs{endgraf} (which we used to use, and which equals the
1373 % unexpandable primative \cs{par}) because \cs{relax} is permitted before
1374 % the opening brace in the syntax of \meta{general text} (for token
1375 % variable assignments, \cs{write}, \cs{message}, and the like).
1376 %
1377 % The character assigned to \cs{endlinechar} is added to the end of all
1378 % lines read in by \TeX. The character assigned to \cs{newlinechar}
1379 % will produce a newline when it occurs in a \cs{write}. Our
1380 % \cs{mfp@keeplines} ensures these are the same and makes the above
1381 % changes in category. This will fail in the following case:
1382 % \cs{endlinechar} is not \verb$^^M$ and the data starts on the same line
1383 % as the command that issued \cs{mfp@keeplines}. But then the output will
1384 % lack only that first linebreak.
1385 % \begin{macrocode}
1386 \newdef\mfp@keeplines{\newlinechar\mfp@ctrlM
1387 \endlinechar\newlinechar \mfp@obeylines}%
1388 % \end{macrocode}
1389 %
1390 % We want our file writes to issue \cs{mfp@keeplines} before the text is
1391 % read (and category codes assigned). Also we often want to add a few
1392 % items to the argument (figure macros append a semi-colon, list macros
1393 % surround with parentheses), so we isolate the common starting code in
1394 % \cs{mfp@write}, and then invoke the appropriate continuation command.
1395 %
1396 % \DescribeMacro{\mfsrc}
1397 % The macro \cs{mfsrc} is the most basic, merely writing its contents. For
1398 % figure macros, we ultimately call
1399 % \DescribeMacro{\mfcmd}
1400 % \cs{mfcmd}, which appends a semicolon, terminating any pending \MF{}
1401 % command. For macros which take a comma separated list of values as their
1402 % arguments, we call
1403 % \DescribeMacro{\mflist}
1404 % \cs{mflist} which surrounds the list in parentheses and appends a
1405 % semicolon
1406 %
1407 % The ending code is in \cs{mfp@src}. The \cs{begingroup} in
1408 % \cs{mfp@write} matches the \cs{endgroup} in \cs{mfp@src}. The group
1409 % isolates the changes to EOLs. We also define \cs{@nl} to expand to an
1410 % active control-M so that it can be used for line breaks in cases where
1411 % it is inconvenient to make EOLs active (in the replacement text of
1412 % \cs{opengraphsfile} and \cs{@mfpic}, for example).
1413 % \begin{macrocode}
1414 \newdef\mfsrc {\mfp@write\mfp@src\mfsrc}%
1415 \newdef\mfcmd {\mfp@write\mfp@cmd}%
1416 \newdef\mflist{\mfp@write\mfp@wlist}%
1417 \newdef\mfp@write{\begingroup\mfp@keeplines \let\@nl\@activectrlM}%
1418 % \end{macrocode}
1419 %
1420 % The macro \cs{mfp@src} does the job of writing to files. The output
1421 % stream \cs{mfp@out} is declared later. The other two commands invoke
1422 % \cs{mfp@src} on a slightly modified argument. The first argument to
1423 % \cs{mfp@src} is the command that called it (for the error message), the
1424 % second is the code to write.
1425 % \begin{macrocode}
1426 \newdef\mfp@src#1#2{%
1427 \mfp@ifopengraphsfile{\immediate\write\mfp@out{#2}}%
1428 {\mfp@nooutput@error{#1}}\endgroup}%
1429 \newdef\mfp@cmd#1{\mfp@src\mfcmd{#1;}}%
1430 \newdef\mfp@wlist#1{\mfp@src\mflist{(#1);}}%
1431 % \end{macrocode}
1432 %
1433 % If \prog{babel} is loaded with some options, certain punctuation will
1434 % be made active. These will then be expanded when written to the graph
1435 % file. \prog{Babel} provides a way to turn this off, but it would be an
1436 % error to run those commands if \prog{babel} is not loaded. Rather than
1437 % try to detect \prog{babel}, we run these commands only if they are
1438 % defined.
1439 % \begin{macrocode}
1440 \def\mfp@safe@activestrue{%
1441 \mfp@ifdefined\@safe@activestrue\@safe@activestrue{}}%
1442 \def\mfp@safe@activesfalse{%
1443 \mfp@ifdefined\@safe@activesfalse\@safe@activesfalse{}}%
1444 % \end{macrocode}
1445 %
1446 %
1447 % \subsection{Initializing the output file}\label{output}
1448 %
1449 % Category 12 characters percent, sharp and backslash signs for the
1450 % \file{.mf} file. The command \cs{mfp@d} is used to write a line of
1451 % dashes above and below each figure to make them stand out when debugging
1452 % the file.
1453 % \begin{macrocode}
1454 \edef\mfp@p{\@xp\@gobble\string\%}% percent (%)
1455 \edef\mfp@s{\@xp\@gobble\string\#}% sharp (#)
1456 \edef\mfp@b{\@xp\@gobble\string\\}% backslash (\)
1457 \newdef\mfp@d{--------------}%
1458 % \end{macrocode}
1459 %
1460 % The current date and time stamp will be written to the \file{.mf} file.
1461 % We calculate it here and store the result in these macros. The commands
1462 % \cs{normalyear} and \cs{normalmonth} are part of \ConTeXt, where they
1463 % have been equated to the primitive commands \cs{year} and \cs{month}
1464 % (which are then redefined).
1465 % \begin{macrocode}
1466 \mfp@ifdefined\two@digits{}%
1467 {\def\two@digits#1{\ifnum#1<10 0\fi\number#1}}%
1468 {%
1469 \mfp@ifdefined\normalmonth
1470 {\let\month\normalmonth\let\year\normalyear}{}%
1471 \count@\time \divide\count@ by 60
1472 \xdef\mfp@now{\number\year/\two@digits\month/\two@digits\day
1473 \space at \two@digits\count@:}%
1474 \multiply\count@ by -60 \advance\count@\time
1475 \xdef\mfp@now{\mfp@now\two@digits\count@}%
1476 }%
1477 % \end{macrocode}
1478 %
1479 % These registers are allocated:
1480 % \begin{itemize}
1481 % \item \cs{mfp@out} Write stream for the \file{.mf} or \file{.mp} file.
1482 % \item \cs{mfp@graph} Read stream used to test existence of files and
1483 % for reading datafiles.
1484 % \item \cs{mfp@count} Number for next \env{mfpic} environment.
1485 % \item \cs{mfp@linetype} Number indexing current line style in
1486 % multi-curve data plots.
1487 % \item \cs{mfp@sequence} Counter incremented with every datapoint written
1488 % from a file to implement the feature that a list of numeric data
1489 % can be plotted against its sequence position.
1490 % \item \cs{mfp@toks} Temporary token register.
1491 % \item \cs{mfp@verbtex} A temporary token list used by \cs{mfpverbtex}.
1492 % \item \cs{ifmfp@switch} Not exactly a register, but a temporary
1493 % switch for passing information from one macro to another.
1494 % \end{itemize}
1495 % \begin{macrocode}
1496 \mfp@DBlog{Declarations used with data and graphs files.}%
1497 \newwrite\mfp@out
1498 \newread\mfp@graph
1499 \newlet\mfp@data\mfp@graph
1500 \newcount\mfp@count
1501 \newcount\mfp@linetype
1502 \newcount\mfp@sequence
1503 \newtoks\mfp@toks
1504 \newtoks\mfp@verbtex
1505 \newif\ifmfp@switch
1506 %</tex>
1507 % \end{macrocode}
1508 %
1509 % We store most of the \mfc{verbatimtex} block that \mfpic{} relies on in
1510 % the file \file{mfpicdef.tex}. This is the code that goes into that
1511 % file
1512 %
1513 % The \cs{mpxshipout} is to cover all three cases of the output of
1514 % `\texttt{mpto -tex}'. In public versions of \MP{} prior to 0.9 there was
1515 % no such command in that output file. In 0.9 and 0.901 that command is
1516 % defined at the start of the file, prior to any verbatimtex, but it is
1517 % buggy. This code overwrites it and fixes the bugs. In later versions a
1518 % good definition is used, but it appears only just before the first
1519 % \mfc{btex} and so will overwrite my definition. Thus all cases are
1520 % served.
1521 % \begin{macrocode}
1522 %<*defs>
1523 \gdef\mpxshipout{\afterassignment\middlempxshipout\setbox0=\hbox}%
1524 \gdef\middlempxshipout{\aftergroup\finishmpxshipout}%
1525 \gdef\finishmpxshipout{\dimen1=\ht0 \dimen2=\dp0
1526 \dimen0=\dimen1 \advance\dimen0\dimen2
1527 \setbox0=\hbox{\hbox{\box0
1528 \ifnum\dimen0>0 \vrule width1sp height\dimen1 depth\dimen2
1529 \else \vrule width1sp height1sp depth0sp\relax
1530 \fi}}%
1531 \ht0=0pt \dp0=0pt \shipout\hbox{\box0}}%
1532 \def\MFPtext#1{\vbox{\def\\{\cr}\MFPcfont\MFPeverylabel
1533 \halign{##\hfil\cr#1\crcr}}}%
1534 % \end{macrocode}
1535 %
1536 % There are vague plans to make the output file equally usable by \MF{}
1537 % and \MP{}. For this to work, \file{grafbase.mf} defines
1538 % \mfc{verbatimtex} to gobble everything to the next colon (which we place
1539 % after each \mfc{etex} we write). This fails if there is a
1540 % \verb$\begingroup$ without matching \verb$\endgroup$ because \MF{} sees
1541 % this as the command \verb$\$ (meaning \mfc{relax}) followed by the \MF{}
1542 % primitive \mfc{begingroup}. But \MF{} doesn't allow gobbled text
1543 % parameters to contain unbalanced groups. Thus, we use the replacements
1544 % defined here, hidden from \MF{} in a \TeX{} input file.
1545 % \begin{macrocode}
1546 \let\MFPbegingroup\begingroup
1547 \let\MFPendgroup\endgroup
1548 %</defs>
1549 % \end{macrocode}
1550 %
1551 % Within \file{mfpic.tex} these commands can be anything unexpandable,
1552 % since we just want them to be written verbatim. It makes sense to give
1553 % them the obvious meanings.
1554 % \begin{macrocode}
1555 %<*tex>
1556 \let\MFPbegingroup\begingroup
1557 \let\MFPendgroup\endgroup
1558 % \end{macrocode}
1559 %
1560 % We store the first several lines that will be written to the output
1561 % file in a few internal macros, so that changing them will be easier.
1562 %
1563 % The first two lines of the output file are comments identifying the
1564 % file, the \mfpic{} version, the tex source file, and the timestamp.
1565 % These are stored in \cs{mfp@versioninfo}. We also let \grafbase{} know
1566 % the \mfpic{} version creating the file. This could catch version
1567 % mismatches. But since older \grafbase{} didn't test this, some
1568 % mismatches will be missed.
1569 %
1570 % After that (\cs{mfp@init@outfile}) we set the \mfc{mode} and the
1571 % \mfc{mag} if not known (both ignored by \MP), and arrange for
1572 % \grafbase{} macros to be loaded.
1573 % \begin{macrocode}
1574 \newdef\mfp@versioninfo{%
1575 \mfp@p\space\[email protected]\mfp@ifmpost{p}{f}, %
1576 generated by Mfpic, v\mfpfileversion\space\mfpfiledate,\@nl
1577 \mfp@p\space from TeX source "\jobname" on \mfp@now\@nl
1578 numeric mfpicversion; mfpicversion := \mfpicversion;\@nl}%
1579 \newdef\mfp@init@outfile{%
1580 if unknown mode: mode := localfont; fi\@nl
1581 if unknown mag: mag := \number\mag/1000; fi\@nl
1582 if unknown grafbase: input grafbase; fi\@nl\@nl}%
1583 % \end{macrocode}
1584 % Then a comparison of the version of this file, stored in
1585 % \cs{mfpicversion} with the version stored in the \grafbase{} variable
1586 % \mfc{grafbaseversion}. This should catch a mismatch caused by an old
1587 % \grafbase{} with a current \mfpic.
1588 % \begin{macrocode}
1589 \newdef\mfp@versioncheck{%
1590 if unknown grafbaseversion: grafbaseversion := 0; fi\@nl
1591 if grafbaseversion <> mfpicversion :\@nl
1592 GBmsg "Bad mfpic installation: mfpic and grafbase %
1593 versions do not match.";\@nl
1594 fi\@nl}%
1595 % \end{macrocode}
1596 %
1597 % This opens the output file and prints a reminder to the user to run
1598 % \MF{} or \MP{}.
1599 % \begin{macrocode}
1600 \newdef\mfp@openfile{%
1601 \ifmfp@nowrite \else \mfp@msg{}%
1602 \Mfpic@msg{Initializing \mfp@filename\mfp@ext.}%
1603 \immediate\openout\mfp@out=\mfp@filename\mfp@ext\relax
1604 \Mfpic@msg{Don't forget to process \mfp@filename\mfp@ext!}%
1605 \Mfpic@msg{Apply \mfp@progname\space to \mfp@filename\mfp@ext%
1606 \mfp@ifmpost{}{, then gftopk to the resulting gf file}.}%
1607 \Mfpic@msg{Then reprocess this file "\jobname".\@nl}%
1608 \fi}%
1609 % \end{macrocode}
1610 %
1611 % A little bit of \LaTeX{} for checking file existence.
1612 % \begin{macrocode}
1613 \mfp@ifundefined\IfFileExists
1614 \def\IfFileExists#1{\openin\mfp@graph=#1\relax
1615 \ifeof\mfp@graph \@xp\@secondoftwo
1616 \else \immediate\closein\mfp@graph \@xp\@firstoftwo
1617 \fi}%
1618 \def\InputIfFileExists#1#2{\IfFileExists{#1}{#2\input #1\relax}}%
1619 \mfp@enddef
1620 % \end{macrocode}
1621 %
1622 % The following is the code involved in opening the output file and
1623 % checking for the existence of already created figures.
1624 % \cs{mfp@checkoutput} checks if the output file of \MP{} or \MF{} exists.
1625 % The first argument is the extension of that output file (\file{tfm} for
1626 % \MF{}, the starting value of the figure counter for \MP{}). We use the
1627 % existence of that output as a signal that there are graphics to be
1628 % included.
1629 %
1630 % Based on the file existence, we set the values of the draft switch, and
1631 % issue a message. Any other actions needed are passed as \arg2 (it
1632 % exists) and \arg3 (it doesn't). These are nonempty only under the
1633 % \opt{metafont} option: we load the font only if the \file{.tfm} exists,
1634 % otherwise we use a the \texttt{dummy} font.
1635 %
1636 % We do not try to load a nonexistent font because that might trigger some
1637 % \prog{maketfm} script which could be disastrous at this point, when the
1638 % \file{.mf} file is in an uncertain state.
1639 % \begin{macrocode}
1640 \newdef\mfp@checkoutput#1#2#3{%
1641 \IfFileExists{\setfilename\mfp@filename{#1}}%
1642 {\global\mfpicdraftfalse #2}%
1643 {\global\mfpicdrafttrue #3\mfp@msg{}%
1644 \Mfpic@msg{No file \setfilename\mfp@filename{#1}.}%
1645 }}%
1646 \newdef\mfp@checkMPoutput{\mfp@checkoutput{\number\mfp@count}{}{}}%
1647 \newdef\mfp@checkMFoutput{\mfp@checkoutput{tfm}%
1648 {\global\font\mfp@graphfont\mfp@filename\relax}%
1649 {\global\let\mfp@graphfont\mfp@dummy}}%
1650 % \end{macrocode}
1651 %
1652 % For \opt{metapost} the output file needs to load some color macros, and
1653 % write some setup for text labels (even if \cs{nomplabels}, because
1654 % \cs{usemplabels could be turned on later}). \MF{} now can also handle
1655 % the definitions in \file{dvipsnam.mp} but it seems a waste to load all
1656 % those definitions just to get more names for grayscales (even given
1657 % that \MF{} can find that file).
1658 % \begin{macrocode}
1659 \newdef\mfp@MPextras{\mfp@toks\@xp{\every@tlabel}%
1660 \mfsrc{%
1661 if unknown Apricot: input dvipsnam.mp; fi\@nl
1662 verbatimtex\@nl
1663 \ifmfp@verbtex \the\mfp@verbtex\@nl \fi
1664 \relax\@nl
1665 \noexpand\input mfpicdef.tex\relax\@nl
1666 \def\noexpand\MFPeverylabel{\the\mfp@toks}\@nl
1667 etex;\@nl
1668 \mfp@ifdefined\mfp@settemplate\mfp@settemplate{}%
1669 }%
1670 \global\mfp@verbtexfalse \global\mfp@verbtex{}%
1671 % \end{macrocode}
1672 % Finally, we process the \MP{}-specific options as they are currently
1673 % known. The \cs{usemplabels} was delayed until now so that the order of
1674 % it and \cs{usemetapost} before now would not matter.
1675 % \begin{macrocode}
1676 \@ifmplabels\usemplabels{}%
1677 \ifmfp@truebbox \usetruebbox \fi
1678 \ifmfp@overlabels \overlaylabels \fi}%
1679 % \end{macrocode}
1680 %
1681 % There are a couple of extras that are only needed by \MF{}, the mode
1682 % and resolution. Unlike the `MPextras' this does not write code, but
1683 % rather \emph{is} code to write. It will occur inside a \cs{write}
1684 % command.
1685 % \begin{macrocode}
1686 \def\mfp@MFextras{%
1687 \mfp@ifdefined\mfp@resolution%
1688 {GBresolution := \mfp@resolution;\@nl}{}%
1689 \mfp@ifdefined\mfp@mode{mode := \mfp@mode;\@nl}{}}%
1690 % \end{macrocode}
1691 %
1692 % All the characters likely to cause problems in a filename are rendered
1693 % harmless with this command. We want to allow macros so backslashes,
1694 % braces and spaces aren't touched.
1695 % \begin{macrocode}
1696 \def\mfp@dospecials{\do\$\do\&\do\#\do\^\do\_\do\%\do\~}%
1697 % \end{macrocode}
1698 % \DescribeMacro{\opengraphsfile}
1699 % This is the main command to set up the output file.
1700 % The name of the output file is its only parameter, and it appends
1701 % the extension \file{.mf} or \file{.mp} depending on the whether option
1702 % \opt{metafont} or \opt{metapost} was chosen. We first nullify \TeX{}
1703 % special characters, then read the graphfile name, then store an
1704 % expanded version.
1705 % \begin{macrocode}
1706 \mfp@DBlog{Macros to open and close graphs files.}%
1707 \newdef\opengraphsfile{\@bsphack
1708 \begingroup
1709 \let\do\@makeother
1710 \mfp@dospecials\@opengraphsfile}%
1711 \newdef\@opengraphsfile#1{%
1712 \xdef\mfp@tempa{#1}%
1713 \endgroup
1714 % \end{macrocode}
1715 %
1716 % With the graphfile name safely stored, we check if a previous one had
1717 % been opened and close it if so. Then we store in \cs{mfp@filename}
1718 % a sanitized version of the name.
1719 %
1720 % A command can determine if it occurs after \cs{opengraphsfile} but
1721 % before \cs{closegraphsfile} by testing whether \cs{mfp@filename} is
1722 % defined. We also save the name of the processing program (\MF{} or \MP)
1723 % and the file extension (\file{.mf} of \file{.mp}) in macros for use in
1724 % messages.
1725 % \begin{macrocode}
1726 \mfp@ifopengraphsfile%
1727 {\Mfpic@warn
1728 {\@nl An attempt has been made to open a graph file, %
1729 \mfp@sanitized\mfp@tempa\@msgbreak
1730 while another, \mfp@filename, is still open. \@msgbreak
1731 Closing \mfp@filename.}\mfp@closegraphsfile}%
1732 {}%
1733 \xdef\mfp@filename{\mfp@sanitized\mfp@tempa}%
1734 \xdef\mfp@progname{meta\mfp@ifmpost{pos}{fon}t}%
1735 \xdef\mfp@ext{.m\mfp@ifmpost{p}{f}}%
1736 % \end{macrocode}
1737 %
1738 % These commands test for the existence of the graphics (\file{.tfm} file
1739 % or first EPS file) and provisionally set \cs{ifmfpicdraft} based on the
1740 % result. Then the \file{.mf} or \file{.mp} file is opened, and the
1741 % automatic settings of \cs{ifmfpicdraft}, etc., are overridden if the
1742 % user has explicitly chosen the \opt{draft} or \opt{final} option. The
1743 % \opt{nowrite} option merely disables the \cs{mfp@src} command, called
1744 % by all the commands that write to the file.
1745 % \begin{macrocode}
1746 \mfp@ifmpost\mfp@checkMPoutput\mfp@checkMFoutput
1747 \mfp@openfile
1748 \ifmfp@draft \global\mfpicdrafttrue \fi
1749 \ifmfp@final \global\mfpicdraftfalse \fi
1750 \ifmfp@nowrite \gdef\mfp@src##1##2{\endgroup}\fi
1751 % \end{macrocode}
1752 %
1753 % Now we set up the header and preamble of the output file, writing
1754 % version info, initializations, version checking code and extra code
1755 % for \MP{}, if required.
1756 %
1757 % Finally, we process options as they are currently known. These were
1758 % delayed until now because they might require a write to the output file.
1759 % Finally, we read the \prog{meta*o*t} log file, if the option to do that
1760 % is in effect.
1761 % \begin{macrocode}
1762 \mfsrc{\mfp@versioninfo \mfp@ifmpost{}\mfp@MFextras
1763 \mfp@init@outfile \mfp@versioncheck}%
1764 \mfp@ifmpost\mfp@MPextras{}%
1765 \ifmfp@clip \clipmfpic \fi
1766 \ifmfp@clearsym \clearsymbols \fi
1767 \ifmfp@noship \stopshipping \fi
1768 \ifmfp@readlog \mfp@readlogfile \fi
1769 \@esphack}%
1770 % \end{macrocode}
1771 %
1772 % \DescribeMacro{\closegraphsfile}
1773 % This command finishes off the output file and undefines \cs{mfp@filename}.
1774 % We define an error message free version \cs{mfp@closegraphsfile} for
1775 % internal use. We unconditionally undefine \cs{mfp@filename} just in
1776 % case.
1777 % \begin{macrocode}
1778 \newdef\closegraphsfile{%
1779 \mfp@ifopengraphsfile{}{\mfp@nooutput@error\closegraphsfile}%
1780 \mfp@closegraphsfile}%
1781 \newdef\mfp@closegraphsfile{%
1782 \mfp@ifopengraphsfile
1783 {\ifmfp@nowrite \else
1784 \mfsrc{\@nl end.}\immediate\closeout\mfp@out
1785 \fi \global\let\mfp@filename\UndEfInEd}{}}%
1786 % \end{macrocode}
1787 %
1788 %
1789 % \subsection{Information from \MF: reading its log file}
1790 %
1791 % \DescribeMacro{\assignmfvalue}\SpecialUsageIndex{\globalassignmfvalue}
1792 % This macro was suggested by Werner Lemberg, who also supplied working
1793 % code. I have made modifications, so I am to blame if it has bugs. It
1794 % writes code to the \file{.mf} file that causes \MF{} to write
1795 % information to its \file{.log} file. If the option \opt{mfpreadlog} has
1796 % been set, that log file will be examined for that information. The
1797 % result, for example, of
1798 % \begin{verbatim}
1799 % \setmfvariable{numeric}{s}{10}
1800 % \assignmfvalue\foo{s+2}
1801 % \end{verbatim}
1802 % is that \cs{foo} will be a macro that expands to `\texttt{12}' (during
1803 % the \TeX{} run following the \MF{} pass). Under \opt{mplabels} a label
1804 % containing \cs{foo} will only be correct in the \file{.mp} file after
1805 % the second \MP{} pass, and so a third \TeX{} run may be required to
1806 % insert the correct figure. To implement localization, the code causes
1807 % the internal command \cs{mfpic-\meta{N}-foo} to be defined to the value,
1808 % where \meta{N} is the number of the current figure. The \cs{foo} is then
1809 % defined to the value of that internal command. Outside any \env{mfpic}
1810 % environment, the internal command is \cs{mfpic--foo}. If the \file{.log}
1811 % file doesn't exist or doesn't yet contain the information, \cs{foo} is
1812 % defined to `???'.
1813 %
1814 % While \cs{mfpicvalue} is merely a signal and doesn't need a
1815 % definition, we give it a useful definition for debugging: its own name.
1816 % It could be accidentally redefined by a user, but that will be harmless;
1817 % the debugging is mainly for me.
1818 %
1819 % It is possible to put \cs{global} in front of \cs{assignmfvalue} and
1820 % its macro will be defined globally in the \TeX{} run, but I could find
1821 % no way to make it global in the \file{.mp} file under \opt{mplabels}.
1822 % Thus, I've created a \cs{globalassignmfvalue}.
1823 % \begin{macrocode}
1824 \edef\mfpicvalue{\string\mfpicvalue}%
1825 \newdef\mfp@cmdname{%
1826 mfpic-\ifin@mfpicenv\number\mfp@count\fi-\@xp\@gobble\string}%
1827 \newdef\assignmfvalue{\mfp@assign\@empty}%
1828 \newdef\globalassignmfvalue{\mfp@assign\global}%
1829 \newdef\mfp@assign#1#2#3{%
1830 #1\edef#2{%
1831 \@ifundefined{\mfp@cmdname#2}{???}{\@nameuse{\mfp@cmdname#2}}}%
1832 \@ifundefined{\mfp@cmdname#2}%
1833 {\mfp@msg{}\Mfpic@msg{No value for \string#2\ifin@mfpicenv\space
1834 in mfpic figure \number\mfp@count\fi.\@nl}}%
1835 {}%
1836 \mfsrc{%
1837 \@ifmplabels{\@nl verbatimtex #1\def\string#2{#2} etex;\@nl}{}%
1838 message "\string\mfpicvalue";\@nl
1839 message "\mfp@cmdname#2";\@nl
1840 show #3;\@nl
1841 message "";}}%
1842 \newlet\assignmpvalue\assignmfvalue
1843 \newlet\globalassignmpvalue\globalassignmfvalue
1844 % \end{macrocode}
1845 %
1846 % The following code is what really makes \cs{assignmfvalue} work. It is
1847 % similar to code in the \prog{metatex} package, adapted by Werner Lemberg
1848 % and then modified by me. It steps through the \mfpic{} output file looking
1849 % for this signal: a line containing only `\verb$\mfpicvalue$'. It then
1850 % reads the next line, creates a macro name from it, and assigns to that
1851 % macro the value it reads on the next line. This is repeated to the end
1852 % of the file.
1853 % \begin{macrocode}
1854 \newdef\strip@gtgt>> #1\mfp@end{#1}%
1855 \newdef\mfp@readlogfile{%
1856 \openin\mfp@data=\[email protected]\relax
1857 \ifeof\mfp@data \Mfpic@msg{No file \[email protected].}%
1858 \else
1859 {%
1860 \mfp@resetwhitespace \endlinechar -1
1861 \catcode`\>12
1862 \def\@mfpicvalue{\mfpicvalue}%
1863 \message{< Mfpic: Reading \[email protected]}%
1864 \mfp@readloglines
1865 \message{>}%
1866 }%
1867 \fi \closein\mfp@data}%
1868 \newdef\mfp@readloglines{%
1869 \read\mfp@data to \mfp@tempa
1870 \ifeof\mfp@data
1871 \else
1872 \ifx\mfp@tempa\@mfpicvalue
1873 \read\mfp@data to \mfp@tempa
1874 \read\mfp@data to \mfp@tempb
1875 \@XP\xdef\@nameuse\mfp@tempa{\@xp\strip@gtgt\mfp@tempb\mfp@end}%
1876 \fi
1877 \@xp\mfp@readloglines
1878 \fi}%
1879 % \end{macrocode}
1880 %
1881 %
1882 %
1883 % \section{\Mfpic{} dimensions}\label{dimensions}
1884 %
1885 % A number of packages, especially figure drawing packages, allocate a
1886 % great many dimension registers. The most familiar example is \PiCTeX{}
1887 % which is at least partially responsible for most ``No room for a new
1888 % \cs{dimen}'' error messages. \Mfpic{} also needs many dimension
1889 % values, but some are set by macros that simply write the value to the
1890 % \file{.mf} file and do not use any registers. A few are stored in
1891 % \TeX{} registers, but most are stored using a trick with font
1892 % dimensions.
1893 % \begin{macrocode}
1894 \mfp@DBlog{Using dummy font's dimensions, to spare TeX registers.}%
1895 % \end{macrocode}
1896 %
1897 % While most fonts have relatively few font dimensions (twenty-two is a
1898 % common number), it turns out that if one loads a font and immediately
1899 % assigns a value to \cs{fontdimen}~$n$, Then \TeX{} acts as if the font
1900 % has \cs{fontdimen}\,s 0 through $n$ available. They can be assigned
1901 % dimension values just like \TeX{} dimension registers.
1902 %
1903 % Virtually all \TeX{} systems have a \file{dummy.tfm}, which contains
1904 % no characters (it is used for syntax checking by some packages and
1905 % classes). Since this trick will only work if we are the first to
1906 % load the font (the \AmSTeX{} document style \file{amsppt.sty} loads
1907 % the dummy font), we use another trick, which is to load it scaled to
1908 % some unlikely value, which \TeX{} treats as a new font.
1909 % \begin{macrocode}
1910 \font\mfp@dummy=dummy scaled 1042
1911 \fontdimen100\mfp@dummy0pt
1912 % \end{macrocode}
1913 %
1914 % Some versions of \file{dummy.tfm} have values already assigned to font
1915 % dimensions 0 through 22. It would probably not hurt to use those, but
1916 % we'll be cautious and use only font dimensions 23 and up, making 78
1917 % available.
1918 %
1919 % We use an auxiliary count register to keep track of new font dimens.
1920 % \begin{macrocode}
1921 \newcount\mfp@fdc
1922 \mfp@fdc22
1923 % \end{macrocode}
1924 %
1925 % We define a macros that mimics the behavior of \cs{newdimen}, for
1926 % allocating font dimension numbers. It increments \cs{mfp@fdc} and
1927 % defines its argument \arg{1} to expand to a reference to the
1928 % \cs{fontdimen} with that number. The syntax it produces is valid as
1929 % the left side of a dimension assignment and also as a dimension
1930 % that may follow a real factor and \cs{the}. For example, later we say
1931 % \cs{newfdim}\cs{pointsize} and give it the value \texttt{2pt}. Then
1932 % \verb$\the\pointsize$ prints this value and
1933 % \verb$\pointsize = 0.5\pointsize$ is a valid assignment.
1934 % \begin{macrocode}
1935 \newdef\newfdim#1{%
1936 \global\advance\mfp@fdc1
1937 \xdef#1{\fontdimen\number\mfp@fdc\mfp@dummy}%
1938 \wlog{\string#1=\fontdimen\number\mfp@fdc\mfp@dummy}}%
1939 % \end{macrocode}
1940 % \TeX{} will not accept font dimensions in its syntax for the dimension
1941 % arithmetic commands \cs{advance}, \cs{multiply} and \cs{divide}. In the
1942 % rare cases where we need to do this we assign the value to a temporary
1943 % register and calculate with it.
1944 %
1945 % We allocate a couple of boxes. At the end of an \mfpic{}
1946 % environment, \cs{@wholegraph} is loaded with the picture (possibly
1947 % null) as it exists then. Inside the environment, when text labels are
1948 % processed, \cs{@textbox} holds this text temporarily so it can be
1949 % measured, moved about, etc. We also define abbreviations for the
1950 % frequent commands that specify the dimensions of \cs{@textbox}
1951 % \begin{macrocode}
1952 \mfp@DBlog{A box register for whole labeled graph, %
1953 and a temporary one.}%
1954 \newbox\@wholegraph
1955 \newbox\@textbox
1956 \newdef\tb@ht{\ht\@textbox}%
1957 \newdef\tb@dp{\dp\@textbox}%
1958 \newdef\tb@wd{\wd\@textbox}%
1959 % \end{macrocode}
1960 %
1961 % When labels are processed, they are accumulated in the box
1962 % \cs{@alltlabels}. We allocate it, and four \cs{newfdim}\,s for the
1963 % location of three of the sides (We don't need the fourth). The box
1964 % \cs{@backtext} holds `background text', that is, text accumulated
1965 % between \cs{startbacktext} and \cs{stopbacktext}.
1966 % \begin{macrocode}
1967 \newbox\@alltlabels
1968 \newbox\@backtext
1969 \newfdim\@tlabelstop
1970 \newfdim\@tlabelsbot
1971 \newfdim\@tlabelsleft
1972 % \end{macrocode}
1973 %
1974 % The following fontdims record the dimensions of the box containing the
1975 % picture. We need to adjust them when the text labels are added to the
1976 % picture, because \TeX{} doesn't do it automatically. For example,
1977 % kerning left outside the picture will not change the picture box's
1978 % reference point.
1979 % \begin{macrocode}
1980 \mfp@DBlog{Internal dimension parameters for graph dimensions...}%
1981 \newfdim\@graphright
1982 \newfdim\@graphleft
1983 \newfdim\@graphtop
1984 \newfdim\@graphbot
1985 \mfp@DBlog{...and dimension parameters for tlabel positioning.}%
1986 \newfdim\tb@raise
1987 \newfdim\tb@moveright
1988 \newfdim\tb@totalht
1989 % \end{macrocode}
1990 %
1991 % The following are for label adjustments. The first two are used to
1992 % implement the feature that all labels can be simultaneously shifted an
1993 % equal amount. The third is for the feature that the label can be a
1994 % certain distance separated from the point where it is placed. And the
1995 % last establishes the distance between a label and a path surrounding it.
1996 % \begin{macrocode}
1997 \newfdim\tlabel@hadj
1998 \newfdim\tlabel@vadj
1999 \newfdim\tlabel@sep
2000 \newfdim\tlpath@sep
2001 \tlabel@hadj0pt
2002 \tlabel@vadj0pt
2003 \tlabel@sep0pt
2004 \tlpath@sep0pt
2005 % \end{macrocode}
2006 %
2007 % It can be argued that dimensions not needed by \TeX{} should be stored
2008 % in the output file rather than allocating (font) dimensions. These are
2009 % everything below from \cs{pointsize} through \cs{symbolspace},
2010 % inclusive. This would make synchrony between \TeX{} and \MF{} easier
2011 % to maintain. Those that are needed by \TeX{} are then few enough to be
2012 % regular \cs{dimen} registers, making them automatically local to each
2013 % \env{mfpic} environment. Unfortunately, changing to such a scheme could
2014 % break some past \mfpic{} files. It would also require recoding every
2015 % command that now writes one of these dimensions to the output.
2016 %
2017 % The following are default parameters for various graphics commands that
2018 % take an optional argument for the size of something.
2019 % \begin{itemize}
2020 % \item\cs{mfpicunit}\SpecialUsageIndex{mfpicunit}, the unit of length in
2021 % a picture. \cs{@mfpicunit} is used internally.
2022 % \item\cs{pointsize}\SpecialUsageIndex{pointsize}, the diameter of a
2023 % \cs{point}.
2024 % \item\cs{shadespace}\SpecialUsageIndex{shadespace}, the spacing of dots
2025 % in \cs{shade}.
2026 % \item\cs{polkadotspace}\SpecialUsageIndex{polkadotspace}, the spacing of
2027 % polkadots.
2028 % \item\cs{hatchspace}\SpecialUsageIndex{hatchspace}, the spacing of hatch
2029 % lines.
2030 % \item\cs{headlen}\SpecialUsageIndex{headlen}, the size of arrowheads
2031 % (except on axes).
2032 % \item\cs{axisheadlen}\SpecialUsageIndex{axisheadlen}, the size of the
2033 % arrowhead for $x$- and $y$-axes.
2034 % \item\cs{sideheadlen}\SpecialUsageIndex{sideheadlen}, the size of the
2035 % arrowhead for border axes.
2036 % \item\cs{hashlen}\SpecialUsageIndex{hashlen}, the length of tic marks on
2037 % axes.
2038 % \item\cs{dashlen}\SpecialUsageIndex{dashlen}, the length of dashes in
2039 % \cs{dashed}.
2040 % \item\cs{dashspace}\SpecialUsageIndex{dashspace}, the space between such
2041 % dashes.
2042 % \item\cs{dotsize}\SpecialUsageIndex{dotsize}, the size of dots for
2043 % \cs{dotted}.
2044 % \item\cs{griddotsize}\SpecialUsageIndex{griddotsize}, the size of dots
2045 % for \cs{grid} and \cs{plrgridpoints}.
2046 % \item\cs{dotspace}\SpecialUsageIndex{dotspace}, the space between such
2047 % dots.
2048 % \item\cs{symbolspace}\SpecialUsageIndex{symbolspace}, the space between
2049 % symbols used in a \cs{plot} command.
2050 % \end{itemize}
2051 % We allocate them, and then initialize them.
2052 % \begin{macrocode}
2053 \mfp@DBlog{User level dimension parameters, with default settings.}%
2054 \newfdim\mfpicunit
2055 \newfdim\@mfpicunit % internal version
2056 \newfdim\pointsize
2057 \newfdim\shadespace
2058 \newfdim\polkadotspace
2059 \newfdim\hatchspace
2060 \newfdim\headlen
2061 \newfdim\axisheadlen
2062 \newfdim\sideheadlen
2063 \newfdim\hashlen
2064 \newfdim\dashlen
2065 \newfdim\dashspace
2066 \newfdim\dotsize
2067 \newfdim\griddotsize
2068 \newfdim\dotspace
2069 \newfdim\symbolspace
2070 \mfpicunit1pt
2071 \pointsize2pt
2072 \shadespace1pt
2073 \polkadotspace10pt
2074 \hatchspace3pt
2075 \headlen3pt
2076 \axisheadlen5pt
2077 \sideheadlen0pt
2078 \hashlen4pt
2079 \dashlen4pt
2080 \dashspace4pt
2081 \dotsize0.5pt
2082 \griddotsize0.5pt
2083 \dotspace3pt
2084 \symbolspace5pt
2085 % \end{macrocode}
2086 %
2087 % Font dimensions are global, and so not restricted to an \env{mfpic}
2088 % environment even when assigned inside one. This would require the
2089 % user to restore a value every time one picture needed a different
2090 % value from the rest. To avoid requiring this, the following macro is
2091 % used to save all values of these dimensions at the start of a picture,
2092 % and to restore the saved values at the end. Some internal dimensions
2093 % (all the \cs{@graph...}, \cs{@tlabels...} and \cs{tb@...}) don't need
2094 % saving since they are reset with each picture.
2095 % \begin{macrocode}
2096 \newdef\save@mfpicdimens{%
2097 \edef\restore@mfpicdimens{%
2098 \mfpicunit \the\mfpicunit
2099 \pointsize \the\pointsize
2100 \shadespace \the\shadespace
2101 \polkadotspace \the\polkadotspace
2102 \hatchspace \the\hatchspace
2103 \headlen \the\headlen
2104 \axisheadlen \the\axisheadlen
2105 \sideheadlen \the\sideheadlen
2106 \hashlen \the\hashlen
2107 \dashlen \the\dashlen
2108 \dashspace \the\dashspace
2109 \dotsize \the\dotsize
2110 \griddotsize \the\griddotsize
2111 \dotspace \the\dotspace
2112 \symbolspace \the\symbolspace
2113 \tlabel@hadj \the\tlabel@hadj
2114 \tlabel@vadj \the\tlabel@vadj
2115 \tlabel@sep \the\tlabel@sep
2116 \tlpath@sep \the\tlpath@sep}}%
2117 % \end{macrocode}
2118 %
2119 % Here are the few dimension registers we do allocate:
2120 % \SpecialUsageIndex{\mfpframesep}\cs{mfpframesep}, and
2121 % \SpecialUsageIndex{\mfpframethickness}\cs{mfpframethickness}
2122 % govern frames.
2123 % \SpecialUsageIndex{\mfpicheight}\cs{mfpicheight} and
2124 % \SpecialUsageIndex{\mfpicwidth}\cs{mfpicwidth} are set
2125 % after each picture to that picture's size. A \cs{vskip} of
2126 % \SpecialUsageIndex{\mfpiccaptionskip}\cs{mfpiccaptionskip} is placed
2127 % between figure and caption by \cs{tcaption}. We also allocate a
2128 % frequently used scratch register
2129 % \begin{macrocode}
2130 \newdimen\mfp@scratch
2131 \newdimen\mfpframesep
2132 \newdimen\mfpframethickness
2133 \newdimen\mfpicheight
2134 \newdimen\mfpicwidth
2135 \newskip\mfpiccaptionskip
2136 \mfpframethickness0.4pt
2137 \mfpframesep2pt
2138 \mfpiccaptionskip\medskipamount
2139 % \end{macrocode}
2140 %
2141 %
2142 %
2143 % \section{Helper macros}\label{helper}
2144 %
2145 % \DescribeMacro{\mfpicnumber}
2146 % We make a user-level macro for setting the number of the next graph.
2147 % The original purpose of this is so that the font file could have
2148 % characters in the positions of printable characters. Then creating a
2149 % composite figure is as easy as changing fonts: \marg{\cs{pic} ABABAAB}.
2150 % The motivation came from a discussion on \texttt{comp.text.tex} started
2151 % by someone who wanted to input a sequence of 0's and 1's and get a
2152 % sequence of black and white squares. For \MP{} users it is not very
2153 % important.
2154 % \begin{macrocode}
2155 \def\mfpicnumber#1{\global\mfp@count#1\relax}%
2156 % \end{macrocode}
2157 %
2158 % \DescribeMacro{\mfpaddto}
2159 % When placing text at intervals on an axis, we need to automatically
2160 % calculate coordinates to feed to the \cs{tlabel} command. The
2161 % following is a utility macro to add two real numbers. It is currently
2162 % used only in the \cs{axislabels} command, so it needn't be globally
2163 % defined, but it might be handy in the future.
2164 % \begin{itemize}
2165 % \item[] \arg{1} is a \emph{macro} that expands to some number.
2166 % \item[] \arg{2} is a number to add to it.
2167 % \end{itemize}
2168 % The result is stored again in \arg{1}, overwriting the old value.
2169 %
2170 % \DescribeMacro{\mfpmultiply}
2171 % This is the multiplicative version, with the same syntax and behavior.
2172 % It is not used anywhere yet.
2173 % \begin{macrocode}
2174 \newdef\mfpaddto#1#2{\mfp@scratch#1pt \advance\mfp@scratch#2pt
2175 \edef#1{\strip@pt\mfp@scratch}}%
2176 \newdef\mfpmultiply#1#2{\mfp@scratch#1pt \mfp@scratch#2\mfp@scratch
2177 \edef#1{\strip@pt\mfp@scratch}}%
2178 \mfp@ifundefined\strip@pt
2179 \begingroup
2180 \lccode`\/`\p
2181 \lccode`\?`\t
2182 \lowercase{%
2183 \endgroup
2184 \def\rem@pt#1.#2/?}{#1\ifnum#2>\z@.#2\fi}%
2185 \def\strip@pt{\@xp\rem@pt\the}%
2186 \mfp@enddef
2187 % \end{macrocode}
2188 %
2189 % \DescribeMacro{\pointdef}
2190 % A point defining macro, suggested by a user.
2191 % \begin{itemize}
2192 % \item[] \arg{1} is a symbolic name for a point, only letters.
2193 % \item[] \arg{2} and \arg{3} are the coordinates.
2194 % \item[] Usage: \cs{pointdef}\marg{A}\parg{2,5} makes \cs{A} expand
2195 % to \texttt{(2,5)}, \cs{Ax} to \texttt{2}, and \cs{Ay} to
2196 % \texttt{5}.
2197 % \end{itemize}
2198 % \begin{macrocode}
2199 \newdef\pointdef#1(#2,#3){%
2200 \@ifundefined{#1} {}{\Mfpic@warn{\mfp@b#1 already defined.}}%
2201 \@ifundefined{#1x}{}{\Mfpic@warn{\mfp@b#1x already defined.}}%
2202 \@ifundefined{#1y}{}{\Mfpic@warn{\mfp@b#1y already defined.}}%
2203 \@namedef{#1}{(#2,#3)}\@namedef{#1x}{#2}\@namedef{#1y}{#3}}%
2204 % \end{macrocode}
2205 %
2206 % \DescribeMacro{\setmfarray}
2207 % This enables the simultaneous definition of \MF{} (or \MP) variables
2208 % such as \mfc{A1}, \mfc{A2}, etc., by writing
2209 % \cs{setmfarray}\marg{\meta{type}}\marg{\meta{name}}\marg{\meta{list}},
2210 % the \meta{name} being any \MF{} variable without a suffix, the list being
2211 % a comma separated list of items of the appropriate \meta{type}.
2212 % For example, \cs{setmfarray}\marg{pair} would require a list of
2213 % pairs.
2214 %
2215 % \SpecialUsageIndex{\numericarray}
2216 % As with \cs{setmfvariable}, we provide a few abbreviations.
2217 % \cs{numericarray} is for arrays of numeric variables,
2218 % \SpecialUsageIndex{\pairarray} \cs{pairarray} for arrays of pair
2219 % variables and \SpecialUsageIndex{\colorarray}\cs{colorarray} is for
2220 % arrays of color variables. Finally, to set arrays globally, there is
2221 % \SpecialUsageIndex{\globalsetmfarray}\cs{globalsetmfarray}.
2222 % \begin{macrocode}
2223 \newdef\setmfarray#1#2{\mfsrc{setarray (#1) (#2)}\mfp@writedata}%
2224 \newlet\setmparray\setmfarray
2225 \newdef\pairarray{\setmfarray{pair}}%
2226 \newdef\numericarray{\setmfarray{numeric}}%
2227 \newdef\colorarray{\setmfarray{color}}%
2228 \newdef\rgbcolorarray{\setmfarray{rgbcolor}}%
2229 \newdef\cmykcolorarray{\setmfarray{cmykcolor}}%
2230 \newdef\globalsetmfarray#1#2{\mfsrc{gsetarray (#1)(#2)}\mfp@writedata}%
2231 \newlet\globalsetmparray\globalsetmfarray
2232 % \end{macrocode}
2233 %
2234 % \DescribeMacro{\lightershade}
2235 % Shade adjustment macros. \cs{lightershade} just multiplies
2236 % \cs{shadespace} by $1.2$.
2237 % \DescribeMacro{\darkershade}
2238 % While \cs{darkershade} divides by $1.2$ (actually, multiplies by
2239 % $1/1.2$)
2240 % \begin{macrocode}
2241 \newdef\lightershade{\shadespace1.2\shadespace}%
2242 \newdef\darkershade{\shadespace.83333\shadespace}%
2243 % \end{macrocode}
2244 %
2245 % \DescribeMacro{\dashlineset}
2246 % The following arrange for contrastive dashed lines. \cs{dashlineset}
2247 % just resets the default parameters that the \cs{dashed} macro uses,
2248 % \DescribeMacro{\dotlineset}
2249 % \cs{dotlineset} sets these parameters so that \cs{dashed} produces
2250 % something almost dotted.
2251 % \begin{macrocode}
2252 \newdef\dashlineset{\dashlen4pt \dashspace4pt }%
2253 \newdef\dotlineset{\dashlen1pt \dashspace2pt }%
2254 % \end{macrocode}
2255 %
2256 % \DescribeMacro{\pointfilltrue}
2257 % With the commands \cs{pointfilltrue} or \cs{pointfillfalse} the user
2258 % can specify points drawn with the \cs{point} command to be either
2259 % filled in or
2260 % \DescribeMacro{\pointfillfalse}
2261 % not.
2262 % \begin{macrocode}
2263 \let\ifpointfill\iftrue
2264 \newdef\pointfilltrue{\mfp@let\ifpointfill\iftrue}%
2265 \newdef\pointfillfalse{\mfp@let\ifpointfill\iffalse}%
2266 % \end{macrocode}
2267 %
2268 % \CMF{} has very flexible looping capabilities. Before version 0.8 there
2269 % was no \mfpic{} interface because it seemed that \cs{mfsrc} was the
2270 % simplest way to access this capability. Anything else would have to
2271 % be either a clone of \cs{mfsrc} or limit the possibilities. However, I
2272 % now believe it might be a good thing to have a structured way to perform
2273 % repetitive actions at the \MF{} level.
2274 %
2275 % As of version 0.9, \mfpic{} will allow loops outside \env{mfpic}
2276 % environments. It seems like a reasonable thing to be allowed to do.
2277 % Fortunately, the macro names are already unique.
2278 %
2279 % \DescribeMacro{\mfpfor}
2280 % This is the simplest: it writes the word \mfc{for} plus the contents of
2281 % its only mandatory argument, followed by a colon. The loop is ended by
2282 % \DescribeMacro{\endmfpfor}
2283 % \cs{endmfpfor} which merely writes the text \mfc{endfor}.
2284 % \begin{macrocode}
2285 \newdef\mfpfor#1{\begingroup\mfsrc{for #1:}}%
2286 \newdef\endmfpfor{\mfsrc{endfor}\endgroup}%
2287 % \end{macrocode}
2288 %
2289 % \DescribeMacro{\mfploop}
2290 % The macro \cs{mfploop} starts a loop with \mfc{forever}. The user is
2291 % expected to provide an escape condition with
2292 % \DescribeMacro{\mfpuntil}
2293 % \cs{mfpuntil}, which can be placed anywhere among the commands contained
2294 % in the \env{mfploop} environment.
2295 % \DescribeMacro{\endmfploop}
2296 % The macro \cs{endmfploop} is a clone of \cs{endmfpfor} except for the
2297 % warning. Grouping keeps the warning from being turned off if
2298 % \cs{mfpuntil} occurs in a nested loop.
2299 % \begin{macrocode}
2300 \newdef\mfploop{%
2301 \begingroup\mfsrc{forever:}\let\@nountil\mfp@untilwarn}%
2302 \newdef\mfpuntil#1{\mfcmd{exitif #1}\let\@nountil\@empty}%
2303 \newdef\endmfploop{\@nountil\endmfpfor}%
2304 % \end{macrocode}
2305 %
2306 % \DescribeMacro{\mfpwhile}
2307 % This emulates a while-loop, the condition being given in the mandatory
2308 % argument. It has the same behavior, and writes almost the same code as
2309 % \cs{mfploop} with an immediate \cs{mfpuntil} using the negative of the
2310 % condition.
2311 % \DescribeMacro{\endmfpwhile}
2312 % The closing, \cs{endmfpwhile}, is again the same as \cs{endmfpfor}.
2313 % \begin{macrocode}
2314 \newdef\mfpwhile#1{\begingroup\mfcmd{forever: exitif not(#1)}}%
2315 \newlet\endmfpwhile\endmfpfor
2316 % \end{macrocode}
2317 %
2318 % \DescribeMacro{\plr}
2319 % A little utility to convert a list of pairs into another list of
2320 % pairs, where the given list are assumed to be polar coordinates and the
2321 % results are their Cartesian counterparts. This is guaranteed to work as
2322 % expected only in macros with a list argument, or for a single pair.
2323 % \DescribeMacro{\midpoint}
2324 % And one to calculate the midpoint, given two points separated by a comma.
2325 % Can be used in graphics macros where a point is required.
2326 % \begin{macrocode}
2327 \newdef\plr#1{map (polar) (#1)}%
2328 \newdef\midpoint#1{(0.5[#1])}%
2329 % \end{macrocode}
2330 %
2331 %
2332 %
2333 % \section{Macros to implement prefix commands}\label{prefix}
2334 %
2335 % Some \mfpic{} macros, like \cs{circle} create a path. When used without
2336 % a prefix, they also draw the path. At the \MF{} level, every figure
2337 % macro is syntactically a path expression. Other macros are prefix macros
2338 % and operate on a figure macro that follows. Every prefix accepts a path
2339 % expression as input and has a path as its return value, so a combination
2340 % prefix + path expression is again a path expression.
2341 %
2342 % Prefixes may also have side effects, such as adding some ink to the
2343 % current picture. Such prefixes are called \emph{rendering} macros.
2344 %
2345 % Rendering macros normally return the same path as their argument, but
2346 % there are macros that modify the path. Some apply a linear transform,
2347 % some close an open path, some return a subpath. These we call
2348 % \emph{modification} macros.
2349 %
2350 % This scheme is quite simple, but unfortunately too simple. To avoid
2351 % having to explicitly type a rendering prefix every time, a figure
2352 % macro needs to know if a rendering prefix has occured, so prefix macros
2353 % need to pass information to the figure macro (and to later prefixes).
2354 %
2355 % Moreover, \MF{} abhors an `isolated expression', so the first prefix
2356 % has to write something with a different syntax, and pass the info that
2357 % it has already done so on to later prefixes, who need to test that
2358 % info. Thus, every prefix macro needs to know if it is the first or a
2359 % later one. They test this \cs{if} command and also set it to false. The
2360 % figure macros, which are last in the chain, close by resetting it true.
2361 % \begin{macrocode}
2362 \mfp@DBlog{Tests to control multiple prefix commands.}%
2363 \newif\if@mfpstart\@mfpstarttrue
2364 % \end{macrocode}
2365 %
2366 % If a prefix is a rendering prefix, it writes its rendering code and sets
2367 % the following switch to false, letting the figure macro know it needn't
2368 % invoke the default rendering. Figure macros close by resetting it true.
2369 % Appending macros don't even look at it, while modifying macros test it
2370 % and act on the results of that test.
2371 % \begin{macrocode}
2372 \newif\if@mfprend\@mfprendtrue
2373 % \end{macrocode}
2374 %
2375 % The following macro is always (and only) invoked by the first prefix
2376 % macro (or the figure macro, if there are no prefixes). It writes the
2377 % code that prevents an isolated expression. It stores the following path
2378 % expression in the variable \gbc{curpath}. Thus every combination of
2379 % prefixes followed by a figure macro is syntactically a \MF{} variable
2380 % assignment command.
2381 % \begin{macrocode}
2382 \newdef\mfp@storepath{\mfsrc{\@nl store (curpath)}}%
2383 % \end{macrocode}
2384 %
2385 % Every prefix and figure macro has to invoke \cs{mfp@first}, since each
2386 % is potentially the first in the sequence. If \cs{@mfpstart} is true, it
2387 % writes the storing command, sets \cs{@mfpstartfalse}, and says that
2388 % rendering is needed. (The rendering macros immediately cancel that
2389 % switch.)
2390 % \begin{macrocode}
2391 \newdef\mfp@first{\relax
2392 \if@mfpstart \mfp@storepath \@mfprendtrue \@mfpstartfalse\fi}%
2393 % \end{macrocode}
2394 %
2395 % Every rendering macro invokes this next command. After the first-stage
2396 % code it writes its rendering command (via \cs{mfsrc}) and passes on the
2397 % info that rendering is no longer required of the figure macro.
2398 % \begin{macrocode}
2399 \newdef\mfp@rendmac{\mfp@first \@mfprendfalse \mfsrc}%
2400 % \end{macrocode}
2401 %
2402 % The \emph{figure} macros proceed as follows: (i)~they invoke the
2403 % \cs{mfp@first} code, then (ii)~write a rendering macro if necessary
2404 % (\cs{mfp@autorend}), (iii)~then make \cs{@mfpstarttrue} (for the next
2405 % figure) and write \MF{} code that defines the path. The \cs{mfp@modmac}
2406 % macros do only the first two, then write their modification code,
2407 % counting on the following figure macro to do (iii). The idea is that
2408 % [modifier + figure] should act the same as if the path it defines were
2409 % encoded as a single figure command.
2410 % \begin{macrocode}
2411 \newdef\mfp@modmac{\mfp@first\mfp@autorend\mfsrc}%
2412 \newdef\mfp@autorend{\if@mfprend\@xp\mfp@render\fi}%
2413 % \end{macrocode}
2414 %
2415 % Only axis and arrow commands (plus \cs{reverse}) use \cs{mfp@addmac}.
2416 % As the name suggests, something is added onto an existing figure. That
2417 % is, it is designed to ignore the rendering state and not invoke implicit
2418 % rendering. If no explicit rendering occurs, the figure macro that
2419 % follows invokes a rendering. For arrows, this causes the arrowhead to be
2420 % drawn on top of the drawing of the shaft.
2421 %
2422 % It would seem \cs{reverse} doesn't fit this name, but it also needs to
2423 % be transparent to the rendering state so that it will work in
2424 % combination with arrows.
2425 %
2426 % \cs{mfp@addmac} simply invokes the common first-stage code and writes
2427 % its \MF{} code.
2428 % \begin{macrocode}
2429 \newdef\mfp@addmac{\mfp@first \mfsrc}%
2430 % \end{macrocode}
2431 %
2432 % The \cs{mfp@addmac} and \cs{mfp@modmac} macros differ when there are no
2433 % preceeding rendering macros. In that case it is as if \cs{draw} (or
2434 % more generally \cs{mfp@render}) precedes the \cs{mfp@modmac} macro. That
2435 % drawing happens \emph{in addition to} any rendering macros that follow.
2436 % This implicitly added \cs{draw} is not present for \cs{mfp@addmac}
2437 % macros; it is added by the following figure macro. The effect of this is
2438 % the \cs{mfp@addmac} macros perform their additions on top of an already
2439 % rendered figure.
2440 %
2441 % \DescribeMacro{\setrender}
2442 % As mentioned above, when a figure macro is invoked without a rendering
2443 % prefix, it will invoke some default. That default is stored in a macro
2444 % and can be changed for special effects. Initially we define it as
2445 % \cs{draw} (with empty optional argument) to draw solid paths in the
2446 % default color, but we provide a command for the user to change it.
2447 % \begin{macrocode}
2448 \newdef\mfp@render{\draw[]}%
2449 \newdef\setrender{\mfp@def\mfp@render}%
2450 % \end{macrocode}
2451 %
2452 % A figure macro will invoke the common first-stage code and the rendering
2453 % check. It also resets the \cs{@mfpstart} switch. Because a figure macro
2454 % completes an assignment command in \MF, it writes its code with
2455 % \cs{mfcmd}, which places a semicolon at the end. We define the first
2456 % part (all but the writing) as a separate command because there are a few
2457 % cases where we need to delay that writing.
2458 % \begin{macrocode}
2459 \newdef\mfp@figmacbase{\mfp@first \mfp@autorend \@mfpstarttrue}%
2460 \newdef\mfp@figmac{\mfp@figmacbase\mfcmd}%
2461 % \end{macrocode}
2462 %
2463 % The list macros take as their last argument a list of $(x,y)$ pairs (or
2464 % occasionally a list of numbers). That list can either be typed directly
2465 % into the \TeX{} source file (inside braces, separated by commas) or be
2466 % present in an external datafile. Either way, the data is written as a
2467 % list within an enclosing pair of parentheses. Since these are all
2468 % figure macros, \cs{mfp@listmac} starts out just like \cs{mfp@figmac},
2469 % but it writes only part of its arguments, the last one (the data list)
2470 % being handled by \cs{mfp@writedata}.
2471 %
2472 % \cs{mfp@writedata} looks ahead to see if the token \cs{datafile}
2473 % follows, if it does \cs{mfp@writefile} is invoked, which gobbles
2474 % the \cs{datafile} token and processes the filename that should follow it.
2475 % Otherwise, \cs{mflist} is invoked to write the list in braces
2476 % that should follow.
2477 %
2478 % \cs{mfp@writedata} is also used by non-figure macros such as the axis
2479 % marks macros, plus \cs{piechart} and \cs{barchart}.
2480 % \begin{macrocode}
2481 \newdef\mfp@listmac#1{\mfp@figmacbase\mfsrc{#1}\mfp@writedata}%
2482 \newdef\mfp@writedata{\mfp@iftoken\datafile{\mfp@writefile}{\mflist}}%
2483 \newdef\mfp@writefile{%
2484 \mfp@ifopengraphsfile
2485 {\mfp@processfile{\mfp@rwdata}}{\mfp@nooutput@error\datafile}}%
2486 % \end{macrocode}
2487 %
2488 % \DescribeMacro{\mftitle}
2489 % This is mainly for debugging the example files. \cs{mfp@title} takes
2490 % two arguments: the command that called it (for the error message of
2491 % \cs{mfp@src}), and some \TeX{} code. That code is written into the string
2492 % argument of the \grafbase{} command \gbc{mftitle} and ends up in the
2493 % \MF{} \file{.log} file and as a comment in the GF file. \cs{mftitle}
2494 % merely calls \cs{mfp@title}, while
2495 % \DescribeMacro{\tmtitle}
2496 % \cs{tmtitle} also writes the argument to the \TeX{} \file{.log} file and
2497 % typesets it in the document.
2498 %
2499 % We write the argument as a token list because that is the the easiest
2500 % verbatim-like way to do it.
2501 % \begin{macrocode}
2502 \newdef\mftitle#1{\@bsphack\mfp@title\mftitle{#1}\@esphack}%
2503 \newdef\tmtitle#1{\mfp@title\tmtitle{#1}\wlog{\the\mfp@toks}{#1}}%
2504 \newdef\mfp@title#1#2{\mfp@toks{#2}%
2505 \mfp@write\mfp@src#1{mftitle "\the\mfp@toks";}}%
2506 % \end{macrocode}
2507 %
2508 %
2509 %
2510 % \section{Macros for getting data from files}\label{rwdata}
2511 %
2512 % The following command contains the common code to open a data file for
2513 % reading. The second parameter is the filename, the first is what to do
2514 % if it exists and is nonempty. We first try to \cs{openin} the file and
2515 % issue an error message if that fails. Then we skip any initial blank
2516 % lines and comments and complain if that takes us to the end of the
2517 % file. Otherwise we execute the command specified. Afterwards, since
2518 % each \cs{plotdata} command in a given \env{mfpic} environment
2519 % starts with the linetype at which the previous one ended, we allow the
2520 % value of \cs{mfp@linetype} to survive this group but not any enclosing
2521 % group.
2522 % \begin{macrocode}
2523 \newdef\mfp@processfile#1#2{%
2524 \openin\mfp@data=#2\relax
2525 \ifeof\mfp@data \mfp@nofile@error{#2}%
2526 \else
2527 \mfp@DBlog{Opening file #2 for data.}%
2528 {%
2529 \mfp@resetwhitespace \mfp@setcomment
2530 \mfp@skipblanklines
2531 \ifeof\mfp@data
2532 \mfp@nodata@error{#2}%
2533 \else
2534 \message{< Mfpic: Reading #2}%
2535 #1%
2536 \message{>}%
2537 \fi
2538 \@xp
2539 }\@xp\mfp@linetype\number\mfp@linetype\relax
2540 \mfp@DBlog{Closing file #2.}%
2541 \fi
2542 \closein\mfp@data}%
2543 % \end{macrocode}
2544 %
2545 % When reading files it is important that white space in the files
2546 % always have the same meaning for \TeX{}. This utility resets spaces,
2547 % tabs and EOLs to the standard categories.
2548 % \begin{macrocode}
2549 \newdef\mfp@resetwhitespace{\mfp@restorepar
2550 \endlinechar`\^^M \catcode`\^^M5 \catcode`\ 10 \catcode`\^^I10 }%
2551 % \end{macrocode}
2552 %
2553 % \cs{mfp@skipcomments}
2554 % does what it says, skipping comments in a data file. It reads a
2555 % line from a previously opened file (input stream \cs{mfp@data}) and
2556 % compares it to \cs{@empty}. It calls itself when they are equal (a
2557 % comment line, a blank line would put a \cs{par} token in \cs{mfp@data}).
2558 % When this macro finishes, \cs{mfp@temp} contains either \cs{par} (blank
2559 % line or EOF) or real data.
2560 % \begin{macrocode}
2561 \newdef\mfp@skipcomments{\read\mfp@data to \mfp@temp
2562 \ifx\mfp@temp\@empty \@xp\mfp@skipcomments\fi}%
2563 % \end{macrocode}
2564 %
2565 % \cs{mfp@skipblanklines}
2566 % first skips comments. After that \cs{mfp@temp} can contain \cs{par},
2567 % indicating either EOF or a blank line, or something else. In the first
2568 % case (EOF) the macro terminates, in the second case (blank) it calls
2569 % itself again, in the other case (something else) it also terminates,
2570 % having presumably found real data.
2571 %
2572 % When this is called, a file should already be open using the handle
2573 % \cs{mfp@data}.
2574 % \begin{macrocode}
2575 \newdef\mfp@skipblanklines{\mfp@skipcomments
2576 \ifeof\mfp@data
2577 \else\ifx\mfp@temp\mfp@par \@XP\mfp@skipblanklines
2578 \fi\fi}%
2579 % \end{macrocode}
2580 %
2581 % The following two commands, \cs{mfp@rwdata} and \cs{mfp@rwdataloop}
2582 % perform the work of writing the file (read stream \cs{mfp@data} opened
2583 % by \cs{mfp@processfile}).
2584 %
2585 % The figure counter \cs{mfp@count} is reused (this should all be inside
2586 % a group) to keep track of how many lines of the data file have been
2587 % written to one line of the output. The token \cs{sequence} in a
2588 % \cs{using} specification will expand to the value of the counter
2589 % \cs{mfp@sequence}.
2590 %
2591 % When \cs{mfp@rwdata} is called, a non-blank line has been read to the
2592 % macro \cs{mfp@temp}, to which we now add a space. The macro
2593 % \cs{mfp@buffer} is what will be written to the output file as soon as it
2594 % is long enough. We initialize it by defining it to be an open
2595 % parenthesis followed by the result of applying \cs{parse@data} to the
2596 % contents of \cs{mfp@temp}. Then we call \cs{mfp@rwdataloop}, which does
2597 % the remaining reading and all the writing.
2598 % \begin{macrocode}
2599 \newdef\mfp@nextdatum{\@xp\parse@data\mfp@temp\mfp@end}%
2600 \newdef\mfp@rwdata{\mfp@count1 \mfp@sequence1
2601 \def\sequence{\number\mfp@sequence}%
2602 \edef\mfp@temp{\mfp@temp\space}%
2603 \edef\mfp@buffer{(\mfp@nextdatum}\mfp@rwdataloop}%
2604 % \end{macrocode}
2605 %
2606 % At this point, the buffer has been started with the first datum, so we
2607 % read another line. If that is blank, we write the buffer (and the closing
2608 % parenthesis and a semicolon) and terminate the loop. Otherwise we have
2609 % read another datum and then we:
2610 % \begin{enumerate}
2611 % \item increment the sequence counter,
2612 % \item add a comma to the buffer,
2613 % \item test whether the buffer is `full', and if so, write the buffer
2614 % to the output and clear it, then
2615 % \item add the datum to the buffer.
2616 % \end{enumerate}
2617 % The buffer is `full' when \cs{mfp@count} (the number of data in the
2618 % buffer) exceeds \cs{mfp@dataperline}.
2619 %
2620 % \cs{mfp@rwdataloop} loops by calling itself at the end. Whenever
2621 % \cs{mfp@temp} is empty (comment line read), (1)--(4) are skipped and
2622 % another line read.
2623 % \begin{macrocode}
2624 \newdef\mfp@rwdataloop{%
2625 \read\mfp@data to \mfp@temp
2626 \ifx\mfp@temp\mfp@par
2627 \mfcmd{\mfp@buffer)}%
2628 \else
2629 \ifx\mfp@temp\@empty
2630 \else
2631 \edef\mfp@temp{\mfp@temp\space}%
2632 \advance\mfp@sequence1
2633 \edef\mfp@buffer{\mfp@buffer\mfp@join}%
2634 \ifnum\mfp@count<\mfpdataperline\relax \advance\mfp@count1
2635 \else \mfsrc{\mfp@buffer}\mfp@count1 \def\mfp@buffer{}%
2636 \fi
2637 \edef\mfp@buffer{\mfp@buffer\mfp@nextdatum}%
2638 \fi
2639 \@xp\mfp@rwdataloop
2640 \fi}%
2641 % \end{macrocode}
2642 %
2643 % \section{Various \mfpic{} Settings.}\label{mfpsettings}
2644 %
2645 % \subsection {\CMF{} settings}\label{MFsettings}
2646 %
2647 % \DescribeMacro{\penwd}
2648 % Macros that write changes in default \grafbase{} variables now use the
2649 % construct ``\gbc{save x; <type> x; x := <value>;}'' (via a call to
2650 % \cs{setmfvariable}). This makes changes local if inside a given \env{mfpic}
2651 % environment, global if outside. An exception is \gbc{penwd} which, as an
2652 % internal variable uses `\gbc{interim}' instead (via the \grafbase{}
2653 % command \gbc{resizedrawpen}).
2654 %
2655 % \SpecialUsageIndex{\drawpen}
2656 % \cs{drawpen} was the original command used to set the pen diameter
2657 % (prior to version 0.2.13). At some point it was replaced by
2658 % \SpecialUsageIndex{\pen}\cs{pen}. However \cs{penwd} seems to be more
2659 % consistent with other commands (e.g., \cs{shadewd}), and we keep all three.
2660 % \begin{macrocode}
2661 \newdef\pen#1{\mfcmd{\@nl resizedrawpen (#1)}}%
2662 \newlet\penwd\pen \newlet\drawpen\pen
2663 % \end{macrocode}
2664 %
2665 % \DescribeMacro{\shadewd}
2666 % The \cs{shade} macro works in \MF{} by adding many copies of the small
2667 % picture \gbc{shadedot} to the figure, in \MP{} the parameters
2668 % \gbc{shadewd} and \cs{shadespace} are simply used to calculate a level
2669 % of gray and a color fill is used.
2670 %
2671 % \DescribeMacro{\polkadotwd}
2672 % However, both \MF{} and \MP{} handle polkadots the same. The only
2673 % difference is \MF's need for fitting to a pixel grid. But that is
2674 % handled in \grafbase.
2675 % \begin{macrocode}
2676 \newdef\shadewd#1{\setmfnumeric{shadewd}{#1}}%
2677 \newdef\polkadotwd#1{\setmfnumeric{polkadotwd}{#1}}%
2678 % \end{macrocode}
2679 %
2680 % \DescribeMacro{\hatchwd}
2681 % The thickness of lines in the hatching fill is set by \cs{hatchwd}.
2682 % \begin{macrocode}
2683 \newdef\hatchwd#1{\setmfnumeric{hatchwd}{#1}%
2684 \setmfvariable{pen}{hatchpen}{pencircle scaled hatchwd}}%
2685 % \end{macrocode}
2686 %
2687 % \DescribeMacro{\dashpattern}
2688 % A dash pattern consists (internal to \MF) of an array of lengths. The
2689 % \grafbase{} command \gbc{dashpat} accepts a name, and a sequence of
2690 % numbers representing the sizes of dashes and spaces, and builds this
2691 % array. It differs from \cs{numericarray} in that a little additional
2692 % checking is done (at the \grafbase{} level).
2693 % \begin{macrocode}
2694 \newdef\dashpattern#1{\mfsrc{save #1; dashpat (#1)}\mfp@writedata}%
2695 % \end{macrocode}
2696 %
2697 % \DescribeMacro{\settension}
2698 % This sets the default tension for any command (for example, \cs{curve})
2699 % that takes an optional argument that contains a tension value. This
2700 % includes also \cs{function}, \cs{plrfcn}, \cs{fcncurve}, \cs{datafile},
2701 % \cs{plotdata}. It also sets the default tension for \cs{sclosed} and
2702 % \cs{bclosed}. The value should be at least $3/4$.
2703 % \begin{macrocode}
2704 \newdef\settension#1{\setmfnumeric{default_tension}{#1}}%
2705 % \end{macrocode}
2706 %
2707 % \subsection{Settings for text label placement in figures}
2708 % \label{labelsettings}
2709 %
2710 % \cs{tlabel}\,s are `justified' by placing a particular point of the
2711 % text at the location specified. The \cs{tlabel} command accepts an
2712 % optional argument containing two letters. There are 4 possibilities
2713 % for the first and three for the second. It turns out to be easier to
2714 % process these if we have a command that converts these to numbers, and
2715 % then \cs{ifcase} can be used. There is a third part of the optional
2716 % argument usable only in \MP{}: a number indicating degrees of rotation.
2717 %
2718 % \DescribeMacro{\tlabeljustify}
2719 % The multi-part definition of \cs{tlabeljustify} is to guard
2720 % against confusing error messages if some part of this optional argument
2721 % is empty. The code assumes that if there are only 2, 1 or no parts, then
2722 % later parts should be left unchanged. The rotation part is empty by
2723 % default (rather than 0), because some commands will emit a warning if
2724 % a nonempty rotation exists without \opt{mplabels}.
2725 %
2726 % The result of \cs{tlabeljustify} is that \cs{tl@vpos} is set equal to
2727 % $-1$ if the first letter is (default) \texttt{B} (for Baseline), and
2728 % 0--2 if it is \texttt{b} (bottom), \texttt{c} (center) or \texttt{t}
2729 % (top). Similarly, \cs{tl@hpos} is set equal to $-1$ if the second
2730 % letter is (default) \texttt{l} (for left), and 0 or 1 if it is
2731 % \texttt{c} (center) or \texttt{r} (right). Making the defaults
2732 % negative means they must be handled by the \cs{else} portion of any
2733 % \cs{ifcase}.
2734 %
2735 % The rotation part is just saved in \cs{tl@rot}. This is true even
2736 % without \opt{mplabels}, in case it is turned on later. It is ignored by
2737 % \cs{tlabel} without \opt{mplabels}, but a warning is issued here anyway.
2738 % \begin{macrocode}
2739 \newcount\tl@vpos \newcount\tl@hpos
2740 \newdef\mfp@tlh@l{-1}%
2741 \newdef\mfp@tlh@c{0}%
2742 \newdef\mfp@tlh@r{1}%
2743 \newdef\mfp@tlv@B{-1}%
2744 \newdef\mfp@tlv@b{0}%
2745 \newdef\mfp@tlv@c{1}%
2746 \newdef\mfp@tlv@t{2}%
2747 \newdef\tl@rot{}\tl@vpos-1 \tl@hpos-1
2748 \newdef\tlabeljustify#1{\mfp@ifexist{#1}{\mfp@justify#1\mfp@end}}%
2749 \newdef\mfp@justify#1#2\mfp@end{\mfp@local\mfp@vconv{#1}%
2750 \mfp@ifexist{#2}{\mfp@@justify#2\mfp@end}}%
2751 \newdef\mfp@@justify#1#2\mfp@end{\mfp@local\mfp@hconv{#1}%
2752 \mfp@local\edef\tl@rot{#2}%
2753 \@ifmplabels{}%
2754 {\mfp@ifexist{#2}%
2755 {\Mfpic@warn{Rotation of labels is not supported without the %
2756 mplabels\@msgbreak option. Rotation setting\on@line\space
2757 may be ignored.}}%
2758 }}%
2759 \newdef\mfp@vconv#1{%
2760 \@ifundefined{mfp@tlv@#1}%
2761 {\tl@vpos-1 \mfp@justify@error}%
2762 {\tl@vpos\@nameuse{mfp@tlv@#1}\relax}}%
2763 \newdef\mfp@hconv#1{%
2764 \@ifundefined{mfp@tlh@#1}%
2765 {\tl@hpos-1 \mfp@justify@error}%
2766 {\tl@hpos\@nameuse{mfp@tlh@#1}\relax}}%
2767 % \end{macrocode}
2768 %
2769 % \DescribeMacro{\tlpathjustify}
2770 % This acts just like \cs{tlabeljustify} from the user's point of view.
2771 % Since it is only for users, and not used internally, it merely defines
2772 % three macros that are passed to \cs{tlabeljustify} when no justification
2773 % parameter is present for a \cs{tlabel}-path command.
2774 % \begin{macrocode}
2775 \newdef\tlpathjustify#1{%
2776 \mfp@ifexist{#1}{\tlp@justify#1\mfp@end}}%
2777 \newdef\tlp@justify#1#2\mfp@end{\mfp@def\tlpath@v{#1}%
2778 \mfp@ifexist{#2}{\tlp@@justify#2\mfp@end}}%
2779 \newdef\tlp@@justify#1#2\mfp@end{%
2780 \mfp@def\tlpath@h{#1}\mfp@def\tlpath@r{#2}}%
2781 \tlpathjustify{cc}%
2782 % \end{macrocode}
2783 %
2784 % \DescribeMacro{\tlpointsep}
2785 % This takes an absolute length as its argument and sets parameters that
2786 % determine by how much a tlabel is separated from the point it is placed
2787 % at. This is in case something is drawn at that point, such as a dot or
2788 % a hash mark on an axis.
2789 %
2790 % \DescribeMacro{\tlpathsep}
2791 % This takes an absolute length and sets parameters that determine by how
2792 % much a path created by one of the \cs{tlabel\meta{path}} macros is
2793 % separated from the label it surrounds.
2794 %
2795 % \DescribeMacro{\tlabelsep}
2796 % This simply issues both the above commands. This is for compatibility
2797 % with \mfpic{} versions 0.7 or earlier, where both these separations were
2798 % determined by the same parameters.
2799 %
2800 % \DescribeMacro{\tlabeloffset}
2801 % \cs{tlabeloffset}, on the other hand, takes two arguments: dimensions,
2802 % representing offsets of labels from their point of placement. This is
2803 % mainly so that, if labels seem to be off, they can all be shifted with
2804 % one command.
2805 %
2806 % Both these values are written to the \MF{} file for the sake of the
2807 % commands that draw rectangles or ovals around labels.
2808 % \begin{macrocode}
2809 \newdef\tlpointsep#1{\mfp@local\tlabel@sep#1\relax
2810 \setmfnumeric{label_sep}{\the\tlabel@sep}}%
2811 \newdef\tlpathsep#1{\mfp@local\tlpath@sep#1\relax
2812 \setmfnumeric{labelpath_sep}{\the\tlpath@sep}}%
2813 \newdef\tlabelsep#1{\tlpointsep{#1}\tlpathsep{#1}}%
2814 \newdef\tlabeloffset#1#2{%
2815 \mfp@local\tlabel@hadj#1\relax \mfp@local\tlabel@vadj#2\relax
2816 \setmfpair{label_adjust}%
2817 {(\the\tlabel@hadj,\the\tlabel@vadj)}}%
2818 % \end{macrocode}
2819 %
2820 % \DescribeMacro{\everytlabel}
2821 % Every line of a multiline label is written inside a group, so
2822 % adjustments to baselineskip and other things are difficult or
2823 % impossible. Therefore, \cs{everytlabel} is provided to define code to be
2824 % inserted before the label code, outside these groups. The messing around
2825 % with the token register \cs{mfp@toks} is so one can put definitions in
2826 % the code without having to double \arg{} characters.
2827 %
2828 % The command \cs{extra@endtlabel} is called at the end of every
2829 % \cs{tlabel}. Normally it does nothing, but the \cs{tlabels} command
2830 % defines it to repeat the start of a loop.
2831 % \begin{macrocode}
2832 \newdef\everytlabel{\afterassignment\mfp@everytlabel\mfp@toks}%
2833 \newdef\mfp@everytlabel{\mfp@local\edef\every@tlabel{\the\mfp@toks}%
2834 \mfp@ifmpost
2835 {\mfp@ifopengraphsfile
2836 {\mfcmd{verbatimtex\@nl
2837 \def\noexpand\MFPeverylabel{\the\mfp@toks} etex}}%
2838 {}}%
2839 {}}%
2840 \newdef\every@tlabel{}%
2841 \newdef\extra@endtlabel{}%
2842 % \end{macrocode}
2843 %
2844 % Without \opt{mplabels} it is impossible to use \MP{} variables in
2845 % a text label placement parameter. I have occasionally found it useful
2846 % to have a \TeX{} version of the numeric variable \gbc{pi}.
2847 % \begin{macrocode}
2848 \newdef\pinumber{3.14159}%
2849 % \end{macrocode}
2850 %
2851 % \subsection{Other settings}\label{othersettings}
2852 %
2853 % \DescribeMacro{\headshape}
2854 % This sets the arrowhead shape. The parameters are: the ratio of width
2855 % to length, the tension (see \file{grafbase.dtx}) and a boolean
2856 % (\gbc{true} or \gbc{false}) to say whether the the head is filled, or
2857 % only the barbs are drawn. It would be more consistent with other
2858 % commands to have one \TeX{} parameter with commas separating the
2859 % components, but this is legacy code.
2860 % \begin{macrocode}
2861 \newdef\headshape#1#2#3{\mfcmd{\@nl headshape (#1, #2, #3)}}%
2862 % \end{macrocode}
2863 %
2864 % There are up to 4 optional arguments to any given \cs{arrow} command,
2865 % and these can take any one of 6 special indicators ({\mytt b}, {\mytt c},
2866 % {\mytt f}, {\mytt l}, {\mytt r} or {\mytt s}). Here we define macros
2867 % to handle these options. Each macro is fed a \emph{value}. For example,
2868 % the indicator {\mytt b} must be followed by a length, and that length is
2869 % the argument of \cs{mfp@arr@b}.
2870 % \begin{macrocode}
2871 \newdef\mfp@arr@b#1{\edef\mfp@hlocate{#1}}%
2872 \newdef\mfp@arr@c#1{\edef\mfp@hcolour{#1}}%
2873 \newdef\mfp@arr@l#1{\edef\mfp@hlength{#1}}%
2874 \newdef\mfp@arr@r#1{\edef\mfp@hrotate{#1}}%
2875 \newlet\mfp@arr@f\mfp@arr@b
2876 \newlet\mfp@arr@s\mfp@arr@l
2877 % \end{macrocode}
2878 %
2879 % The \cs{arc} and \cs{circle} commands take an optional argument that
2880 % indicates how the arc or circle is defined (and therefore the format of
2881 % the non-optional argument). These are passed to different \grafbase{}
2882 % commands whose names start with \gbc{arc} or \gbc{circle}. The commands
2883 % below store the rest of that name. The switch is set true by the
2884 % \cs{arc} command and false by \cs{circle}.
2885 % \begin{macrocode}
2886 \newdef\mfp@arc@s{pps}%
2887 \newdef\mfp@arc@t{ppp}%
2888 \newdef\mfp@arc@p{\ifmfp@switch plr\fi}%
2889 \newdef\mfp@arc@a{\ifmfp@switch alt\fi}%
2890 \newdef\mfp@arc@c{cp\ifmfp@switch s\fi}%
2891 \newdef\mfp@arc@r{pp (\mfp@T)}%
2892 \newdef\mfp@arc@q{pp (\mfp@F)}%
2893 % \end{macrocode}
2894 %
2895 % \DescribeMacro{\mfpdefinecolor}
2896 % \prog{Mfpic} supports color under \MP{} by writing all color
2897 % definitions to the output \file{.mp} file. In order to support a
2898 % \LaTeX-like color syntax, all the color models allowed by the color
2899 % package correspond to a \grafbase{} function that returns a \MP{}
2900 % color value. For example, \gbc{cmyk(.3,.3,0,.7)} returns \gbc{(0,0,.3)},
2901 % a very dark blue. This can be set by
2902 % \cs{mfpdefinecolor}\marg{vdblue}\marg{cmyk}\marg{.3,.3,0,.7}.
2903 %
2904 % Several commands are provided to set certain special colors. Currently
2905 % we have the following commands, setting the color of the same name as
2906 % the command (except \cs{backgroundcolor} which sets a color named
2907 % \gbc{background}):
2908 % \cs{drawcolor}\SpecialUsageIndex{\drawcolor},\\
2909 % \cs{fillcolor}\SpecialUsageIndex{\fillcolor},
2910 % \cs{hatchcolor}\SpecialUsageIndex{\hatchcolor},
2911 % \cs{headcolor}\SpecialUsageIndex{\headcolor},
2912 % \cs{pointcolor}\SpecialUsageIndex{\pointcolor},
2913 % \cs{tlabelcolor}\SpecialUsageIndex{\tlabelcolor}, and\\
2914 % \cs{backgroundcolor}\SpecialUsageIndex{\backgroundcolor}.
2915 %
2916 % These commands support the \LaTeX-like syntax:\\
2917 % \indent\cs{fillcolor}\oarg{\meta{model}}\marg{\meta{parameters}}.\\
2918 % The code for \cs{backgroundcolor} has to be spelled out since the
2919 % command name has the string `\texttt{color}', but the color does not.
2920 % \begin{macrocode}
2921 \newdef\mfpdefinecolor#1#2#3{\setmfcolor{#1}{#2(#3)}}%
2922 \newdef\mfp@defclr#1#2#3{%
2923 \setmfcolor{#1}{\mfp@ifempty{#2}{#3}{#2(#3)}}}%
2924 \newdef\mfp@newcolorcmd#1{%
2925 \@namedef{#1\mfp@C}{\mfp@nullopt{\mfp@defclr{#1\mfp@C}}}}%
2926 \mfp@newcolorcmd{draw}\mfp@newcolorcmd{fill}\mfp@newcolorcmd{tlabel}%
2927 \mfp@newcolorcmd{hatch}\mfp@newcolorcmd{head}\mfp@newcolorcmd{point}%
2928 \def\backgroundcolor{\mfp@nullopt{\mfp@defclr{background}}}%
2929 % \end{macrocode}
2930 %
2931 % When \cs{plotdata} is used to draw several graphs from one file, each
2932 % sequence of non-blank lines corresponds to a different curve with a
2933 % different style of rendering. The user has the option to cycle through
2934 % different dashing patterns, different colors, or different symbols.
2935 %
2936 % Internally, \cs{plotdata} issues the command \cs{mfp@setstyle} (which
2937 % can be defined to be any rendering macro), followed by a path defining
2938 % command such as \cs{curve} or \cs{polyline}, followed by a command
2939 % that reads the data and writes it in a suitable format. The following
2940 % commands essentially allow the user to select the rendering macro.
2941 % They start by resetting \cs{mfp@linetype}, the count register that keeps
2942 % track of how many curves have been drawn, then they define
2943 % \cs{mfp@setstyle}.
2944 %
2945 % \DescribeMacro{\dashedlines}
2946 % \cs{dashedlines} uses the rendering prefix \cs{gendashed} with 6
2947 % different dashing patterns \gbc{dashtype0} through \gbc{dashtype5}.
2948 % These are actually selected in \MF{} through the command
2949 % \gbc{getdashpat}. This takes care of cycling back to
2950 % \gbc{dashtype0} when the number of available dash patterns is exceeded.
2951 % Dashed lines is the default.
2952 % \begin{macrocode}
2953 \newdef\dashedlines{\mfp@local\mfp@linetype0
2954 \mfp@def\mfp@setstyle{\gendashed{getdashpat \number\mfp@linetype}}}%
2955 \dashedlines
2956 % \end{macrocode}
2957 %
2958 % \DescribeMacro{\coloredlines}
2959 % This uses \cs{draw} with an optional color parameter set to
2960 % \gbc{colortype0} through (by default) \gbc{colortype7}. These are color
2961 % variables defined by \grafbase{}. It also issues a warning if \MF{} is
2962 % being used. As with \cs{dashedlines}, a \MP{} command \gbc{getcolor}
2963 % selects these colors.
2964 % \begin{macrocode}
2965 \newdef\coloredlines{%
2966 \mfp@ifmpost
2967 {\mfp@local\mfp@linetype0
2968 \mfp@def\mfp@setstyle{\draw[getcolor \number\mfp@linetype]}}%
2969 {\Mfpic@warn{You can't use \mfp@b coloredlines in %
2970 Metafont.\@msgbreak Using \dashedlines instead}%
2971 \dashedlines}}%
2972 % \end{macrocode}
2973 %
2974 % \DescribeMacro{\pointedlines}
2975 % This makes a sort of dotted line, except the dots are actually different
2976 % symbols. It uses the rendering macro \cs{plot} with a parameter cycling
2977 % through 9 different symbols.
2978 % \begin{macrocode}
2979 \newdef\pointedlines{\mfp@local\mfp@linetype0
2980 \mfp@def\mfp@setstyle{\plot{getsymbol \number\mfp@linetype}}}%
2981 % \end{macrocode}
2982 %
2983 % \DescribeMacro{\datapointsonly}
2984 % \cs{datapointsonly} uses symbols like \cs{pointedlines}, but places
2985 % them only at the data points from the file. It uses the rendering macro
2986 % \cs{plotnodes} with a parameter cycling through the same 9 symbols.
2987 % \begin{macrocode}
2988 \newdef\datapointsonly{\mfp@local\mfp@linetype0
2989 \mfp@def\mfp@setstyle{\relax
2990 \plotnodes{getsymbol \number\mfp@linetype}}}%
2991 % \end{macrocode}
2992 %
2993 % \DescribeMacro{\reconfigureplot}
2994 % This command allows the user to set the dashes, colors and symbols used
2995 % by the \cs{plotdata} command. The first argument is the plotting method
2996 % to be changed (\texttt{dashes}, \texttt{colors}, or \texttt{symbols})
2997 % and the second argument is a comma separated list of appropriate type
2998 % variables for \cs{plotdata} to cycle through. For example,
2999 % \cs{reconfigureplot}\marg{dashes} takes a list of dashing patterns
3000 % (previously defined by the \cs{dashpattern} command) separated by
3001 % commas. It writes a command instructing \MF{} to redefine the arrays
3002 % \mfc{dashtype0}, \mfc{dashtype1}, etc., used with \cs{gendashed} when
3003 % \cs{dashedlines} is in effect. The number of patterns is counted by \MF,
3004 % which also handles the mod-ing operation now.
3005 %
3006 % \cs{reconfigureplot}\marg{colors} takes a list of colors (expressions or
3007 % color names previously defined) separated by commas. It redefines
3008 % \gbc{colortype0}, etc., used with \cs{plotdata} when \cs{coloredlines}
3009 % is in effect.
3010 %
3011 % \cs{reconfigureplot}\marg{symbols} takes a list of symbols (\MF{} path
3012 % expressions, one of the symbols available to \cs{plotsymbol}, or path
3013 % names defined by \cs{store}) separated by commas. It redefines
3014 % \gbc{pointtype0}, etc., used by \cs{plotdata} when \cs{pointedlines} or
3015 % \cs{datapointsonly} is in effect.
3016 %
3017 % \DescribeMacro{\defaultplot}
3018 % This restores \mfpic's predefined defaults for dash patterns, colors and
3019 % symbols in \cs{plotdata}. The one argument is one of the words
3020 % \texttt{dashes}, \texttt{colors}, or \texttt{symbols}, indicating which
3021 % plotting method is to be restored.
3022 % \begin{macrocode}
3023 \newdef\reconfigureplot#1{\mfsrc{setdata#1}\mfp@writedata}%
3024 \newdef\defaultplot#1{\mfcmd{default#1}}%
3025 % \end{macrocode}
3026 %
3027 % \DescribeMacro{\mfplinetype}
3028 % The user-level command \cs{mfplinetype} allows the user to set the
3029 % starting value of \cs{mfp@linetype}. The default is to start at $0$.
3030 % \DescribeMacro{\mfplinestyle}
3031 % The macro \cs{mfplinestyle} is an alias for this same command. The names
3032 % `linestyle' and `linetype' come from an analogous system of changing
3033 % rendering in \prog{gnuplot}. (The reason for two names is that
3034 % \prog{gnuplot} documentation was not consistent in its terminology.)
3035 % \begin{macrocode}
3036 \newdef\mfplinetype#1{\mfp@local\mfp@linetype#1\relax}%
3037 \newlet\mfplinestyle\mfplinetype
3038 \mfplinetype{0}%
3039 % \end{macrocode}
3040 %
3041 % \prog{Mfpic} has 6 possible axes, the $x$- and $y$-axes pass through the
3042 % origin, $(0,0)$, the four border axes are at the edges of the graph
3043 % space, possibly offset from it by some amount. These four commands hold
3044 % the amount of that offset in graph units, the default being 0.
3045 % \begin{macrocode}
3046 \newdef\mfp@lshift{0}\newdef\mfp@bshift{0}%
3047 \newdef\mfp@rshift{0}\newdef\mfp@tshift{0}%
3048 % \end{macrocode}
3049 %
3050 % \DescribeMacro{\axismargin}
3051 % The main user-level command for setting the above offsets is
3052 % \cs{axismargin}. Its first argument is one of the letters l, b, r, or t
3053 % to select the axis and the second is the offset in graph units. A
3054 % positive offset represents an inward shift, which is why we call them
3055 % \emph{margins}.
3056 % \DescribeMacro{\setaxismargins}
3057 % The arguments of \cs{setaxismargins} are four offsets for the axes (in
3058 % the above order, which is anticlockwise, starting with the left).
3059 % \DescribeMacro{\setallaxismargins}
3060 % \cs{setallaxismargins} takes one offset and applies it to all axes.
3061 %
3062 % The values are passed on to \MF{} in the variables \gbc{laxis},
3063 % \gbc{baxis}, \gbc{raxis}, and \gbc{taxis}. They are also needed by the
3064 % \cs{axislabels} command so they are saved in macros.
3065 % \begin{macrocode}
3066 \newdef\axismargin#1#2{\setmfnumeric{#1axis}{#2}%
3067 \mfp@local\@namedef{mfp@#1shift}{#2}}%
3068 \newdef\setaxismargins#1#2#3#4{\axismargin l{#1}\axismargin b{#2}%
3069 \axismargin r{#3}\axismargin t{#4}}%
3070 \newdef\setallaxismargins#1{\setaxismargins{#1}{#1}{#1}{#1}}%
3071 % \end{macrocode}
3072 %
3073 % The following converts axis letters to a numeric, making conditionals for
3074 % axes simpler to code (\cs{ifcase} versus six nested \cs{if}\,s).
3075 % Plus we get to define the error message only once. The first argument
3076 % of \cs{mfp@getaxis} is the letter and the third argument is the calling
3077 % command (for the error message). We allow the letter to be instead a word,
3078 % using only the first letter and discarding the rest (\arg2).
3079 % \begin{macrocode}
3080 \def\mfp@axis@x{0}%
3081 \def\mfp@axis@y{1}%
3082 \def\mfp@axis@l{2}%
3083 \def\mfp@axis@b{3}%
3084 \def\mfp@axis@r{4}%
3085 \def\mfp@axis@t{5}%
3086 \def\mfp@getaxis#1#2\mfp@end#3{%
3087 \@ifundefined{mfp@axis@#1}%
3088 {\mfp@errmsg {Invalid axis letter "#1"}%
3089 {The command #3 requires an axis to be designated by one of^^J%
3090 the following letters: x, y, l, b, r, or t. If you proceed, ^^J%
3091 x will be assumed.}\def\mfp@axisnum{0}\def\mfp@axisletter{x}}%
3092 {\edef\mfp@axisnum{\@nameuse{mfp@axis@#1}}\def\mfp@axisletter{#1}}%
3093 \edef\mfp@defaultheadlen{%
3094 \the\ifnum\mfp@axisnum>1 \sideheadlen\else \axisheadlen\fi}}%
3095 % \end{macrocode}
3096 %
3097 % The tick marks (or hash marks) on the axes can be in three possible
3098 % positions: centered on the axes, on one side, or on the other side.
3099 % The default for the $x$- and $y$-axes is centered, for the border axes it
3100 % is inside.
3101 % \DescribeMacro{\setaxismarks}
3102 % For changing this we provide the \cs{setaxismarks} command, whose first
3103 % argument is the axis letter, and whose second argument is one of the
3104 % words \texttt{inside}, \texttt{outside}, \texttt{centered},
3105 % \texttt{ontop}, \texttt{onbottom}, \texttt{onleft}, or \texttt{onright}.
3106 %
3107 % \DescribeMacro{\setxmarks}
3108 % \cs{setxmarks} takes one argument and sets the position for the $x$ axis
3109 % only, while
3110 % \DescribeMacro{\setymarks}
3111 % \cs{setymarks} does the same for the $y$ axis. For the border axes we
3112 % provide
3113 % \DescribeMacro{\setbordermarks}
3114 % \cs{setbordermarks}, which takes four arguments: the positions for the
3115 % left, bottom, right and top axis (in that order).
3116 % \DescribeMacro{\setallbordermarks}
3117 % The abbreviation \cs{setallbordermarks} takes one argument and sets the
3118 % position for all border axis marks to that.
3119 % \begin{macrocode}
3120 \newdef\setaxismarks#1#2{\setmfnumeric{#1tick}{#2}}%
3121 \newdef\setxmarks#1{\setaxismarks x{#1}}%
3122 \newdef\setymarks#1{\setaxismarks y{#1}}%
3123 \newdef\setbordermarks#1#2#3#4{\setaxismarks l{#1}\setaxismarks b{#2}%
3124 \setaxismarks r{#3}\setaxismarks t{#4}}%
3125 \newdef\setallbordermarks#1{\setbordermarks{#1}{#1}{#1}{#1}}%
3126 % \end{macrocode}
3127 %
3128 % The \cs{datafile} and \cs{plotdata} commands originally just created
3129 % polygonal paths, but users requested the ability to draw smooth ones.
3130 % Originally only the commands below (\cs{smoothdata} and
3131 % \cs{unsmoothdata}) were written to do this. Later, these file
3132 % manipulation commands were given optional arguments to achieve the same
3133 % effect, so now the commands below just set the defaults for the optional
3134 % parameter, storing them in the macros \cs{mfp@smoothness} and
3135 % \cs{mfp@tension}. The latter can be used to adjust the tension of the
3136 % \MF{} path if smoothness is `\texttt{s}'.
3137 %
3138 % \DescribeMacro{\smoothdata}
3139 % This takes an option tension argument. It defines \cs{mfp@smoothness} to
3140 % be `\texttt{s}' and \cs{mfp@tension} to be the optional argument.
3141 % Default tension is empty rather than 1 so we can implement a scheme to
3142 % change the actual default used.
3143 % \DescribeMacro{\unsmoothdata}
3144 % The macro \cs{unsmoothdata} defines \cs{mfp@smoothness} to be
3145 % `\texttt{p}' and \cs{mfp@tension} to be empty. The latter might not be
3146 % necessary.
3147 % \begin{macrocode}
3148 \newdef\mfp@smdata#1{\mfp@def\mfp@smoothness{#1}%
3149 \mfp@nullopt{\mfp@def\mfp@tension}}%
3150 \newdef\smoothdata{\mfp@smdata{s}}%
3151 \newdef\unsmoothdata{\mfp@smdata{p}\@empty}%
3152 \unsmoothdata% default
3153 % \end{macrocode}
3154 %
3155 % \DescribeMacro{\using}
3156 % The command \cs{using} is named after a keyword in \prog{gnuplot}. It
3157 % controls which datum is plotted against which by \cs{plotdata} and
3158 % \cs{datafile}.
3159 %
3160 % \DescribeMacro{\usingpairdefault}
3161 % The macro \cs{usingpairdefault} sets the default, which is to read the
3162 % first two space separated words on a line as the $x$ and $y$ coordinate
3163 % of a point. To allow that there might be more data on a line, it is also
3164 % assumed that the second word is followed by a space and the rest of the
3165 % line is read as a third parameter that is not used. In case there are
3166 % only two words, \mfpic{} will always add a space on the end and then the
3167 % third parameter will be empty.
3168 %
3169 % \DescribeMacro{\usingnumericdefault}
3170 % For the occasional command that needs numeric data,
3171 % \cs{usingnumericdefault} sets \cs{using} so that the first
3172 % space-separated word on a line is selected and the remainder of the line
3173 % discarded.
3174 %
3175 % The \cs{parse@data} command reads its argument as delimited
3176 % parameters, and the \cs{using} command tells what those delimiters are.
3177 % For example, in the first part of
3178 % \cs{using}\marg{\#1 \#2 \#3}\marg{(\#1,\#2)}, we are telling
3179 % \cs{parse@data} that everything on a line up to the first space is the
3180 % first parameter, and everything up to the second space is the second
3181 % parameter and the rest of the line is the third parameter. In the second
3182 % part we are telling it that what we write to the output is a pair in
3183 % parentheses with the first two parameters separated by a comma. This
3184 % example is the default as we see here in \cs{usingpairdefault}. This
3185 % command can be issued by a user to return to that default. The user can
3186 % also issue \cs{usingnumericdefault} to write the first word as a single
3187 % numeric for commands like \cs{piechart}.
3188 %
3189 % \DescribeMacro{\mfpdataperline}
3190 % \cs{mfpdataperline} is a user level macro that controls the maximum
3191 % number of points that will be written to a single line in the output.
3192 % \begin{macrocode}
3193 \newdef\using#1#2{\mfp@def\parse@data#1\mfp@end{#2}}%
3194 \newdef\usingpairdefault{\using{##1 ##2 ##3}{(##1,##2)}}%
3195 \newdef\usingnumericdefault{\using{##1 ##2}{##1}}%
3196 \usingpairdefault
3197 \newdef\mfpdataperline{5}%
3198 % \end{macrocode}
3199 %
3200 % The following macros are used internally by \cs{datafile} and
3201 % \cs{plotdata}. A blank line is read as \cs{par} (not the primitive
3202 % \cs{par}, but the literal token \cs{par}, so it tests as equal to
3203 % \cs{mfp@par}. Early versions of \cs{plotdata} wrote a literal \MF{} path
3204 % expression to the output file and \cs{mfp@join} created the \mfc{--}
3205 % between points. Now we write one of the \grafbase{} list-to-path
3206 % commands followed by a comma separated list of points, so \cs{mfp@join}
3207 % has morphed into a comma.
3208 % \begin{macrocode}
3209 \newdef\mfp@par{\par}\newdef\mfp@join{,}%
3210 % \end{macrocode}
3211 %
3212 % \DescribeMacro{\mfpdatacomment}
3213 % The user can change the comment character for data files with
3214 % something like \cs{mfpdatacomment}\marg{\cs{\#}}. This also changes the
3215 % percent character to category `other'. We can also use the percent sign
3216 % as part of the numeric data by placing
3217 % \DescribeMacro{\makepercentother}
3218 % \cs{makepercentother} before the \cs{using} command to turn `\texttt\%'
3219 % into an ordinary character.
3220 % \DescribeMacro{\makepercentcomment}
3221 % \cs{makepercentcomment} returns it to its usual role as a comment. Every
3222 % file reading command issues \cs{mfp@setcomment} before reading. The
3223 % count register \cs{mfp@commentchar} holds the ASCII code of the current
3224 % comment character, the default being the percent sign.
3225 % \begin{macrocode}
3226 \newcount\mfp@commentchar \mfp@commentchar`\%%
3227 \newdef\makepercentother{\@makeother\%}%
3228 \newdef\makepercentcomment{\catcode`\%14 }%
3229 \newdef\mfpdatacomment#1{\mfp@local\mfp@commentchar`#1}%
3230 \newdef\mfp@setcomment{\makepercentother\catcode\mfp@commentchar14 }%
3231 % \end{macrocode}
3232 %
3233 % \DescribeMacro{\fdef}
3234 % The following is for defining functions to be used in \cs{function}
3235 % through \cs{plrregion}. The first argument is the name of the function,
3236 % the second is its variable, the last is the \MF{} code. Obviously its
3237 % use requires a knowledge of the \MF{} language. The function produced is
3238 % a \mfc{vardef}, and can contain almost arbitrary \MF{} code, but must
3239 % end with an expression. Normally it must be a numerical expression, to
3240 % be use in \cs{function}, or a pair expression so it can be used alone in
3241 % the last argument of \cs{parafcn}.
3242 %
3243 % We apply \cs{@makeother} to \arg{} so it doesn't get doubled. The
3244 % \arg{} is frequent in vardefs among the \MF{} gurus.
3245 % \begin{macrocode}
3246 \newdef\fdef{\begingroup\@makeother\#\mfp@keeplines\mfp@fdef}%
3247 \newdef\mfp@fdef#1#2#3{\mfcmd{\@nl save #1;\@nl
3248 vardef #1 (expr #2) = \@nl #3\@nl enddef}\endgroup}%
3249 % \end{macrocode}
3250 %
3251 % The following is executed right after \cs{mfp@grafmacs}. It is a hook
3252 % for adding new definitions inside and \env{mfpic} environment. It is
3253 % initialized to empty, and add-on packages can add to it.
3254 % \begin{macrocode}
3255 \newdef\mfp@additions{}%
3256 % \end{macrocode}
3257 %
3258 %
3259 %
3260 % \section{The user level graphics macros}
3261 %
3262 % This is the start of the definition of \cs{mfp@grafmacs}. It contains
3263 % the definition of every user command that has no purpose outside an
3264 % \env{mfpic} environment. It will be expanded inside every \env{mfpic}
3265 % environment, localizing all these definitions. We do this so we can
3266 % avoid name clashes without giving them all names beginning with \cs{mfp}.
3267 % \begin{macrocode}
3268 \newdef\mfp@grafmacs{%
3269 % \end{macrocode}
3270 %
3271 %
3272 % \subsection{Figure macros}\label{figure}
3273 %
3274 % These are the figure macros. These are implemented as \MF{} paths that
3275 % can be variously rendered, transformed, etc., by the prefix macros of
3276 % subsection~\ref{prefixcommands}.
3277 %
3278 % Most of the \mfpic{} graphic commands take optional arguments. Most of
3279 % them follow the scheme \cs{mfp@command} takes mandatory arguments
3280 % enclosed in braces, and does the work. \cs{command} is simply defined to
3281 % test for an optional argument (with \cs{mfp@defaultopt}) and pass it or a
3282 % default to \cs{mfp@command}. A typical example is \cs{ellipse} defined
3283 % to be \verb$\mfp@defaultopt\mfp@ellipse0$. In some cases, the default
3284 % option is signaled by passing an empty argument via \cs{mfp@nullopt}.
3285 %
3286 % Of the commands that have no optional argument, most simply write
3287 % the appropriate commands to the output file, and require no
3288 % \cs{mfp@} version.
3289 %
3290 % This section contains a description of the behavior of each command and
3291 % its syntax in use. For those that call an \cs{mfp@} version, the
3292 % implementation is in the next section.
3293 %
3294 %
3295 % \subsubsection{Common geometric objects}\label{geometric}
3296 %
3297 % The first few (\cs{rect} through \cs{sector}) are closed paths and
3298 % need not be prefixed with a closing macro before filling, etc.
3299 %
3300 % \DescribeMacro{\rect}
3301 % This takes one mandatory argument, the two diagonally opposite
3302 % corners of the rectangle separated by a comma, and draws the rectangle
3303 % with horizontal and vertical sides having these as two corners. The
3304 % direction of the path (which seldom makes a difference) is such that it
3305 % starts at the first specified point and moves horizontally first.
3306 %
3307 % This is an example of a command that requires no further processing.
3308 % The \cs{mfp@figmac} command sets the appropriate switches and writes its
3309 % argument to the output file, followed by a semicolon.
3310 % \begin{macrocode}
3311 \newdef\rect##1{\mfp@figmac{rect (##1)}}%
3312 % \end{macrocode}
3313 %
3314 % \DescribeMacro{\regpolygon}
3315 % There are four arguments. The first is the number of sides. The second
3316 % is the name of a variable to represent the vertices. The other
3317 % two should be equations locating two vertices or the center and one
3318 % vertex. If the name used is \gbc{Ver}, then the vertices will be
3319 % \gbc{Ver1}, \gbc{Ver2}, etc., numbering anticlockwise. The center is
3320 % \gbc{Ver0}. Case is significant. After the command, the points can be
3321 % referred to in other \mfpic{} commands (except text label commands
3322 % when \opt{mplabels} is not in effect).
3323 % \begin{macrocode}
3324 \newdef\regpolygon##1##2##3##4{%
3325 \mfp@figmac{regularpolygon (##1) (##2) (##3; ##4;)}}%
3326 % \end{macrocode}
3327 %
3328 % \DescribeMacro{\circle}
3329 % This has one optional argument containing one of the letters
3330 % \texttt{t}, \texttt{p} (the default), \texttt{c}, \texttt{s},
3331 % \texttt{r}, or \texttt{q}. Its purpose is to specify what kind of data
3332 % is in the single mandatory argument. These are a subset of the optional
3333 % arguments that the \cs{arc} commad (below) takes, and have almost the
3334 % same meaning:
3335 % \begin{itemize}
3336 % \item \oarg{t}, the three point form needs three points (of course).
3337 % \item \oarg{p}, the polar form needs the center point and the radius.
3338 % This is the default when the optional argument is absent.
3339 % \item \oarg{c}, the center/point form needs the center and one point on
3340 % the circle.
3341 % \item \oarg{s}, the point-sweep form requires two points and the angle of
3342 % arc between them. The angle may be positive or negative. A
3343 % positive angle indicates the number of degrees anticlockwise from
3344 % the first point to the second. Negative means clockwise.
3345 % \item \oarg{r}, the point-radius form requires two points and the
3346 % radius of the circle. Of the two possible circles, it produces the
3347 % one where the anticlockwise arc from the first point to the second
3348 % is not more than 180 degrees.
3349 % \item \oarg{q}, an alternative point-radius with the same parameters.
3350 % It produces the circle
3351 % where the anticlockwise arc from the first point to the second
3352 % is not less than 180 degrees.
3353 % \end{itemize}
3354 %
3355 % Supplying \cs{arc} with the same parameters, or the appropriate superset
3356 % in the case of \oarg{p} and \oarg{c}, would produce a sub-arc of the
3357 % circle that \cs{circle} produces. This is the reason for giving
3358 % \cs{circle} these options: to make diagrams which show a circle and an
3359 % arc on it.
3360 %
3361 % We use \cs{def} instead of \cs{newdef} because we know \LaTeX{} has
3362 % already defined a \cs{circle} command. We now use the same command,
3363 % \cs{mfp@arccircle}, for arcs and circles, setting a switch to tell it
3364 % which to produce.
3365 % \begin{macrocode}
3366 \def\circle{\mfp@switchfalse\mfp@defaultopt\mfp@arccircle{p}}%
3367 % \end{macrocode}
3368 %
3369 % \DescribeMacro{\ellipse}
3370 % \cs{ellipse} has one optional argument, an angle of rotation and one
3371 % mandatory argument, containing the center, the horizontal and vertical
3372 % radii (before rotation), separated by commas.
3373 % \begin{macrocode}
3374 \newdef\ellipse{\mfp@defaultopt\mfp@ellipse{0}}%
3375 % \end{macrocode}
3376 %
3377 % \DescribeMacro{\quarterellipse}
3378 % \DescribeMacro{\halfellipse}
3379 % \DescribeMacro{\fullellipse}
3380 % The next three commands simply call \grafbase{} commands of the same
3381 % name. They draw part or all of an ellipse inscribed in a parallelogram.
3382 % Each requires for its argument three points, separated by commas. For
3383 % \cs{quarterellipse} these points are, respectively, the midpoint of one
3384 % side of a parallelogram, a corner point on that side, and the midpoint
3385 % of the side adjacent to the first at that corner. For \cs{halfellipse}
3386 % they are the midpoints of three successive sides. For \cs{fullellipse}
3387 % they are the center and the midpoints of two adjacent sides. They are
3388 % all simple figmacs with no optional arguments and no star forms.
3389 %
3390 % It would be possible to give all of them the same three arguments,
3391 % for example those of \cs{fullellipse}, but I wanted to put the
3392 % endpoints of the paths into the argument list. The reason
3393 % \cs{quarterellipse} is passed the corner point instead of the center is
3394 % because of the intended use: rounding off an asymmetric corner without
3395 % having to compute the center of the parallelogram.
3396 % \begin{macrocode}
3397 \newdef\quarterellipse##1{\mfp@figmac{quarterellipse (##1)}}%
3398 \newdef\halfellipse##1{\mfp@figmac{halfellipse (##1)}}%
3399 \newdef\fullellipse##1{\mfp@figmac{fullellipse (##1)}}%
3400 % \end{macrocode}
3401 %
3402 % \DescribeMacro{\sector}
3403 % This is the closed curve starting at the center of a circle, out
3404 % along a radius to the circumference of the circle, along an arc of the
3405 % circle, then back to the center. It has one mandatory argument
3406 % containing the center, the radius, and the two angles, separated by
3407 % commas.
3408 % \begin{macrocode}
3409 \newdef\sector##1{\mfp@figmac{sector (##1)}}%
3410 % \end{macrocode}
3411 %
3412 % \DescribeMacro{\arc}
3413 % We have seven (actually 14) ways to specify a circular arc. \cs{arc}
3414 % takes an optional argument: a letter to indicate which of the 7
3415 % specifications. It has one mandatory argument containing the data for
3416 % that specification, separated by commas. It also has a star-form,
3417 % which produces the complementary arc. That is, instead of the arc that
3418 % is specified (as described below) it produces the rest of the circle
3419 % from the end of the specified arc to its start.
3420 %
3421 % The available letters and the corresponding required data are listed
3422 % below. The default optional argument is \oarg{s}.
3423 % \begin{itemize}
3424 % \item \oarg{t}, the three point form needs three ordered pairs.
3425 % \item \oarg{p}, the polar form needs the center point, two angles and
3426 % the radius (in that order).
3427 % \item \oarg{a}, the alternative polar form needs the center, the radius
3428 % and two angles (in that order).
3429 % \item \oarg{c}, the center-point-sweep form needs the center, the
3430 % starting point, and the angle.
3431 % \item \oarg{s}, the points-sweep form requires the starting point, the
3432 % ending point and the angle.
3433 % \item \oarg{r}, the points-radius form requires the starting point, the
3434 % ending point and the radius of the arc. There are two circles with
3435 % the given radius that pass through the given points, and hence
3436 % four possible arcs. One arc on each circle is anticlockwise from
3437 % the first point to the second. Of those two arcs, only one is
3438 % less than $180$ degrees. That one is produced.
3439 % \item \oarg{q} Same as \oarg{r}, except the arc is the larger of two
3440 % anticlockwise arcs.
3441 % \end{itemize}
3442 % \begin{macrocode}
3443 \newdef\arc{\mfp@iftoken*{\arccomplement\mfp@arc}{\mfp@arc}}%
3444 % \end{macrocode}
3445 %
3446 % \DescribeMacro{\pshcircle}
3447 % This final circle is for us complex function theorists. It makes a
3448 % `pseudohyperbolic circle'. This requires a point $z$ inside the circle
3449 % with center $(0,0)$ and radius $1$, and a radius $R < 1$. It produces
3450 % a circle with $R$ as its pseudohyperbolic radius and $z$ as its
3451 % pseudohyperbolic center. The star form switches contexts to the upper
3452 % half-plane.
3453 % \begin{macrocode}
3454 \newdef\pshcircle{\mfp@ifstar\mfp@pshcircle\mfp@F\mfp@T}%
3455 % \end{macrocode}
3456 %
3457 % \DescribeMacro{\hypergeodesic}
3458 % And this final arc is also for we complex function theorists. It makes a
3459 % `hyperbolic geodesic'. This requires two points $z$ and $w$ inside the
3460 % circle $T$ with center $(0,0)$ and radius $1$. It produces a circular arc
3461 % from the first point to the second on the unique circle that passes
3462 % through these two points and meets $T$ at right angles. The star form
3463 % switches contexts to the upper half-plane.
3464 % \begin{macrocode}
3465 \newdef\hypergeodesic{\mfp@ifstar\mfp@hypergeodesic{UHP}{UD}}%
3466 % \end{macrocode}
3467 %
3468 %
3469 % \subsubsection{List macros}\label{list}
3470 %
3471 % The figure macros of this section are all list macros. They produce a
3472 % path from a list of ordered pairs. The list can be explicitly given as a
3473 % mandatory argument containing a comma-separated list of pair
3474 % expressions, or it can be taken from an external datafile. This is true
3475 % for \cs{polyline} through \cs{turtle}. These macros differ only in how
3476 % the data determine the path. (Some of the splines don't connect given
3477 % points, but rather use the points in a different way to determine a
3478 % curve.) The list of pairs is not an argument of any of these. It should
3479 % follow, and is ultimately written to output by the ending code of
3480 % \cs{mfp@listmac}. This is basic to list macros, and will not be repeated
3481 % for each one.
3482 %
3483 % Commands in this section are grouped by the argument structure of the
3484 % command written to the output file. The first twelve come in pairs
3485 % that are distinguished by a boolean parameter, which usually determines
3486 % whether the path produced is closed, followed by the list.
3487 %
3488 % \DescribeMacro{\polyline}
3489 % The most basic, a polyline or polygonal path, \cs{polyline} draws line
3490 % segments from each point to the next.
3491 % \DescribeMacro{\lines}
3492 % \cs{lines} is an alias.
3493 %
3494 % \DescribeMacro{\closedpolyline}
3495 % The macro \cs{closedpolyline} does the same, except it produces a closed
3496 % path, connecting the last point to the first.
3497 % \DescribeMacro{polygon}
3498 % \cs{polygon} is an alias.
3499 %
3500 % \DescribeMacro{\computedspline}
3501 % The \cs{computedspline} command takes a list of points and computes the
3502 % controls of a cubic spline that connects the points. Adjacent segments
3503 % have matching first and second derivatives at the common endpoint. It is
3504 % limited to what is called a \emph{relaxed} spline, which has zero
3505 % curvature at the beginning and ending points.
3506 %
3507 % \DescribeMacro{\closedcomputedspline}
3508 % This is similar, but computes the unique \emph{closed} cubic spline that
3509 % connects a list of points.
3510 %
3511 % The next four commands also produce types of splines. The list of pairs
3512 % is not, however, the points passed through but rather are control points,
3513 % of a sort.
3514 %
3515 % \DescribeMacro{\qspline}
3516 % This produces quadratic splines. The points create the path as follows:
3517 % for successive points $p\sb i, p\sb {i+1}$ in the list, the path passes
3518 % through the midpoint of the line segment connecting $p\sb i$ and
3519 % $p\sb {i+1}$, tangent to that line segment. This causes adjacent
3520 % B\'ezier segments to have matching derivatives at their common
3521 % endpoint. Each three successive data points determines one segment of
3522 % the path.
3523 %
3524 % \DescribeMacro{\closedqspline}
3525 % The closed variant works by creating two additional segments, viewing
3526 % the triples $p\sb{n-1}, p\sb{n}, p\sb1$ and $p\sb{n}, p\sb1, p\sb2$ as
3527 % being `successive'.
3528 %
3529 % \DescribeMacro{\cspline}
3530 % The macro \cs{cspline} produces cubic splines. The points determine the
3531 % curve as follows: for successive points $p\sb i, p\sb {i+1}$ in the
3532 % list, the line segment connecting them is divided into thirds with two
3533 % points $q\sb i$ and $q\sb i'$. The curve then passes through the
3534 % midpoint of the segment from $q\sb {i-1}'$ to $q\sb i$ and tangent to
3535 % that segment. This causes adjacent B\'ezier segments to have matching
3536 % first and second derivatives at their common endpoint. Each four
3537 % successive data points determines one segment of the path.
3538 %
3539 % \DescribeMacro{\closedcspline}
3540 % The closed variant works by viewing the first point as a succesor of the
3541 % last point, creating three additional path segments.
3542 %
3543 % \DescribeMacro{\qbeziers}
3544 % This produces the equivalent of a sequence of \LaTeX{} \cs{qbezier}
3545 % commands. The mandatory argument will be a list of points alternating
3546 % between nodes and control points, ending with the last node.
3547 % \DescribeMacro{\closedqbeziers}
3548 % The closed version ends with the control point between the last node and
3549 % the first. Therefore, the \cs{qbeziers} command needs an odd number of
3550 % points in the list, while \cs{closedqbeziers} needs an even number. If
3551 % this is not the case, the last point in the list is repeated, causing
3552 % the final segment to be a straight line (closed case) or trivial.
3553 %
3554 % Note that quadratic B\'eziers need not be smooth at the nodes unless
3555 % the control points line up. Our plural name distinguishes it from the
3556 % \LaTeX{} command.
3557 %
3558 % \DescribeMacro{\cbeziers}
3559 % Like the above, except it produces a cubic B\'ezier. It requires a
3560 % list of $3n+1$ points in the pattern node-control-control, ending with
3561 % an extra node.
3562 % \DescribeMacro{closedcbeziers}
3563 % The closed version requires only $3n$ points, taking the first for the
3564 % final node.
3565 %
3566 % \DescribeMacro{\fcnspline}
3567 % The above splines are two dimensional splines, that is, functions of
3568 % $t$ with pair values $(x,y)$. One dimensional splines are functions of
3569 % $x$ with numeric values $y$. This command produces the \emph{graph} of
3570 % such a function computed from a supplied list of points. It is required
3571 % that the $x$-values of the points are in increasing order, although it
3572 % will produce some sort of curve as long as adjacet $x$-values are
3573 % distinct. It produces the graph of a \emph{relaxed} spline, in the sense
3574 % that the second derivative $d^2y/dx^2$ is zero at the beginning and end.
3575 %
3576 % \DescribeMacro{\periodicfcnspline}
3577 % This is the same, but instead of requiring the second derivative to be
3578 % zero at both ends, it produces a graph such that the first and second
3579 % derivatives at the end match the ones at the beginning. If a copy of the
3580 % graph is placed with its starting point at the original graph's ending
3581 % point, then there is a smooth join. If the $y$-values of the
3582 % beginning and ending points match, a periodic graph is obtained. For
3583 % these last two commands the paths cannot be closed, and the boolean
3584 % determines the behavior at the endpoints.
3585 %
3586 % The command \cs{mfp@listi} that implements these writes the command
3587 % name and the argument and ends with code to write the list of pairs.
3588 % \begin{macrocode}
3589 \newdef\lines{\mfp@listi{polyline}\mfp@F}%
3590 \newdef\polygon{\mfp@listi{polyline}\mfp@T}%
3591 \newdef\computedspline{\mfp@listi{dospline}\mfp@F}%
3592 \newdef\closedcomputedspline{\mfp@listi{dospline}\mfp@T}%
3593 \newdef\qspline{\mfp@listi{qspline}\mfp@F}%
3594 \newdef\closedqspline{\mfp@listi{qspline}\mfp@T}%
3595 \newdef\cspline{\mfp@listi{cspline}\mfp@F}%
3596 \newdef\closedcspline{\mfp@listi{cspline}\mfp@T}%
3597 \newdef\qbeziers{\mfp@listi{qbezier}\mfp@F}%
3598 \newdef\closedqbeziers{\mfp@listi{qbezier}\mfp@T}%
3599 \newdef\cbeziers{\mfp@listi{cbezier}\mfp@F}%
3600 \newdef\closedcbeziers{\mfp@listi{cbezier}\mfp@T}%
3601 \newdef\fcnspline{\mfp@listi{fcnspline}\mfp@F}%
3602 \newdef\periodicfcnspline{\mfp@listi{fcnspline}\mfp@T}%
3603 \newlet\closedpolyline\polygon
3604 \newlet\polyline\lines
3605 % \end{macrocode}
3606 %
3607 % The next six macros have an optional argument called `tension', a
3608 % numerical value that controls how tightly the path turns at each point
3609 % in the list. If the optional argument is absent (or empty), the
3610 % \grafbase{} command that is written takes only a boolean argument
3611 % (closed or not closed) followed by the list of points. If the tension
3612 % argument is present, a different command is written that also has a tension
3613 % argument. The command name is almost the same, but has a `\gbc{t}'
3614 % prepended. The default tension is the \cs{grafbase}{} variable
3615 % \gbc{default_tension}, set with \cs{settension}, initialized to 1.
3616 % Tension of 0 is ignored (ultimately tension is divided by) and may
3617 % produce error messages from \MF{}.
3618 %
3619 % \DescribeMacro{\curve}
3620 % \cs{curve} draws a smooth curve connecting a list of points. it arranges
3621 % for the curve, at point $p\sb n$ to be traveling parallel to the direction
3622 % from $p\sb {n-1}$ to $p\sb {n+1}$ (except at the first and last point).
3623 %
3624 % \DescribeMacro{\closedcurve}
3625 % The closed version \cs{closedcurve} treats the
3626 % first point and last point the same as the rest. It has the alias
3627 % \DescribeMacro{\cyclic}
3628 % \cs{cyclic}.
3629 %
3630 % \DescribeMacro{\convexcurve}
3631 % This convex version produces a smooth curve that is convex in those
3632 % places where \cs{polyline} (with the same list of points) would produce
3633 % a convex shape.
3634 % \DescribeMacro{\closedconvexcurve}
3635 % It also comes in a closed version, with the alias
3636 % \DescribeMacro{\convexcyclic}
3637 % \cs{convexcyclic}.
3638 %
3639 % \DescribeMacro{\mfbezier}
3640 % This produces the standard \MF{} cubic B\'ezier using the \MF{} path
3641 % join operator (\mfc{..}) with tension given by an optional argument.
3642 % \DescribeMacro{\closedmfbezier}
3643 % The closed version connects the last point to the first in the same way.
3644 %
3645 % The command \cs{mfp@curve} examines the optional argument and writes
3646 % the command name (first argument, possibly modified) with the
3647 % appropriate arguments (the boolean or tension plus boolean).
3648 % \begin{macrocode}
3649 \newdef\curve{\mfp@curve{curve}\mfp@F}%
3650 \newdef\cyclic{\mfp@curve{curve}\mfp@T}%
3651 \newdef\convexcurve{\mfp@curve{ccurve}\mfp@F}%
3652 \newdef\convexcyclic{\mfp@curve{ccurve}\mfp@T}%
3653 \newdef\mfbezier{\mfp@curve{bezier}\mfp@F}%
3654 \newdef\closedmfbezier{\mfp@curve{bezier}\mfp@T}%
3655 \newlet\closedcurve\cyclic
3656 \newlet\closedconvexcurve\convexcyclic
3657 % \end{macrocode}
3658 %
3659 % \DescribeMacro{\fcncurve}
3660 % A `function curve' is the graph of a function of $x$. It should always
3661 % travel left to right. This is not guaranteed by the \cs{curve} macro,
3662 % above, even if the $x$ coordinates are listed in order. \cs{fcncurve} is
3663 % guaranteed to do this if the list of points has the $x$ coordinates so
3664 % ordered.
3665 %
3666 % While the optional argument is called tension, it is not quite the
3667 % same as the tension argument to \cs{curve}, but it has a similar effect.
3668 % The default value is the sane as for \cs{curve}. The above guarantee is
3669 % voided if the value used is ${}\le1/3$.
3670 % \begin{macrocode}
3671 \newdef\fcncurve{\mfp@nullopt\mfp@fcncurve}%
3672 % \end{macrocode}
3673 %
3674 % \DescribeMacro{\turtle}
3675 % Many years ago there was a tool for teaching programming concepts to
3676 % young children. They could draw a figure on a screen by programming a
3677 % `turtle' with a sequence of turns and distances. The following is
3678 % similar. It has a mandatory argument containing a list of ordered pairs.
3679 % The first is the coordinates of the starting point, and each of the rest
3680 % is interpreted as a displacement from the current position, along which
3681 % a line segment is to be drawn. The terminal point of that segment is the
3682 % new current position
3683 % \begin{macrocode}
3684 \newdef\turtle{\mfp@listmac{turtle}}%
3685 % \end{macrocode}
3686 %
3687 %
3688 % \subsubsection{Graphing functions}\label{functions}
3689 %
3690 % \DescribeMacro{\function}
3691 % \prog{Mfpic} provides the ability to plot the graph of any function that
3692 % can be defined in \MF. This is done with the \cs{function} command, a
3693 % figure macro which takes one optional parameter that selects
3694 % the smoothness of the \MF{} path produced. It can be \oarg{p}, which
3695 % draws a polyline path through selected points (much like \cs{polyline}),
3696 % or \oarg{s\meta{tension}} which selects a smooth path (much like
3697 % \cs{curve}\oarg{\meta{tension}}). The tension may be omitted and then
3698 % will be 1 (or the value set by \cs{settension}). The default optional
3699 % argument is \oarg{s}, a smooth curve with the default tension.
3700 %
3701 % There are two mandatory arguments. The second is the function, which
3702 % must be written as a formula (strictly speaking, a \MF{} numerical
3703 % expression) containing only one variable, \texttt{x}. The first
3704 % mandatory argument contains three numbers separated by commas. They are,
3705 % in order, the starting value of \texttt{x}, the ending value, and the
3706 % step size.
3707 %
3708 % \DescribeMacro{\parafcn}
3709 % \cs{parafcn} is similar, except its formula must be an ordered pair of
3710 % formulas (strictly speaking, a \MF{} pair expression) in which
3711 % \texttt{t} is the only variable.
3712 %
3713 % \DescribeMacro{\plrfcn}
3714 % \cs{plrfcn} is similar, except its argument is a formula (a \MF{}
3715 % numeric expression) representing the radius, in which \texttt{t} is the
3716 % only variable, interpreted as the angle coordinate, $\theta$, in degrees.
3717 %
3718 % These three commands are so alike that they call the same macro
3719 % with the name to be written as the first argument and the default
3720 % optional argument as the second. The latter is so that we can reuse it
3721 % for two other commands where the default is different.
3722 % \begin{macrocode}
3723 \newdef\function{\mfp@fcn{function}s}%
3724 \newdef\parafcn{\mfp@fcn{parafcn}s}%
3725 \newdef\plrfcn{\mfp@fcn{plrfcn}s}%
3726 % \end{macrocode}
3727 %
3728 % \DescribeMacro{\btwnfcn}
3729 % The region between two functions \cs{btwnfcn} is a figure macro. It is
3730 % mostly intended for shading or other filling operations so it is already
3731 % closed and, by default, it is not `smooth'. Its parameters are the
3732 % same as those of \cs{function} (above), with two exceptions: the default
3733 % optional argument is \oarg{p} and it has an additional mandatory
3734 % argument, the other function. The resulting \MF{} path travels along the
3735 % graph of the first function from the starting $x$ to the ending $x$,
3736 % thence vertically to the graph of the second function, along it (in
3737 % reverse) to the starting $x$ and finally, vertically to the start of the
3738 % first function's graph.
3739 %
3740 % \DescribeMacro{\btwnplrfcn}
3741 % We also have the polar function version, where the two function
3742 % arguments are as in \cs{plrfcn}. The default option is also \oarg{p}.
3743 % As with \cs{function}, these are implemented by calling a common
3744 % command with the basename of the \grafbase{} command as argument.
3745 %
3746 % \DescribeMacro{\plrregion}
3747 % This is like \cs{btwnplrfcn} with 0 as the first function, but it
3748 % is more efficient. It takes only the other function as an argument.
3749 % Again, the default option is \oarg{p}.
3750 %
3751 % \DescribeMacro{\belowfcn}
3752 % This is like \cs{btwnfcn} with 0 as the first function, but it
3753 % is more efficient. It takes only the other function as an argument.
3754 % The default option is \oarg{p}.
3755 % \begin{macrocode}
3756 \newdef\btwnfcn{\mfp@btwn{btwnfcn}}%
3757 \newdef\btwnplrfcn{\mfp@btwn{btwnplrfcn}}%
3758 \newdef\belowfcn{\mfp@fcn{belowfcn}p}%
3759 \newdef\plrregion{\mfp@fcn{plrregion}p}%
3760 % \end{macrocode}
3761 %
3762 % \DescribeMacro{\levelcurve}
3763 % One way to graph a function of two variables is to draw level curves.
3764 % The figure macro \cs{levelcurve} takes an optional smoothness
3765 % argument (\texttt{[s\meta{tension}]} or \texttt{[p]} with \texttt{p}
3766 % being the default), and two mandatory arguments. The first
3767 % mandatory argument is a `seed' point which is known to lie inside the
3768 % level curve, followed by a comma and a step size. The second is an
3769 % inequality between the function and the level value that is true inside
3770 % the level curve. Strictly speaking, the last argument can be any \MF{}
3771 % boolean valued expression with variables \mfc{x} and \mfc{y}. The simple
3772 % example,\\
3773 % \indent\verb$\levelcurve[p]{(0,0),0.1}{x*x + y*y < 3}$\\
3774 % will draw approximately the circle with radius $\sqrt3$ as a sequence of
3775 % line segments with length $0.1$. That will require about 109 segments.
3776 % Its parameters are similar enough to those of \cs{function} that we
3777 % can use the same interface.
3778 % \begin{macrocode}
3779 \def\levelcurve{\mfp@fcn{levelset}p}%
3780 % \end{macrocode}
3781 %
3782 % We now define two macros for depicting the solution of an
3783 % ordinary differential equation. The first of these, \cs{DEgraph},
3784 % produces the graph of the solution for equations of the form
3785 % $$
3786 % \frac{dy}{dx} = f(x,y),\quad y(x\sb0) = y\sb0.
3787 % $$
3788 % The data required are the \emph{initial values} (the two numbers $x\sb0$
3789 % and $y\sb0$), the formula $f(x,y)$ (an explicit \MF{} numerical
3790 % expression with literal variables \mfc{x} and \mfc{y} as the only
3791 % unknowns. Since \MF{} can only handle paths connecting discrete points,
3792 % also required is a step size which, roughly speaking, is the distance
3793 % between points in graph coordinates, and the number of steps $N$ to use.
3794 % The \MF{} macros then calculate $N$ additional points (the first is
3795 % $(x\sb0,y\sb0)$) and join them together to produce the graph.
3796 %
3797 % The second macro, \cs{DEtrajectory}, draws the trajectory of a
3798 % two-dimentional differential equation of the form
3799 % $$
3800 % \left( \frac{dx}{dt}, \frac{dy}{dt}\right) = (f(x,y,t),g(x,y,t)\,,
3801 % \quad (x(0),y(0)) = (x\sb0,y\sb0)
3802 % $$
3803 % This is not, strictly speaking, a \emph{graph} since that would
3804 % require three dimensions to indicate the relation between $x$, $y$, and
3805 % $t$. Mathematicians call it a trajectory, and it only shows the
3806 % two-dimensional path followed by the moving object. The required data
3807 % are an initial point $(x\sb0,y\sb0)$, the formula for the right-hand side
3808 % (an explicit \MF{} pair-valued expression or a pair of numerical
3809 % expressions in parentheses, with literal variables \mfc{x}, \mfc{y} and
3810 % \mfc{t} as the only unknowns. Also required are a step size and the
3811 % number of steps, as in \cs{DEgraph}.
3812 %
3813 % The method used to calculate the points to connect is a modified version
3814 % of the four-step Runge-Kutta method. The modifications are intended to
3815 % avoid numerical overflow. That is, infinite blow-up in finite time. An
3816 % example is the simple equation
3817 % $$
3818 % \frac{dy}{dx} = y^2 \quad y(0) = 1,
3819 % $$
3820 % whose solution is $y = 1/(1-x)$. The usual definition of
3821 % Runge-Kutta-IV would have one process equally spaced $x$-values. If a
3822 % user had no idea of the character of the solution, and asked for $N$
3823 % $x$-values with separation $h$ to get a graph on $0\le x \le Nh$, and if
3824 % $Nh > 1$, then the result would be either quite different from the actual
3825 % solution (especially around $x=1$), or would reach a point of numerical
3826 % overflow.
3827 %
3828 % Thus our macros require the user to supply a parameter that will be
3829 % interpreted as a distance step: if $h$ is this parameter, instead of
3830 % finding values of $y$ at $x\sb0$, $x\sb{0+h}$, $x\sb{0+2h}$, etc., it
3831 % finds points $(x\sb{n},y\sb{n})$ on the graph so that the
3832 % two-dimensional distance from $(x\sb0,y\sb0)$ to $(x\sb1,y\sb1)$ is $h$,
3833 % then the distance from $(x\sb1,y\sb1)$ to $(x\sb2,y\sb2)$ is also $h$,
3834 % etc. The resulting graph therefore simply follow the graph of $y =
3835 % 1/(1-x)$ a distance roughly $Nh$ and numerical overflow is impossible
3836 % unless the value of $Nh$ exceeds \MF{}'s size limits. There is an
3837 % optional smoothness parameter as in \cs{function}.
3838 % \begin{macrocode}
3839 \newdef\DEgraph{\mfp@fcn{odeRKIV}s}%
3840 \newdef\DEtrajectory{\mfp@fcn{xyRKIV}s}%
3841 % \end{macrocode}
3842 %
3843 % \DescribeMacro{\brownianmotion}
3844 % Used by me once to ilustrate Brownian motion. The argument consists of
3845 % a starting point, the number of steps, and a scale factor, separated
3846 % by commas. It draws a polyline starting with the starting point moving
3847 % in a random direction a random distance, then repeating that from the
3848 % new point, etc., for the number of steps given. The size of each step is
3849 % random, but the scale factor gives the average size.
3850 %
3851 % \DescribeMacro{\browniangraph}
3852 % This approximates the graph of one-dimensional Brownian motion. The
3853 % argument consists of the number of steps and a scale factor/step size,
3854 % separated by commas. It draws a polyline starting at $(0,0)$, moving
3855 % right by the step size and up or down (randomly chosen) by a random
3856 % amount, then repeating that from the new point, etc., for the number of
3857 % steps given.
3858 %
3859 % \DescribeMacro{\randomwalk}
3860 % This is a two dimensional random walk. The argument consists of a
3861 % starting point, the number of steps, and a distance, separated by
3862 % commas. Like \cs{brownianmotion}, it draws a polyline starting at the
3863 % starting point, moving in a random direction, but for this command it
3864 % always moves a fixed distance.
3865 % \begin{macrocode}
3866 \newdef\brownianmotion##1{\mfp@figmac{brownianpath (##1)}}%
3867 \newdef\browniangraph##1{\mfp@figmac{browniangraph (##1)}}%
3868 \newdef\randomwalk##1{\mfp@figmac{randomwalk(##1)}}%
3869 % \end{macrocode}
3870 %
3871 %
3872 % \subsection{Plotting data from files}\label{datafiles}
3873 %
3874 % \DescribeMacro{\plotdata}
3875 % The optional parameter is the smoothness, which may be
3876 % \oarg{s\meta{tension}} for a smooth path or \oarg{p} for a polygonal
3877 % path, or empty to select the default. The default is \oarg{p} when
3878 % \mfpic{} is loaded, but can be changed with \cs{smoothdata} and restored
3879 % with \cs{unsmoothdata}.
3880 % \begin{macrocode}
3881 \newdef\plotdata{\mfp@nullopt\mfp@plotdata}%
3882 % \end{macrocode}
3883 %
3884 % \DescribeMacro{\datafile}
3885 % \cs{datafile} defines a path connecting the points in a datafile. It has
3886 % an optional parameter for the smoothness, as in \cs{plotdata}.
3887 % \begin{macrocode}
3888 \newdef\datafile{\mfp@nullopt\mfp@datafile}%
3889 % \end{macrocode}
3890 %
3891 %
3892 % \subsection{The prefix commands}\label{prefixcommands}
3893 %
3894 %
3895 % \subsubsection{Storing and reusing a figure}\label{storing}
3896 %
3897 % \DescribeMacro{\store}
3898 % This stores an \mfpic{} path in a \MF{} path variable. The argument is
3899 % the variable name. It should be followed by an \mfpic{} figure macro
3900 % (such as \cs{rect}\marg{...}). The stored path can be reused via the
3901 % \cs{mfobj} command. This command is written as a \cs{mfp@rendmac} even
3902 % though it does no rendering. This is so (1)~it will turn off implicit
3903 % rendering (any rendering must be explicitly written) and (2) it can be
3904 % placed anywhere within the prefix area. This is new behavior with
3905 % version 0.7. Prior to this it was required to place the path to be
3906 % stored as a second argument. Though that argument could contain other
3907 % prefixes in addition to the path, it was required that no other prefixes
3908 % precede \cs{store}. Note that \cs{store} takes a second argument but
3909 % it merely puts it back. This is so that the old syntax (with the figure
3910 % macro in braces) will continue to work.
3911 %
3912 % \DescribeMacro{\norender}
3913 % Occasionally it is useful to turn off rendering (say we want to add an
3914 % arrowhead to a subpath of a path that is already rendered). One could
3915 % put \cs{store} at the start with an unused name, but as every path is
3916 % already stored in \gbc{curpath}, that seems redundant. So here is a
3917 % prefix macro with null rendering and no side effects. It is exactly
3918 % like \cs{mfp@rendmac}, except it does not end with \cs{mfsrc}.
3919 % \begin{macrocode}
3920 \newdef\store##1##2{\mfp@rendmac{stored (##1)}##2}%
3921 \newdef\norender{\mfp@first\@mfprendfalse}%
3922 % \end{macrocode}
3923 %
3924 % \DescribeMacro{\mfobj}
3925 % This is the interface to use a \cs{store}-d object.
3926 % \cs{mfobj}\marg{\meta{name}} is a figure macro, and should act exactly
3927 % the same as if the figure macro that had been stored in the variable
3928 % were typed in its place. Its one argument is the variable name.
3929 %
3930 % Instead of the variable name, the argument can contain any reasonable
3931 % \MF{} path expression. In this context ``reasonable'' means it should
3932 % contain no special \TeX{} characters that might expand upon being
3933 % written to the output file. In particular, the backslash and `\verb$~$'
3934 % should especially be avoided.
3935 %
3936 % \DescribeMacro{\mpobj}
3937 % The macro \cs{mpobj} is just another name for the same command.
3938 % \begin{macrocode}
3939 \newlet\mfobj\mfp@figmac \newlet\mpobj\mfobj
3940 % \end{macrocode}
3941 %
3942 % \DescribeMacro{\mfpimage}
3943 % The command \cs{mfpimage} starts a group in which drawing commands
3944 % work just as usual, except they draw in a picture variable, whose name
3945 % is the only mandatory argument to \cs{mfpimage}.
3946 % \DescribeMacro{\endmfpimage}
3947 % The command \cs{endmfpimage} ends that group. There is an optional
3948 % argument to set the reference point of the created picture, the default
3949 % being \gbc{(0,0)}. The resulting picture can then be placed using
3950 % \cs{putmfpimage}.
3951 % \begin{macrocode}
3952 \newdef\mfpimage{\mfp@defaultopt\mfp@image{(0,0)}}%
3953 \newdef\endmfpimage{\mfcmd{\@nl concludeimage}}%
3954 % \end{macrocode}
3955 %
3956 % \DescribeMacro{\putmfpimage}
3957 % This takes the name of a picture variable created with the
3958 % \cs{mfpimage} environment (or even with the \cs{tile} environment), and
3959 % places it with its reference point at the points in a list.
3960 % \begin{macrocode}
3961 \newdef\putmfpimage##1{\mfsrc{\@nl putimage (##1)}\mfp@writedata}%
3962 % \end{macrocode}
3963 %
3964 %
3965 % \subsubsection{Subpaths}
3966 %
3967 % \DescribeMacro{\cutoffbefore}
3968 % This macro take one mandatory argument which is an object stored with
3969 % \cs{store}. It modifies the path it is prefixed to so that it starts
3970 % at its first point of intersection with the object, cutting off any
3971 % earlier part of the path.
3972 %
3973 % \DescribeMacro{\cutoffafter}
3974 % This is similar, except the modified path ends at the last point of
3975 % intersection between the following path and the object, cutting off
3976 % any later part of the path. It is internally the same as applying
3977 % \cs{cutoffbefore} to the reversed path and reversing the result.
3978 %
3979 % \DescribeMacro{\trimpath}
3980 % This trims off the specified absolute amounts from the start and end of
3981 % the path. The amounts can be specified as two absolute dimensions
3982 % separated by a comma, or a single dimension. In the second case, that
3983 % dimension is used at both the start and end.
3984 %
3985 % The implementation uses \cs{mfp@modi} which simply reads the argument
3986 % and writes it (via \cs{mfp@modmac}) as a set of parameters to the
3987 % appropriate \grafbase{} command. With \cs{trimpath}, however, we have to
3988 % parse that argument with \cs{mfp@getdimens}.
3989 % \begin{macrocode}
3990 \newdef\cutoffafter {\mfp@modi{cutoffafter}}%
3991 \newdef\cutoffbefore{\mfp@modi{cutoffbefore}}%
3992 \newdef\trimpath##1{\mfp@getdimens##1,,\mfp@end
3993 \mfp@modi{trimmedpath}\mfp@thedimens}%
3994 % \end{macrocode}
3995 %
3996 % \DescribeMacro{\partpath}
3997 % This produces a subpath of the following path. Its mandatory argument
3998 % contains two numbers separated by a comma. The numbers should be between
3999 % 0 and 1 and produce a fraction of the following path.
4000 % \DescribeMacro{\subpath}
4001 % The macro \cs{subpath} has a similar argument, but the numbers are
4002 % between $0$ and the number of segments in the path, and it produces the
4003 % equivalent of \MF's \mfc{subpath} primitive.
4004 % \begin{macrocode}
4005 \newdef\partpath{\mfp@modi{partialpath}}%
4006 \newdef\subpath{\mfp@modi{gsubpath}}%
4007 % \end{macrocode}
4008 %
4009 % \subsubsection{Drawing a curve}\label{drawing}
4010 %
4011 % These are rendering macros that draw the curve in some fashion: solid,
4012 % dashed, colored, etc.
4013 %
4014 % \DescribeMacro{\draw}
4015 % \cs{draw} takes one optional argument, a color. In \MF{}, where the
4016 % color commands return a numeric, if it is ${}\ge 1$ (representing white)
4017 % the path is subtracted from the picture, otherwise it is drawn in black
4018 % (the default). The default in \MP{} is \gbc{drawcolor}.
4019 %
4020 % We signal the use of the default color by passing a null optional
4021 % argument. Because several commands handle color the same way, and all
4022 % are rendering macros, we have a common macro that only needs the name of
4023 % the \grafbase{} command.
4024 % \begin{macrocode}
4025 \newdef\draw{\mfp@nullopt{\mfp@clroptrend{drawn}}}%
4026 % \end{macrocode}
4027 %
4028 % \DescribeMacro{\doubledraw}
4029 % Behaves something like \cs{draw}, except it draws a double line. It
4030 % takes two optional arguments; the first is the distance between the
4031 % centers of the two lines (default \gbc{2penwd}) and the second is a
4032 % color.
4033 % \begin{macrocode}
4034 \newdef\doubledraw{\mfp@defaultopt\mfp@doubledraw{2penwd}}%
4035 % \end{macrocode}
4036 %
4037 % \DescribeMacro{\dashed}
4038 % \cs{dashed} and \cs{dotted} take one optional argument, which should
4039 % contain the length of the dashes (diameter of
4040 % \DescribeMacro{\dotted}
4041 % dots) and the length of the spaces between, separated by a comma.
4042 %
4043 % Several rendering macros take an optional argument which is written as
4044 % the first parameter of a \grafbase{} command. Thus all are handled with
4045 % a single macro whose arguments are the name of the command and the
4046 % default for the optional argument.
4047 % \begin{macrocode}
4048 \newdef\dashed{\mfp@optrendi{DASHED}{\the\dashlen,\the\dashspace}}%
4049 \newdef\dotted{\mfp@optrendi{dotted}{\the\dotsize,\the\dotspace}}%
4050 % \end{macrocode}
4051 %
4052 % \cs{gendashed} takes one mandatory argument, the name of a dash pattern
4053 % previously defined by \cs{dashpattern}. The implementing macro,
4054 % \cs{mfp@rendi}, is like the above, except it doesn't need to perform the
4055 % option processing.
4056 % \begin{macrocode}
4057 \newdef\gendashed{\mfp@rendi{gendashed}}%
4058 % \end{macrocode}
4059 %
4060 % \DescribeMacro{\zigzag}
4061 % This draws a zigzag, crossing from one side of the following path to
4062 % the other. It has one required argument containing four dimensions,
4063 % \meta{dim$\sb1$} through \meta{dim$\sb4$}, separated by commas. What is
4064 % drawn depends on whether the path is closed or open. For an open path,
4065 % this draws the start of the path for a distance \meta{dim$\sb1$},
4066 % followed by zigzags, followed by the end of the path for a distance
4067 % \meta{dim$\sb2$}. For a closed path the first two dimensions are
4068 % ignored and the zigzags follow the entire path.
4069 %
4070 % The last two dimensions define the size and slant of each `zig'. If we
4071 % think of the zigzags as representing a periodic wave, \meta{dim$\sb3$}
4072 % is the wavelength and \meta{dim$\sb4$} is the amplitude (distance from
4073 % the true path to the sharp points).
4074 %
4075 % \DescribeMacro{\sinewave}
4076 % This is similar, but the result is a smooth sinewave shaped rendering.
4077 %
4078 % \DescribeMacro{\coil}
4079 % This creates a coil, or corkscrew-shaped rendering. In this case
4080 % \meta{dim$\sb3$} is the distance from one loop to the next and
4081 % \meta{dim$\sb4$} is the maximum distance to each side of the path.
4082 % An alias,
4083 % \DescribeMacro{\corkscrew}
4084 % \cs{corkscrew}, is provided.
4085 %
4086 % Both \cs{sinewave} and \cs{corkscrew} take an optional `tension'
4087 % argument that affects the smoothness of the result. The default is $1$
4088 % and the higher the value the closer they become to a zigzag.
4089 % \begin{macrocode}
4090 \newdef\zigzag{\mfp@rendi{zigzag}}%
4091 \newdef\sinewave {\mfp@defaultopt{\mfp@wiggle{sinewave}}1}%
4092 \newdef\coil{\mfp@defaultopt{\mfp@wiggle{corkscrew}}1}%
4093 \newlet\corkscrew\coil
4094 % \end{macrocode}
4095 %
4096 % \cs{plot} is like \cs{dotted}, except the dots are variously shaped
4097 % symbols. It takes one optional argument containing the size of the
4098 % symbol and the spacing, separated by a comma, and one mandatory
4099 % argument, the name of the symbol. This can in principal be any
4100 % expression of type \mfc{picture} or \mfc{path}. (In \MP, type
4101 % \mfc{string} is also permitted). For the size parameter to work
4102 % correctly, the symbol should be a path, and it should have 1
4103 % as it's natural size. \Mfpic{} provides the predefined paths
4104 % \texttt{Triangle}, \texttt{Square}, \texttt{Circle}, \texttt{Star},
4105 % \texttt{Diamond}, \texttt{Plus}, \texttt{Cross} and \texttt{Asterisk}.
4106 % The first 5 have filled-in versions: \texttt{SolidTriangle}, etc.
4107 %
4108 % The utility \cs{mfp@optrendii} is similar \cs{mfp@optrendi} except it
4109 % takes an additional argument, in this case, the first mandatory argument
4110 % of \cs{plot}.
4111 % \begin{macrocode}
4112 \newdef\plot{%
4113 \mfp@optrendii{doplot}{\the\pointsize,\the\symbolspace}}%
4114 % \end{macrocode}
4115 %
4116 % \DescribeMacro{\plotnodes}
4117 % Sometimes, rather than equally spaced dots or symbols, we would rather
4118 % have a symbol at each `node' of the following path. If the path is
4119 % created by a list macro, then usually each point in the list is a node
4120 % (but some of the spline paths are exceptions). For other figures, the
4121 % nodes can seem pretty random. For example, a \cs{circle} command without
4122 % optional argument produces a curve with 8 equally spaced nodes, but with
4123 % optional argument the nodes depend on how it is drawn and the size of
4124 % any angle parameter.
4125 %
4126 % \cs{plotnodes} has almost the same syntax as \cs{plot}, but since it
4127 % places the symbols only at the nodes of the path, there is no spacing
4128 % parameter in the optional argument.
4129 % \begin{macrocode}
4130 \newdef\plotnodes{\mfp@optrendii{plotnodes}{\the\pointsize}}%
4131 % \end{macrocode}
4132 %
4133 % \DescribeMacro{\showcontrols}
4134 % Mainly for debugging, this places a symbol at the precontrol and
4135 % postcontrol of each node, and draws a line segment from each symbol to
4136 % the node. The names of two symbols are given in a mandatory argument,
4137 % separated by commas. As a special case, if either symbol is just the
4138 % number `\mfc{0}', it is not drawn. There is an optional argument for
4139 % the size of these symbols. If the size is zero, neither symbol is drawn.
4140 % That is useful if one only wants to see the line segments.
4141 % \begin{macrocode}
4142 \newdef\showcontrols{\mfp@optrendii{showcontrols}{\the\pointsize}}%
4143 % \end{macrocode}
4144 %
4145 %
4146 % \subsubsection{Closing a curve}\label{closing}
4147 %
4148 % There are several commands used to close paths (by prefixing them to
4149 % figure macros). The \grafbase{} commands that implement closing have a
4150 % common naming pattern. They all contain the string `\texttt{closed},
4151 % to which is added a distinguishing prefix. If the command takes a
4152 % tension argument, the letter `\texttt{t}' is appended. The corresponding
4153 % command without the `\texttt{t}' calls it with a default tension value.
4154 %
4155 % These macros all call \cs{mfp@close}, feeding it the proper prefix and
4156 % the tension value (empty if there is no tension option).
4157 %
4158 % \DescribeMacro{\sclosed}
4159 % The first, \cs{sclosed}, closes smoothly in the same manner that
4160 % \cs{curve} creates a smooth path.
4161 %
4162 % \DescribeMacro{\bclosed}
4163 % The second, \cs{bclosed}, uses an ordinary \MF{} B\'ezier. These two
4164 % have an optional argument: the amount of tension to put in the
4165 % connecting link. This makes no sense with the rest.
4166 %
4167 % \DescribeMacro{\lclosed}
4168 % The macro \cs{lclosed} always draws a straight line from the end of a
4169 % path to its start.
4170 %
4171 % \DescribeMacro{\cbclosed}
4172 % The macro \cs{cbclosed} computes a closure by calculating cubic B-spline
4173 % control points from the path data and then generating a connecting
4174 % spline (see \cs{cspline}).
4175 %
4176 % \DescribeMacro{\qbclosed}
4177 % The macro \cs{qbclosed} is similar, but quadratic B-splines are used.
4178 %
4179 % \DescribeMacro{\uclosed}
4180 % At one time \cs{uclosed} was defined in a more complicated manner than
4181 % necessary, but actually produced exactly the same path as \cs{bclosed}.
4182 % So now they are just made to be equal.
4183 % \begin{macrocode}
4184 \newdef\bclosed{\mfp@nullopt{\mfp@close b}}%
4185 \newdef\sclosed{\mfp@nullopt{\mfp@close s}}%
4186 \newdef\lclosed{\mfp@close l{}}%
4187 \newdef\cbclosed{\mfp@close{cb}{}}%
4188 \newdef\qbclosed{\mfp@close{qb}{}}%
4189 \newlet\uclosed\bclosed
4190 % \end{macrocode}
4191 %
4192 % \DescribeMacro{\makesector}
4193 % Takes a following arc and draws the sector (even if the center point
4194 % is not known). It really only works if prefixed to one of the
4195 % \cs{arc} commands, but it will attempt to create something even for
4196 % other paths. It calculates the center of the circle containing the arc
4197 % and connects that to the endpoints with two straight lines.
4198 % \begin{macrocode}
4199 \newdef\makesector{\mfp@modmac{makesector}}%
4200 % \end{macrocode}
4201 %
4202 %
4203 % \subsubsection{Filling a closed curve}\label{filling}
4204 %
4205 % The next few prefix macros fill the interior of the closed path that
4206 % follows with some sort of pattern. The path must be closed; if not,
4207 % the path will simply be drawn with a solid line.
4208 %
4209 % \DescribeMacro{\tess}
4210 % \cs{tess} takes one mandatory argument, the name of a previously defined
4211 % tile (see subsection~\ref{composite}), and fills with shifted copies of
4212 % the tile.
4213 % \begin{macrocode}
4214 \newdef\tess{\mfp@rendi{tess}}%
4215 % \end{macrocode}
4216 %
4217 % \DescribeMacro{\shade}
4218 % \cs{shade} is implemented in \MF{} by filling a region with a pattern
4219 % of dots, simulating gray. It take one optional parameter, the separation
4220 % between dots, defaulting to \cs{shadespace}. The size of the dots is
4221 % set by issuing the command \cs{shadewd}. In \MP{} a gray fill is
4222 % used but the syntax is the same. It would be better to just use
4223 % \cs{gfill} instead (described later).
4224 %
4225 % \DescribeMacro{\polkadot}
4226 % This command is actually meant to fill with a pattern of large dots.
4227 % It also takes the separation between dots (default \cs{polkadotspace})
4228 % as an optional argument. The command \cs{polkadotwd} sets the size of
4229 % the dots.
4230 % \begin{macrocode}
4231 \newdef\shade{\mfp@optrendi{shade}{\the\shadespace}}%
4232 \newdef\polkadot{\mfp@optrendi{polkadot}{\the\polkadotspace}}%
4233 % \end{macrocode}
4234 %
4235 % \DescribeMacro{\thatch}
4236 % The hatching macros mostly take two optional parameters, the
4237 % separation of the hatching lines (default \cs{hatchspace}) and their
4238 % color. One slight exception is \cs{thatch}, which is called by all the
4239 % others. Its first optional argument is the separation \emph{and} the
4240 % angle (default $0$) of the lines, separated by a comma. The other
4241 % hatching macros have a fixed angle.
4242 % \DescribeMacro{\lhatch}
4243 % The macro \cs{lhatch} has lines at a $-45$ degree angle (upper left to
4244 % lower right),
4245 % \DescribeMacro{\rhatch}
4246 % \cs{rhatch} produces the opposite diagonal (angle $45$ degrees), and
4247 % \DescribeMacro{\xhatch}
4248 % \cs{xhatch} does both sets of lines (cross hatching).
4249 % \begin{macrocode}
4250 \newdef\thatch{\mfp@defaultopt\mfp@thatch{\the\hatchspace,0}}%
4251 \newdef\lhatch{\mfp@defaultopt\mfp@lhatch{\the\hatchspace}}%
4252 \newdef\rhatch{\mfp@defaultopt\mfp@rhatch{\the\hatchspace}}%
4253 \newdef\xhatch{\mfp@defaultopt\mfp@xhatch{\the\hatchspace}}%
4254 \newlet\hatch\xhatch
4255 % \end{macrocode}
4256 %
4257 % \DescribeMacro{\gradient}
4258 % The \cs{gradient} command approximates a linear gradient fill using
4259 % adjacent strips of different colors. It takes one mandatory argument
4260 % containing three items separated by commas. The first is a
4261 % \mfc{vardef}-ed function that produces the colors, the second is the
4262 % thickness of the color strips and the third is the angle these strips
4263 % make with the horizontal.
4264 %
4265 % \DescribeMacro{\areagradient}
4266 % This allows more general shading. It produces a fill consisting of
4267 % differently colored ``pixels''. It also takes one mandatory argument
4268 % containing three items separated by commas. The first is a
4269 % function of two variables that produces the colors, the second is the
4270 % width of the pixels and the third is their height.
4271 %
4272 % \DescribeMacro{\radialgradient}
4273 % This allows shading in a concentric circular pattern. It produces a fill
4274 % consisting of differently colored circular strips. It also takes one
4275 % mandatory argument containing three items separated by commas. The first
4276 % is a function of one variable that produces the colors, the second is
4277 % the thickness of the circular strips, and the third is an ordered pair
4278 % (the center the circles).
4279 % \begin{macrocode}
4280 \newdef\gradient{\mfp@rendi{axialgradient}}%
4281 \newdef\areagradient{\mfp@rendi{areagradient}}%
4282 \newdef\radialgradient{\mfp@rendi{radialgradient}}%
4283 % \end{macrocode}
4284 %
4285 % \DescribeMacro{\gfill}
4286 % \cs{gfill} take one optional argument, the color with which to fill.
4287 % Under \MF{} the color must be a numeric (representing a level of gray)
4288 % or one of the color functions, which are defined in \file{grafbase.mf}
4289 % to return numeric values.
4290 %
4291 % \DescribeMacro{\gclear}
4292 % \cs{gclear} will actually fill with the color \texttt{background} in \MP.
4293 % This merely covers what originally was there.
4294 %
4295 % \DescribeMacro{\gclip}
4296 % \cs{gclip} clears the outside of a region, but it is a true clip
4297 % operation, completely different from \cs{gclear}.
4298 % \begin{macrocode}
4299 \newdef\gfill{\mfp@nullopt{\mfp@clroptrend{filled}}}%
4300 \newdef\gclear{\mfp@rendmac{unfilled}}%
4301 \newdef\gclip{\mfp@rendmac{Clip}}%
4302 % \end{macrocode}
4303 %
4304 %
4305 % \subsubsection{Modifying a curve}\label{transforming}
4306 %
4307 % The following are transformation prefixes. They are all (except
4308 % \cs{reverse}, for reasons covered in section~\ref{prefix}) implemented
4309 % with \cs{mfp@modmac}. Most have a mandatory argument, the parameters of
4310 % the transformation. Because of the implementation, one can insert
4311 % rendering macros between a transformation macro and the path being
4312 % transformed, and they will apply to the untransformed path.
4313 %
4314 % If the \env{mfpic} environment has different $x$ and $y$ scales, the
4315 % \cs{rotatepath} and \cs{reflectpath} compensates so that the result is
4316 % congruent to the original. This is what users seem to expect. The rest
4317 % do not compensate and users don't seem to mind.
4318 % \begin{itemize}
4319 % \item \cs{reverse} and \cs{xyswappath} have no argument.
4320 % \item \cs{reversepath} = \cs{reverse}.
4321 % \item \cs{rotatepath} takes \marg{\meta{point},\meta{angle}}.
4322 % \item \cs{shiftpath} takes \marg{\meta{pair}}.
4323 % \item \cs{scalepath} takes \marg{\meta{center of scaling},\meta{factor}}.
4324 % \item \cs{xscalepath} takes \marg{\meta{x-center},\meta{factor}}.
4325 % \item \cs{yscalepath} takes \marg{\meta{y-center},\meta{factor}}.
4326 % \item \cs{slantpath} takes \marg{\meta{y-pivot},\meta{factor}}.
4327 % \item \cs{xslantpath} = \cs{slantpath}.
4328 % \item \cs{yslantpath} takes \marg{\meta{x-pivot},\meta{factor}}.
4329 % \item \cs{reflectpath} takes \marg{\meta{point1},\meta{point2}}, the
4330 % endpoints of a `mirror'.
4331 % \item \cs{transformpath} takes \marg{\meta{transformer}}, a \MF{}
4332 % `transformer' (see ``The \MF book'', page~212).
4333 % \end{itemize}
4334 %
4335 % All of them simply write the \grafbase{} command of nearly the same
4336 % name, with the same arguments, via
4337 % \cs{mfp@modi}.\SpecialUsageIndex{\reversepath}\SpecialUsageIndex{\reverse}
4338 % \SpecialUsageIndex{\xyswappath}\SpecialUsageIndex{\rotatepath}
4339 % \SpecialUsageIndex{\shiftpath}\SpecialUsageIndex{\scalepath}
4340 % \SpecialUsageIndex{\xscalepath}\SpecialUsageIndex{\yscalepath}
4341 % \SpecialUsageIndex{\slantpath}\SpecialUsageIndex{\xslantpath}
4342 % \SpecialUsageIndex{\yslantpath}\SpecialUsageIndex{\reflectpath}
4343 % \SpecialUsageIndex{\transformpath}
4344 %
4345 % \begin{macrocode}
4346 \newdef\reversepath{\mfp@addmac{reverse}}%
4347 \newlet\reverse\reversepath
4348 \newdef\xyswappath{\mfp@modmac{xyswappedpath}}%
4349 \newdef\rotatepath{\mfp@modi{rotatedpath}}%
4350 \newdef\shiftpath{\mfp@modi{shiftedpath}}%
4351 \newdef\scalepath{\mfp@modi{scaledpath}}%
4352 \newdef\xscalepath{\mfp@modi{xscaledpath}}%
4353 \newdef\yscalepath{\mfp@modi{yscaledpath}}%
4354 \newdef\xslantpath{\mfp@modi{xslantedpath}}%
4355 \newlet\slantpath\xslantpath
4356 \newdef\yslantpath{\mfp@modi{yslantedpath}}%
4357 \newdef\reflectpath{\mfp@modi{reflectedpath}}%
4358 \newdef\transformpath{\mfp@modi{transformedpath}}%
4359 % \end{macrocode}
4360 %
4361 % \DescribeMacro{\parallelpath}
4362 % This is not an affine transformation, but is a transformation of sorts.
4363 % It tries to define a curve that parallels the following curve at a fixed
4364 % distance. The mandatory argument is the separation, in graph units. It
4365 % is sort of experimental and will probably fail if the path that follows
4366 % is too wild. Since \cs{doubledraw} shares code with \cs{parallelpath},
4367 % that too will probably fail in similar circumstances.
4368 % \begin{macrocode}
4369 \newdef\parallelpath{\mfp@modi{parapath}}%
4370 % \end{macrocode}
4371 %
4372 % \DescribeMacro{\randomizepath}
4373 % This, too, is a nonaffine transformation. It tries to define a curve
4374 % that remains smooth if the original is, but applies random shifts to the
4375 % nodes and random changes to the direction at each node.
4376 %
4377 % The only argument is mandatory and consists of a maximum shift (in graph
4378 % units) and a `weirdness' (a pure number) separated by a comma.
4379 %
4380 % The maximum shift can be a number, in which case it is the maximum
4381 % possible distance and there is no preferred direction, or it can be an
4382 % ordered pair, in which case it gives maximum horizontal and vertical
4383 % shift amounts.
4384 %
4385 % The `weirdness' is applied to path directions. If it is 0, there is no
4386 % change in directions of the path at nodes. If it is a positive number
4387 % $w$, a random angle of up to $\pm 30 w$ is added to the directions at
4388 % each node. Also a random scaling between $2^{-w}$ and $2^w$ is applied
4389 % to the control vectors. Also, if a path has a corner, the angle between
4390 % the two sides is randomly adjusted to be between $2^{-w}$ and $2^w$
4391 % times its original size.
4392 %
4393 % \DescribeMacro{\randomlines}
4394 % This is a simpler version whose mandatory argument contains only the
4395 % maximum shift parameter. It shifts the nodes and connects the results
4396 % with straight lines.
4397 % \begin{macrocode}
4398 \newdef\randomizepath{\mfp@modi{randompath}}%
4399 \newdef\randomlines{\mfp@modi{randomlines}}%
4400 % \end{macrocode}
4401 %
4402 % \DescribeMacro{\interpolatepath}
4403 % This prefix macro has one mandatory argument containing a number and a path,
4404 % separated by a comma. The number can be any \MF{} numeric expression and
4405 % the path can be any \MF{} path expression. The number should normally be
4406 % in the range $0$ to $1$ and the path normally a variable (e.g, defined using
4407 % \cs{store}). It returns a path which is between the one in its argument
4408 % and the one that follows. If the number is $0$, the following path is
4409 % returned unchanged, if the number is $1$ the path in the argument is
4410 % returned.
4411 % \begin{macrocode}
4412 \newdef\interpolatepath{\mfp@modi{interpolatedpath}}%
4413 % \end{macrocode}
4414 %
4415 % \DescribeMacro{\arccomplement}
4416 % This can precede an arc and then returns its complement. It starts at
4417 % the last point of the following arc and ends at the beginning of that
4418 % arc. The sense of the resulting arc (clockwise or anticlockwise) is the
4419 % same as the arc it is applied to. If the following path is not an arc,
4420 % the result is an arc that connects the end of the path to the beginning,
4421 % but may bear no obvious relation to that path.
4422 % \begin{macrocode}
4423 \newdef\arccomplement{\mfp@modmac{arccomplement}}%
4424 % \end{macrocode}
4425 %
4426 %
4427 % \subsubsection{Adding arrowheads (and tails)}\label{arrows}
4428 %
4429 % Paths can now have heads and tails and something placed in the
4430 % middle. Also the head, tail or the `something' can be any symbol. In
4431 % addition to the \cs{plotsymbol} possibilities, there is \gbc{Arrowhead},
4432 % which is the arrowhead of previous \mfpic{} versions, as well as
4433 % \gbc{Leftharpoon} and \gbc{Rightharpoon}, which are the left and right
4434 % halves.
4435 %
4436 % Intended for middle or tail of an arrow are \gbc{Crossbar}, \gbc{Leftbar}
4437 % and \gbc{Rightbar}, and for the tail there are \gbc{Lefthook} and
4438 % \gbc{Righthook}. \gbc{Crossbar} cuts right across the shaft
4439 % (perpendicular unless a rotation option is present) while \gbc{Leftbar}
4440 % extends to the left (from the point of view of someone facing in the
4441 % direction of the path. Similarly \gbc{Lefthook} curls to the left of the
4442 % arrow's shaft.
4443 %
4444 % All the new arrow commands take one mandatory argument, the name of the
4445 % symbol, followed by up to four optional arguments. Three of the optional
4446 % arguments are the same for all commands: these set the color, the size
4447 % and the amount of rotation of the symbol. Normally the symbol is
4448 % adjusted to `point' in the direction of the path (\gbc{Crossbar} is
4449 % actually perpendicular to it); with the rotation option it can be
4450 % adjusted.
4451 %
4452 % For example, \oarg{c red} makes the symbol red, \oarg{l 5pt} or \oarg{s
4453 % 5pt} scales the symbol so its nominal size or length is 5 points,
4454 % \oarg{r 10} rotates the symbol 10 degrees (anticlockwise) from its
4455 % default position.
4456 %
4457 % The other optional argument depends on the command: for heads it is an
4458 % amount to shift the head backward, for tails the amount to shift it
4459 % forward, and for things placed in the middle, it is the fraction of the
4460 % length of the path along which the symbol is placed.
4461 %
4462 % For example, \oarg{b 2pt} shifts a head two points backward, \oarg{f
4463 % 2pt} shifts a tail 2 points forward and \oarg{f .5} puts the symbol
4464 % right in the middle.
4465 %
4466 % The letters are mnemonics, being the initial letters of the words
4467 % `color', `length' or `size', `rotate', `back', and `forward' or
4468 % `fraction'. Actually, the letters \texttt{s} and \texttt{l} have
4469 % identical effects since I couldn't decide which mnemonic was more
4470 % natural. Oddly, \texttt{b} and \texttt{f} have identical effects also.
4471 % So if you accidentally use \oarg{b 2pt} for a tail, it will still be
4472 % shifted \emph{forward}! The reason for this is that these \mfpic{}
4473 % commands all correspond to \grafbase{} commands that have the same
4474 % argument structure. Both \texttt{b} and \texttt{f} simply cause the
4475 % accompanying value to be written into the fourth argument, while the
4476 % different commands use that argument differently. (You can shift a
4477 % tail backwards with a negative argument, if you really need that.)
4478 %
4479 % \DescribeMacro{\arrowhead}\SpecialUsageIndex{\arrow}
4480 % The \cs{arrowhead} command has a star-form which allows part of the
4481 % path beyond the tip of the arrowhead to be erased. The presence of a
4482 % star ultimately changes the \MF{} command passed on to later macros.
4483 % It does so by passing to \cs{mfp@arrowhead} the word `\texttt{true}' for
4484 % the star-form and `\texttt{false}' otherwise.
4485 %
4486 % The old \cs{arrow} command first checks for a star, and passes to
4487 % \cs{mfp@arrow} either an `\texttt{x}' or an empty parameter. This is
4488 % used to construct the \grafbase{} command name. We use \cs{def}
4489 % because \prog{eplain} defines one also.
4490 % \begin{macrocode}
4491 \newdef\arrowhead{\mfp@ifstar\mfp@arrowhead\mfp@T\mfp@F}%
4492 \def\arrow{\mfp@ifstar\mfp@arrow{x}{}}%
4493 % \end{macrocode}
4494 %
4495 % \DescribeMacro{\arrowtail}
4496 % Tails are just like heads except that there is no star-form and the
4497 % \grafbase{} command name (second parameter of \cs{mfp@arr}) is
4498 % different.
4499 % \DescribeMacro{\arrowmid}
4500 % And \cs{arrowmid} is just like \cs{arrowtail} except for the command
4501 % name and the different default for the position optional argument.
4502 % \begin{macrocode}
4503 \newdef\arrowtail##1{\mfp@arr 0{tailpath (##1)}}%
4504 \newdef\arrowmid##1{\mfp@arr{0.5}{midpath (##1)}}%
4505 % \end{macrocode}
4506 %
4507 % This ends the prefix macros.
4508 %
4509 %
4510 % \subsection{Transforming the coordinate system}\label{coordinate}
4511 %
4512 % \DescribeMacro{\coords}
4513 % The following apply transforms to the \MF{} coordinate system, and
4514 % these can be localized with the \env{coords} environment. In plain
4515 % \TeX{} \cs{coords} starts the environment and
4516 % \DescribeMacro{\endcoords}
4517 % \cs{endcoords} closes it. The transforms apply when the curve is
4518 % \emph{rendered} and do not affect what paths are defined. Thus, for
4519 % example, \cs{store} will store the same path whatever the state of the
4520 % coordinate system. In terms of \grafbase{} commands, only \gbc{vtr} and
4521 % \gbc{ztr} are changed, and these are only applied when rendering.
4522 %
4523 % \DescribeMacro{\applyT}
4524 % These are implemented by \cs{applyT} which takes as its argument a \MF{}
4525 % `transformer'.
4526 %
4527 % These commands (except \cs{turn}, kept for backward compatibility) have
4528 % no optional arguments, only mandatory arguments containing the
4529 % parameters of the transformation. \cs{rotate} rotates around the origin,
4530 % \cs{rotatearound} rotates around a given point, \cs{turn} takes the point
4531 % as an optional argument, defaulting to $(0,0)$.
4532 %
4533 % Transformations are applied in reverse of the order they appear in the
4534 % file (i.e., the most recent first). This applies even if \env{coords}
4535 % environments are nested, except that at \cs{endcoords} the state at
4536 % the matching \cs{coords} is restored.
4537 % \begin{macrocode}
4538 \newdef\coords{\mfsrc{\@nl bcoords\@nl}}%
4539 \newdef\endcoords{\mfsrc{\@nl ecoords\@nl}}%
4540 \newdef\applyT##1{\mfsrc{\@nl hide(apply_t (##1))}}%
4541 \def\rotate##1{\applyT{rotated ##1}}%
4542 \newdef\rotatearound##1##2{%
4543 \applyT{rotatedaround (##1, ##2)}}%
4544 \newdef\turn{\mfp@defaultopt\mfp@turn{(0,0)}}%
4545 \newdef\reflectabout##1##2{\applyT{reflectedabout (##1, ##2)}}%
4546 \let\mirror\reflectabout
4547 \newdef\shift##1{\applyT{shifted ##1}}% pair.
4548 \def\scale##1{\applyT{scaled ##1}}% same scaling
4549 \newdef\xscale##1{\applyT{xscaled ##1}}%
4550 \newdef\yscale##1{\applyT{yscaled ##1}}%
4551 \newdef\zscale##1{\applyT{zscaled ##1}}%
4552 \newdef\xslant##1{\applyT{xslant ##1}}%
4553 \newdef\yslant##1{\applyT{yslant ##1}}%
4554 \newdef\zslant##1{\applyT{zslant ##1}}%
4555 \newdef\boost##1{\applyT{boost ##1}}%
4556 \newdef\xyswap{\applyT{xyswap}}%
4557 % \end{macrocode}
4558 %
4559 %
4560 % \subsection{Axes and grids}\label{axes}
4561 %
4562 % An axis would normally not be thought of as a figure macro, because one
4563 % would not want to position them arbitrarily nor transform them. One
4564 % would also not want the hassle of having always to specify the origin,
4565 % etc. However, one would want to occasionally make them dotted or dashed
4566 % or colored.
4567 %
4568 % \DescribeMacro{\axes}
4569 % The original \cs{axes} was therefore not a figure macro. It always drew
4570 % both axes with solid lines.
4571 % \DescribeMacro{\xaxis}
4572 % Later \cs{xaxis} and \cs{yaxis} were introduced, which mimicked the
4573 % behavior of \cs{axes}. For backward
4574 % \DescribeMacro{\yaxis}
4575 % compatibility, the old behavior is supported with the old commands. The
4576 % optional argument to \cs{axes}, \cs{xaxis} and \cs{yaxis} is the length
4577 % of the arrowhead, defaulting to \cs{the}\cs{axisheadlen}.
4578 % \begin{macrocode}
4579 \newdef\xaxis{\mfp@defaultopt{\mfp@simple{xaxis}}{\the\axisheadlen}}%
4580 \newdef\yaxis{\mfp@defaultopt{\mfp@simple{yaxis}}{\the\axisheadlen}}%
4581 \newdef\axes{\mfp@defaultopt {\mfp@simple{axes}}{\the\axisheadlen}}%
4582 % \end{macrocode}
4583 %
4584 % \DescribeMacro{\axis}
4585 % When border axes were added, all the code was revamped, and now we
4586 % create axes as figure macros. It also became clear there was so
4587 % much common code that it would be better to implement the syntax
4588 % \cs{axis}\marg{l}, etc., rather than have separate commands \cs{laxis},
4589 % etc. for all six possible axes. Therefore, only the $x$- and $y$-axes
4590 % have their own commands. The \cs{axis} command has one optional argument
4591 % (the arrowhead length) and one mandatory argument, a single letter
4592 % designating the axis to draw.
4593 %
4594 % \DescribeMacro{\axisline}
4595 % The \cs{axisline} command is provided for users who want more control.
4596 % It is a figure macro that produces the corresponding line, and the user
4597 % can use all the flexibility of the \cs{arrowhead} command if necessary.
4598 % \begin{macrocode}
4599 \newdef\axis{\mfp@nullopt\mfp@axis}%
4600 \newdef\axisline##1{\mfp@figmac{axisline.##1}}%
4601 % \end{macrocode}
4602 %
4603 % \DescribeMacro{\doaxes}
4604 % \cs{doaxes} takes one optional argument, the arrowhead length, and one
4605 % mandatory argument, all the axes to draw. These should be just letters
4606 % with nothing separating them except optional spaces. \cs{doaxes} is
4607 % implemented via the self-looping macro \cs{mfp@doaxis}.
4608 %
4609 % \DescribeMacro{\border}
4610 % The \cs{border} command is almost equivalent to \cs{doaxes}\marg{lbrt},
4611 % except it is a figure macro. With it, the whole picture can be filled
4612 % with a background color, or outlined in any available rendering.
4613 % \begin{macrocode}
4614 \newdef\doaxes{\mfp@nullopt\mfp@doaxes}%
4615 \newdef\border{\mfp@figmac{borderrect}}%
4616 % \end{macrocode}
4617 %
4618 % \DescribeMacro{\axismarks}
4619 % Hash marks (or tick marks) on the axes are provided by the
4620 % \cs{axismarks} command (\cs{marks} was the original choice, but that
4621 % turned out to conflict with one of e\kern-.06em\TeX's primitives).
4622 % For brevity, therefore, we also have separate commands
4623 % \DescribeMacro{\xmarks}
4624 % \cs{xmarks},
4625 % \cs{ymarks}\SpecialUsageIndex\ymarks,
4626 % \cs{lmarks}\SpecialUsageIndex\lmarks,
4627 % \cs{bmarks}\SpecialUsageIndex\bmarks,
4628 % \cs{rmarks}\SpecialUsageIndex\rmarks, and
4629 % \cs{tmarks}\SpecialUsageIndex\tmarks.
4630 %
4631 % \cs{axismarks} has two mandatory arguments: the letter for the axis, and
4632 % a comma separated list of numbers giving the positions on the axis. It
4633 % functions as a list macro (see previous discussion of types of macros)
4634 % and so the list of numbers can be prescribed by an external file
4635 % \cs{datafile}\marg{\meta{file}}. One must be sure to issue an
4636 % appropriate \cs{using} command to produce a numeric list in the output.
4637 % This is the main reason for the \cs{usingnumericdefault} command.
4638 %
4639 % I had a change of heart after the \cs{axis} command, and I made things
4640 % simpler to code here by putting the optional argument of \cs{axismarks}
4641 % after the first mandatory argument. I could justify this because I
4642 % expect most users will use the shorter versions that don't require the
4643 % first argument (that is, the expectation that optional arguments come
4644 % first is still satisfied). The optional argument is the length of the
4645 % marks. The position of the marks is controlled separately by the
4646 % \cs{setaxismarks} command, described in subsection~\ref{othersettings}.
4647 % \begin{macrocode}
4648 \newdef\axismarks##1{\mfp@defaultopt{\mfp@marks{##1}}{\the\hashlen}}%
4649 \newdef\xmarks{\axismarks x}%
4650 \newdef\ymarks{\axismarks y}%
4651 \newdef\lmarks{\axismarks l}%
4652 \newdef\bmarks{\axismarks b}%
4653 \newdef\rmarks{\axismarks r}%
4654 \newdef\tmarks{\axismarks t}%
4655 % \end{macrocode}
4656 %
4657 % \DescribeMacro{\grid}
4658 % The command \cs{grid} is, I think, inaccurately named: the word `grid'
4659 % suggests a set of lines, but this actually produces dots. Its function
4660 % is to allow a visualization of the coordinates. The dots are located at
4661 % the points whose coordinates are integer multiples of two numbers, which
4662 % are given in the single mandatory argument separated by commas. The
4663 % optional first argument is the diameter of the dots. This defaults to
4664 % \cs{griddotsize}, initially \texttt{0.5pt}.
4665 %
4666 % Because of my concerns about the name, I have provided two aliases:
4667 % \cs{gridpoints}\SpecialUsageIndex{\gridpoints} (for consistency with
4668 % \cs{gridlines}, below) and \cs{lattice}\SpecialUsageIndex{\lattice}.
4669 %
4670 % \DescribeMacro{\gridlines}
4671 % Macro \cs{gridlines} has no optional argument and takes the same
4672 % mandatory argument as \cs{grid}. It draws horizontal and vertical lines
4673 % intersecting at all the dots that \cs{grid} would draw. Some packages
4674 % (and \ConTeXt) define a \cs{grid} command so we use \cs{def} here
4675 % instead of \cs{newdef}.
4676 %
4677 % \DescribeMacro{\hgridlines}
4678 % This draws only the horizontal lines and its argument is the separation
4679 % (in graph units) between successive lines.
4680 % \DescribeMacro{\vgridlines}
4681 % \cs{vgridlines} is the vertical version.
4682 %
4683 % No arguments are shown because \cs{mfp@simple} or \cs{mfp@simplei} will
4684 % read what it needs.
4685 % \begin{macrocode}
4686 \def\grid{\mfp@defaultopt{\mfp@simplei{vargrid}}{\the\griddotsize}}%
4687 \newlet\gridpoints\grid \newlet\lattice\grid
4688 \newdef\gridlines{\mfp@simple{gridlines}}%
4689 \newdef\vgridlines{\mfp@simple{vgridlines}}%
4690 \newdef\hgridlines{\mfp@simple{hgridlines}}%
4691 % \end{macrocode}
4692 %
4693 % \DescribeMacro{\plrgrid}
4694 % The command \cs{plrgrid} takes one mandatory argument which contains two
4695 % numbers separated by a comma. The first is a radius (in graph
4696 % coordinates) and the second an angle. It draws circular arcs at integer
4697 % multiples of the radius, and radial lines at integer multiples of the
4698 % angle. It fills the picture rectangle and is clipped to that rectangle.
4699 %
4700 % \DescribeMacro{\plrgridpoints}
4701 % \cs{plrgridpoints} is similar but places only dots at the intersections
4702 % of these arcs and rays. It takes an optional argument for the size of
4703 % the dots, default \cs{griddotsize}.
4704 % \DescribeMacro{\gridarcs}
4705 % The macro \cs{gridarcs} draws only the arcs. Its only parameter is the
4706 % distance between them (in graph units).
4707 % \DescribeMacro{\gridrays}
4708 % The macro \cs{gridrays} draws only the rays and its parameter is the
4709 % angle separating the rays.
4710 %
4711 % \DescribeMacro{\plrpatch}
4712 % \cs{plrpatch} draws: a circular arc at a starting radius, then
4713 % increments that radius by a step size and draws another arc, etc., and
4714 % finally draws an arc at the ending radius. It does a similar thing for
4715 % radial lines and angles. It takes one mandatory argument, which contains
4716 % $6$ numbers separated by commas: starting radius, ending radius, radius
4717 % step, starting angle, ending angle, angle step.
4718 % \begin{macrocode}
4719 \newdef\plrgrid{\mfp@simple{polargrid}}%
4720 \newdef\plrgridpoints{%
4721 \mfp@defaultopt{\mfp@simplei{polargridpoints}}{\the\griddotsize}}%
4722 \newdef\gridarcs{\mfp@simple{gridarcs}}%
4723 \newdef\gridrays{\mfp@simple{gridrays}}%
4724 \newdef\plrpatch{\mfp@simple{polarpatch}}%
4725 % \end{macrocode}
4726 %
4727 % \DescribeMacro{\vectorfield}The \cs{vectorfield} command draws arrows to
4728 % represent a vector field. It takes one optional argument, the length of
4729 % the arrowhead (default \cs{headlen}), and three mandatory arguments. The
4730 % first is like \cs{grid}: it contains two numbers, separated by commas.
4731 % The arrows are located at the points whose coordinates are integer
4732 % multiples of two numbers. The second argument is the formula for the
4733 % vector field. It should consist of a pair expression in which the only
4734 % unknowns are the variables \texttt{x} and \texttt{y}. The last argument
4735 % should contain a boolean expression in which the only unknowns are
4736 % \texttt{x} and \texttt{y}. The macro steps through the relevant set of
4737 % points and draws the vector only if the boolean is true at that point.
4738 % The set of points considered includes only those inside the axis margins
4739 % (set by \cs{axismargin} and related commands). If all such points should
4740 % have an arrow, use \texttt{true} for the third argument.
4741 % \begin{macrocode}
4742 \newdef\vectorfield{%
4743 \mfp@defaultopt{\mfp@vectorfield{}}{\the\headlen}}%
4744 \newdef\plrvectorfield{%
4745 \mfp@defaultopt{\mfp@vectorfield{plr}}{\the\headlen}}%
4746 % \end{macrocode}
4747 %
4748 %
4749 % \subsection{Visualizing points}\label{points}
4750 %
4751 % \DescribeMacro{\point}
4752 % \cs{point} draws a dot or a small circle. It takes one optional
4753 % argument, the diameter of the dot, and one mandatory argument, the ordered
4754 % pair (or comma separated list of them) at which to draw a dot. After
4755 % \cs{pointfillfalse}, the dots will be unfilled (i.e., small circles),
4756 % after \cs{pointfilltrue} (the default), they will be solid. Like the
4757 % grid macros, it is not a figure macro, but merely does its drawing and
4758 % is not subject to any prefix macros.
4759 %
4760 % \DescribeMacro{\plotsymbol}
4761 % In order to mark points with other than circles, we have the
4762 % \cs{plotsymbol} command, so-called because it uses the same symbols as
4763 % the \cs{plot} command (previously discussed). There is an optional
4764 % argument that gives the size of the symbol, a mandatory argument with
4765 % the name of the symbol, and a second mandatory argument which
4766 % is a comma separated list of ordered pairs for the locations.
4767 %
4768 % For both these commands, the default optional argument is
4769 % \cs{the}\cs{pointsize}. These are list macros: in place of a list of
4770 % points in braces, one can use the \cs{datafile} construct.
4771 % \begin{macrocode}
4772 \newdef\point{\mfp@defaultopt\mfp@point{\the\pointsize}}%
4773 \newdef\plotsymbol{\mfp@defaultopt\mfp@plotsymbol{\the\pointsize}}%
4774 % \end{macrocode}
4775 %
4776 % \DescribeMacro{\plottext}
4777 % We keep \cs{plottext} for backward compatability. It is equivalent
4778 % to a \cs{tlabel} command with a different default for the justification
4779 % (\oarg{cc}) and the arguments rearranged. The order for \cs{plottext}
4780 % is: optional justification, then \TeX{} label, then list of points.
4781 % Because of the complication involved in making it work, in this case we
4782 % do not allow a datafile to replace the list of points. All this
4783 % command now does is perform a simplified version of the start of the
4784 % \cs{tlabel} command and jump to one of its internals, \cs{mfp@thelabel}.
4785 % \begin{macrocode}
4786 \newdef\plottext{\begingroup\mfp@resetwhitespace\mp@mksharpother
4787 \mfp@defaultopt\mfp@plottext{cc}}%
4788 % \end{macrocode}
4789 %
4790 %
4791 % \subsection{Some composite objects}\label{composite}
4792 %
4793 % \DescribeMacro{\tile}
4794 % A tile is syntactically a \MF{} picture variable. The commands between
4795 % \cs{tile} and \cs{endtile} (or \cs{begin}\marg{tile} and
4796 % \cs{end}\marg{tile}) should be any sequence of \mfpic{} figure macros
4797 % with possible prefix macros. They will be drawn not on the main picture
4798 % (\gbc{currentpicture}), but on the picture given by the name in the
4799 % \cs{tile} command's argument.
4800 %
4801 % The argument has five parts separated by commas, the first is the
4802 % name, the second is the unit of length (some absolute dimension like
4803 % \mfc{1pt}), the next two are the width and height (pure numbers, the
4804 % actual dimensions being these numbers times the unit of length), the
4805 % last is one of the words \mfc{true} or \mfc{false}, indicating whether
4806 % tile should be clipped to these dimensions (true) or allowed to extend
4807 % beyond them (false).
4808 % \begin{macrocode}
4809 \newdef\tile{\mfp@simple{tile}}%
4810 \newdef\endtile{\mfcmd{\@nl endtile}}%
4811 % \end{macrocode}
4812 %
4813 % \DescribeMacro{\patharr}
4814 % A path array is a set of \MF{} path variables each having the same base
4815 % name followed by a different numeric suffix. This command turns off
4816 % rendering and simply assigns these variables in order to the path
4817 % expressions written by the figure macros between \cs{patharr} and
4818 % \cs{endpatharr}. It works by redefining \cs{mfp@storepath}, issued by all
4819 % the figure macros. These variables can be accessed in \mfpic{} by using
4820 % the \cs{mfobj} command. The name of the path array \emph{without} a
4821 % numeric suffix is a \MF{} numeric variable whose value is the number of
4822 % array elements.
4823 %
4824 % \emph{Explicit} rendering commands will work in the sense that the
4825 % affected path will be rendered in addition to being assigned to the
4826 % variable. The only parameter is the common base name of the variables.
4827 % \begin{macrocode}
4828 \newdef\patharr##1{\begingroup
4829 \mfsrc{hide(numeric ##1; path ##1[]; ##1 = 0)}%
4830 \def\mfp@storepath{\mfsrc{\@nl store (##1[incr ##1])}}%
4831 \setrender{}}%
4832 \newdef\endpatharr{\endgroup}%
4833 % \end{macrocode}
4834 %
4835 % \DescribeMacro{\connect}
4836 % This starts an environment that can contain any sequence of figure
4837 % macros. The environment functions as a single large \cs{mfp@figmac}, the
4838 % figure being the path obtained by connecting all the paths
4839 % \DescribeMacro{\endconnect}
4840 % (up to the following \cs{endconnect} command) by straight lines from the
4841 % end of one to the beginning of the next. It is implemented via a path
4842 % array, so the individual figures within the environment have implicit
4843 % rendering turned off. Explicit rendering commands within the
4844 % environment will have the expected effect.
4845 %
4846 % The \cs{mfp@checklatexenv} at the end allows \cs{connect} to be used as
4847 % a \LaTeX{} environment.
4848 % \begin{macrocode}
4849 \newdef\connect{\mfp@figmac{begingroup; save mfpicnexus}%
4850 \patharr{mfpicnexus}}%
4851 \newdef\endconnect{\endpatharr
4852 \mfcmd{\@nl mkpoly (\mfp@F, mfpicnexus)\@nl endgroup}%
4853 \mfp@checklatexenv{connect}{\aftergroup\@mfpstarttrue}{}}%
4854 % \end{macrocode}
4855 %
4856 %
4857 % \subsection{Other graphical features}\label{otherfeatures}
4858 %
4859 % And now for something completely different.
4860 %
4861 % \DescribeMacro{\piechart}
4862 % Actually, nothing is drawn by the \cs{piechart} command; it only defines
4863 % a path array and a few other internal variables. Since nothing is
4864 % drawn by this command, it makes sense to allow it outside the drawing
4865 % environment, so it has been made available outside \env{mfpic}
4866 % environments with the command name \cs{mfppiechart}(page
4867 % \pageref{charts}).
4868 %
4869 % The \cs{piechart} command takes one optional argument and two mandatory
4870 % argument. The first mandatory argument contains the center and radius of
4871 % the chart separated by a comma; the second is the list of data. The
4872 % optional argument contains a letter and an optional angle. The letter
4873 % can be `\texttt{c}' for clockwise or `\texttt{a}' for anticlockwise and
4874 % determines the direction around the pie the different wedges will be drawn.
4875 % The angle determines the angle of the first edge (in the given
4876 % direction) of the first wedge. The default letter is \texttt{c} and the
4877 % default angle is $90$ degrees, which starts the first wedge at
4878 % 12~o'clock and proceeds from there either clockwise or anticlockwise..
4879 %
4880 % \cs{piechart} acts like a list macro in that the above arguments should
4881 % be followed by either a list of numbers in braces or a \cs{datafile}
4882 % command (with numbers in a datafile). If this feature is used, an
4883 % appropriate \cs{using} command is needed. If the numbers are listed one
4884 % per line, then \cs{usingnumericdefault} should work.
4885 %
4886 % \DescribeMacro{\piewedge}
4887 % Each individual wedge (elements of the above mentioned path array) may
4888 % be drawn using the \cs{piewedge} command, which is a figure macro. That
4889 % command takes one optional argument that determines how the wedge is
4890 % drawn (described below) and one mandatory argument, the number of the
4891 % wedge. Without the optional argument, \cs{piewedge}\marg{1} draws the
4892 % first wedge in the position given by the arguments of the \cs{piechart}
4893 % command, as described above.
4894 %
4895 % The optional arguments can be:
4896 % \begin{itemize}
4897 % \item \oarg{x\meta{distance}}, the wedge is `exploded': drawn
4898 % shifted radially outward from the center of the pie chart by
4899 % \meta{distance} (in graph units).
4900 % \item \oarg{s(\meta{dx},\meta{dy})}, the wedge is shifted from its
4901 % position by \meta{dx} horizontally and \meta{dy} vertically (in
4902 % graph units).
4903 % \item \oarg{m(\meta{x},\meta{y})}, the wedge is moved so that its
4904 % point is at coordinates \parg{\meta{x},\meta{y}}.
4905 % \end{itemize}
4906 % \begin{macrocode}
4907 \newlet\piechart\mfppiechart
4908 \newdef\piewedge{\mfp@defaultopt\mfp@piewedge{d}}%
4909 % \end{macrocode}
4910 %
4911 % \DescribeMacro{\barchart}
4912 % As with \cs{piechart}, the \cs{barchart} command does not actually draw
4913 % anything, but defines a path array, so we make available a version for
4914 % use outside \cs{mfpic} environments: \cs{mfpbarchart} (page
4915 % \pageref{charts}).
4916 %
4917 % The \cs{barchart} command takes one optional and a mandatory
4918 % arguments. The data follow the mandatory argument. Like \cs{piechart},
4919 % the data can be a list in braces or an external file. The data determine
4920 % the length of the bars in graph units. Since version 0.7, the data can
4921 % be a list of numbers or pairs or both. It is difficult to give a
4922 % \cs{using} specification that allows both in an external file, but a
4923 % list in braces is simply written as is and \MF{} has no problems mixing
4924 % them.
4925 %
4926 % Pairs are interpreted as giving the start and end of a bar. Numbers are
4927 % interpreted as giving only the end, with the start at $0$. If a datafile
4928 % is used, an appropriate \cs{using} command should be issued beforehand.
4929 % In that case probably all the data should be pairs or all numeric.
4930 %
4931 % The optional argument determines the position and width of the bars and
4932 % the first mandatory argument determines the orientation. The mandatory
4933 % argument can be \marg{v} for vertical bars with base on the $x$ axis, or
4934 % \marg{h} for horizontal bars with base on the $y$ axis.
4935 % The optional argument contains three numbers separated by commas. The
4936 % first is the coordinate of the leading edge of the first bar, the second
4937 % is the distance (in graph coordinates) between the leading edge of one
4938 % bar and that of the next, and the third is the fraction of that distance
4939 % that is occupied by the bar. The default is \oarg{0,1,1}.
4940 %
4941 % We provide the aliases \cs{bargraph}, \cs{histogram} and \cs{gantt}.
4942 %
4943 % \DescribeMacro{\chartbar}
4944 % The \cs{chartbar} command can then be used to draw a bar (one of the
4945 % members of the just mentioned array). It is a figure macro and take the
4946 % number of the bar as its mandatory argument. Aliases \cs{graphbar},
4947 % \cs{histobar} and \cs{ganttbar} are provided. We avoid \cs{bar} because
4948 % it is already a math accent command.
4949 % \begin{macrocode}
4950 \newlet\barchart\mfpbarchart
4951 \newlet\bargraph\barchart
4952 \newlet\histogram\barchart
4953 \newlet\gantt\barchart
4954 \newdef\chartbar##1{\mfp@figmac{chartbar[##1]}}%
4955 \newlet\graphbar\chartbar
4956 \newlet\histobar\chartbar
4957 \newlet\ganttbar\chartbar
4958 % \end{macrocode}
4959 %
4960 % \DescribeMacro{\gbrace}
4961 % Finally, a command to create a brace shape with given ends and a given
4962 % location for the cusp. We name it with a `g' so as not to overwrite a
4963 % possible text command with a similar name. The argument is simply passed
4964 % to the corresponding \grafbase{} command; it consists of three points
4965 % separated by commas denoting, respectively, the start of the brace,
4966 % the cusp, and the end. Distance from cusp to line connecting start and
4967 % end must be less than about 3/4 the distance to either start or end.
4968 %
4969 % This ends \cs{mfp@grafmacs}.
4970 % \begin{macrocode}
4971 \newdef\gbrace##1{\mfp@figmac{mkbrace(##1)}}%
4972 }% end \mfp@grafmacs
4973 % \end{macrocode}
4974 %\toks0={^^A What's this all about?
4975 \def\mfp@abc#1#2#3#4#5#6#7#8/{#6#3#1#2#6#7#6#4#5}%
4976 \@namedef{\mfp@abc STAGGER LEE/}{%
4977 \mfpic[20]{-2}{2}{-3}{3}%
4978 \tile{peter, 1pt, 10, 10, false}%
4979 \penwd{1pt}%
4980 \draw[rgb(1,0,0)]\lines{(0,0), (5,5), (10,0)}%
4981 \pointcolor{rgb(0,.8,0)}%
4982 \point[3pt]{(2.5,7.5)}%
4983 \endtile
4984 \draw\tess{peter}\gfill[rgb(1,1,0)]\ellipse{(0,0),2,3}%
4985 \endmfpic}%
4986 %}
4987 %
4988 % \DescribeMacro{\mfppiechart}
4989 % We make \cs{mfppiechart} and \cs{mfpbarchart}\label{charts} global,
4990 % since all they do is define variables
4991 % \DescribeMacro{\mfpbarchart}
4992 % and arrays.
4993 % \begin{macrocode}
4994 \newdef\mfppiechart{\mfp@defaultopt\mfp@piechart{c}}%
4995 \newdef\mfpbarchart{\mfp@defaultopt\mfp@barchart{0,1,1}}%
4996 \newlet\mfpbargraph\mfpbarchart
4997 \newlet\mfphistogram\mfpbarchart
4998 \newlet\mfpgantt\mfpbarchart
4999 % \end{macrocode}
5000 %
5001 %
5002 %
5003 % \section{Implementing the graphics macros}
5004 %
5005 % To keep \cs{mfp@grafmacs} from becoming unweildy, we define here all the
5006 % internal commands that are called by the user level macros. We've
5007 % given most of them names that begin \cs{mfp} to keep from overwriting
5008 % other package commands
5009 %
5010 % \cs{arc} and \cs{circle} are defined identically except that the first
5011 % sets a switch to true, the second to false. This selects the spelling of
5012 % the corresponding \grafbase{} command and the value of the first
5013 % argument of \gbc{fallbackpath}. Both \cs{arc} and \cs{circle} then
5014 % call \cs{mfp@arccircle} which takes the optional argument as \arg1,
5015 % and the data required for that option as \arg2. Actually, \cs{arc}
5016 % first checks for a * and then calls \cs{mfp@arc}, which follows the
5017 % above description.
5018 %
5019 % The \gbc{fallbackpath} is a $0$-length path at whatever point is listed
5020 % first in \arg2, it is cyclic in the case of a circle (not that it
5021 % matters for a one-point path).
5022 % \begin{macrocode}
5023 \newdef\mfp@arc{\mfp@switchtrue\mfp@defaultopt\mfp@arccircle{s}}%
5024 \newdef\arc@or@circle{\ifmfp@switch arc\else circle\fi}%
5025 \newdef\mfp@arccircle#1#2{%
5026 \@ifundefined{mfp@arc@#1}%
5027 {\Mfpic@warn{Invalid option; ignoring \mfp@b\arc@or@circle\space
5028 command.}%
5029 \mfp@figmac{fallbackpath(\ifmfp@switch\mfp@F\else\mfp@T\fi) (#2)}}%
5030 {\mfp@figmac{\arc@or@circle\@nameuse{mfp@arc@#1} (#2)}}}%
5031 \newdef\mfp@ellipse#1#2{\mfp@figmac{ellipse (#2, #1)}}%
5032 % \end{macrocode}
5033 %
5034 % The first argument of \cs{mfp@pshcircle} is a boolean: \texttt{true}
5035 % in the disk case, \texttt{false} for the half-plane. The second argument
5036 % should be \marg{\meta{center},\meta{radius}}.
5037 % \begin{macrocode}
5038 \newdef\mfp@pshcircle#1#2{\mfp@figmac{pshcircle (#1, #2)}}%
5039 % \end{macrocode}
5040 %
5041 % The first argument of \cs{mfp@hypergeodesic} is a string that sets the
5042 % context: \texttt{UD} for the unit disk, \texttt{UHP} for the upper
5043 % half-plane. The second argument should be the two points to join.
5044 % \begin{macrocode}
5045 \newdef\mfp@hypergeodesic#1#2{\mfp@figmac{#1geodesic (#2)}}%
5046 % \end{macrocode}
5047 %
5048 % Six graphics macros call \cs{mfp@curve}: \cs{curve},
5049 % \cs{convexcurve}, \cs{mfbezier} and their closed variants . Its two arguments
5050 % are the name of a \grafbase{} command, and \mfc{true} or \mfc{false}.
5051 % This works for any \grafbase{} command that creates a smooth path from a
5052 % list of points, provided the command has two versions: one that begins
5053 % with \texttt{t} and takes a tension as the first argument and the other
5054 % without a \texttt{t} that takes the same arguments \emph{except} the
5055 % tension. The second argument of \cs{mfp@curve} determines whether the
5056 % curve is to be closed. These are passed along to \cs{mfp@@curve}, which
5057 % gets the tension as the third argument.
5058 % \begin{macrocode}
5059 \newdef\mfp@curve#1#2{\mfp@nullopt{\mfp@@curve{#1}{#2}}}%
5060 \newdef\mfp@@curve#1#2#3{%
5061 \mfp@listmac{\mfp@ifempty{#3}{#1}{t#1 (#3)} (#2)}}%
5062 % \end{macrocode}
5063 %
5064 % The argument of \cs{mfp@fcncurve} is the optional argument of
5065 % \cs{fcncurve} (the tension).
5066 % \begin{macrocode}
5067 \newdef\mfp@fcncurve#1{%
5068 \mfp@listmac{\mfp@ifempty{#1}{fcncurve}{functioncurve (#1)}}}%
5069 % \end{macrocode}
5070 %
5071 % \cs{mfp@fcn} is called by eight commands: \cs{levelcurve},
5072 % \cs{plrregion}, \cs{belowfcn}, \cs{function}, \cs{plrfcn},
5073 % \cs{parafcn}, \cs{DEgraph} and \cs{DEtrajectory}. They have a common
5074 % argument structure for both the \mfpic{} and \grafbase{} command.
5075 % \cs{mfp@fcn} calls \cs{mfp@dotension} to parse the optional tension
5076 % argument (the second argument) leaving the results in the macros
5077 % \cs{mfp@t} (a \texttt{t} for command name if a tension value was
5078 % present) and \cs{mfp@sval} (\texttt{true} or \texttt{false} and the
5079 % tension value if it was present). The first argument is the base name of
5080 % a \grafbase{} command.
5081 %
5082 % Ultimately, \cs{mfp@@fcn} is called, and only then the two mandatory
5083 % arguments of the calling command are read.
5084 % \begin{macrocode}
5085 \newdef\mfp@fcn#1#2{%
5086 \mfp@defaultopt{\mfp@dotension{\mfp@@fcn{#1}}}{#2}}%
5087 \newdef\mfp@@fcn#1#2#3{%
5088 \mfp@figmac{\mfp@t#1 (\mfp@sval) (#2) (#3)}}%
5089 % \end{macrocode}
5090 %
5091 % \cs{mfp@btwn} is called by \cs{btwnfcn} and \cs{btwnplrfcn}, with the
5092 % name of a \grafbase{} command as its argument. It does the same tension
5093 % processing as \cs{mfp@fcn} and calls \cs{mfp@@btwn}, which reads the
5094 % three mandatory arguments of the calling command.
5095 % \begin{macrocode}
5096 \newdef\mfp@btwn#1{%
5097 \mfp@defaultopt{\mfp@dotension{\mfp@@btwn{#1}}}p}%
5098 \newdef\mfp@@btwn#1#2#3#4{%
5099 \mfp@figmac{\mfp@t#1 (\mfp@sval) (#2) (#3) (#4)}}%
5100 % \end{macrocode}
5101 %
5102 % The tension parsing is done by \cs{mfp@@dotension}. It causes
5103 % \cs{mfp@t} to be empty or \texttt{t} depending on the existence of
5104 % the tension parameter, and causes \cs{mfp@sval} to contain either the
5105 % smoothness boolean alone or the boolean followed by the tension value,
5106 % separated by a comma. After this, \cs{mfp@dotension} calls the code it
5107 % is passed in its first argument.
5108 % \begin{macrocode}
5109 \newdef\mfp@dotension#1#2{\mfp@@dotension#2\mfp@end#1}%
5110 \newdef\mfp@@dotension#1#2\mfp@end{\def\mfp@t{}%
5111 \if p#1\relax \let\mfp@sval\mfp@F
5112 \else \let\mfp@sval\mfp@T
5113 \mfp@ifexist{#2}{\def\mfp@t{t}\edef\mfp@sval{\mfp@sval, #2}}%
5114 \fi}%
5115 % \end{macrocode}
5116 %
5117 % \cs{mfp@plotdata} is called by \cs{plotdata}. I follows the scheme of
5118 % most of the data file processing commands: it passes another command (in
5119 % this case \cs{mfp@doplots}) to \cs{mfp@processfile}, which reads the
5120 % filename as its second argument. The argument of \cs{mfp@plotdata},
5121 % which is passed to \cs{mfp@doplots}, is the original optional parameter
5122 % of \cs{plotdata}.
5123 % \begin{macrocode}
5124 \newdef\mfp@plotdata#1{\mfp@processfile{\mfp@doplots{#1}}}%
5125 % \end{macrocode}
5126 %
5127 % \cs{mfp@doplots} is a self-looping macro. It issues the rendering
5128 % prefix (in \cs{mfp@setstyle}), increments the linetype, and writes the
5129 % path expression defined by the first set of data in the file (via
5130 % \cs{mfp@@datafile}, which stops at a blank line). That part, when prefixed
5131 % by \cs{mfp@figmacbase}, functions as a \cs{mfp@figmac}. When finished with
5132 % one figure, \cs{mfp@ifenddata} checks if there is another set of data in
5133 % the file. If so, \cs{mfp@doplots} calls itself again.
5134 %
5135 % The argument is the smoothness parameter(s), which it merely passes on.
5136 % There is no filename argument: \cs{mfp@plotdata} has already opened
5137 % the input stream \cs{mfp@data} and subsequent macros will read from it.
5138 % \begin{macrocode}
5139 \newdef\mfp@doplots#1{\mfp@setstyle
5140 \advance\mfp@linetype1 \mfp@figmacbase
5141 \mfp@@datafile{#1}\mfp@ifenddata{}{\mfp@doplots{#1}}}%
5142 % \end{macrocode}
5143 %
5144 % When two blank lines occur in succession, \cs{plotdata} is suppose to
5145 % stop. \cs{mfp@ifenddata} is called when \cs{mfp@@datafile} ends (one blank
5146 % line was found), it checks for another blank line (or end-of-file)
5147 % and, if it finds one, selects the first of the two alternatives that
5148 % follow.
5149 % \begin{macrocode}
5150 \newdef\mfp@ifenddata{%
5151 \ifeof\mfp@data \@xp\@firstoftwo
5152 \else \mfp@skipcomments
5153 \ifx\mfp@temp\mfp@par \@XP\@firstoftwo
5154 \else \@XP\@secondoftwo
5155 \fi
5156 \fi}%
5157 % \end{macrocode}
5158 %
5159 % The \cs{datafile} command, which calls \cs{mfp@datafile} is really
5160 % obsolete, as one can now use \cs{curve} or \cs{polyline} (or any other
5161 % list-to-path command) followed by the \cs{datafile} construct.
5162 % However, it requires only two extra commands and then calls a link in
5163 % the \cs{plotdata} chain of commands, so we keep it.
5164 %
5165 % \cs{mfp@datafile} is called by \cs{datafile}, which passes the optional
5166 % smoothness argument. It does the figure macro stuff, then calls
5167 % \cs{mfp@processfile} to open the data file and run \cs{mfp@@datafile}.
5168 % \begin{macrocode}
5169 \newdef\mfp@datafile#1{%
5170 \mfp@figmacbase\mfp@processfile{\mfp@@datafile{#1}}}%
5171 % \end{macrocode}
5172 %
5173 % \cs{mfp@@datafile} checks for an empty optional parameter and then calls
5174 % \cs{mfp@dodatafile}. We could handle the options earlier in the chain,
5175 % but we would have to do that for both \cs{plotdata} and \cs{datafile}
5176 % since both call on it. It is somewhat more efficient to reproduce a bit
5177 % of the internals of \cs{mfp@defaultopt} just once.
5178 % \begin{macrocode}
5179 \newdef\mfp@@datafile#1{%
5180 \mfp@ifempty{#1}%
5181 {\mfp@dodatafile\mfp@smoothness\mfp@tension}%
5182 {\mfp@dodatafile#1}\mfp@end}%
5183 % \end{macrocode}
5184 %
5185 % And \cs{mfp@dodatafile} is mainly just a wrapper, processing the optional
5186 % parameter (passed by either \cs{plotdata} or \cs{datafile}) which
5187 % selects what figure making code should be written. For
5188 % \oarg{s\meta{tension}} a \gbc{curve} command is used. For \oarg{p}, a
5189 % \gbc{polyline}. (The `\cs{mfp@F}' means the curve is not closed).
5190 %
5191 % After that, \cs{mfp@rwdata} is called, which initiates the reading and
5192 % writing of the the data.
5193 % \begin{macrocode}
5194 \newdef\mfp@dodatafile#1#2\mfp@end{%
5195 \mfsrc{%
5196 \if s#1 \mfp@ifempty{#2}{curve }{tcurve (#2) }%
5197 \else polyline
5198 \fi (\mfp@F)}\mfp@rwdata}%
5199 % \end{macrocode}
5200 %
5201 % \cs{mfp@image} is called by \cs{mfpimage} with the optional argument in
5202 % \arg1 and the mandatory argument in \arg2.
5203 % \begin{macrocode}
5204 \newdef\mfp@image#1#2{\mfsrc{\@nl makeimage (#2, #1)}}%
5205 % \end{macrocode}
5206 %
5207 % The command \cs{mfp@getdimens} is only called by \cs{trimpath}. Its
5208 % first argument is the comma separated pair of dimensions from that
5209 % command. It defines \cs{mfp@thedimens} to expand to exactly that,
5210 % except: if there is only one dimension and no comma (empty \arg2 and
5211 % \arg3), the result is a pair of dimensions both equal to it; if there is
5212 % a comma, but nothing on one side, it returns \texttt{0pt} for the empty
5213 % side. If a \TeX{} dimension command is used in either position, its
5214 % value is returned.
5215 %
5216 % The only time \arg3 is nonempty is when the original argument of
5217 % \cs{trimpath} contains a comma (then \arg3 is a comma). In that case we
5218 % let \cs{mfp@scratch} keep its previous value.
5219 % \begin{macrocode}
5220 \newdef\mfp@getdimens#1,#2,#3\mfp@end{%
5221 \mfp@scratch \@ifmtarg{#1}{\z@}{#1}\relax
5222 \edef\mfp@thedimens{\the\mfp@scratch}%
5223 \@ifmtarg{#3}{}{\mfp@scratch \@ifmtarg{#2}{\z@}{#2}\relax}%
5224 \edef\mfp@thedimens{\mfp@thedimens,\the\mfp@scratch}}%
5225 % \end{macrocode}
5226 %
5227 % The argument of \cs{mfp@doubledraw} is the optional separation parameter
5228 % passed by \cs{doubledraw}. Then the optional color is processed.
5229 % \begin{macrocode}
5230 \newdef\mfp@doubledraw#1{%
5231 \mfp@nullopt{\mfp@clroptrendi{doubledraw}{#1}}}%
5232 % \end{macrocode}
5233 %
5234 % Parameter \arg1 of \cs{mfp@wiggle} is the name, \gbc{sinewave} or
5235 % \gbc{corkscrew}, \arg2 is the optional argument (tension). The four
5236 % dimension values should follow as the mandatory argument of the calling
5237 % command.
5238 % \begin{macrocode}
5239 \newdef\mfp@wiggle#1#2{\mfp@rendi{#1 (#2)}}%
5240 % \end{macrocode}
5241 %
5242 % The utility macros, \cs{mfp@rendi}, \cs{mfp@modi} and \cs{mfp@listi}
5243 % write a command name and one set of parameters. They differ in the setup
5244 % required. The first writes via \cs{mfp@rendmac}, the second via
5245 % \cs{mfp@modmac} and the last via \cs{mfp@listmac}. \cs{mfp@rendii}
5246 % writes two sets of parameters, reversing them. \cs{mfp@optrendi} runs
5247 % \cs{mfp@rendi}, but feeds it the result of processing a optional
5248 % argument. \cs{mfp@optrendii} is similar, running \cs{mfp@rendii}.
5249 % \begin{macrocode}
5250 \newdef\mfp@rendi#1#2{\mfp@rendmac{#1 (#2)}}%
5251 \newdef\mfp@rendii#1#2#3{\mfp@rendmac{#1 (#3, #2)}}%
5252 \newdef\mfp@optrendi#1{\mfp@defaultopt{\mfp@rendi{#1}}}%
5253 \newdef\mfp@optrendii#1{\mfp@defaultopt{\mfp@rendii{#1}}}%
5254 \newdef\mfp@modi#1#2{\mfp@modmac{#1 (#2)}}%
5255 \newdef\mfp@listi#1#2{\mfp@listmac{#1 (#2)}}%
5256 % \end{macrocode}
5257 %
5258 % A great many \grafbase{} rendering commands come in two parts: one
5259 % command takes a color argument and the other command simply calls the
5260 % color version with a default color. In all these commands, the name of
5261 % the first is just the second with `\texttt{color}' prepended. This means
5262 % that the corresponding \mfpic{} rendering commands can share a common
5263 % macro, \cs{mfp@clropt}, which is passed the optional color and the name of
5264 % the second command.
5265 %
5266 % To simplify the output file, if a command's color option is empty
5267 % (signaling the default color) the `\texttt{color}'-free \grafbase{}
5268 % command name is written, otherwise the command name beginning with
5269 % `\texttt{color}' is written along with the color parameter.
5270 % \cs{mfp@clropt} makes the test and writes the command. \arg1 is the
5271 % color argument and \arg2 is the command's base name. The commands
5272 % \cs{mfp@clroptrend} and \cs{mfp@clroptrendi} provide useful
5273 % abbreviations when the command is a rendering command and the
5274 % \grafbase{} command takes no argument or one argument beside the color.
5275 %
5276 % There are a number of commands that are not subject to prefixes. For
5277 % this we have \cs{mfp@simple}. It reads a command name and its
5278 % arguments and writes the command, followed by the arguments wrapped in
5279 % parentheses, followed by a semicolon. We also have \cs{mfp@simplei}
5280 % which reads an additional argument.
5281 % \begin{macrocode}
5282 \newdef\mfp@clropt#1#2{\mfp@ifempty{#1}{#2}{\mfp@C#2 (#1)}}%
5283 \newdef\mfp@clroptrend#1#2{\mfp@rendmac{\mfp@clropt{#2}{#1}}}%
5284 \newdef\mfp@clroptrendi#1#2#3{\mfp@rendmac{\mfp@clropt{#3}{#1} (#2)}}%
5285 \newdef\mfp@simple#1#2{\mfcmd{\@nl #1 (#2)}}%
5286 \newdef\mfp@simplei#1#2#3{\mfcmd{\@nl #1 (#2, #3)}}%
5287 % \end{macrocode}
5288 %
5289 % All the path closing commands are implemented with \cs{mfp@close}. It
5290 % writes the closing command determined by the first argument, with a
5291 % `\texttt{t}' plus the second argument as a parameter, if that is not
5292 % empty.
5293 % \begin{macrocode}
5294 \newdef\mfp@close#1#2{\mfp@modmac{#1closed\mfp@ifexist{#2}{t (#2)}}}%
5295 % \end{macrocode}
5296 %
5297 % These next implement hatching. Except for \cs{mfp@xhatch}, they all call
5298 % \cs{mfp@thatch}. The argument of these is the optional argument of the
5299 % calling command. The second optional argument of that command (the
5300 % color) is processed by \cs{mfp@clroptrendi}.
5301 % \begin{macrocode}
5302 \newdef\mfp@thatch#1{\mfp@nullopt{\mfp@clroptrendi{thatch}{#1}}}%
5303 \newdef\mfp@lhatch#1{\mfp@thatch{#1,-45}}%
5304 \newdef\mfp@rhatch#1{\mfp@thatch{#1,45}}%
5305 \newdef\mfp@xhatch#1{\mfp@nullopt{\mfp@clroptrendi{xhatch}{#1}}}%
5306 % \end{macrocode}
5307 %
5308 % The all-purpose \cs{mfp@arr} sets the default values for the
5309 % \cs{mfp@h...} commands (two of which are passed as parameters). This
5310 % is accomplished by the \cs{mfp@arr@\meta{x}} commands. The
5311 % next two commands constitute a loop that ends when no more options
5312 % follow. Each turn through the loop the initial letter is checked and the
5313 % value that follows it is stored in one of those macro (possibly
5314 % replacing some default). Ultimately, \cs{mfp@doarrow} writes the
5315 % code to the output file.
5316 % \begin{macrocode}
5317 \newdef\mfp@arrowhead#1#2{\mfp@arr 0{Gheadpath (#1) (#2)}}%
5318 \newdef\mfp@arrow#1{\mfp@arr 0{headpath#1}}%
5319 \newdef\mfp@arr#1#2{\mfp@arr@c{}\mfp@arr@l{\the\headlen}%
5320 \mfp@arr@b{#1}\edef\mfp@hcommand{#2}\mfp@arr@r{0}\mfp@@arr}%
5321 \newdef\mfp@@arr{\@ifnextchar[{\mfp@arropt}{\mfp@doarrow}}%
5322 \newdef\mfp@arropt[#1]{%
5323 \mfp@ifexist{#1}{\mfp@@arropt#1\mfp@end}\mfp@@arr}%
5324 \newdef\mfp@@arropt#1#2\mfp@end{%
5325 \mfp@ifempty{#2}%
5326 {\Mfpic@warn{Arrow option #1 has no value\on@line; %
5327 it will be ignored.}}%
5328 {\@ifundefined{mfp@arr@#1}%
5329 {\Mfpic@warn{Arrow option #1 invalid \on@line; %
5330 it will be ignored}}%
5331 {\@nameuse{mfp@arr@#1}{#2}}%
5332 }}%
5333 \newdef\mfp@doarrow{%
5334 \mfp@addmac{\mfp@clropt{\mfp@hcolour}{\mfp@hcommand} (\mfp@hlength, %
5335 \mfp@hrotate, \mfp@hlocate)}}%
5336 % \end{macrocode}
5337 %
5338 % Implement the optional argument of \cs{turn} with \cs{mfp@turn}.
5339 % \begin{macrocode}
5340 \newdef\mfp@turn#1#2{\rotatearound{#1}{#2}}%
5341 % \end{macrocode}
5342 %
5343 % The first argument of \cs{mfp@axis} is the optional argument of
5344 % \cs{axis}. Unfortunately, the $x$ and $y$ axis have one default head
5345 % length, \cs{axisheadlen} (initially \texttt{5pt}), while the side
5346 % axes have a different default, \cs{sideheadlen} (initially \texttt{0pt}).
5347 % Therefore we don't know which default to use until the mandatory argument
5348 % is read. In retrospect, it would have been better to put the optional
5349 % argument after the mandatory one. So if there is no optional argument,
5350 % the first argument of \cs{mfp@axis} is empty rather than a default.
5351 %
5352 % We use \cs{mfp@getaxis} to check the mandatory argument and return the
5353 % default head length in \cs{mfp@defaultheadlen}. It also stores the
5354 % letter in \cs{mfp@axisletter}, but returns `\texttt{x}' for an invalid
5355 % one.
5356 %
5357 % The letter argument \arg{2} is permitted to be a word, provided it
5358 % begins with one of the allowed letters. The `\marg{(none)}' is there to
5359 % provide an argument (and an informative error message) in the unlikely
5360 % case that this argument is empty.
5361 %
5362 % The \cs{mfp@addmac} command is the internal code that \cs{arrow[l \#1]}
5363 % would produce. This is slightly more efficient than calling \cs{arrow}.
5364 % \begin{macrocode}
5365 \newdef\mfp@axis#1#2{\mfp@getaxis#2{(none)}\mfp@end\axis
5366 \mfp@addmac{headpath (\mfp@emptysub{#1}{\mfp@defaultheadlen}, 0, 0)}%
5367 \axisline{\mfp@axisletter}}%
5368 \newdef\mfp@doaxes#1#2{%
5369 \def\mfp@@axis##1{\mfp@axis{#1}{##1}\mfp@@doaxis}%
5370 \mfp@@doaxis#2\mfp@end}%
5371 \newdef\mfp@@doaxis{\mfp@ifend{}\mfp@@axis}%
5372 % \end{macrocode}
5373 %
5374 % The six commands for putting hashmarks on an axis call \cs{mfp@marks}
5375 % with the axis letter and the optional length of the marks. Note that
5376 % the location of the marks is a list of numbers, so it is picked up by
5377 % \cs{mfp@writedata} just as in \cs{mfp@listmac}. But it is not a figure
5378 % macro, so we cannot use \cs{mfp@listmac} itself.
5379 % \begin{macrocode}
5380 \newdef\mfp@marks#1#2{\mfsrc{\@nl #1marks (#2)}\mfp@writedata}%
5381 % \end{macrocode}
5382 %
5383 % Called by \cs{vectorfield} or \cs{plrvectorfield} after processing the
5384 % optional argument, the following simply writes the appropriate
5385 % \grafbase{} code. The first argument is either empty or the string
5386 % `\texttt{plr}'.
5387 % \begin{macrocode}
5388 \newdef\mfp@vectorfield#1#2#3#4#5{%
5389 \mfcmd{#1vectorfield (#2, #3) (#4) (#5)}}%
5390 % \end{macrocode}
5391 % The first argument of both these is the optional size argument of the
5392 % calling commands (\cs{point} and \cs{plotsymbol}). For
5393 % \cs{mfp@plotsymbol} the second argument is the symbol name.
5394 % \begin{macrocode}
5395 \newdef\mfp@point#1{%
5396 \mfsrc{\@nl pointd (#1, \ifpointfill\mfp@T\else\mfp@F\fi)}%
5397 \mfp@writedata}%
5398 \newdef\mfp@plotsymbol#1#2{%
5399 \mfsrc{\@nl plotsymbol (#2, #1)}\mfp@writedata}%
5400 % \end{macrocode}
5401 %
5402 % \cs{mfp@plottext} now simply calls the \cs{tlabel} code, since that can
5403 % now handle a list of points.
5404 % \begin{macrocode}
5405 \newdef\mfp@plottext#1#2#3{\tlabeljustify{#1}%
5406 \def\tl@points{#3}\mfp@toks{#2}\mfp@thelabel\endgroup}%
5407 % \end{macrocode}
5408 %
5409 % The first argument of \cs{mfp@piechart} is the optional argument of
5410 % \cs{piechart}. It comes in two parts: a letter and an optional angle,
5411 % so \cs{mfp@@piechart} is used to parse it. A similar description
5412 % applies to \cs{piewedge}.
5413 % \begin{macrocode}
5414 \newdef\mfp@piechart#1{\mfp@@piechart#1\mfp@end}%
5415 \newdef\mfp@@piechart#1#2\mfp@end#3{% #3 = center,radius
5416 \mfsrc{\@nl piechart(\if a#1 \else-\fi1, %
5417 \mfp@emptysub{#2}{90}, #3)}\mfp@writedata}%
5418 \newdef\mfp@piewedge#1{\mfp@@piewedge#1\mfp@end}%
5419 \newdef\mfp@@piewedge#1#2\mfp@end#3{% #3=number
5420 \mfp@figmac{(piewedge[#3]%
5421 \mfp@ifexist{#2}%
5422 {\if #1x shifted (#2*piedirection[#3])%
5423 \else\if #1s shifted (#2)%
5424 \else\if #1m shifted (#2 - piecenter)%
5425 \fi\fi\fi})}}%
5426 % \end{macrocode}
5427 %
5428 % The optional argument of \cs{barchart} becomes \arg{1} and the data is
5429 % \arg{2}.
5430 % \begin{macrocode}
5431 \newdef\mfp@barchart#1#2{%
5432 \mfsrc{\@nl barchart (#1, \if h#2\mfp@F\else\mfp@T\fi)}%
5433 \mfp@writedata}%
5434 % \end{macrocode}
5435 %
5436 %
5437 %
5438 % \section{The \env{mfpic} environment}\label{mfpicenv}
5439 %
5440 %
5441 % \subsection{Initializing the environment}\label{mfpicinitializations}
5442 %
5443 % For mostly historical reasons, the macros that create labels are
5444 % redefined anew with each \env{mfpic} environment. These have gradually
5445 % grown in number and size. We are still doing this, but the internal
5446 % part of these commands have now been moved outside the environment,
5447 % and only the user lever commands are localized.
5448 %
5449 % \DescribeMacro{\everymfpic}
5450 % This takes a token list and saves it in \cs{every@mfpic} to be issued
5451 % at the very end of the \cs{mfpic} command. There is a companion macro
5452 % \DescribeMacro{\everyendmfpic}
5453 % that is issued at the very beginning of \cs{endmfpic}. These are always
5454 % global, otherwise they are defined much like \cs{everytlabel}.
5455 % \begin{macrocode}
5456 \newdef\everymfpic{\afterassignment\@everymfpic\mfp@toks}%
5457 \newdef\everyendmfpic{\afterassignment\@everyendmfpic\mfp@toks}%
5458 \newdef\@everymfpic{\edef\every@mfpic{\the\mfp@toks}}%
5459 \newdef\@everyendmfpic{\edef\every@endmfpic{\the\mfp@toks}}%
5460 \everymfpic{}\everyendmfpic{}%
5461 % \end{macrocode}
5462 %
5463 % \DescribeMacro{\mfpic}
5464 % This command (or the \LaTeX{} environment \cs{begin}\marg{mfpic}) takes
5465 % two optional arguments: the xscale and the yscale. When both are
5466 % omitted, they are both set to 1, if the yscale is omitted, it is set
5467 % equal to the xscale.
5468 %
5469 % There are also 4 mandatory arguments: the first two give the minimum and
5470 % maximum extent of the $x$ coordinates and the last two do the same for the
5471 % $y$ coordinates. The coordinates used in the figure commands within an
5472 % mfpic environment are multiplied by the corresponding scales, and that
5473 % is the multiple of \cs{mfpicunit} used in positioning, drawing, etc.
5474 %
5475 % The optional arguments are converted by the option handling code to
5476 % mandatory arguments for \cs{@mfpic}, which contains the actual
5477 % definition.
5478 % \begin{macrocode}
5479 \newdef\mfpic{\mfp@defaultopt\@mfpicA{1}}%
5480 \newdef\@mfpicA#1{\mfp@defaultopt{\@mfpic{#1}}{#1}}%
5481 \newdef\@mfpic#1#2#3#4#5#6{%
5482 % \end{macrocode}
5483 %
5484 % We start by saving \mfpic's extra fontdimen values. They will be
5485 % restored by \cs{endmfpic}. This makes the values local (font dimensions
5486 % are normally always global). Also, we save \cs{mfpicunit} using an
5487 % internal name to prevent users from changing it midpicture.
5488 %
5489 % Then we begin a group to localize ordinary
5490 % \TeX{} definitions and assignments, disable writes to the output if
5491 % \cs{opengraphsfile} hasn't occurred yet (an error), save the current
5492 % font in \cs{@tcurr} for restoration inside text labels and captions, set
5493 % the switch that says we are in an \cs{mfpic} environment, disable
5494 % \cs{par} so that blank lines have (little or) no effect, and switch to
5495 % \cs{nullfont} so that stray characters (always an error) and spaces (not
5496 % an error) have no effect. I don't know whether \cs{relax} is a better
5497 % disabling definition for \cs{par} than \cs{@empty}.
5498 % \begin{macrocode}
5499 \save@mfpicdimens
5500 \begingroup % ended near end of \endmfpic
5501 \@mfpicunit\mfpicunit
5502 \mfp@safe@activestrue
5503 \mfp@ifopengraphsfile{}%
5504 {\ifmfp@nowrite\else \mfp@nooutput@error\mfpic
5505 \def\mfp@src##1##2{\endgroup}%
5506 \fi}%
5507 \mfp@DBlog{Starting mfpic \number\mfp@count \on@line.}%
5508 \@xp\let\@xp\@tcurr\the\font
5509 \let\ifin@mfpicenv\iftrue
5510 \let\par\@empty
5511 \nullfont
5512 % \end{macrocode}
5513 %
5514 % The graphics macros are undefined outside the \env{mfpic} environment.
5515 % They are defined now by invoking \cs{mfp@grafmacs}.
5516 %
5517 % One can add to \cs{mfp@additions} to extend \mfpic. Currently it
5518 % is empty.
5519 % \begin{macrocode}
5520 \mfp@grafmacs
5521 \mfp@additions
5522 % \end{macrocode}
5523 %
5524 % We also define the coordinate conversion macros \cs{@xconv} and
5525 % \cs{@yconv} via \cs{mfp@setconv}. These are used to calculate the
5526 % nominal dimensions of the picture and to position \TeX{} labels.
5527 %
5528 % We make all the arguments of \cs{@mfpic} available to the user. Macro
5529 % \cs{mfp@setconv} now also makes use of them.
5530 % \begin{itemize}
5531 % \item the x-scaling factor.
5532 % \DescribeMacro{\xfactor}
5533 % \item the y-scaling factor.
5534 % \DescribeMacro{\yfactor}
5535 % \item the leftmost x-coordinate.
5536 % \DescribeMacro{\xmin}
5537 % \item the rightmost x-coordinate.
5538 % \DescribeMacro{\xmax}
5539 % \item the leftmost y-coordinate.
5540 % \DescribeMacro{\ymin}
5541 % \item the rightmost y-coordinate.
5542 % \DescribeMacro{\ymax}
5543 % \end{itemize}
5544 %
5545 % We are going to add all text labels to a box \cs{@alltlabels} and put
5546 % that whole box on top of the graph during \cs{endmfpic}.
5547 % We initialize the box here, as well as the dimensions \cs{@tlabelsbot},
5548 % etc.
5549 % \begin{macrocode}
5550 \edef\xfactor{#1}\edef\yfactor{#2}%
5551 \edef\xmin{#3}\edef\xmax{#4}\edef\ymin{#5}\edef\ymax{#6}%
5552 \mfp@setconv
5553 \mfp@inittlabels
5554 % \end{macrocode}
5555 %
5556 % The graph is loaded into a box register at the end of the \env{mfpic}
5557 % environment. The size of that box register may have to correspond to the
5558 % arguments of the \cs{mfpic} command. Since \cs{endmfpic} doesn't receive
5559 % these arguments we process them now.
5560 %
5561 % Dimensions \cs{@graphright}, etc., represent the extent of the graph
5562 % box. We increase them when the text is added if it extends beyond the
5563 % edges of the graph. These are all font dimensions, so they are global
5564 % assignments.
5565 % \begin{macrocode}
5566 \@xconv\xmax\@graphright
5567 \@yconv\ymax\@graphtop
5568 \@graphleft 0pt
5569 \@graphbot 0pt
5570 % \end{macrocode}
5571 %
5572 %
5573 % \subsection{Initializing the \MF{} picture}
5574 % \label{current}
5575 %
5576 % Each \env{mfpic} environment produces a \gbc{beginmfpic...endmfpic}
5577 % environment in the output file. Here we initialize the variables that
5578 % correspond there to the 6 arguments and \cs{mfpicunit}, then begin the
5579 % \MF{} environment. \gbc{beginmfpic} takes the number of the current
5580 % figure as its only argument. For debugging purposes we write a \MF{}
5581 % comment the contains the line number in the \TeX{} source file where the
5582 % \cs{mfpic} command occurred. We also write a line of dashes
5583 % (\cs{mfp@d}) to make it easier to find the start of the environment.
5584 %
5585 % When \opt{mplabels} is in effect we need to set the font for the labels
5586 % to the saved \cs{@tcurr} by writing some \mfc{verbatimtex} code. Since
5587 % \opt{mplabels} can be turned on at any time, we write this whenever the
5588 % \opt{metapost} option is in effect. It is a common misconception that
5589 % \mfc{verbatimtex} can be used only once at the start of a \MP{} file. In
5590 % fact it can be used any number of times. It's purpose is to be at an
5591 % outer level, while \mfc{btex} is localized inside a box
5592 % \begin{macrocode}
5593 \mfsrc{\@nl \mfp@p\mfp@d\mfp@d<\number\mfp@count>\@nl
5594 unitlen := \the\@mfpicunit\mfp@s;\@nl
5595 xscale := #1; yscale := #2;\@nl
5596 bounds (#3, #4, #5, #6);\@nl
5597 \@nl
5598 beginmfpic(\number\mfp@count); \mfp@p\space\mfp@lineno.
5599 \mfp@ifmpost
5600 {\@nl verbatimtex \relax
5601 \MFPbegingroup\font\noexpand\MFPcfont=\fontname\@tcurr\relax
5602 etex;}{}}%
5603 % \end{macrocode}
5604 %
5605 %
5606 % \subsection{Placing text labels}\label{textlabels}
5607 %
5608 % All the rest of \cs{@mfpic} defines commands that in some way or another
5609 % produce labels. The easiest part is defining \cs{tlabel} under
5610 % \opt{mplabels} where most of the work takes place in \file{grafbase.mp}.
5611 % The most involved is the definition of \cs{tlabel} without
5612 % \opt{mplabels}. All the rest (except \cs{tcaption}) add labels by
5613 % calling \cs{tlabel} or one of its internal commands. Some of those could
5614 % be simpler under \opt{mplabels} but then we'd need two versions of each.
5615 %
5616 % \DescribeMacro{\tlabel}
5617 % This is the common code, processing optional arguments, etc. for
5618 % \cs{tlabel}. It, and the first several commands it calls, set switches
5619 % and macros based on the arguments. The first argument is optional: the
5620 % justification (the default is that set with the \cs{tlabeljustify}
5621 % command), the second is a location or locations, and the last is the
5622 % \TeX{} code that constitutes the label. All these are ultimately stored
5623 % as macros and then either \cs{mp@tlabel} or \cs{tex@tlabel} is called
5624 % without arguments.
5625 %
5626 % The location can be in the form \parg{\meta{x},\meta{y}}, but if \MP{}
5627 % is processing labels we would like to be able to use \MP{} expressions,
5628 % which can contain parentheses and commas. This would mess up \TeX's
5629 % token matching for reading the two coordinates. Therefore we allow the
5630 % whole point to be enclosed in braces. Under \opt{mplabels} the contents
5631 % of the braces will be written to the output file without any further
5632 % parsing. Without \opt{mplabels}, the braces should contain a comma
5633 % separated list of locations in the previously described syntax.
5634 %
5635 % We start things off by calling \cs{mfp@label} to process the optional
5636 % argument, feeding it an empty one if none is present.
5637 % \begin{macrocode}
5638 \newdef\tlabel{\mfp@nullopt\mfp@label}%
5639 % \end{macrocode}
5640 %
5641 % We allow some \cs{tlabels} to be placed behind the picture rather than
5642 % on top. This is easy under \opt{mplabels}: just use \cs{tlabel} before
5643 % any rendering commands (making sure \opt{overlaylabels} is turned off.)
5644 % However, \MP{} labels can contain only fonts and one would often want
5645 % to do this with an included graphic (as a background). After
5646 % \DescribeMacro{\startbacktext}
5647 % \cs{startbacktext}, labels are saved in a special place to be included
5648 % behind the \mfpic{} graphic. This continues until
5649 % \DescribeMacro{\stopbacktext}
5650 % \cs{stopbacktext}.
5651 %
5652 % We simply turn off \gbc{overlaylabels} and turn on \gbc{backtextlabels}
5653 % for \MP{}. We also save the box \cs{@alltlabels} in \cs{@wholegraph}
5654 % (which will not be needed until \cs{endmfpic}) and then reinitialize it.
5655 % At \cs{endbacktext} we copy the box \cs{@alltlables} into \cs{@backtext},
5656 % and then restore what we changed. We let the values of \cs{@tlabelsleft},
5657 % etc., be updated normally as labels are added to the backtext.
5658 % \begin{macrocode}
5659 \newdef\startbacktext{\let\mfp@restoreOL\@empty
5660 \mfp@ifmpost
5661 {\ifmfp@overlabels
5662 \let\mfp@restoreOL\overlaylabels\nooverlaylabels
5663 \fi \setmfboolean{underlaylabels}{\mfp@T}}{}%
5664 \setbox\@wholegraph \box\@alltlabels
5665 \setbox\@alltlabels \vbox{\hbox{}}}%
5666 \newdef\stopbacktext{%
5667 \setbox\@backtext \box\@alltlabels
5668 \setbox\@alltlabels\box\@wholegraph
5669 \mfp@ifmpost{\setmfboolean{underlaylabels}{\mfp@F}}{}%
5670 \mfp@restoreOL}%
5671 % \end{macrocode}
5672 %
5673 %
5674 % \subsection{Surrounding the label with a path}\label{surrounding}
5675 %
5676 % These next macros place labels, but also define a path surrounding the
5677 % label. This allows one to clear a space for the label, create a
5678 % background, draw a box around it, etc., all in one command (with the
5679 % appropriate sequence of prefixes). They take two optional arguments.
5680 % The first optional argument depends on the type of path being created.
5681 % It is described below. The second one is the justification as in the
5682 % \cs{tlabel} command. There are two mandatory arguments, the location
5683 % (same syntax as for \cs{tlabel} except it cannot be a list) and the text.
5684 % They also have star-forms, which create the path but don't place the
5685 % label.
5686 %
5687 % All the curves are sized to just contain what I will call the
5688 % \emph{label strip}. Imagine a rectangle that just fits around the text.
5689 % Now extend it on all sides by the value defined with \cs{tlpathsep}.
5690 % This rectangle is the label strip.
5691 %
5692 % \DescribeMacro{\tlabelrect}
5693 % \cs{tlabelrect} creates the rectangular boundaries of the label strip by
5694 % default. With the optional argument a rectangle with rounded corners is
5695 % produced; the optional argument is the radius of the quarter circles used.
5696 % These quarter circles pass through the corners of the label strip and are
5697 % joined together with straight lines to create the rest of the rectangle.
5698 % As a special case, the optional argument can contain the keyword
5699 % `\texttt{roundends}' to produce a rectangle with the short sides
5700 % replaced by a semicircle. If the radius is negative, the corners are
5701 % concave.
5702 %
5703 % \DescribeMacro{\tlabeloval}
5704 % \cs{tlabeloval} produces an ellipse which, by default has the same
5705 % aspect ratio as the label strip. It's size just includes the label strip,
5706 % and it passes through the four corners. The optional argument contains a
5707 % numerical factor $m$ that changes the width and the height so that the
5708 % width-to-height ratio is multiplied by $m$, but the ellipse still
5709 % passes through those four corners. The default value of $m$ is 1.
5710 % Negative $m$ has the same effect as $|m|$. If $m=0$ a rectangle is
5711 % produced.
5712 %
5713 % \DescribeMacro{\tlabelellipse}
5714 % \cs{tlabelellipse} produces an ellipse, where the optional argument $a$
5715 % is the ratio of its width to its height. The default for $a$ is 1, which
5716 % produces a circle. Negative $a$ has the same effect as $|a|$. If $a =
5717 % 0$, a rectangle is produced.
5718 %
5719 % \DescribeMacro{\tlabelcircle}
5720 % To get a circle one can use \cs{tlabelellipse} without the optional
5721 % argument, or with argument \oarg{1}. However, it makes for a more
5722 % readable source if the command reflects the shape. \cs{tlabelcircle} is
5723 % defined to be essentially \cs{tlabelellipse}\oarg{1}, but it first
5724 % checks for the \texttt{*} and passes it along in front of the \oarg{1}.
5725 %
5726 % We implement the other three by calling \cs{mfp@labelpath} with the name
5727 % of the curve (\texttt{rect}, \texttt{oval}, or \texttt{ellipse}) and the
5728 % default value of the optional argument (\texttt{0}, \texttt{1}, and
5729 % \texttt{1}, respectively) as arguments.
5730 % \begin{macrocode}
5731 \newdef\tlabelrect{\mfp@labelpath{rect}{0}}%
5732 \newdef\tlabeloval{\mfp@labelpath{oval}{1}}%
5733 \newdef\tlabelellipse{\mfp@labelpath{ellipse}{1}}%
5734 \newdef\tlabelcircle{%
5735 \mfp@iftoken*{\tlabelellipse*[1]}{\tlabelellipse[1]}}%
5736 % \end{macrocode}
5737 %
5738 %
5739 % \subsection{Placing multiple text labels}\label{multiple}
5740 %
5741 % One of the more onerous things about labels in \env{mfpic} environments
5742 % used to be the shear amount of typing required. The following commands
5743 % are intended to reduce the work by having to repeat only the arguments.
5744 %
5745 % \DescribeMacro{\tlabels}
5746 % This command takes only one argument containing any sequence of valid
5747 % arguments for the \cs{tlabel} command, optionally separated by
5748 % whitespace (but not blank lines).
5749 %
5750 % We begin a group, reset whitespace to normal, and call the command that
5751 % reads the argument.
5752 % \begin{macrocode}
5753 \newdef\tlabels{\begingroup
5754 \mfp@resetwhitespace\mp@mksharpother \mfp@labels}%
5755 % \end{macrocode}
5756 %
5757 % Labelling axes generates a lot of \cs{tlabel} commands, or a single
5758 % \cs{tlabels} command with a lot of arguments. Given that such labels
5759 % have much in common (e.g., for the $x$ axis the $y$ coordinate and the
5760 % justification are usually the same for all the labels) we can do still
5761 % better at abbreviating this task.
5762 %
5763 % \DescribeMacro{\axislabels}
5764 % The \cs{axislabels} command takes a mandatory argument (the axis)
5765 % followed by an optional argument (the justification, as in the
5766 % \cs{tlabel} command), followed by another mandatory argument, a comma
5767 % separated list of items of the form \marg{\meta{label}}\meta{coord}. The
5768 % label is placed at that coordinate on the given axis.
5769 %
5770 % Here we call \cs{mfp@axislabel}, feeding it the arguments of the current
5771 % \cs{@mfpic} command.
5772 % \begin{macrocode}
5773 \newlet\axislabels\mfp@axislabels
5774 % \end{macrocode}
5775 %
5776 %
5777 % \subsection{Captions}\label{captions}
5778 %
5779 % Captions are not added immediately by the \cs{tcaption} command. That
5780 % command redefines \cs{mfp@docaption} to add it, and \cs{endmfpic}
5781 % executes \cs{mfp@docaption}. For now, \cs{mfp@docaption} does nothing.
5782 %
5783 % \DescribeMacro{\tcaption}
5784 % \cs{tcaption} takes an optional argument that holds two numbers,
5785 % separated by a comma. The first number determines the maximum width of a
5786 % one line caption. Captions larger than that multiple of the width of the
5787 % graphic will be reset as a paragraph, whose lines have length the second
5788 % number times the width of the graph. The defaults are \oarg{1.2,1}.
5789 % \begin{macrocode}
5790 \let\mfp@docaption\@empty
5791 \newdef\tcaption{\mfp@defaultopt\mfp@caption{1.2,1.0}}%
5792 % \end{macrocode}
5793 %
5794 % Finally, invoke the \cs{everymfpic} tokens.
5795 % \begin{macrocode}
5796 \every@mfpic}% End of \@mfpic
5797 % \end{macrocode}
5798 %
5799 %
5800 %
5801 % \section{Implementing the label and caption macros}
5802 %
5803 % \cs{mfp@setconv} uses the stored arguments of the surrounding
5804 % \env{mfpic} environment: \cs{xfactor} and \cs{yfactor}
5805 % are the scale factors; \cs{xmin} and \cs{ymin} are the coordinates of
5806 % the lower left corner. It defines two macros used to convert graph
5807 % coordinates into actual dimensions relative to the lower left corner of
5808 % the picture. The second argument of \cs{@xconv} and \cs{@yconv} is a
5809 % dimension register in which the converted result is returned. We make
5810 % the final assignment global for consistency (font dimension assignments
5811 % are always global). We don't really need to define \cs{mfp@setconv}
5812 % and then call it. We could just define \cs{@xconv} and \cs{@yconv}.
5813 % However, I consider it possible I might someday need to allow these
5814 % conversion functions to be changed on the fly, and then it would be
5815 % easier to just call \cs{mfp@setconv}.
5816 % \begin{macrocode}
5817 \newdef\mfp@setconv{%
5818 \def\@xconv##1##2{% ##1 = coord. ##2 = dimension register or fdim
5819 {\mfp@scratch=##1\@mfpicunit
5820 \advance\mfp@scratch by -\xmin\@mfpicunit
5821 \mfp@scratch=\xfactor\mfp@scratch
5822 \global ##2=\mfp@scratch}}%
5823 \def\@yconv##1##2{% ditto
5824 {\mfp@scratch=##1\@mfpicunit
5825 \advance\mfp@scratch by -\ymin\@mfpicunit
5826 \mfp@scratch=\yfactor\mfp@scratch
5827 \global ##2=\mfp@scratch}}}%
5828 \newdef\mfp@inittlabels{%
5829 \setbox\@alltlabels\vbox{\hbox{}}%
5830 \setbox\@backtext\vbox{\hbox{}}%
5831 \@tlabelsbot \maxdimen
5832 \@tlabelstop -\maxdimen
5833 \@tlabelsleft \maxdimen}%
5834 % \end{macrocode}
5835 %
5836 % The first argument of \cs{mfp@label} is the justification option. After
5837 % starting a group (it is ended in \cs{mfp@label@@}, we restore the
5838 % meaning of whitespace and give \texttt\# a safe catcode for writing to the
5839 % output, if necessary (\opt{mplabels}). Then we run \cs{tlabeljustify} on
5840 % the optional argument. An empty argument means any previously set values
5841 % won't be changed. Then we check for a left parenthesis and assume the
5842 % \parg{\meta{x},\meta{y}} syntax in that case, calling \cs{mfp@label@}
5843 % to process it. All it does is pack it in braces and call
5844 % \cs{mfp@label@@}. If no parentheses we skip to \cs{mfp@label@@}.
5845 %
5846 % Then \cs{mfp@label@@} gets a point or list of points as its first argument
5847 % and the label code as the second. It defines the macro \cs{tl@points} to
5848 % equal the point (or list) and puts the label into a token register.
5849 %
5850 % After all the data are stored away, we call \cs{mfp@thelabel} with no
5851 % parameters. Then the group (begun by \cs{mfp@label}) is ended, and the
5852 % \cs{extra@endtlabel} command invoked.
5853 % \begin{macrocode}
5854 \newdef\mfp@label#1{\begingroup\mfp@resetwhitespace\mp@mksharpother
5855 \tlabeljustify{#1}\@ifnextchar({\mfp@label@}{\mfp@label@@}}%
5856 \newdef\mfp@label@(#1,#2){\mfp@label@@{(#1,#2)}}%
5857 \newdef\mfp@label@@#1#2{\def\tl@points{#1}\mfp@toks{#2}\mfp@thelabel
5858 \endgroup\extra@endtlabel}%
5859 % \end{macrocode}
5860 %
5861 % At this point all the necessary information has been stored and
5862 % \cs{mfp@thelabel} merely branches depending on \opt{mplabels}.
5863 %
5864 % Clearly we could have put this code at the end of \cs{mfp@label@@} instead
5865 % of invoking this command. The point of doing things this way is so that
5866 % other commands too can store away the necessary info while doing other
5867 % things and simply call \cs{mfp@thelabel} to get the label placed.
5868 % \begin{macrocode}
5869 \newdef\mfp@thelabel{\@ifmplabels\mp@tlabel\tex@tlabel}%
5870 % \end{macrocode}
5871 %
5872 % We now come to the main code under \opt{mplabels}, which should just
5873 % arrange to write the correct commands to the output file. All labels are
5874 % passed as \mfc{btex ... etex} structures via the command \cs{mfp@btex}
5875 % below. The definition of \cs{MFPtext} will have been written earlier by
5876 % \cs{opengraphsfile}.
5877 % \begin{macrocode}
5878 \newdef\mfp@btex#1{btex \noexpand\MFPtext{#1} etex}%
5879 % \end{macrocode}
5880 %
5881 % The command \gbc{newgblabel}, defined in \file{graphbase.mp} for placing
5882 % labels, uses three parameters to justify the text. If we didn't have to
5883 % support the \texttt{B} vertical placement option, there would be only
5884 % two. All the other options involve placement \emph{relative} to the
5885 % bounding box. But the baseline is absolute: \MP{} always puts it at
5886 % $y$ coordinate 0 in the picture returned by \gbc{btex}. The first two
5887 % parameters are numerical and the third is boolean. The
5888 % first represents the fraction of the text that lies left of given
5889 % point. The second is the fraction of the text below the point. If the
5890 % third parameter is \mfc{true}, this fraction ignores the depth of the
5891 % text (so $0$ indicates baseline placement); if it is false, the depth
5892 % is accounted for (so $0$ indicates the very bottom of the text).
5893 %
5894 % By this point the letters of the optional parameter have been converted
5895 % to integer values for \cs{tl@hpos} and \cs{tl@vpos} by
5896 % \cs{tlabeljustify}. The following converts these integers to comma
5897 % separated parameters as described above using \cs{ifcase}.
5898 %
5899 % The fourth parameter of \gbc{newgblabel} is the angle of rotation. Empty
5900 % rotation is converted to the angle 0, otherwise it is written as is.
5901 % All four parameters are stored in \cs{mfp@MPpos} by the invocation of
5902 % \cs{mfp@setMPpos}.
5903 % \begin{macrocode}
5904 \newdef\mfp@setMPpos{%
5905 \edef\mfp@MPpos{%
5906 \ifcase\tl@hpos .5\or 1\else 0\fi, % horizontal
5907 \ifcase\tl@vpos0\or .5\or 1\else 0\fi, % vertical
5908 \ifnum \tl@vpos<0 \mfp@T\else\mfp@F\fi, % true=Baseline
5909 \mfp@emptysub{\tl@rot}{0}}}%
5910 % \end{macrocode}
5911 %
5912 % \cs{mp@tlabel} is the code called by \cs{tlabel} when \opt{mplabels} is
5913 % in effect. At this point all the data needed are stored in macros and
5914 % we just have to put it together. Thus, it has no parameters and other
5915 % commands can prepare the data and simply invoke it (or, more usually,
5916 % invoke \cs{mfp@thelabel} which invokes \cs{tex@tlabel} or \cs{mp@tlabel} as
5917 % appropriate). The \gbc{newgblabel} command is written with the
5918 % justification and two more parameters: the label tokens, and the point
5919 % (or list of points).
5920 % \begin{macrocode}
5921 \newdef\mp@tlabel{\mfp@setMPpos
5922 \mfcmd{\@nl newgblabel(\mfp@MPpos)(\mfp@btex{\the\mfp@toks})\@nl
5923 (\tl@points)}}%
5924 % \end{macrocode}
5925 %
5926 % When \opt{mplabels} is not in effect, we use \TeX{} to position the
5927 % label. We put the label in a box (\cs{@textbox}) so we can measure and
5928 % position it. It is a \cs{vbox} so we can have multiline labels. This is
5929 % effected by wrapping it in a simple, left-aligned, one column
5930 % \cs{halign}, defining \cs{\bsl} to be \cs{cr}. We make this procedure a
5931 % separate macro, since we need to do the identical thing in the
5932 % \cs{tlabelpath} code.
5933 % \begin{macrocode}
5934 \newdef\set@textbox#1{%
5935 \setbox\@textbox\vbox{\def\\{\cr}\mfp@restorepar
5936 \mfp@safe@activesfalse\@tcurr\every@tlabel
5937 \halign{##\hfil\cr#1\crcr}}}%
5938 % \end{macrocode}
5939 %
5940 % We call \cs{tex@tlabel} to perform the necessary positioning. Again, all
5941 % the necessary data has been stored so \cs{tex@tlabel} takes no parameters.
5942 % Before calling the (rather extensive) positioning code, we have to
5943 % process the (possible) list of points into separate points. Spaces
5944 % outside parentheses are consumed by \cs{@ifnextchar} and separating
5945 % commas (even if there are too many) are gobbled by the
5946 % \cs{mfp@ifendorcomma}. Oddly, this code works even if the separating commas
5947 % are omitted, but the \opt{mplabels} code does not.
5948 % \begin{macrocode}
5949 \newdef\tex@tlabel{\@xp\@textlabel\tl@points\mfp@end}%
5950 \newdef\@textlabel{\mfp@ifendorcomma{}\@textlabel\@@textlabel}%
5951 \newdef\@@textlabel(#1,#2){\tex@@tlabel{#1}{#2}\@textlabel}%
5952 % \end{macrocode}
5953 %
5954 % This is the code that sets and positions the label. We compute its total
5955 % height to simplify later code. The macro \cs{tb@ht} expands to
5956 % \cs{ht}\cs{@textbox} and \cs{tb@dp} to \cs{dp}\cs{@textbox}.
5957 % \begin{macrocode}
5958 \newdef\tex@@tlabel#1#2{%
5959 \set@textbox{\the\mfp@toks}%
5960 \mfp@scratch\tb@ht \advance\mfp@scratch\tb@dp
5961 \tb@totalht\mfp@scratch
5962 \@xconv{#1}\mfp@scratch
5963 % \end{macrocode}
5964 %
5965 % The following computes whether the leftmost extent of the picture will
5966 % be increased by the addition of the label. The macro \cs{tb@wd} expands
5967 % to \cs{wd}\cs{@textbox}.
5968 %
5969 % We have convert the $x$ coordinate of the label's location to a distance
5970 % from the left edge of the picture. We then subtract from that the amount
5971 % of the label extending to the left of this location. Then we add or
5972 % subtract the separation of the label from its location. Finally, we
5973 % simply add the horizontal adjustment defined by the user with
5974 % \cs{tlabeloffset}. The value of \cs{@tlabelsleft} is set equal to this
5975 % if it was greater. We save the calculated value in \cs{tb@moveright},
5976 % because it is exactly the amount we'll need to \cs{kern} later to
5977 % position the label.
5978 % \begin{macrocode}
5979 \begingroup
5980 \ifcase\tl@hpos \advance\mfp@scratch -0.5\tb@wd % center
5981 \or \advance\mfp@scratch -\tb@wd % right
5982 \advance\mfp@scratch -\tlabel@sep
5983 \else \advance\mfp@scratch \tlabel@sep % left (default)
5984 \fi
5985 \advance\mfp@scratch \tlabel@hadj
5986 \ifdim \mfp@scratch<\@tlabelsleft
5987 \@tlabelsleft\mfp@scratch
5988 \fi
5989 \tb@moveright\mfp@scratch
5990 \endgroup
5991 % \end{macrocode}
5992 %
5993 % Now we base the calculations on the uppermost extent of picture and
5994 % label. Otherwise the idea is the same, and we may increase
5995 % \cs{@tlabelstop}. Again we save the calculated result (in \cs{tb@raise})
5996 % for later positioning of the label.
5997 % \begin{macrocode}
5998 \@yconv{#2}\mfp@scratch
5999 \begingroup
6000 \ifcase\tl@vpos \advance\mfp@scratch \tb@totalht
6001 \advance\mfp@scratch \tlabel@sep % bottom
6002 \or \advance\mfp@scratch 0.5\tb@totalht % center
6003 \or \advance\mfp@scratch -\tlabel@sep % top
6004 \else \advance\mfp@scratch \tb@ht % baseline (default)
6005 \fi
6006 \advance\mfp@scratch \tlabel@vadj
6007 \ifdim \mfp@scratch>\@tlabelstop
6008 \@tlabelstop\mfp@scratch
6009 \fi
6010 \tb@raise\mfp@scratch
6011 \endgroup
6012 % \end{macrocode}
6013 %
6014 % Finally we compute the lowermost extent, and save it in \cs{@tlabelsbot}.
6015 % \begin{macrocode}
6016 \begingroup
6017 \ifcase\tl@vpos \advance\mfp@scratch \tlabel@sep % bottom
6018 \or \advance\mfp@scratch -0.5\tb@totalht % center
6019 \or \advance\mfp@scratch -\tb@totalht
6020 \advance\mfp@scratch -\tlabel@sep % top
6021 \else \advance\mfp@scratch -\tb@dp % baseline (default)
6022 \fi
6023 \advance\mfp@scratch \tlabel@vadj
6024 \ifdim \mfp@scratch<\@tlabelsbot
6025 \@tlabelsbot\mfp@scratch
6026 \fi
6027 \endgroup
6028 % \end{macrocode}
6029 %
6030 % Now we've computed the new size of \cs{@alltlabels} and we put the
6031 % new label on top of it with the above calculated kerns.
6032 % \begin{macrocode}
6033 \global \setbox\@alltlabels
6034 \vtop{\unvbox\@alltlabels
6035 \vbox to 0pt{\kern-\tb@raise
6036 \hbox{\kern\tb@moveright\box\@textbox}\vss}}%
6037 }% End \tex@@tlabel
6038 % \end{macrocode}
6039 %
6040 % The argument of \cs{mfp@labels} is the ostensible argument of
6041 % \cs{tlabels}. Looping is accomplished by defining \cs{extra@endtlabel}
6042 % to repeat \cs{mfp@dolabel}.
6043 %
6044 % If \cs{mfp@dolabel} sees the end-of-loop delimiter it ends the group and
6045 % gobbles the delimiter. Otherwise it calls \cs{tlabel}, which sees the
6046 % next set of arguments, places the label, and repeats the loop.
6047 % \begin{macrocode}
6048 \newdef\mfp@labels#1{\let\extra@endtlabel\mfp@dolabel
6049 \mfp@dolabel#1\mfp@end}%
6050 \newdef\mfp@dolabel{\mfp@ifend\endgroup\tlabel}%
6051 % \end{macrocode}
6052 %
6053 % \cs{mfp@labelpath} stores the name of the path in \cs{mfp@name} and the
6054 % default argument in \cs{mfp@param}, then check for a \texttt{*} and set
6055 % a switch based on it before calling \cs{mfp@tlpath}. The
6056 % \cs{mfp@figmacbase} must be outside the group so the switches it sets
6057 % will survive for later commands to detect.
6058 % \begin{macrocode}
6059 \newdef\mfp@labelpath#1#2{\mfp@figmacbase
6060 \begingroup % ended in \tlabelpath@
6061 \def\mfp@name{#1}\def\mfp@param{#2}%
6062 \mfp@ifstar\mfp@tlpath\mfp@switchtrue\mfp@switchfalse}%
6063 % \end{macrocode}
6064 %
6065 % Process the first optional argument, which has value of \cs{mfp@param}
6066 % as default. The second one is a justification with a default set by the
6067 % user with \cs{tlpathjustify} or the initial \texttt{[cc]} setting. Once
6068 % these are processed, we check whether a parentheses follows, calling one
6069 % of two different handlers for the location parameter(s).
6070 % \begin{macrocode}
6071 \newdef\mfp@tlpath#1{#1\mfp@defaultopt\mfp@@tlpath\mfp@param}%
6072 \newdef\mfp@@tlpath#1{\edef\mfp@param{#1}%
6073 \mfp@defaultopt\mfp@tlpath@{\tlpath@v\tlpath@h\tlpath@r}}%
6074 \newdef\mfp@tlpath@#1{\mfp@resetwhitespace\mp@mksharpother
6075 \tlabeljustify{#1}\@ifnextchar({\@tlabelpath}{\@@tlabelpath}}%
6076 % \end{macrocode}
6077 %
6078 % These handlers just stuff the point into a macro and call the command
6079 % that reads the label code. The name \cs{tl@points} is plural (even
6080 % though only one point is supported) because the internal command that
6081 % places the label expects this macro.
6082 % \begin{macrocode}
6083 \newdef\@tlabelpath(#1,#2){\@@tlabelpath{(#1,#2)}}%
6084 \newdef\@@tlabelpath#1#2{%
6085 \def\tl@points{#1}\mfp@toks{#2}\tlabelpath@}%
6086 % \end{macrocode}
6087 %
6088 % By this point, all the elements we need are gathered. For the purposes
6089 % of the label we have \cs{mfp@toks} holding the label code,
6090 % \cs{tl@points} holding the location, and \cs{tlabeljustify} encoding
6091 % the adjustments. For the path, we have the type in \cs{mfp@name}, and the
6092 % one optional parameter parameter in \cs{mfp@param}.
6093 %
6094 % Under \opt{mplabels} we expect \MP{} to measure the text. Otherwise we
6095 % measure the text in \TeX{} and feed the bounding box corners to \MF{}
6096 % for making the path. If \cs{ifmfp@switch} is false we place the text by
6097 % calling \cs{mfp@thelabel}. All the data needed by \cs{mfp@thelabel} have
6098 % already been stored in macros by previous commands in the chain. Then we
6099 % complete the command by ending the group that \cs{mfp@labelpath}
6100 % started.
6101 % \begin{macrocode}
6102 \newdef\tlabelpath@{\@ifmplabels{}{\measure@textbox{\the\mfp@toks}}%
6103 \mfp@setMPpos
6104 \mfcmd{text\mfp@name x (\mfp@MPpos)\@nl
6105 (\@ifmplabels{origin, \mfp@btex{\the\mfp@toks}}{\tb@ll, \tb@ur}, %
6106 \mfp@param) (\tl@points)}%
6107 \ifmfp@switch\else \mfp@thelabel\fi \endgroup}%
6108 % \end{macrocode}
6109 %
6110 % Here we define the command that measures the text. It is almost a clone
6111 % of a similar code sequence in \cs{tex@tlabel}, but it produces the \gbc{ll}
6112 % and \gbc{ur} (corners of the boundingbox) that the \grafbase{} code
6113 % needs.
6114 % \begin{macrocode}
6115 \newdef\measure@textbox#1{\set@textbox{#1}%
6116 \mfp@scratch-\tb@dp
6117 \edef\tb@ll{(0, \the\mfp@scratch)}%
6118 \edef\tb@ur{(\the\tb@wd, \the\tb@ht)}}%
6119 % \end{macrocode}
6120 %
6121 % The argument of \cs{mfp@axislabels} is the axis letter.
6122 %
6123 % We start by determining the default justification. which is different
6124 % for each axis (for example, for the left axis it is \oarg{cr} but for
6125 % the bottom axis it is \oarg{tc}). For all of them, one of the parts is
6126 % \texttt{c}, so after resetting whitespace we initialize them both to
6127 % this and later change only the one that needs it.
6128 %
6129 % Also, one of the coordinates of a label will be given by the argument,
6130 % while the other is the location of the axis. However, which coordinate
6131 % is which is different for different axes. What we do is feed this
6132 % position to \cs{mfp@xcoord} and \cs{mfp@ycoord}. Both are initialized to
6133 % the identity macro, but one is changed to expand to just the axis
6134 % position. The axis position for $x$ and $y$ axis is 0. For border axes
6135 % it is calculated by adding the border axis shift to the border
6136 % coordinate.
6137 % \begin{macrocode}
6138 \newdef\mfp@axislabels#1{%
6139 \begingroup % ended in \mfp@(@)doaxislabel
6140 \mfp@resetwhitespace
6141 \tl@vpos1 \tl@hpos0
6142 \let\mfp@xcoord\@firstofone \let\mfp@ycoord\@firstofone
6143 \mfp@getaxis#1\relax\mfp@end\axislabels
6144 \ifcase\mfp@axisnum\relax
6145 \tl@vpos2 \def\mfp@ycoord{0}\or
6146 \tl@hpos1 \def\mfp@xcoord{0}\or
6147 \tl@hpos1\edef\mfp@xcoord{\mfp@lshift}%
6148 \mfpaddto\mfp@xcoord\xmin\or
6149 \tl@vpos2\edef\mfp@ycoord{\mfp@bshift}%
6150 \mfpaddto\mfp@ycoord\ymin\or
6151 \tl@hpos-1 \edef\mfp@xcoord{-\mfp@rshift}%
6152 \mfpaddto\mfp@xcoord\xmax\or
6153 \tl@vpos0 \edef\mfp@ycoord{-\mfp@tshift}%
6154 \mfpaddto\mfp@ycoord\ymax
6155 \fi
6156 % \end{macrocode}
6157 %
6158 % Now one of \cs{mfp@xcoord} or \cs{mfp@ycoord} expands to the axis
6159 % position. We change it so that it does this while gobbling the
6160 % parameter, and then call \cs{mfp@@axislabels}, feeding it an empty
6161 % argument as the default optional argument. We also give \texttt\# a safe
6162 % catcode for writing to a \file{.mp} file.
6163 % \begin{macrocode}
6164 \ifx\@firstofone\mfp@xcoord
6165 \edef\mfp@ycoord##1{\mfp@ycoord}%
6166 \else
6167 \edef\mfp@xcoord##1{\mfp@xcoord}%
6168 \fi \mp@mksharpother\mfp@nullopt\mfp@@axislabels}%
6169 % \end{macrocode}
6170 %
6171 % \cs{mfp@@axislabels} processes the contents of the optional parameter
6172 % and calls \cs{mfp@doaxislabel} on the list of labels.
6173 % \begin{macrocode}
6174 \newdef\mfp@@axislabels#1#2{%
6175 \tlabeljustify{#1}\mfp@doaxislabel#2,\mfp@end}%
6176 % \end{macrocode}
6177 %
6178 % \cs{mfp@doaxislabel} checks for the end delimiter or a comma (the latter
6179 % is an error). In the first case it ends all label processing, in the
6180 % second it repeats itself, otherwise it continues with
6181 % \cs{mfp@@doaxislabel}.
6182 %
6183 % The argument of \cs{mfp@@doaxislabel} should be the label. This command
6184 % stores the label in \cs{mfp@toks}, then again checks for the delimiter
6185 % or an comma (both are errors). In the first case it ends the process; in
6186 % the second it goes back to \cs{mfp@doaxislabel} for another try. In both
6187 % cases the label is discarded as we don't know where to put it. If
6188 % neither the delimiter nor a comma occurs, \cs{mfp@mkaxislabel} is run.
6189 %
6190 % The argument of \cs{mfp@mkaxislabel} (everything to the next comma) is the
6191 % location. The command \cs{mfp@mkaxislabel} does nothing if the location
6192 % parameter is empty, otherwise it stores the location as a pair and calls
6193 % \cs{mfp@thelabel} to place the label. Finally, it repeats
6194 % \cs{mfp@doaxislabel} for the next iteration.
6195 % \begin{macrocode}
6196 \newdef\mfp@doaxislabel{%
6197 \mfp@ifendorcomma\endgroup\mfp@doaxislabel\mfp@@doaxislabel}%
6198 \newdef\mfp@@doaxislabel#1{\mfp@toks{#1}%
6199 \mfp@ifendorcomma\endgroup\mfp@doaxislabel\mfp@mkaxislabel}%
6200 \newdef\mfp@mkaxislabel#1,{%
6201 \@ifmtarg{#1}{}%
6202 {\edef\tl@points{(\mfp@xcoord{#1},\mfp@ycoord{#1})}\mfp@thelabel}%
6203 \mfp@doaxislabel}%
6204 % \end{macrocode}
6205 %
6206 % \cs{mfp@caption} has one mandatory argument, the caption's text. In it, the
6207 % \cs{\bsl} command forces line breaks. This works by forcing the width to
6208 % be greater than any reasonable setting of the maximum line width. When
6209 % this happens, the caption is reset in a \cs{vbox} and \cs{\bsl} is
6210 % redefined like a normal line break.
6211 % \begin{macrocode}
6212 \newdef\mfp@caption#1{\begingroup\mfp@resetwhitespace
6213 \mfp@@caption#1\mfp@end}%
6214 \long\def\mfp@@caption#1,#2\mfp@end#3{\endgroup
6215 \def\mfp@docaption{%
6216 \setbox\@textbox
6217 \hbox{\def\\{\hskip\@M\p@\let\\\relax}\mfp@restorepar
6218 \mfp@safe@activesfalse\@tcurr#3}%
6219 % \end{macrocode}
6220 %
6221 % If the above \cs{hbox} is too wide, we re-assign \cs{@textbox} to a
6222 % \cs{vbox} with \cs{hsize} determined by the second part of the optional
6223 % argument. \cs{mfp@capsettings} implements the \opt{centeredcaptions}
6224 % and \opt{raggedcaptions} options.
6225 % \begin{macrocode}
6226 \mfp@scratch\wd\@wholegraph
6227 \ifdim\tb@wd>#1\mfp@scratch
6228 \setbox\@textbox
6229 \hbox{%
6230 \vbox{%
6231 \hsize#2\mfp@scratch \mfp@restorepar
6232 \leftskip0pt \rightskip0pt\relax
6233 \mfp@capsettings
6234 \mfp@safe@activesfalse
6235 \noindent\@tcurr #3%
6236 }% End vbox.
6237 }% End hbox.
6238 \fi
6239 % \end{macrocode}
6240 %
6241 % Here we determine the wider of the graph or the caption, then put the
6242 % graph and caption together by centering them in \cs{hbox}es with this
6243 % width, stacked one atop the other with \cs{mfpiccaptionskip} (default:
6244 % \cs{medskipamount}) in between.
6245 % \begin{macrocode}
6246 \ifdim \mfp@scratch<\tb@wd \mfp@scratch\tb@wd \fi
6247 \global\setbox\@wholegraph
6248 \vbox{\hbox to \mfp@scratch{\hss\box\@wholegraph\hss}%
6249 \nointerlineskip \vskip\mfpiccaptionskip
6250 \hbox to \mfp@scratch{\hss\box\@textbox\hss}}% End vbox.
6251 }% End \mfp@docaption.
6252 }% End \mfp@@caption.
6253 % \end{macrocode}
6254 %
6255 % The following is used in \cs{endmfpic}. The first argument of
6256 % \cs{mfp@adjustdim} is a border dimension of the box containing all the
6257 % labels, the second is a comparison between that and the corresponding
6258 % dimension of the graph box, which is the third argument. The last is the
6259 % macro holding the adjustments needed when \opt{truebbox} is used. The
6260 % first and last line compensate for the fact that the bbox need not start
6261 % at $(0,0)$. The second line checks if the label box extends past the
6262 % graph's edge and adjusts the graph's dimension is it does.
6263 % \begin{macrocode}
6264 \def\mfp@adjustdim#1#2#3#4{%
6265 \mfp@scratch#1\relax \advance\mfp@scratch-#4 bp
6266 \ifdim\mfp@scratch#2#3\relax #3\mfp@scratch \fi
6267 #1\mfp@scratch}%
6268 % \end{macrocode}
6269 %
6270 %
6271 %
6272 % \section{Placing the picture: \cs{endmfpic}}\label{endmfpic}
6273 %
6274 % \DescribeMacro{\endmfpic}
6275 % By the time \cs{endmfpic} is reached, the \MF{} code for the figure has
6276 % all been written to the output file. The labels have all been
6277 % accumulated and arrangements have been made to add the caption.
6278 %
6279 % Under \opt{metapost}, write a right brace to match the left written
6280 % by \cs{mfpic} Then write the \cs{grafbase} command \gbc{endmfpic},
6281 % followed by a comment telling which figure number it is, and the line
6282 % number in the \TeX{} source where the \cs{endmfpic} occurred.
6283 % \begin{macrocode}
6284 \mfp@DBlog{Definition of closure of mfpic environment.}%
6285 \newdef\endmfpic{\every@endmfpic
6286 \mfsrc{%
6287 \mfp@ifmpost{\@nl verbatimtex \relax\MFPendgroup\space etex;}{}\@nl
6288 endmfpic; \mfp@p\space(\number\mfp@count) \mfp@lineno.\@nl
6289 \mfp@p\mfp@d\mfp@d\mfp@d\@nl}%
6290 \ifmfpicdebug\wlog{}\wlog{Mfpic: ENTERED endmfpic.}\wlog{}\fi
6291 % \end{macrocode}
6292 %
6293 % The code to load and place the box is skipped if figure shipping was
6294 % turned off.
6295 % \begin{macrocode}
6296 \ifmfp@noship \else
6297 % \end{macrocode}
6298 %
6299 %
6300 % \subsection{Loading and measuring the graphic}\label{loading}
6301 %
6302 % Now we load the graphic. It would be at this point that we could add a
6303 % \cs{write18} to process the figure on-the-fly. Of course that would
6304 % require re-initializing the output file with each graphic (i.e., the
6305 % equivalent of issuing \cs{opengraphsfile} at every \cs{mfpic} and
6306 % \cs{closegraphsfile} at every \cs{endmfpic}.)
6307 % \begin{macrocode}
6308 \global\setbox\@wholegraph
6309 \vbox{%
6310 % \end{macrocode}
6311 %
6312 % If draft mode has been detected or set by the user, we just make a box
6313 % of the size specified with the figure number inside it.
6314 % \begin{macrocode}
6315 \ifmfpicdraft
6316 \vbox to \@graphtop{\vss
6317 \hbox to \@graphright{%
6318 \kern2pt \mfpdraftfont\#\number\mfp@count\hss}%
6319 \kern2pt}%
6320 \else
6321 % \end{macrocode}
6322 %
6323 % The \opt{truebbox} option works at the \MP{} level. Without it the
6324 % height of the EPS bounding box will actually be the calculated value
6325 % of \cs{@graphtop}. With it, the box will be its natural height. But
6326 % in either case, the value will actually be increased by up to
6327 % \texttt{2bp} because of rounding, so the bounding box height is what we
6328 % use in the \MP{} case. For \MF{} we use the nominal height calculated in
6329 % \cs{mfpic}.
6330 % \begin{macrocode}
6331 \mfp@ifmpost{\vbox}{\vbox to \@graphtop}%
6332 {\vss
6333 % \end{macrocode}
6334 %
6335 % \cs{@graphfilename} holds the name of the \MP{} output figure. (It will be
6336 % ignored by the \opt{metafont} option.) We test if the file exists before
6337 % doing the graphic inclusion because of the large number of confusing error
6338 % messages many graphic inclusion packages generate otherwise. When absent
6339 % we substitute the figure filename for \cs{@setmfpicgraphic}.
6340 % \begin{macrocode}
6341 \edef\@graphfilename{%
6342 \setfilename\mfp@filename{\number\mfp@count}}%
6343 \mfp@ifmpost
6344 {\IfFileExists{\@graphfilename}{}%
6345 {\Mfpic@msg{No graph file: \@graphfilename\space.}%
6346 \let\@setmfpicgraphic\nofile@setmfpgraphic}%
6347 % \end{macrocode}
6348 %
6349 % We put the graphic in an \cs{hbox} of the required width and close off
6350 % the boxes.
6351 % \begin{macrocode}
6352 \hbox}%
6353 {\hbox to \@graphright}%
6354 {\@xp\@setmfpicgraphic\@xp{\@graphfilename}\hss}%
6355 \kern0pt
6356 }% End vbox
6357 \fi
6358 }%% End \setbox\@wholegraph \vbox
6359 % \end{macrocode}
6360 %
6361 % We change the horizontal and vertical dimensions under \opt{metapost} in
6362 % case \opt{truebbox} was in effect, but also because they are almost always
6363 % rounded up to whole numbers of \texttt{bp} and therefore, even without
6364 % \opt{truebbox}, the calculated values needn't be correct.
6365 % \begin{macrocode}
6366 \mfp@ifmpost
6367 {\@graphright\wd\@wholegraph
6368 \@graphtop\ht\@wholegraph}{}%
6369 \ifmfpicdebug
6370 \wlog{Mfpic debug: Dimensions of wholegraph before labels %
6371 are added, and before truebbox adjustments:}%
6372 \wlog{Mfpic: graphleft = \the\@graphleft}%
6373 \wlog{Mfpic: graphright = \the\@graphright}%
6374 \wlog{Mfpic: graphtop = \the\@graphtop}%
6375 \wlog{Mfpic: graphbot = \the\@graphbot}%
6376 \wlog{Mfpic: graphwd = \the\wd\@wholegraph}%
6377 \wlog{Mfpic: graphht = \the\ht\@wholegraph}%
6378 \wlog{Mfpic: graphdp = \the\dp\@wholegraph}%
6379 \wlog{}%
6380 \fi
6381 % \end{macrocode}
6382 %
6383 %
6384 % \subsection{Adding labels and caption}\label{addlabel}
6385 %
6386 % We now add the boxes \cs{@alltlabels} and \cs{@backtext} onto the graph
6387 % box. But first we have to adjust for \cs{mfpicllx} and \cs{mfpiclly}
6388 % which can only be known after the graphics inclusion. We reset those
6389 % boxes so their contents are shifted by these values. We only need to do
6390 % this if labels have have actually been added. The signal that this has
6391 % happened is that the label dimensions are no longer $\pm$\cs{maxdimen}.
6392 % This doesn't indicate whether it is \cs{@alltlabels} or \cs{@backtext}
6393 % (or both) that is nonempty, so one of the box resets may be redundant.
6394 % \begin{macrocode}
6395 \ifmfpicdebug
6396 \wlog{Mfpic debug: Dimensions of alltlabels, before %
6397 truebbox adjustments:}%
6398 \mfp@scratch\mfpicllx bp\relax
6399 \wlog{Mfpic: mfpicllx = \the\mfp@scratch}%
6400 \mfp@scratch\mfpiclly bp\relax
6401 \wlog{Mfpic: mfpiclly = \the\mfp@scratch}%
6402 \wlog{Mfpic: tlabelsleft = \the\@tlabelsleft}%
6403 \wlog{Mfpic: tlabelstop = \the\@tlabelstop}%
6404 \wlog{Mfpic: tlabelsbot = \the\@tlabelsbot}%
6405 \wlog{}%
6406 \fi
6407 \ifdim\@tlabelsleft < \maxdimen
6408 \setbox\@alltlabels\vtop to 0pt{%
6409 \kern \mfpiclly bp
6410 \moveleft \mfpicllx bp \box\@alltlabels\vss}%
6411 \setbox\@backtext \vtop to 0pt{%
6412 \kern \mfpiclly bp
6413 \moveleft \mfpicllx bp \box\@backtext \vss}%
6414 % \end{macrocode}
6415 % Then we adjust \cs{@tlabelsleft}, etc. for the boundingbox offset.
6416 % The graph dimensions are also adjusted if the tlabel dimensions extend
6417 % past the edges.
6418 % \begin{macrocode}
6419 \mfp@adjustdim\@tlabelsleft <\@graphleft \mfpicllx
6420 \mfp@adjustdim\@tlabelstop >\@graphtop \mfpiclly
6421 \mfp@adjustdim\@tlabelsbot <\@graphbot \mfpiclly
6422 \ifmfpicdraft\else
6423 \setbox\@wholegraph
6424 \vtop{\offinterlineskip
6425 \box\@backtext\kern-\ht\@wholegraph
6426 \unvbox\@wholegraph\box\@alltlabels}%
6427 \fi
6428 \fi
6429 % \end{macrocode}
6430 %
6431 % The method for putting labels in \cs{@alltlabels} does not add any width
6432 % on the left, nor any height to the top or depth to the bottom of that box
6433 % (that \TeX{} can detect), but we have saved their values and now we can
6434 % use them. For example, if \cs{@graphleft} is negative after the above,
6435 % then a label sticks out to the left, but \TeX{} thinks it has no width.
6436 % Therefore put \cs{kern}\texttt{-}\cs{@graphleft} to move the graph
6437 % rightward. The height and depth are taken care of by putting it in
6438 % \cs{vbox} with the calculated total height and moving the graph upward
6439 % with \cs{kern}\texttt{-}\cs{@graphbot}. The rightward extensions do get
6440 % detected by \TeX.
6441 % \begin{macrocode}
6442 \ifmfpicdebug
6443 \wlog{Mfpic debug: Dimensions of alltlabels after %
6444 truebbox adjustments:}%
6445 \wlog{Mfpic: tlabelsleft = \the\@tlabelsleft}%
6446 \wlog{Mfpic: tlabelstop = \the\@tlabelstop}%
6447 \wlog{Mfpic: tlabelsbot = \the\@tlabelsbot}%
6448 \wlog{}%
6449 \fi
6450 \mfp@scratch\@graphtop
6451 \advance\mfp@scratch by -\@graphbot
6452 \global \setbox\@wholegraph
6453 \vbox to \mfp@scratch{\vss
6454 \hbox{\kern-\@graphleft\box\@wholegraph}%
6455 \kern-\@graphbot}% End vbox.
6456 % \end{macrocode}
6457 %
6458 % Now add the caption, then set the parameters \cs{mfpicheight} and
6459 % \cs{mfpicwidth} for user to examine. The debug info now should show
6460 % graphwd${}={}$graphright${}-{}$graphleft,
6461 % graphht${}={}$graphtop${}-{}$graphbot, and graphdp${}= 0$.
6462 % \begin{macrocode}
6463 \ifmfpicdebug
6464 \wlog{Mfpic debug: Dimensions of wholegraph after %
6465 labels are added:}%
6466 \wlog{Mfpic: graphleft = \the\@graphleft}%
6467 \wlog{Mfpic: graphright = \the\@graphright}%
6468 \wlog{Mfpic: graphtop = \the\@graphtop}%
6469 \wlog{Mfpic: graphbot = \the\@graphbot}%
6470 \wlog{Mfpic: graphwd = \the\wd\@wholegraph}%
6471 \wlog{Mfpic: graphht = \the\ht\@wholegraph}%
6472 \wlog{Mfpic: graphdp = \the\dp\@wholegraph}%
6473 \wlog{}%
6474 \fi
6475 \mfp@docaption
6476 \ifmfpicdebug
6477 \wlog{Mfpic debug: Values after tcaption added:}%
6478 \wlog{Mfpic: graphleft = \the\@graphleft}%
6479 \wlog{Mfpic: graphright = \the\@graphright}%
6480 \wlog{Mfpic: graphtop = \the\@graphtop}%
6481 \wlog{Mfpic: graphbot = \the\@graphbot}%
6482 \wlog{Mfpic: graphwd = \the\wd\@wholegraph}%
6483 \wlog{Mfpic: graphht = \the\ht\@wholegraph}%
6484 \wlog{Mfpic: graphdp = \the\dp\@wholegraph}%
6485 \wlog{}%
6486 \fi
6487 \global\mfpicheight\ht\@wholegraph
6488 \global\mfpicwidth\wd\@wholegraph
6489 % \end{macrocode}
6490 %
6491 %
6492 % \subsection{Placing the graphic}\label{placing}
6493 %
6494 % Add a frame around the box \cs{@wholegraph} in draft mode (so its size
6495 % can be seen) since there is practically nothing in it except the picture
6496 % number and perhaps some tlabels.
6497 % \begin{macrocode}
6498 \ifmfpicdraft
6499 \setbox\@wholegraph
6500 \hbox{\@mfpframed{-\mfpframethickness}{\box\@wholegraph}}%
6501 \fi
6502 % \end{macrocode}
6503 % Now we save the graph globally, for placement after \cs{endgroup}. This
6504 % is so that tokens placed by \cs{everypar} will be typeset in the current
6505 % font (instead of \cs{nullfont}). Then we advance the figure count and
6506 % end the group started by the \cs{mfpic} command.
6507 % \begin{macrocode}
6508 \global\setbox\@wholegraph\box\@wholegraph
6509 \global \advance\mfp@count1
6510 \fi % \ifmfp@noship
6511 \endgroup % Begun near start of \@mfpic
6512 % \end{macrocode}
6513 % If the \cs{savepic} command occurred prior to this, then \cs{s@vemfpic}
6514 % is defined and we save this picture in the box named in that command and
6515 % stored in the macro \cs{s@vemfpic}. Otherwise, \cs{s@vemfpic} is
6516 % undefined, and we place the picture (\cs{@wholegraph}) in the document.
6517 % Afterward, we undefine \cs{s@vemfpic}. Note: if \opt{noship} is in
6518 % force, it remains defined, so the next picture will be stored.
6519 % \begin{macrocode}
6520 \ifmfp@noship \else
6521 \mfp@ifdefined\s@vemfpic
6522 {\global\setbox\s@vemfpic\box\@wholegraph}%
6523 {\leavevmode\box\@wholegraph}%
6524 \global\let\s@vemfpic\UndEfInEd
6525 \fi
6526 % \end{macrocode}
6527 % Then we restore the values of extra font dimensions that were saved.
6528 % Just in case, we unset the switch \cs{in@mfpicenv} and then arrange for
6529 % spaces to be ignored in case this is a \LaTeX{} environment. (I think we
6530 % shouldn't ignore spaces, but I was overruled. The argument was that
6531 % \cs{end}\marg{mfpic} should behave like \cs{endmfpic}. I don't buy it,
6532 % but I will keep things the way they were since version 0.4.)
6533 % \begin{macrocode}
6534 \restore@mfpicdimens
6535 \mfp@checklatexenv{mfpic}{\@ignoretrue}{}%
6536 \global\let\in@mfpicenv\iffalse
6537 \ignorespaces
6538 }% endmfpic
6539 % \end{macrocode}
6540 %
6541 % The following is a little utility to run at \cs{foo} or \cs{endfoo} to
6542 % see if was initiated as a \LaTeX{} environment or as a plain command.
6543 % The first argument is the environment name, the second is what to do
6544 % if that is the current environment, and the third is what to do
6545 % otherwise. In the two cases we now use it, the third argument is
6546 % empty.
6547 % \begin{macrocode}
6548 \ifmfp@latex
6549 \newdef\mfp@checklatexenv#1#2#3{%
6550 \def\mfp@tempa{#1}\ifx\mfp@tempa\@currenvir #2\else #3\fi}%
6551 \else
6552 \newdef\mfp@checklatexenv#1#2#3{#3}%
6553 \fi
6554 % \end{macrocode}
6555 %
6556 %
6557 %
6558 % \section{Additional features}\label{additional}
6559 %
6560 %
6561 % \subsection{Saving a copy of the picture}\label{saving}
6562 %
6563 % \DescribeMacro{\newsavepic}
6564 % One saves a picture by first allocating a save box with
6565 % \cs{newsavepic}\cs{mypic}, then saying \cs{savepic}\cs{mypic}
6566 % beforehand. The \cs{endmfpic} code detects that this has been done and
6567 % saves the picture in \cs{mypic}. It can be placed with
6568 % \cs{usepic}\cs{mypic}.
6569 %
6570 % \cs{newsavepic} is just a clone of \LaTeX's \cs{newsavebox}. The one
6571 % argument is a control sequence.
6572 % \begin{macrocode}
6573 \ifmfp@latex
6574 \newlet\newsavepic\newsavebox
6575 \else
6576 \newdef\newsavepic#1{%
6577 \mfp@ifdefined{#1}%
6578 {\mfp@errmsg{Command \string #1 already defined}%
6579 {You have used \newsavepic with an already defined or an^^J%
6580 improper control sequence. Replace #1 with another name.^^J%
6581 If you proceed, \newsavepic will be ignored.}}%
6582 {\@nameuse{newbox}#1}}%
6583 \fi
6584 \newlet\newpic\newsavepic
6585 % \end{macrocode}
6586 %
6587 % \DescribeMacro{\savepic}
6588 % All \cs{savepic} really does is define \cs{s@vepic} to its argument,
6589 % which should be a control sequence defined by \cs{newsavepic} (or
6590 % \cs{newbox}).
6591 % \begin{macrocode}
6592 \newdef\savepic#1{\relax
6593 \mfp@ifdefined{#1}{\gdef\s@vemfpic{#1}}%
6594 {\mfp@errmsg{Box \string#1 undefined}%
6595 {You tried to save a picture in a box which had not been^^J%
6596 previously allocated. Use \newsavepic to allocate a box.}}}%
6597 % \end{macrocode}
6598 %
6599 % \DescribeMacro{\usepic}
6600 % \cs{usepic} takes one argument, a control sequence that should have
6601 % been previously used in a \cs{savepic} comamnd. It just places the box
6602 % with the primitive \cs{copy} command.
6603 % \begin{macrocode}
6604 \newdef\usepic#1{\leavevmode \copy#1\relax}%
6605 % \end{macrocode}
6606 %
6607 %
6608 % \subsection{Putting a frame around it}\label{frame}
6609 %
6610 % This is essentially code I wrote years ago to have a framing command
6611 % that had two properties not enjoyed by some example `\cs{boxit}' commands
6612 % for plain\TeX: It should have a baseline the same as the baseline of the
6613 % contents, and it should work as an environment, not by reading an
6614 % argument (so verbatim material could be included).
6615 %
6616 % \DescribeMacro{\mfpframed}
6617 % \cs{mfpframed} takes an optional argument (the separation) and a
6618 % mandatory argument, the contents.
6619 % \DescribeMacro{\mfpframe}
6620 % \cs{mfpframe}$\ldots$\cs{endmfpframe} is an environment and
6621 % \cs{mfpframe} also takes the separation as an optional argument.
6622 %
6623 % \DescribeMacro{\framed}
6624 % \cs{framed} is a common command (\ConTeXt{} has one, a few packages also
6625 % define it), therefore we only define it if it is not already defined.
6626 % \begin{macrocode}
6627 \newdef\mfpframed{\mfp@defaultopt\@mfpframed\mfpframesep}%
6628 \newdef\mfpframe{\mfp@defaultopt\@mfpframe\mfpframesep}%
6629 \newdef\@mfpframed#1#2{\@mfpframe{#1}#2\endmfpframe}%
6630 \newdef\@mfpframe#1{%
6631 \leavevmode\hbox\bgroup
6632 \mfpframesep#1\relax
6633 \vrule width\mfpframethickness
6634 \vtop\bgroup
6635 \vbox\bgroup
6636 \hrule height\mfpframethickness
6637 \kern\mfpframesep
6638 \hbox\bgroup \kern\mfpframesep \ignorespaces}%
6639 \newdef\endmfpframe{\unskip
6640 \kern\mfpframesep
6641 \egroup % end hbox
6642 \egroup % end vbox
6643 \kern\mfpframesep
6644 \hrule height\mfpframethickness
6645 \egroup % end vtop
6646 \vrule width\mfpframethickness
6647 \egroup}% end hbox
6648 \mfp@ifdefined\framed{}{\let\framed\mfpframed}%
6649 % \end{macrocode}
6650 %
6651 %
6652 % \subsection{Adding \mfc{verbatimtex} to the \file{.mp}
6653 % file}\label{verbatimtex}
6654 %
6655 % \DescribeMacro{\mfpverbtex}
6656 % This is a user level utility for putting some \mfc{verbatimtex} material
6657 % in the output file for \MP. We allow the user to do this even before
6658 % \cs{opengraphsfile} by appending it to a token register and setting a
6659 % flag for that command to test.
6660 %
6661 % We now want \texttt\% signs to be written to the output, but also
6662 % want to allow the construct
6663 % \begin{verbatim}
6664 % \mfpverbtex% Comment
6665 % {<tex code>}\end{verbatim}
6666 % to function as users might expect. We therefore perform a
6667 % \cs{futurelet} (which should set \cs{mfp@next} equal to the opening
6668 % brace) but we do it solely to get \TeX's scanning mechanism past the
6669 % comment before we change the category of \texttt\%.
6670 % \begin{macrocode}
6671 \def\mfpverbtex{\futurelet\mfp@next\@mfpverbtex}%
6672 % \end{macrocode}
6673 %
6674 % We start a group, change \texttt\% and \texttt\# to `other' so they
6675 % can be written normally, then continue after loading the code into the
6676 % token register \cs{mfp@toks}.
6677 % \begin{macrocode}
6678 \def\@mfpverbtex{%
6679 \begingroup
6680 \@makeother\#\@makeother\%\mfp@keeplines
6681 \afterassignment\mfp@writetex\global\mfp@toks}%
6682 % \end{macrocode}
6683 % We end the group and then either write it to the
6684 % output, between the commands \gbc{verbatimtex} and \cs{etex},
6685 % or append it to \cs{mfp@verbtex} and set the switch to tell
6686 % \cs{opengraphsfile} that there is material to write when the output file
6687 % is opened.
6688 % \begin{macrocode}
6689 \newif\ifmfp@verbtex
6690 \def\mfp@writetex{%
6691 \mfp@ifopengraphsfile
6692 {\mfp@ifmpost
6693 {\mfcmd{verbatimtex\@nl\the\mfp@toks\@nl\mfp@p\@nl etex}}%
6694 {\mfp@noMP@error\mfpverbtex}%
6695 \global\mfp@verbtexfalse\global\mfp@verbtex{}}%
6696 {\edef\mfp@tempa{\the\mfp@verbtex\the\mfp@toks}%
6697 \global\mfp@verbtex\@xp{\mfp@tempa}%
6698 \global\mfp@verbtextrue}%
6699 \endgroup
6700 }%
6701 % \end{macrocode}
6702 %
6703 %
6704 %
6705 % \section{Finale}\label{finale}
6706 %
6707 % Set the default starting graphic number. We used to start at 0 and
6708 % increment it at the start of each picture, but now we start at 1 and
6709 % increment it at the end of each picture.
6710 % \begin{macrocode}
6711 \mfpicnumber{1}%
6712 % \end{macrocode}
6713 %
6714 % Set the font for missing or draft mode figures (for the file name or
6715 % figure number). This will already have been defined if \file{mfpic.sty}
6716 % was used, so here we can probably assume \LaTeX{} wasn't used, and
6717 % \cs{tt} ought to be available.
6718 % \begin{macrocode}
6719 \mfp@ifdefined\mfpdraftfont{}{\newdef\mfpdraftfont{\tt}}%
6720 % \end{macrocode}
6721 %
6722 % Restore the meaning of \cs{+}, and execute the command that restores all
6723 % the saved category codes and \cs{newlinechar}. Input user defaults in
6724 % the file \file{mfpic.usr}.
6725 % \begin{macrocode}
6726 \mfp@DBlog{Punctuation, etc., will revert to old catcodes now.}%
6727 \let\+\mfpsaveplus
6728 \mfp@restoreALL%
6729 \InputIfFileExists{mfpic.usr}{}{}%
6730 %</tex>
6731 % \end{macrocode}
6732 %
6733 %\clearpage
6734 %\Finale
6735 %\endinput