| 1 |
% File: mfpguide.tex |
| 2 |
% A part of mfpic 1.10 2012/12/03 |
| 3 |
% |
| 4 |
% Tutorial on mfpic |
| 5 |
\documentclass[letterpaper]{article} |
| 6 |
|
| 7 |
\usepackage[chapters]{mfpdoc} |
| 8 |
|
| 9 |
\renewcommand{\thefigure}{\thesection.\arabic{figure}} |
| 10 |
|
| 11 |
\newenvironment{mfpfig}[1] |
| 12 |
{\figure[htb] \centering \refstepcounter{figure} \label{#1}} |
| 13 |
{\par\medskip Figure \thefigure. \endfigure} |
| 14 |
|
| 15 |
\ifpdf |
| 16 |
\usepackage[pdftex,final]{graphics} |
| 17 |
\else |
| 18 |
\usepackage[dvips,final]{graphics} |
| 19 |
\fi |
| 20 |
|
| 21 |
\usepackage[metapost]{mfpic} |
| 22 |
\opengraphsfile{guide} |
| 23 |
|
| 24 |
\dotsize1pt |
| 25 |
|
| 26 |
\ifpdf |
| 27 |
\expandafter\usepackage\expandafter |
| 28 |
[\mfpHyOpts,plainpages=false,naturalnames=true]{hyperref} |
| 29 |
\expandafter\pdfstringdefDisableCommands\expandafter |
| 30 |
{\mfpHyDisable} |
| 31 |
|
| 32 |
\fi |
| 33 |
|
| 34 |
\def\theHfigure{\thefigure} |
| 35 |
|
| 36 |
\begin{document} |
| 37 |
|
| 38 |
\title{\Mfp: A Short Introduction} |
| 39 |
\author{Daniel H. Luecking\thanks{luecking at uark dot edu}} |
| 40 |
\date{\mfpfiledate} |
| 41 |
|
| 42 |
\maketitle |
| 43 |
\tableofcontents |
| 44 |
|
| 45 |
\chapter{Introduction}\label{sec:intro} |
| 46 |
|
| 47 |
As this document aims only to instruct the reader in the building of |
| 48 |
figures with \mfp{}, we will not be too concerned with the intricacies |
| 49 |
of running programs in various operating systems and \TeX{} |
| 50 |
distributions. What will be described here is the simplest case: a |
| 51 |
command-line system in which commands are typed at a keyboard. To |
| 52 |
simplify things further, we will assume that \mfp{} is used with the |
| 53 |
\opt{metapost} option, in a \LaTeX{} document, with \pdfLaTeX{} as the |
| 54 |
compiler. An appendix will discuss some of the differences when these |
| 55 |
assumptions are not satisfied. |
| 56 |
|
| 57 |
We will start right out with the ``Hello, world'' of \mfp{}. Construct a |
| 58 |
\LaTeX{} document by typing the following in a text editor and saving it |
| 59 |
as \file{first.tex}. |
| 60 |
\begin{verbatim} |
| 61 |
% first.tex |
| 62 |
\documentclass{article} |
| 63 |
\usepackage[metapost]{mfpic} |
| 64 |
\opengraphsfile{myfigs} |
| 65 |
\begin{document} |
| 66 |
My first figure: |
| 67 |
\begin{mfpic}[72]{-1}{1}{-1}{1} |
| 68 |
\ellipse{(0,0),1,.5} |
| 69 |
\end{mfpic} |
| 70 |
\closegraphsfile |
| 71 |
\end{document} |
| 72 |
\end{verbatim} |
| 73 |
Run the command |
| 74 |
\begin{ex} |
| 75 |
\texttt{pdflatex first} |
| 76 |
\end{ex} |
| 77 |
which should create several files, the two most important being |
| 78 |
\file{first.pdf} and \file{myfigs.mp}. You can go ahead and open |
| 79 |
\file{first.pdf}. You should see a 2 inch by 2 inch square with |
| 80 |
something similar to `\texttt{\#1}' in the lower left corner. This shows |
| 81 |
where the picture will be when it has been created. |
| 82 |
|
| 83 |
Now run the command |
| 84 |
\begin{ex} |
| 85 |
\texttt{mpost myfigs} |
| 86 |
\end{ex} |
| 87 |
which should create the file \file{myfigs.1}. This is an EPS file |
| 88 |
(Encapsulated PostScript) and can be opened in GhostScript or GSview or |
| 89 |
similar Postscript viewing program to see an ellipse. |
| 90 |
|
| 91 |
If you are viewing \file{first.pdf} in Acrobat Reader or Adobe Reader, |
| 92 |
you will need to close it. Now repeat the \pdfLaTeX{} step: |
| 93 |
\begin{ex} |
| 94 |
\texttt{pdflatex first} |
| 95 |
\end{ex} |
| 96 |
and then view the file \file{first.pdf}. You should see something very |
| 97 |
close to figure~\ref{fig1}. |
| 98 |
\begin{mfpfig}{fig1} |
| 99 |
My first figure: |
| 100 |
\begin{mfpic}[72]{-1}{1}{-1}{1} |
| 101 |
\ellipse{(0,0),1,.5} |
| 102 |
\end{mfpic} |
| 103 |
\end{mfpfig} |
| 104 |
|
| 105 |
What can go wrong? According to Murphy's Law: anything. If \mfp{} is not |
| 106 |
properly installed, one could obtain messages of files not found. If |
| 107 |
that happens, determine (from your \TeX{} system's documentation) where |
| 108 |
\TeX{} input files should go and make sure that \file{mfpic.sty}, |
| 109 |
\file{mfpic.tex} and \file{mfpicdef.tex} reside there. Similarly, find |
| 110 |
out where \MP{} inputs should go and make sure that \file{grafbase.mp} |
| 111 |
and \file{dvipsnam.mp} reside there. Then run whatever command your |
| 112 |
\TeX{} system might require to ``update the filename database''. You may |
| 113 |
safely ignore the message from \mfp{} itself that \file{myfigs.1} is not |
| 114 |
found (on the first run of \pdfLaTeX). This file should be created only |
| 115 |
after running \texttt{mpost}. |
| 116 |
|
| 117 |
If you get an error message from \LaTeX{}, carefully check your typing. |
| 118 |
Also check whether an older version of \mfp{} might have been used |
| 119 |
instead of the current version. If you get an error message from \MP{} |
| 120 |
do the same, especially checking the typing within the \env{mfpic} |
| 121 |
environment. If you get a message from \MP{} that ``Grafbase'' believes |
| 122 |
your \mfp{} installation may be broken, check the log files |
| 123 |
(\file{first.log} and \file{myfigs.log}) to find out the locations of |
| 124 |
these input files: |
| 125 |
\begin{ex} |
| 126 |
\file{mfpic.tex} and \file{grafbase.mp} |
| 127 |
\end{ex} |
| 128 |
and make sure that both these files are from the most recently installed |
| 129 |
\mfp{} package. If you are only evaluating \mfp{} without committing to |
| 130 |
installing it, just make sure all the files mentioned in the previous |
| 131 |
paragraphs are in the current directory. |
| 132 |
|
| 133 |
If \pdfLaTeX{} complains it can't write on the file \file{first.pdf}, |
| 134 |
unload \file{first.pdf} from your pdf viewer and try again. |
| 135 |
|
| 136 |
If the figures look a little choppy in Acrobat Reader, turn on ``smooth |
| 137 |
line art'' in the edit preferences dialogue. |
| 138 |
|
| 139 |
I will assume that eventually all went well and you are now able to |
| 140 |
obtain the ellipse of figure~\ref{fig1}. Each time you change an |
| 141 |
\env{mfpic} environment or the options to the package, you potentially |
| 142 |
change the file \file{myfigs.mp} produced and you should repeat the |
| 143 |
sequence: |
| 144 |
\begin{verbatim} |
| 145 |
pdflatex first |
| 146 |
mpost myfigs |
| 147 |
pdflatex first |
| 148 |
\end{verbatim} |
| 149 |
to be sure of seeing the changes. |
| 150 |
|
| 151 |
One thing you might notice about figure~\ref{fig1} is that the ellipse |
| 152 |
is positioned quite a bit above the base line of the text. This is |
| 153 |
because \mfp{} reserves the amount of space specified in the arguments |
| 154 |
of the \env{mfpic} environment. These arguments were |
| 155 |
\verb$[72]{-1}{1}{-1}{1}$, which means that each unit in the picture is |
| 156 |
72 times the value of \cs{mfpicunit}, that is, about one inch. The first |
| 157 |
pair of mandatory arguments, \verb${-1}{1}$, indicate the |
| 158 |
$x$-coordinates run from $-1$ to $1$. Since these differ by 2, they |
| 159 |
indicate a width of two inches. The second pair similarly represents a |
| 160 |
height of two inches. But the ellipse is centered at $(0,0)$, which is |
| 161 |
one inch above the bottom (bottom is at $y = -1$), and its vertical |
| 162 |
radius is .5. So the lowest point on the ellipse should be 0.5 inches |
| 163 |
above the bottom of the space reserved. \Mfp{} provides a way to fit the |
| 164 |
space reserved to the actual extent of `ink' in the picture. That is by |
| 165 |
the option \opt{truebbox}: |
| 166 |
\begin{verbatim} |
| 167 |
\usepackage[metapost,truebbox]{mfpic} |
| 168 |
\end{verbatim} |
| 169 |
This would then produce something like figure~\ref{fig2}. |
| 170 |
From now on, this option will be in effect in our examples. |
| 171 |
\usetruebbox |
| 172 |
\begin{mfpfig}{fig2} |
| 173 |
My first figure: |
| 174 |
\begin{mfpic}[72]{-1}{1}{-1}{1} |
| 175 |
\ellipse{(0,0),1,.5} |
| 176 |
\end{mfpic} |
| 177 |
\end{mfpfig} |
| 178 |
|
| 179 |
Even though the arguments to the \env{mfpic} environment are ignored in |
| 180 |
determining the size of the figure (under \opt{truebbox}), they are |
| 181 |
still needed in order to establish the coordinate system that the |
| 182 |
ordered pairs refer to (for example \texttt{(0,0)} in the \cs{ellipse} |
| 183 |
arguments). |
| 184 |
|
| 185 |
\chapter{Positioning text}\label{sec:text} |
| 186 |
|
| 187 |
By now you are probably thinking: ``This so-called `Hello, world' |
| 188 |
of \mfp{} doesn't say `Hello, world' anywhere!'' We correct that |
| 189 |
with the following example: |
| 190 |
\begin{verbatim} |
| 191 |
\begin{mfpic}[72]{-1}{1}{-1}{1} |
| 192 |
\ellipse{(0,0),1,.5} |
| 193 |
\tlabel[cc](0,0){Hello, world.} |
| 194 |
\end{mfpic} |
| 195 |
\end{verbatim} |
| 196 |
This should give you figure~\ref{fig3}. |
| 197 |
\begin{mfpfig}{fig3} |
| 198 |
\begin{mfpic}[72]{-1}{1}{-1}{1} |
| 199 |
\ellipse{(0,0),1,.5} |
| 200 |
\tlabel[cc](0,0){Hello, world.} |
| 201 |
\end{mfpic} |
| 202 |
\end{mfpfig} |
| 203 |
|
| 204 |
The \cs{tlabel} command places the given text at the given position |
| 205 |
($(0,0)$) adjusted according to the optional argument \texttt{[cc]}, |
| 206 |
which says to center the text (both vertically and horizontally) at that |
| 207 |
location. The \texttt{[cc]} is optional. Without it, the text would have |
| 208 |
the leftmost point of its baseline (the imaginary line that most letters |
| 209 |
sit on) placed at $(0,0)$. |
| 210 |
|
| 211 |
You are no doubt thinking: ``The ellipse doesn't really match the |
| 212 |
text. What you need is some macro that measures the text and produces an |
| 213 |
oval with similar dimensions.'' For that we have the \cs{tlabeloval} |
| 214 |
command. The \cs{tlabeljustify} command in the example below is to |
| 215 |
communicate to both the text placement and the curve generation |
| 216 |
procedures that they are to be centered at the point $(0,0)$. (We'll see |
| 217 |
an easier way to do this later.) |
| 218 |
\begin{verbatim} |
| 219 |
\begin{mfpic}[72]{-1}{1}{-1}{1} |
| 220 |
\tlabeljustify{cc} |
| 221 |
\tlabeloval(0,0){Hello, world.} |
| 222 |
\end{mfpic} |
| 223 |
\end{verbatim} |
| 224 |
This produces figure~\ref{fig4}. |
| 225 |
\begin{mfpfig}{fig4} |
| 226 |
\begin{mfpic}[72]{-1}{1}{-1}{1} |
| 227 |
\tlabeljustify{cc} |
| 228 |
\tlabeloval(0,0){Hello, world.} |
| 229 |
\end{mfpic} |
| 230 |
\end{mfpfig} |
| 231 |
|
| 232 |
This would be better still if a little space is left around the text so |
| 233 |
the ellipse doesn't touch it. The \cs{tlpathsep} command can do that: |
| 234 |
\begin{verbatim} |
| 235 |
\begin{mfpic}[72]{-1}{1}{-1}{1} |
| 236 |
\tlabeljustify{cc} |
| 237 |
\tlpathsep{3pt} |
| 238 |
\tlabeloval(0,0){Hello, world.} |
| 239 |
\end{mfpic} |
| 240 |
\end{verbatim} |
| 241 |
producing figure~\ref{fig5}. |
| 242 |
\begin{mfpfig}{fig5} |
| 243 |
\begin{mfpic}[72]{-1}{1}{-1}{1} |
| 244 |
\tlabeljustify{cc} |
| 245 |
\tlpathsep{3pt} |
| 246 |
\tlabeloval(0,0){Hello, world.} |
| 247 |
\end{mfpic} |
| 248 |
\end{mfpfig} |
| 249 |
|
| 250 |
It would be nice to make the text pop out a bit with some color% |
| 251 |
\footnote{Colors are included in this document only to give |
| 252 |
examples of their use in \prog{mfpic}. I do not necessarily |
| 253 |
recommend any of them.}% |
| 254 |
. You can do that by adding \verb$\gfill[yellow]$ in front of either |
| 255 |
\verb$\ellipse$ or \verb$\tlabeloval$: |
| 256 |
\begin{verbatim} |
| 257 |
\begin{mfpic}[72]{-1}{1}{-1}{1} |
| 258 |
\tlpathsep{3pt} |
| 259 |
\tlabeljustify{cc} |
| 260 |
\gfill[yellow]\tlabeloval(0,0){Hello, world.} |
| 261 |
\end{mfpic} |
| 262 |
\end{verbatim} |
| 263 |
This will produce figure~\ref{fig6}. |
| 264 |
\begin{mfpfig}{fig6} |
| 265 |
\begin{mfpic}[72]{-1}{1}{-1}{1} |
| 266 |
\tlpathsep{3pt} |
| 267 |
\tlabeljustify{cc} |
| 268 |
\gfill[yellow]\tlabeloval(0,0){Hello, world.} |
| 269 |
\end{mfpic} |
| 270 |
\end{mfpfig} |
| 271 |
|
| 272 |
Notice that now the boundary of the oval has not been drawn. This is the |
| 273 |
standard behavior of \mfp{}. A figure command alone will draw the |
| 274 |
figure. If you want some other rendering than that, you must explicitly |
| 275 |
provide all of it. To get the boundary back, simply add \verb$\draw$ |
| 276 |
before the \verb$\gfill$. You can draw the curve in a color other than |
| 277 |
black with an optional argument. We can also make the line thicker with |
| 278 |
the command \verb$\penwd$: |
| 279 |
\begin{verbatim} |
| 280 |
\begin{mfpic}[72]{-1}{1}{-1}{1} |
| 281 |
\penwd{1.5pt} |
| 282 |
\tlpathsep{3pt} |
| 283 |
\tlabeljustify{cc} |
| 284 |
\draw[blue]\gfill[yellow]\tlabeloval(0,0){Hello, world.} |
| 285 |
\end{mfpic} |
| 286 |
\end{verbatim} |
| 287 |
This will produce figure~\ref{fig7}. |
| 288 |
\begin{mfpfig}{fig7} |
| 289 |
\begin{mfpic}[72]{-1}{1}{-1}{1} |
| 290 |
\penwd{1.5pt} |
| 291 |
\tlpathsep{3pt} |
| 292 |
\tlabeljustify{cc} |
| 293 |
\draw[blue]\gfill[yellow]\tlabeloval(0,0){Hello, world.} |
| 294 |
\end{mfpic} |
| 295 |
\end{mfpfig} |
| 296 |
|
| 297 |
This last version doesn't look too bad, but it seems that the oval ought |
| 298 |
to be a little fatter (slightly higher than it is now). By default, |
| 299 |
\verb$\tlabeloval$ will make the ratio of width to height the same as |
| 300 |
that of the text, or rather of the text plus the additional space |
| 301 |
specified by \verb$\tlpathsep$. This can be changed with an optional |
| 302 |
argument, a number that multiplies the width-to-height ratio. Decreasing |
| 303 |
this ratio will decrease the width (slightly) and increase the height. |
| 304 |
Here we have also omitted the \cs{tlabeljustify} command and shown that |
| 305 |
\cs{tlabeloval} takes a second optional argument that can be used to |
| 306 |
`justify' both the curve and the text. To use this, one must explicitly |
| 307 |
include the first optional argument; if the default is intended, an |
| 308 |
empty pair of brackets may be used. |
| 309 |
\begin{verbatim} |
| 310 |
\begin{mfpic}[72]{-1}{1}{-1}{1} |
| 311 |
\penwd{1.5pt} |
| 312 |
\tlpathsep{3pt} |
| 313 |
\draw[blue]\gfill[yellow]\tlabeloval[.8][cc](0,0){Hello, world.} |
| 314 |
\end{mfpic} |
| 315 |
\end{verbatim} |
| 316 |
This will produce figure~\ref{fig8}. |
| 317 |
\begin{mfpfig}{fig8} |
| 318 |
\begin{mfpic}[72]{-1}{1}{-1}{1} |
| 319 |
\penwd{1.5pt} |
| 320 |
\tlpathsep{3pt} |
| 321 |
\draw[blue]\gfill[yellow]\tlabeloval[.8][cc](0,0){Hello, world.} |
| 322 |
\end{mfpic} |
| 323 |
\end{mfpfig} |
| 324 |
|
| 325 |
The \cs{tlabeloval} command places the label last, after the action of |
| 326 |
all the preceding macros; therefore the text ends up on top of |
| 327 |
everything else. The \cs{tlabeloval} command also has a \mbox{`*-form'} that |
| 328 |
does everything \emph{except} place the text. Finally, ovals are not the |
| 329 |
only thing that can be used to surround text. See the manual |
| 330 |
(\file{mfpic-doc.pdf}) and below for others. |
| 331 |
|
| 332 |
Here is a more common use of \verb$tlabel$ commands: labeling a graph |
| 333 |
and axes. In the following example we have given \cs{tlabel} the option |
| 334 |
\texttt{[bl]} to place the bottom left corner of the text at the given |
| 335 |
coordinates. However, we have used \verb$\tlpointsep{3pt}$, which has |
| 336 |
the effect of shifting text away from its nominal location, to prevent the |
| 337 |
text from colliding with the curve.% |
| 338 |
\footnote{One can also use \cs{tlabelsep}, which is equivalent to |
| 339 |
\cs{tlpathsep} plus \cs{tlpointsep}.} |
| 340 |
The value set by \cs{tlpointsep} has an effect only if the point is on |
| 341 |
the edge of the text, so there would be no shifting with the |
| 342 |
\texttt{[cc]} placement used earlier. |
| 343 |
\begin{verbatim} |
| 344 |
\begin{mfpic}[72]{0}{2.5}{0}{1} |
| 345 |
\tlpointsep{3pt} |
| 346 |
\polyline{(0,.2),(.5,1),(1,.7),(1.5,0),(2,.3)} |
| 347 |
\tlabel[bl](.5,1){Max output} |
| 348 |
\dashed\polyline{(0,.2),(.5,.6),(1,.3),(1.5,.7),(2,.1)} |
| 349 |
\tlabel[bl](1.5,.7){Max input} |
| 350 |
\end{mfpic} |
| 351 |
\end{verbatim} |
| 352 |
This will produce figure~\ref{fig9}. |
| 353 |
\begin{mfpfig}{fig9} |
| 354 |
\begin{mfpic}[72]{0}{2.5}{0}{1} |
| 355 |
\tlpointsep{3pt} |
| 356 |
\polyline{(0,.2),(.5,1),(1,.7),(1.5,0),(2,.3)} |
| 357 |
\tlabel[bl](.5,1){Max output} |
| 358 |
\dashed\polyline{(0,.2),(.5,.6),(1,.3),(1.5,.7),(2,.1)} |
| 359 |
\tlabel[bl](1.5,.7){Max input} |
| 360 |
\end{mfpic} |
| 361 |
\end{mfpfig} |
| 362 |
|
| 363 |
Notice that \verb$\polyline$ alone produces a solid line while |
| 364 |
\verb$\dashed\polyline$ makes a dashed line. Let us close this section |
| 365 |
by dressing up this figure with axes, some fat dots marking the |
| 366 |
keypoints, and hash marks on the axes: |
| 367 |
\begin{verbatim} |
| 368 |
\begin{mfpic}[72]{0}{2.5}{0}{1} |
| 369 |
\tlpointsep{3pt} |
| 370 |
\polyline{(0,.2),(.5,1),(1,.7),(1.5,0),(2,.3)} |
| 371 |
\point[3pt]{(0,.2),(.5,1),(1,.7),(1.5,0),(2,.3)} |
| 372 |
\tlabel[bl](.5,1){Max output} |
| 373 |
\dashed\polyline{(0,.2),(.5,.6),(1,.3),(1.5,.7),(2,.1)} |
| 374 |
\pointfillfalse |
| 375 |
\point[3pt]{(0,.2),(.5,.6),(1,.3),(1.5,.7),(2,.1)} |
| 376 |
\tlabel[bl](1.5,.7){Max input} |
| 377 |
\axes |
| 378 |
\xmarks{0,0.5,1,1.5,2} |
| 379 |
\axislabels x{{$50$} .5, {$100$} 1, {$150$} 1.5, {$200$} 2} |
| 380 |
\end{mfpic} |
| 381 |
\end{verbatim} |
| 382 |
This will produce figure~\ref{fig10}. |
| 383 |
\begin{mfpfig}{fig10} |
| 384 |
\begin{mfpic}[72]{0}{2.5}{0}{1} |
| 385 |
\tlpointsep{3pt} |
| 386 |
\polyline{(0,.2),(.5,1),(1,.7),(1.5,0),(2,.3)} |
| 387 |
\point[3pt]{(0,.2),(.5,1),(1,.7),(1.5,0),(2,.3)} |
| 388 |
\tlabel[bl](.5,1){Max output} |
| 389 |
\dashed\polyline{(0,.2),(.5,.6),(1,.3),(1.5,.7),(2,.1)} |
| 390 |
\pointfillfalse |
| 391 |
\point[3pt]{(0,.2),(.5,.6),(1,.3),(1.5,.7),(2,.1)} |
| 392 |
\tlabel[bl](1.5,.7){Max input} |
| 393 |
\axes |
| 394 |
\xmarks{0,0.5,1,1.5,2} |
| 395 |
\axislabels x{{$50$} .5, {$100$} 1, {$150$} 1.5, {$200$} 2} |
| 396 |
\end{mfpic} |
| 397 |
\end{mfpfig} |
| 398 |
|
| 399 |
The optional argument of \verb$\point$ specifies the diameter of the |
| 400 |
points to draw. The command \verb$\pointfillfalse$ forces the points to |
| 401 |
be drawn as open circles. The axes configure themselves to the size |
| 402 |
specified in the argument of the \env{mfpic} environment. The |
| 403 |
\verb$axislabels$ command takes as arguments a letter, to specify the |
| 404 |
axis, and a comma separated list of labels, each of which is specified |
| 405 |
by some text to place (in braces) and the x-coordinate to place it at. |
| 406 |
|
| 407 |
\chapter{Drawing figures} |
| 408 |
|
| 409 |
\Mfp{} has several predefined figures and commands to obtain essentially |
| 410 |
any curve (provided one can obtain enough points on it with sufficient |
| 411 |
precision). We've already seen \verb$\polyline$ and \verb$\ellipse$. The |
| 412 |
former needs a list of points to connect with line segments and the |
| 413 |
latter needs the center and radii of the ellipse. The \verb$\ellipse$ |
| 414 |
also takes an optional argument: the number of degrees to rotate the |
| 415 |
ellipse. Here we list some of the more common such figures. Remember |
| 416 |
that all of them will produce some sort of line drawing if used alone. |
| 417 |
They can be preceded by \verb$\dashed$ to make the lines dashed or |
| 418 |
\verb$\dotted$ to make them dotted. If the figure is a closed curve, |
| 419 |
\verb$\gfill$ will fill it in. |
| 420 |
\begin{verbatim} |
| 421 |
\begin{mfpic}[72]{0}{4}{0}{1} |
| 422 |
\rect{(0,0),(1,.75)} |
| 423 |
\circle{(1.5,.5),.45} |
| 424 |
\arc[s]{(3,0),(2,1),45} |
| 425 |
\ellipse[20]{(3.5, 0.5), 0.6, 0.4} |
| 426 |
\end{mfpic} |
| 427 |
\end{verbatim} |
| 428 |
This produces figure~\ref{fig11}. The \verb$\arc$ command has several |
| 429 |
forms. The optional argument picks the form to use. This one specifies |
| 430 |
the endpoints of the circular arc and the angle of the arc (the angle |
| 431 |
between the radii from the center of the circle to those two points). |
| 432 |
Other possibilities are a three-point form (option \texttt{[t]}), a |
| 433 |
polar form (option \texttt{[p]}), and a center-point-sweep form (option |
| 434 |
\texttt{[c]}, specify a center, starting point, and angle). See the |
| 435 |
manual for details. The default (what would be assumed if no optional |
| 436 |
argument is given) is \oarg{s} and is called the ``point-sweep'' form. |
| 437 |
\begin{mfpfig}{fig11} |
| 438 |
\begin{mfpic}[72]{0}{4}{0}{1} |
| 439 |
\rect{(0,0),(1,.75)} |
| 440 |
\circle{(1.5,.5),.45} |
| 441 |
\arc[s]{(3,0),(2,1),45} |
| 442 |
\ellipse[20]{(3.5, 0.5), 0.6, 0.4} |
| 443 |
\end{mfpic} |
| 444 |
\end{mfpfig} |
| 445 |
|
| 446 |
The \cs{polyline} command draws straight lines connecting points. We can |
| 447 |
also draw smooth curves. Lets take the same points from our |
| 448 |
\cs{polyline} example (figure~\ref{fig9}), but change \cs{polyline} to |
| 449 |
\cs{curve}, omit the text, and add the points from figure~\ref{fig10}: |
| 450 |
\begin{verbatim} |
| 451 |
\begin{mfpic}[72]{0}{2.5}{0}{1} |
| 452 |
\curve{(0,.2),(.5,1),(1,.7),(1.5,0),(2,.3)} |
| 453 |
\point[3pt]{(0,.2),(.5,1),(1,.7),(1.5,0),(2,.3)} |
| 454 |
\dashed\curve{(0,.2),(.5,.6),(1,.3),(1.5,.7),(2,.1)} |
| 455 |
\pointfillfalse |
| 456 |
\point[3pt]{(0,.2),(.5,.6),(1,.3),(1.5,.7),(2,.1)} |
| 457 |
\end{mfpic} |
| 458 |
\end{verbatim} |
| 459 |
This should produce figure~\ref{fig12}. |
| 460 |
\begin{mfpfig}{fig12} |
| 461 |
\begin{mfpic}[72]{0}{2.5}{0}{1} |
| 462 |
\curve{(0,.2),(.5,1),(1,.7),(1.5,0),(2,.3)} |
| 463 |
\point[3pt]{(0,.2),(.5,1),(1,.7),(1.5,0),(2,.3)} |
| 464 |
\dashed\curve{(0,.2),(.5,.6),(1,.3),(1.5,.7),(2,.1)} |
| 465 |
\pointfillfalse |
| 466 |
\point[3pt]{(0,.2),(.5,.6),(1,.3),(1.5,.7),(2,.1)} |
| 467 |
\end{mfpic} |
| 468 |
\end{mfpfig} |
| 469 |
|
| 470 |
This is somewhat unsatisfying. One could improve the result by selecting |
| 471 |
more points, or by increasing the `tension' in the curve. |
| 472 |
|
| 473 |
Roughly speaking, tension determines how straight the segments between |
| 474 |
the points are, and how sharp the turns at each point. High tension |
| 475 |
makes the curve look a little more like a polyline. The default tension |
| 476 |
is 1, a tension of about 5 makes the result look somewhat like a |
| 477 |
polyline with very slightly rounded corners, very high tensions make the |
| 478 |
curve indistinguishable from a polyline. Tension must (almost) always be |
| 479 |
greater than $0.75$. |
| 480 |
|
| 481 |
Another effect of increased tension is to reduce the little wobbles we |
| 482 |
can see in the first curve. Let's try a tension of 1.5, which can be |
| 483 |
specified as an optional argument to \cs{curve}: |
| 484 |
\begin{verbatim} |
| 485 |
\begin{mfpic}[72]{0}{2.5}{0}{1} |
| 486 |
\curve[1.5]{(0,.2),(.5,1),(1,.7),(1.5,0),(2,.3)} |
| 487 |
\point[3pt]{(0,.2),(.5,1),(1,.7),(1.5,0),(2,.3)} |
| 488 |
\dashed\curve[1.5]{(0,.2),(.5,.6),(1,.3),(1.5,.7),(2,.1)} |
| 489 |
\pointfillfalse |
| 490 |
\point[3pt]{(0,.2),(.5,.6),(1,.3),(1.5,.7),(2,.1)} |
| 491 |
\end{mfpic} |
| 492 |
\end{verbatim} |
| 493 |
This give figure~\ref{fig13}. |
| 494 |
\begin{mfpfig}{fig13} |
| 495 |
\begin{mfpic}[72]{0}{2.5}{0}{1} |
| 496 |
\curve[1.5]{(0,.2),(.5,1),(1,.7),(1.5,0),(2,.3)} |
| 497 |
\point[3pt]{(0,.2),(.5,1),(1,.7),(1.5,0),(2,.3)} |
| 498 |
\dashed\curve[1.5]{(0,.2),(.5,.6),(1,.3),(1.5,.7),(2,.1)} |
| 499 |
\pointfillfalse |
| 500 |
\point[3pt]{(0,.2),(.5,.6),(1,.3),(1.5,.7),(2,.1)} |
| 501 |
\end{mfpic} |
| 502 |
\end{mfpfig} |
| 503 |
|
| 504 |
When we use \cs{curve}, there is no way \MP{} can tell if we are just |
| 505 |
connecting points or if we are trying to graph a function. |
| 506 |
It \emph{cannot} enforce the requirement, which every function must |
| 507 |
satisfy, that the curve should travel left-to-right. The command |
| 508 |
\cs{fcncurve} does enforce this (assuming the points to be connected are |
| 509 |
listed in left-to-right order). This command also permits an optional |
| 510 |
tension argument. The dotted line in figure~\ref{fig14} is produced with |
| 511 |
\cs{curve}, the solid one with \cs{fcncurve}. One might conceivably want |
| 512 |
to decrease the tension a bit here. |
| 513 |
\begin{verbatim} |
| 514 |
\begin{mfpic}[72]{0}{2.5}{0}{1} |
| 515 |
\dotted\curve{(0,.2),(.5,0),(.85,.5),(1,1),(1.5,0),(2,.3)} |
| 516 |
\fcncurve{(0,.2),(.5,0),(.85,.5),(1,1),(1.5,0),(2,.3)} |
| 517 |
\pointfillfalse |
| 518 |
\point[3pt]{(0,.2),(.5,0),(.85,.5),(1,1),(1.5,0),(2,.3)} |
| 519 |
\end{mfpic} |
| 520 |
\end{verbatim} |
| 521 |
\begin{mfpfig}{fig14} |
| 522 |
\begin{mfpic}[72]{0}{2.5}{0}{1} |
| 523 |
\dotted\curve{(0,.2),(.5,0),(.85,.5),(1,1),(1.5,0),(2,.3)} |
| 524 |
\fcncurve{(0,.2),(.5,0),(.85,.5),(1,1),(1.5,0),(2,.3)} |
| 525 |
\pointfillfalse |
| 526 |
\point[3pt]{(0,.2),(.5,0),(.85,.5),(1,1),(1.5,0),(2,.3)} |
| 527 |
\end{mfpic} |
| 528 |
\end{mfpfig} |
| 529 |
|
| 530 |
Other figures available include\leftmargini=2\leftmargini |
| 531 |
\begin{description} |
| 532 |
\item[\cs{cyclic}] Used just like \cs{curve} but closes the path |
| 533 |
(connects the last point smoothly to the starting point). |
| 534 |
\item[\cs{polygon}] Used just like \cs{polyline} except it connects the |
| 535 |
last point to the first with a straight line. |
| 536 |
\item[\cs{sector}] Makes a wedge with two straight lines and an arc. The |
| 537 |
arguments are almost the same as \cs{arc}\oarg{p}, but the order is |
| 538 |
different: center, radius and two angles. |
| 539 |
\end{description} |
| 540 |
|
| 541 |
Here are some other curves that, like \cs{tlabeloval}, are proportioned |
| 542 |
to fit given text. All have a \texttt{*}-form that draws the path |
| 543 |
without placing the text. |
| 544 |
\begin{description} |
| 545 |
\item[\cs{tlabelrect}] This produces a rectangle. It has the same usage |
| 546 |
as \cs{tlabeloval}, except the first optional argument specifies |
| 547 |
the radius of quarter-circles used to make rounded corners. |
| 548 |
\item[\cs{tlabelellipse}] This is similar to \cs{tlabeloval} |
| 549 |
except that instead of modifying the width-to-height ratio, the |
| 550 |
first optional argument \emph{is} the width-to-height ratio. If that |
| 551 |
argument is 1 (the default) you get a circle. |
| 552 |
\item[\cs{tlabelcircle}] This produces a circle, of course. |
| 553 |
\end{description} |
| 554 |
|
| 555 |
|
| 556 |
\chapter{Functions} |
| 557 |
|
| 558 |
\CMP{} is able to calculate a number of functions natively, and still |
| 559 |
more have been defined in \mfp{}. Also available are the usual |
| 560 |
arithmetic operations. Any valid \MP{} expression, containing |
| 561 |
one unknown \gbc{x} and producing a numerical result can be graphed. |
| 562 |
|
| 563 |
Here is an example of the graphs of $y = x^2$ and $y = \pm\sqrt{x}$. |
| 564 |
Note that exponentials are denoted by \texttt{**} and it is important to |
| 565 |
note that it has the same precedence as multiplication (denoted by a |
| 566 |
single \texttt{*}). That is, in a formula like \mfc{3*3**2}, the |
| 567 |
operations are performed in order, left to right, producing $(3\cdot |
| 568 |
3)^2 = 81$ and not $3\cdot 3^2 = 27$. Parentheses are needed if the |
| 569 |
latter is intended: \mfc{3*(3**2)}. |
| 570 |
\begin{verbatim} |
| 571 |
\setlength{\mfpicunit}{1cm} |
| 572 |
\begin{mfpic}{-2.5}{2.5}{-1.5}{4} |
| 573 |
\function{-2,2,.1}{x**2} |
| 574 |
\function{0,2,.1}{sqrt x} |
| 575 |
\function{0,2,.1}{-sqrt x} |
| 576 |
\axes |
| 577 |
\xmarks{-2,-1,1,2} |
| 578 |
\ymarks{-1,1,2,3} |
| 579 |
\tlpointsep{3pt} |
| 580 |
\axislabels x{{$-2$}-2,{$-1$}-1,{$1$}1,{$2$}2} |
| 581 |
\axislabels y{{$-1$}-1,{$1$}1,{$2$}2,{$3$}3} |
| 582 |
\end{mfpic} |
| 583 |
\end{verbatim} |
| 584 |
This produces figure~\ref{fig15}. |
| 585 |
\begin{mfpfig}{fig15} |
| 586 |
\setlength{\mfpicunit}{1cm} |
| 587 |
\begin{mfpic}{-2.5}{2.5}{-1.5}{4} |
| 588 |
\function{-2,2,.1}{x**2} |
| 589 |
\function{0,2,.1}{sqrt x} |
| 590 |
\function{0,2,.1}{-sqrt x} |
| 591 |
\axes |
| 592 |
\xmarks{-2,-1,1,2} |
| 593 |
\ymarks{-1,1,2,3} |
| 594 |
\tlpointsep{3pt} |
| 595 |
\axislabels x{{$-2$}-2,{$-1$}-1,{$1$}1,{$2$}2} |
| 596 |
\axislabels y{{$-1$}-1,{$1$}1,{$2$}2,{$3$}3} |
| 597 |
\end{mfpic} |
| 598 |
\end{mfpfig} |
| 599 |
|
| 600 |
The command \cs{function} has two arguments. The first contains the |
| 601 |
starting and ending x-values of the desired graph, followed by a |
| 602 |
\emph{step size}. Generally the smaller the steps the better the |
| 603 |
accuracy, but \MP{} has a limit on the number of steps (usually about |
| 604 |
2000). There is also an optional argument which can be \oarg{s}, the |
| 605 |
default, which means the graph is to be smooth, or \oarg{p}, which means |
| 606 |
the graph is constructed by connecting the calculated points with |
| 607 |
straight lines. Here is the same example with larger step size to |
| 608 |
emphasize the difference (see figure~\ref{fig16}) |
| 609 |
\begin{verbatim} |
| 610 |
\setlength{\mfpicunit}{1cm} |
| 611 |
\begin{mfpic}{-2.5}{2.5}{-1.5}{4} |
| 612 |
\function[p]{-2,2,.5}{x**2} |
| 613 |
\function[p]{0,2,.5}{sqrt x} |
| 614 |
\function[p]{0,2,.5}{-sqrt x} |
| 615 |
\axes |
| 616 |
\xmarks{-2,-1,1,2} |
| 617 |
\ymarks{-1,1,2,3} |
| 618 |
\tlpointsep{3pt} |
| 619 |
\axislabels x{{$-2$}-2,{$-1$}-1,{$1$}1,{$2$}2} |
| 620 |
\axislabels y{{$-1$}-1,{$1$}1,{$2$}2,{$3$}3} |
| 621 |
\end{mfpic} |
| 622 |
\end{verbatim} |
| 623 |
\begin{mfpfig}{fig16} |
| 624 |
\setlength{\mfpicunit}{1cm} |
| 625 |
\begin{mfpic}{-2.5}{2.5}{-1.5}{4} |
| 626 |
\function[p]{-2,2,.5}{x**2} |
| 627 |
\function[p]{0,2,.5}{sqrt x} |
| 628 |
\function[p]{0,2,.5}{-sqrt x} |
| 629 |
\axes |
| 630 |
\xmarks{-2,-1,1,2} |
| 631 |
\ymarks{-1,1,2,3} |
| 632 |
\tlpointsep{3pt} |
| 633 |
\axislabels x{{$-2$}-2,{$-1$}-1,{$1$}1,{$2$}2} |
| 634 |
\axislabels y{{$-1$}-1,{$1$}1,{$2$}2,{$3$}3} |
| 635 |
\end{mfpic} |
| 636 |
\end{mfpfig} |
| 637 |
|
| 638 |
In addition, one can increase the tension in the curve drawn by putting |
| 639 |
a tension value after the \gbc{s} in \oarg{s}. For a tension of 2.4: |
| 640 |
\cs{function}\oarg{s2.4}\marg{\dots}. |
| 641 |
|
| 642 |
The functions available include \gbc{sqrt} and all the trig functions: |
| 643 |
\gbc{sin x} assumes \gbc{x} is an angle in radians, \mfc{sind x} assumes |
| 644 |
it is in degrees, with a similar naming convention for the remaining |
| 645 |
trig functions. The inverses are \gbc{asin x}, \gbc{acos x}, and |
| 646 |
\gbc{atan x}, which produce angles in degrees, and \gbc{invsin x}, etc., |
| 647 |
which produce angles in radians. There is also \gbc{ln~x} or \gbc{log~x} |
| 648 |
for the natural logarithm, \gbc{exp~x} for $e^x$, \gbc{logten}~\gbc{x} |
| 649 |
for the base 10 logarithm, \gbc{logtwo}~\gbc{x} for base 2, and |
| 650 |
\gbc{logbase} for other bases: |
| 651 |
\gbc{logbase(16)}~\gbc{x} (for example) for base 16. The general syntax of |
| 652 |
these functions is the following: if the argument is \gbc{x} alone or a |
| 653 |
pure number alone or the particular case of a number followed by \gbc{x} |
| 654 |
(no \gbc{*} in between!) then parentheses are not needed. Example: |
| 655 |
\gbc{sin~2x}. For almost anything else, parentheses are required: |
| 656 |
\gbc{sin(3*x)} or \gbc{sin(x**2)}. |
| 657 |
|
| 658 |
Some other functions available are the hyperbolic functions, \gbc{sinh x}, |
| 659 |
\gbc{cosh x}, etc. (all 6 of them), and the inverses of three of them: |
| 660 |
\gbc{asinh x}, \gbc{acosh x}, and \gbc{atanh x}. |
| 661 |
|
| 662 |
These functions (or any \MP{} numeric expression) can also be used in |
| 663 |
any of the coordinates of points in drawing commands like \cs{polyline} |
| 664 |
(but not usually in text placement commands like \cs{tlabeloval}). For |
| 665 |
example (from now on the value of \cs{mfpicunit} is set to |
| 666 |
\texttt{1cm}):\setlength{\mfpicunit}{1cm} |
| 667 |
\begin{verbatim} |
| 668 |
\begin{mfpic}{-.5}{2.5}{-1.5}{1.5} |
| 669 |
\polyline{(2,-sqrt 2),(1,-1),(.5,- sqrt .5),(0,0), |
| 670 |
(.5,sqrt .5),(1,1),(2,sqrt 2)} |
| 671 |
\axes |
| 672 |
\xmarks{1,2} |
| 673 |
\ymarks{-1,1} |
| 674 |
\tlpointsep{3pt} |
| 675 |
\axislabels x{{$1$}1,{$2$}2} |
| 676 |
\axislabels y{{$-1$}-1,{$1$}1} |
| 677 |
\end{mfpic} |
| 678 |
\end{verbatim} |
| 679 |
\begin{mfpfig}{fig17} |
| 680 |
\begin{mfpic}{-.5}{2.5}{-1.5}{1.5} |
| 681 |
\polyline{(2,-sqrt 2),(1,-1),(.5,- sqrt .5),(0,0), |
| 682 |
(.5,sqrt .5),(1,1),(2,sqrt 2)} |
| 683 |
\axes |
| 684 |
\xmarks{1,2} |
| 685 |
\ymarks{-1,1} |
| 686 |
\tlpointsep{3pt} |
| 687 |
\axislabels x{{$1$}1,{$2$}2} |
| 688 |
\axislabels y{{$-1$}-1,{$1$}1} |
| 689 |
\end{mfpic} |
| 690 |
\end{mfpfig} |
| 691 |
|
| 692 |
There are other types of functions: parametric functions, and polar |
| 693 |
coordinate versions. \Mfp{} provides \cs{parafcn} and \cs{plrfcn} to |
| 694 |
graph these. The \cs{parafcn} requires a starting value, and ending |
| 695 |
value and a step size just as in \cs{function}, but in the second |
| 696 |
argument there must be either a pair of expressions in the variable |
| 697 |
\gbc{t}, separated by a comma and enclosed in parentheses, or a single |
| 698 |
\emph{pair-valued} expression. \CMP{} and \mfp{} provide only a few |
| 699 |
pair-valued functions; one is used below. |
| 700 |
|
| 701 |
The second argument of \cs{plrfcn} must contain a single numeric |
| 702 |
expression in the variable \gbc{t}, and indicates a function of $\theta$ |
| 703 |
to be graphed in polar coordinates: $r = f(\theta)$. In the following |
| 704 |
example (figure~\ref{fig22}), we draw a portion of the graph of $x = |
| 705 |
y^2$ by representing it as the graph of the parametric equations $x = |
| 706 |
t^2$, $y = t$, and a portion of a circle of radius $1.5$ by representing |
| 707 |
it as the graph of the pair-valued function \mfc{dir(t)}. The expression |
| 708 |
\mfc{dir(t)} gives the point whose distance from $(0,0)$ is $1$ in the |
| 709 |
direction given by the angle \mfc{t}. |
| 710 |
\begin{verbatim} |
| 711 |
\begin{mfpic}{-2}{4}{-2}{2} |
| 712 |
\parafcn{-2,2,.1}{(t**2,t)} |
| 713 |
\dotted\parafcn{45,315,5}{1.5*dir(t)} |
| 714 |
\end{mfpic} |
| 715 |
\end{verbatim} |
| 716 |
\begin{mfpfig}{fig22} |
| 717 |
\begin{mfpic}{-2}{4}{-2}{2} |
| 718 |
\parafcn{-2,2,.1}{(t**2,t)} |
| 719 |
\dotted\parafcn{45,315,5}{1.5*dir(t)} |
| 720 |
\end{mfpic} |
| 721 |
\end{mfpfig} |
| 722 |
|
| 723 |
|
| 724 |
Here is an example of a graph of the polar coordinate function |
| 725 |
$r=2\sin 3\theta$ (figure~\ref{fig23}). We use the degree version |
| 726 |
\mfc{sind} in order to work with integers. |
| 727 |
\begin{verbatim} |
| 728 |
\begin{mfpic}{-2}{2}{-2}{2} |
| 729 |
\plrfcn{0,180,5}{2*sind 3t} |
| 730 |
\end{mfpic} |
| 731 |
\end{verbatim} |
| 732 |
\begin{mfpfig}{fig23} |
| 733 |
\begin{mfpic}{-2}{2}{-2}{2} |
| 734 |
\plrfcn{0,180,5}{2*sind 3t} |
| 735 |
\end{mfpic} |
| 736 |
\end{mfpfig} |
| 737 |
|
| 738 |
|
| 739 |
\chapter{Transforming figures} |
| 740 |
|
| 741 |
\CMP{} is capable of any affine transformation (things like shifting, |
| 742 |
rotating, scaling, reflecting and slanting) of any path. The figures |
| 743 |
we've been dealing with so far (\cs{ellipse}, \cs{curve}, \cs{function}, |
| 744 |
etc.) all produce, in the \MP{} code, the definition of some path (as |
| 745 |
well as a drawing of that path). \Mfp{} provides for different methods |
| 746 |
of `drawing' the path with \emph{prefix macros}. We've seen \cs{dashed}, |
| 747 |
\cs{dotted}, \cs{gfill} so far, in addition to the default \cs{draw}. |
| 748 |
\Mfp{} also provides for modifying the shape and position of the path |
| 749 |
with other prefixes. Here's a simple example. |
| 750 |
\begin{verbatim} |
| 751 |
\begin{mfpic}{-.5}{2.5}{-.5}{2.5} |
| 752 |
\rotatepath{(1,.5), 45}\rect{(0,0),(2,1)} |
| 753 |
\point{(1,.5)} |
| 754 |
\end{mfpic} |
| 755 |
\end{verbatim} |
| 756 |
The command \cs{rotatepath} obviously rotates the path that follows, but |
| 757 |
it needs to know what the center of rotation will be, and how much to |
| 758 |
rotate. These are given in its mandatory argument, separated by a comma. |
| 759 |
The example above (pictured in figure~\ref{fig18}) rotates 45 degrees |
| 760 |
around the center of the rectangle. |
| 761 |
\begin{mfpfig}{fig18} |
| 762 |
\begin{mfpic}{-.5}{2.5}{-.5}{2.5} |
| 763 |
\rotatepath{(1,.5), 45}\rect{(0,0),(2,1)} |
| 764 |
\point{(1,.5)} |
| 765 |
\end{mfpic} |
| 766 |
\end{mfpfig} |
| 767 |
|
| 768 |
Notice that we have no drawing prefix. A combination of |
| 769 |
transformation-plus-figure is treated as a figure in its own right and |
| 770 |
behaves the same. If we want the figure dashed, we could write |
| 771 |
\begin{verbatim} |
| 772 |
\dashed\rotatepath{(1,.5),45}\rect{(0,0),(2,1)} |
| 773 |
\end{verbatim} |
| 774 |
It may not be obvious, but we can also write a drawing macro between |
| 775 |
the rotation and the figure, producing figure~\ref{fig19} |
| 776 |
\begin{verbatim} |
| 777 |
\begin{mfpic}{-.5}{2.5}{-.5}{2.5} |
| 778 |
\rotatepath{(1,.5), 45}\draw\rect{(0,0),(2,1)} |
| 779 |
\point{(1,.5)} |
| 780 |
\end{mfpic} |
| 781 |
\end{verbatim} |
| 782 |
\begin{mfpfig}{fig19} |
| 783 |
\begin{mfpic}{-.5}{2.5}{-.5}{2.5} |
| 784 |
\rotatepath{(1,.5), 45}\draw\rect{(0,0),(2,1)} |
| 785 |
\point{(1,.5)} |
| 786 |
\end{mfpic} |
| 787 |
\end{mfpfig} |
| 788 |
|
| 789 |
This illustrates another property of \mfp{} macros: the combination of a |
| 790 |
rendering prefix and a figure is also treated the same as a figure in |
| 791 |
its own right: the same figure as the one that follows. In fact, the |
| 792 |
only difference between \cs{rect} and \cs{draw}\cs{rect} in this |
| 793 |
example is that the second one has a minor(!) side effect: the |
| 794 |
rectangle is drawn. |
| 795 |
|
| 796 |
Finally, try to guess what happens if we add another prefix at the |
| 797 |
front: |
| 798 |
\begin{verbatim} |
| 799 |
\begin{mfpic}{-.5}{2.5}{-.5}{2.5} |
| 800 |
\dotted\rotatepath{(1,.5), 45} |
| 801 |
\draw\rect{(0,0),(2,1)} |
| 802 |
\end{mfpic} |
| 803 |
\end{verbatim} |
| 804 |
and if we add another rotation in front of that. |
| 805 |
\begin{verbatim} |
| 806 |
\begin{mfpic}{-.5}{2.5}{-.5}{2.5} |
| 807 |
\rotatepath{(0,0),45} |
| 808 |
\dotted\rotatepath{(1,.5), 45} |
| 809 |
\draw\rect{(0,0),(2,1)} |
| 810 |
\end{mfpic} |
| 811 |
\end{verbatim} |
| 812 |
|
| 813 |
|
| 814 |
Available transformations include |
| 815 |
\begin{display}\raggedright |
| 816 |
\cs{scalepath}, \cs{shiftpath}, \cs{xscalepath}, \cs{yscalepath}, |
| 817 |
\cs{slantpath}, and \cs{reflectpath}. |
| 818 |
\end{display} |
| 819 |
See the manual for a description of what arguments are required for |
| 820 |
each. Here's a final example, producing figure~\ref{fig20} |
| 821 |
\begin{verbatim} |
| 822 |
\begin{mfpic}{-.5}{2.5}{-.5}{2.5} |
| 823 |
\shiftpath{(-1,1)}\draw[red]\slantpath{.5,1}\dotted |
| 824 |
\rotatepath{(0,0), 90}\dashed\rect{(0,0),(2,1)} |
| 825 |
\point{(0,0),(2,1)} |
| 826 |
\tlpointsep{2pt} |
| 827 |
\tlabel[tr](0,0){$(0,0)$} |
| 828 |
\tlabel[bl](2,1){$(2,1)$} |
| 829 |
\end{mfpic} |
| 830 |
\end{verbatim} |
| 831 |
\begin{mfpfig}{fig20} |
| 832 |
\begin{mfpic}{-.5}{2.5}{-.5}{2.5} |
| 833 |
\shiftpath{(-1,1)}\draw[red]\slantpath{.5,1}\dotted |
| 834 |
\rotatepath{(0,0), 90}\dashed\rect{(0,0),(2,1)} |
| 835 |
\point{(0,0),(2,1)} |
| 836 |
\tlpointsep{2pt} |
| 837 |
\tlabel[tr](0,0){$(0,0)$} |
| 838 |
\tlabel[bl](2,1){$(2,1)$} |
| 839 |
\end{mfpic} |
| 840 |
\end{mfpfig} |
| 841 |
|
| 842 |
\chapter{Rendering figures} |
| 843 |
|
| 844 |
\emph{Rendering} is the act of making a description of a figure visible. |
| 845 |
Examples are: drawing a solid curve, drawing a dashed curve, or filling |
| 846 |
its interior, For \mfp{} figure macros the default, in the absence of |
| 847 |
explicit commands, is to use \cs{draw}. That is, |
| 848 |
\begin{verbatim} |
| 849 |
\rect{(0,0),(1,2)} |
| 850 |
\end{verbatim} |
| 851 |
has the same result as |
| 852 |
\begin{verbatim} |
| 853 |
\draw\rect{(0,0),(1,2)} |
| 854 |
\end{verbatim} |
| 855 |
The default rendering can be changed. Just say |
| 856 |
\cs{setrender}\marg{\cs{dashed}}, and all figures afterward will be dashed |
| 857 |
(see figure~\ref{fig21}). |
| 858 |
\begin{verbatim} |
| 859 |
\begin{mfpic}{0}{2}{0}{1} |
| 860 |
\setrender{\dashed} |
| 861 |
\rect{(0,0),(1,1)} |
| 862 |
\circle{(1.5,.5),.5} |
| 863 |
\end{mfpic} |
| 864 |
\end{verbatim} |
| 865 |
\begin{mfpfig}{fig21} |
| 866 |
\begin{mfpic}{0}{2}{0}{1} |
| 867 |
\setrender{\dashed} |
| 868 |
\rect{(0,0),(1,1)} |
| 869 |
\circle{(1.5,.5),.5} |
| 870 |
\end{mfpic} |
| 871 |
\end{mfpfig} |
| 872 |
The \cs{setrender} command can be inside an \env{mfpic} environment to |
| 873 |
affect only later commands in that figure, or outside to affect all |
| 874 |
later \mfp{} figures. |
| 875 |
|
| 876 |
We give a few examples now of the renderings possible. These divide |
| 877 |
more-or-less into those that trace a path and those that fill in a path. |
| 878 |
In order to fill in a path, it must be a closed path, of course, but |
| 879 |
\MP{} distinguishes between closed paths and those that merely happen to |
| 880 |
end where they began. There is a good reason for this: \MP{} cannot, |
| 881 |
without human aid, know if two points are the same, or merely |
| 882 |
accidentally so close that the accuracy of the program sees them as the |
| 883 |
same. It requires human aid in the form of an explicit request to |
| 884 |
create a closed path. Of the \mfp{} macros we've seen so far, |
| 885 |
\cs{ellipse}, \cs{circle}, \cs{rect}, \cs{polygon}, and \cs{cyclic} |
| 886 |
produce closed paths, but \cs{polyline}, \cs{curve}, \cs{function}, |
| 887 |
\cs{parafcn}, and \cs{plrfcn} do not. Also producing closed paths are |
| 888 |
\cs{tlabeloval} and its relatives. |
| 889 |
|
| 890 |
The following example illustrates filling with a hatching pattern |
| 891 |
(parallel lines) and an \emph{unfilling}. Clearing the interior of a |
| 892 |
path may not seem like rendering, but it is treated in exactly the same way |
| 893 |
(think of it as a negative rendering). We first hatch a rectangle, then |
| 894 |
clear out a smaller rectangle with rounded corners to place our text |
| 895 |
inside. The results are in figure~\ref{fig24}. |
| 896 |
\begin{verbatim} |
| 897 |
\begin{mfpic}{0}{2}{0}{2} |
| 898 |
\draw[red]\lhatch[2pt][blue]\rect{(0,0),(2,2)} |
| 899 |
\gclear\tlabelrect[6pt][cc](1,1){Hatching!} |
| 900 |
\end{mfpic} |
| 901 |
\end{verbatim} |
| 902 |
\begin{mfpfig}{fig24} |
| 903 |
\begin{mfpic}{0}{2}{0}{2} |
| 904 |
\draw[red]\lhatch[2pt][blue]\rect{(0,0),(2,2)} |
| 905 |
\gclear\tlabelrect[6pt][cc](1,1){Hatching!} |
| 906 |
\end{mfpic} |
| 907 |
\end{mfpfig} |
| 908 |
This example illustrates that \cs{lhatch} fills with left slanting |
| 909 |
lines. And that it takes two optional arguments. The first is the |
| 910 |
distance between lines, and the second is the color to make the lines. |
| 911 |
There are also \cs{rhatch} which slants the lines the other way, |
| 912 |
\cs{xhatch} which uses both slants, and \cs{thatch} which can draw |
| 913 |
the lines at any angle. |
| 914 |
|
| 915 |
Here is another example of rendering (figure~\ref{fig26}). The new |
| 916 |
macro is \cs{polkadot}. We've repeated this example twice to |
| 917 |
show the effect of changing the order of the prefixes. Each prefix |
| 918 |
applies its rendering to the result of everything to the right of it. In |
| 919 |
the second example the hatching goes over the dots (and a bit of the |
| 920 |
dashes as well). If the \cs{gfill} were first, it would cover almost |
| 921 |
everything else. |
| 922 |
\begin{verbatim} |
| 923 |
\begin{mfpic}{0}{6}{0}{2} |
| 924 |
\penwd{2pt} |
| 925 |
\hatchwd{2pt} |
| 926 |
\drawcolor{blue} |
| 927 |
\hatchcolor{red} |
| 928 |
\fillcolor{green} |
| 929 |
\dashed\polkadot\rhatch[5pt]\gfill[yellow]\rect{(0,0),(2.8,1.8)} |
| 930 |
\rhatch[5pt]\dashed\polkadot\gfill[yellow]\rect{(3,0),(5.8,1.8)} |
| 931 |
\end{mfpic} |
| 932 |
\end{verbatim} |
| 933 |
We've added a couple of other new features to this example. To emphasize |
| 934 |
effects, we've increased the thickness of the drawing pen (\cs{penwd}) |
| 935 |
and the hatch lines (\cs{hatchwd}). We've also used the \cs{drawcolor} |
| 936 |
macro and its relatives to set the colors to be used. The \cs{polkadot} |
| 937 |
macro uses the color set by \cs{fillcolor}; so does \cs{gfill} if no |
| 938 |
optional color is given. |
| 939 |
\begin{mfpfig}{fig26} |
| 940 |
\begin{mfpic}{0}{6}{0}{2} |
| 941 |
\penwd{2pt} |
| 942 |
\hatchwd{2pt} |
| 943 |
\drawcolor{blue} |
| 944 |
\hatchcolor{red} |
| 945 |
\fillcolor{green} |
| 946 |
\dashed\polkadot\rhatch[5pt]\gfill[yellow]\rect{(0,0),(2.8,1.8)} |
| 947 |
\rhatch[5pt]\dashed\polkadot\gfill[yellow]\rect{(3,0),(5.8,1.8)} |
| 948 |
\end{mfpic} |
| 949 |
\end{mfpfig} |
| 950 |
|
| 951 |
If one wants to plot several curves in a single graph, they often need |
| 952 |
to be rendered differently. The three methods we've seen so far, |
| 953 |
\cs{draw}, \cs{dashed}, and \cs{dotted}, may not be enough. The |
| 954 |
\cs{dashed} and \cs{dotted} commands permit an optional argument to |
| 955 |
adjust the length of the dashes and spaces, and size of the dots. One |
| 956 |
can also change the curve thickness with \cs{penwd}. But |
| 957 |
that may not be `different' enough. \Mfp{} provides a few solutions. |
| 958 |
When color is available, they may be drawn in different colors. When |
| 959 |
not, there are two possibilities: \cs{gendashed} and \cs{plot}. |
| 960 |
|
| 961 |
The first, \cs{gendashed}, is a generalized dashing macro. It takes one |
| 962 |
mandatory argument, the name of a dashing pattern. Named dashing |
| 963 |
patterns may be created with the \cs{dashpattern} command, as shown by |
| 964 |
the following example (see figure~\ref{fig27}): |
| 965 |
\begin{verbatim} |
| 966 |
\begin{mfpic}{-3.5}{3.5}{-1.2}{1.2} |
| 967 |
\dashpattern{dotdash}{0pt,4pt,3pt,4pt} |
| 968 |
\gendashed{dotdash}\function{-pi,pi,.2}{sin 2x} |
| 969 |
\function{-pi,pi,.2}{cos 2x} |
| 970 |
\axes |
| 971 |
\end{mfpic} |
| 972 |
\end{verbatim} |
| 973 |
\begin{mfpfig}{fig27} |
| 974 |
\begin{mfpic}{-3.5}{3.5}{-1.2}{1.2} |
| 975 |
\dashpattern{dotdash}{0pt,4pt,3pt,4pt} |
| 976 |
\gendashed{dotdash}\function{-pi,pi,.2}{sin 2x} |
| 977 |
\function{-pi,pi,.2}{cos 2x} |
| 978 |
\axes |
| 979 |
\end{mfpic} |
| 980 |
\end{mfpfig} |
| 981 |
|
| 982 |
The \cs{dashpattern} command takes a name and an even number of lengths. |
| 983 |
The first, third, etc., lengths represent the lengths of dashes |
| 984 |
(\texttt{0pt} means a dot), and the second, fourth, etc., represent |
| 985 |
spaces. The given pattern is dot-space-dash-space. This pattern, when |
| 986 |
used in a \cs{gendashed} command, is repeated for the length of the |
| 987 |
curve. |
| 988 |
|
| 989 |
This last example illustrates that the predefined \MP{} variable |
| 990 |
\gbc{pi} (equal to 3.14159) can be used pretty much anywhere a number |
| 991 |
can be used (except, often, in text label commands). |
| 992 |
|
| 993 |
Another way to get more distinctive curves is to `dot' them with |
| 994 |
something other than tiny dots. The \cs{plot} command does that. It |
| 995 |
takes one mandatory argument, the name of a symbol to use instead of a |
| 996 |
dot. Here are the same two curves \cs{plot}-ed (figure~\ref{fig28}): |
| 997 |
\begin{verbatim} |
| 998 |
\begin{mfpic}{-3.5}{3.5}{-1.2}{1.2} |
| 999 |
\setlength{\pointsize}{2.5pt} |
| 1000 |
\plot{Triangle}\function{-pi,pi,.2}{sin 2x} |
| 1001 |
\plot[2pt,6pt]{SolidCircle}\function{-pi,pi,.2}{cos 2x} |
| 1002 |
\axes |
| 1003 |
\end{mfpic} |
| 1004 |
\end{verbatim} |
| 1005 |
\begin{mfpfig}{fig28} |
| 1006 |
\begin{mfpic}{-3.5}{3.5}{-1.2}{1.2} |
| 1007 |
\setlength{\pointsize}{2.5pt} |
| 1008 |
\plot{Triangle}\function{-pi,pi,.2}{sin 2x} |
| 1009 |
\plot[2pt,6pt]{SolidCircle}\function{-pi,pi,.2}{cos 2x} |
| 1010 |
\axes |
| 1011 |
\end{mfpic} |
| 1012 |
\end{mfpfig} |
| 1013 |
|
| 1014 |
The \cs{plot} command takes an optional argument to specify the size of |
| 1015 |
the symbols and the spacing between them. The size of the symbols can |
| 1016 |
also be adjusted by changing the length command \cs{pointsize} (that also |
| 1017 |
adjusts the size of the dots placed with the \cs{point} command). |
| 1018 |
|
| 1019 |
In this last example, \cs{plotnodes} is similar to \cs{plot}, except it |
| 1020 |
placed the symbols at the `nodes' defined by the path command. In the |
| 1021 |
case of \cs{function}, these are the points $(x_k, f(x_k))$ with $x_k$ |
| 1022 |
stepping through all the $x$-values determined by the first argument of |
| 1023 |
\cs{function} (figure~\ref{fig29}). |
| 1024 |
\begin{verbatim} |
| 1025 |
\begin{mfpic}{-3.5}{3.5}{-1.2}{1.2} |
| 1026 |
\plotnodes[2.5pt]{Square}\function{-pi,pi,pi/16}{sin 2x} |
| 1027 |
\axes |
| 1028 |
\end{mfpic} |
| 1029 |
\end{verbatim} |
| 1030 |
\begin{mfpfig}{fig29} |
| 1031 |
\begin{mfpic}{-3.5}{3.5}{-1.2}{1.2} |
| 1032 |
\plotnodes[2.5pt]{Square}\function{-pi,pi,pi/16}{sin 2x} |
| 1033 |
\axes |
| 1034 |
\end{mfpic} |
| 1035 |
\end{mfpfig} |
| 1036 |
|
| 1037 |
See the manual for the list of predefined symbols available to the |
| 1038 |
\cs{plot} and \cs{plotnodes} command. |
| 1039 |
|
| 1040 |
\chapter{More on text} |
| 1041 |
|
| 1042 |
The text positioning commands used so far in this guide are entirely |
| 1043 |
handled by \TeX{} or \LaTeX. This is why we have occasionally had to say |
| 1044 |
that certain things could be done ``except in text placement commands''. |
| 1045 |
It is possible for text positioning to be done within \MP, making many |
| 1046 |
things possible that couldn't be done otherwise. For example, text can |
| 1047 |
be rotated about the point of placement. You are probably thinking that |
| 1048 |
\LaTeX{} can rotate text, but it is not all that easy to arrange for the |
| 1049 |
point on the graph where we place the text to be the center of rotation. |
| 1050 |
Below are two examples, in which we attempt to place the text separated |
| 1051 |
from $(0,0)$ by \texttt{5pt} and rotated 45 degrees around $(0,0)$. In |
| 1052 |
the first we try to use \LaTeX's \cs{rotatebox} command, and in the |
| 1053 |
second we turn on \MP{} handling of labels and use a rotation option to |
| 1054 |
the \cs{tlabel} command. |
| 1055 |
\begin{verbatim} |
| 1056 |
\begin{mfpic}{0}{1}{0}{1} |
| 1057 |
\point{(0,0)} |
| 1058 |
\polyline{(0,0),(1,1)} |
| 1059 |
\tlabel[Bl](0,0){\rotatebox{45}{\hspace{5pt}Test text}} |
| 1060 |
\end{mfpic} |
| 1061 |
\end{verbatim} |
| 1062 |
\begin{verbatim} |
| 1063 |
\usemplabels |
| 1064 |
\begin{mfpic}{0}{1}{0}{1} |
| 1065 |
\point{(0,0)} |
| 1066 |
\polyline{(0,0),(1,1)} |
| 1067 |
\tlpointsep{5pt} |
| 1068 |
\tlabel[Bl45](0,0){Test text} |
| 1069 |
\end{mfpic} |
| 1070 |
\end{verbatim} |
| 1071 |
\begin{figure}[!hb] |
| 1072 |
\centering |
| 1073 |
\begin{minipage}{4cm} |
| 1074 |
\centering |
| 1075 |
\begin{mfpic}{0}{1}{0}{1} |
| 1076 |
\point{(0,0)} |
| 1077 |
\polyline{(0,0),(1,1)} |
| 1078 |
\tlabel[Bl](0,0){\rotatebox{45}{\hspace{5pt}Test text}} |
| 1079 |
\end{mfpic}\renewcommand\thefigure{\thesection.\arabic{figure}a} |
| 1080 |
\refstepcounter{figure}\label{fig30a} |
| 1081 |
\par\medskip (a) |
| 1082 |
\end{minipage}\addtocounter{figure}{-1}\qquad |
| 1083 |
\begin{minipage}{4cm}\usemplabels |
| 1084 |
\centering |
| 1085 |
\begin{mfpic}{0}{1}{0}{1} |
| 1086 |
\point{(0,0)} |
| 1087 |
\polyline{(0,0),(1,1)} |
| 1088 |
\tlpointsep{5pt} |
| 1089 |
\tlabel[Bl45](0,0){Test text} |
| 1090 |
\end{mfpic}\renewcommand\thefigure{\thesection.\arabic{figure}b} |
| 1091 |
\refstepcounter{figure}\label{fig30b} |
| 1092 |
\par\medskip (b) |
| 1093 |
\end{minipage} |
| 1094 |
|
| 1095 |
\medskip Figure \thesection.\arabic{figure}. |
| 1096 |
\end{figure} |
| 1097 |
|
| 1098 |
The first produces figure~\ref{fig30a} and the second produces |
| 1099 |
figure~\ref{fig30b}. Our goal was to get the baseline of the text lined |
| 1100 |
up with the reference line drawn. |
| 1101 |
|
| 1102 |
In the first example, \LaTeX's \cs{rotatebox} command produces the |
| 1103 |
following result, where we put a frame around both the unrotated text |
| 1104 |
and the rotated result to emphasize what \LaTeX{} sees as the |
| 1105 |
boundaries: |
| 1106 |
$$ |
| 1107 |
\hbox{\setlength\fboxsep{0pt}% |
| 1108 |
\fbox{\rotatebox{45}{\fbox{\hspace{5pt}Test text}}}} |
| 1109 |
$$ |
| 1110 |
This is then placed by the \cs{tlabel} command with the lower left |
| 1111 |
corner of the \emph{outer} box at $(0,0)$. But \LaTeX's axis of rotation |
| 1112 |
was at the lower left corner of the inner box. In the second case, \MP{} |
| 1113 |
placed the label. The command \cs{tlpointsep}\marg{5pt} and the parameter |
| 1114 |
\oarg{Bl45} explicitly request that the label be placed with its left |
| 1115 |
baseline 5 points from $(0,0)$ and rotated 45 degrees \emph{about the |
| 1116 |
point $(0,0)$}. |
| 1117 |
|
| 1118 |
The \cs{usemplabels} command used above asks \MP{} to arrange for the |
| 1119 |
setting of labels. Adding the option \opt{mplabels} to the |
| 1120 |
\cs{usepackage} command that loads \mfp{} has the same effect for the |
| 1121 |
whole document. There can be problems with using \MP{} to set labels. |
| 1122 |
One is that \MP{} has to call a \file{tex} program to do the actual |
| 1123 |
typesetting, and then one must either make arrangements that ensure |
| 1124 |
\MP{} will call \LaTeX, or never use any macros in the labels that are |
| 1125 |
not defined in plain\TeX. If one does arrange for \LaTeX{} to be used, |
| 1126 |
one needs to arrange that a \LaTeX{} preamble is prepended to the output |
| 1127 |
\file{.mp} file. The \cs{mfpverbtex} command can be used for this. |
| 1128 |
|
| 1129 |
The command \cs{nomplabels} can be used to return to having labels set |
| 1130 |
at the document level. For the rest of this guide, we have |
| 1131 |
\opt{mplabels} in effect. |
| 1132 |
|
| 1133 |
There are a few more commands that place text on the picture. All of |
| 1134 |
them pass the final responsability for text placement to \MP{} if |
| 1135 |
\opt{mplabels} is in effect. See the manual for more details. |
| 1136 |
|
| 1137 |
|
| 1138 |
\chapter{Arrows} |
| 1139 |
|
| 1140 |
The command \cs{arrow} adds an arrowhead onto the \emph{end} of any path |
| 1141 |
that follows. For this to have predictable effects, you need to know |
| 1142 |
which part of a curve is the end, and which the start. Not surprisingly, |
| 1143 |
for the commands that connect a list of points in order the first point |
| 1144 |
in the list is the start point and the last point is the end. Except the |
| 1145 |
closed paths (\cs{cyclic}, \cs{polygon}, etc.); for them, the start and |
| 1146 |
the end points are the same, but the order of the points gives a |
| 1147 |
direction to the arrowhead. The default \cs{circle} has an anticlockwise |
| 1148 |
direction, but if the circle is defined by three points (for example) |
| 1149 |
the direction of the circle is determined by the order in which the |
| 1150 |
points are written. |
| 1151 |
|
| 1152 |
Anyway, here are a few examples, illustrating the use of \cs{arrow}, and |
| 1153 |
some of its optional arguments. |
| 1154 |
\begin{verbatim} |
| 1155 |
\begin{mfpic}{0}{4}{0}{4} |
| 1156 |
\arrow[r-5]\circle{(1,1),.5} |
| 1157 |
\arrow[b4pt]\arrow\polyline{(3,2),(3,0)} |
| 1158 |
\arrow[cred]\reverse\arrow\polyline{(0,3),(2,3)} |
| 1159 |
\arrow[l 5pt]\rect{(4,2),(2,4)} |
| 1160 |
\end{mfpic} |
| 1161 |
\end{verbatim} |
| 1162 |
See figure~\ref{fig31} for the results of this example. There are four |
| 1163 |
possible optional arguments, the first character inside the brackets |
| 1164 |
tells what option the rest of the argument applies to. The first example |
| 1165 |
above starts with `\texttt{r}', which stands for `rotate' and asks for |
| 1166 |
the arrowhead to be rotated $-5$ degrees (positive rotation means |
| 1167 |
anticlockwise, negative means clockwise). This is frequently useful for |
| 1168 |
arrows on curved paths, as the default direction (tangent to the path) |
| 1169 |
often just looks wrong). The second example starts with `\texttt{b}', |
| 1170 |
which stands for `backset' and it moves the head back \texttt{4pt} from |
| 1171 |
where it would otherwise be placed. In the example, this is used to put |
| 1172 |
a double arrowhead on the line. In the third example we put an arrow at |
| 1173 |
both ends by reversing the sense of the curve in between the two |
| 1174 |
\cs{arrow} prefixes. We also used the letter `\texttt{c}' in the |
| 1175 |
optional argument of one arrowhead. This stands for `color' and the |
| 1176 |
requested color is `\texttt{red}'. Finally, the \texttt{l} option |
| 1177 |
(that's a lowercase `ell', not the number `one') changes the length of |
| 1178 |
the arrowhead to 5 points (from the \verb$3pt$ default).% |
| 1179 |
\footnote{I have put a space between the \texttt{l} and the |
| 1180 |
\texttt{5pt} so it won't be mistaken for `$15$pt. Normally one |
| 1181 |
should avoid spaces in \mfp{} optional arguments, but this is one |
| 1182 |
case where it will cause no harm.} |
| 1183 |
\begin{mfpfig}{fig31} |
| 1184 |
\begin{mfpic}{0}{4}{0}{4} |
| 1185 |
\arrow[r-5]\circle{(1,1),.5} |
| 1186 |
\arrow[b4pt]\arrow\polyline{(3,2),(3,0)} |
| 1187 |
\arrow[cred]\reverse\arrow\polyline{(0,3),(2,3)} |
| 1188 |
\arrow[l 5pt]\rect{(4,2),(2,4)} |
| 1189 |
\end{mfpic} |
| 1190 |
\end{mfpfig} |
| 1191 |
|
| 1192 |
The options can be combined in one command: |
| 1193 |
\cs{arrow}\oarg{cblue}\oarg{b4pt}\oarg{r25}\oarg{l6pt} would produce a |
| 1194 |
\texttt{6pt} long blue arrowhead rotated 25 degrees anticlockwise, set |
| 1195 |
back \texttt{4pt}. The setting back is done in the direction determined |
| 1196 |
\emph{after} rotation. The order of the options is not significant. |
| 1197 |
|
| 1198 |
The shape of the arrowhead can be changed with the \cs{headshape} |
| 1199 |
command. The following example draws the arrowhead first normally, and |
| 1200 |
then after an instance of this command. We draw it a third time, exactly |
| 1201 |
like the second time, except we use the *-form. We have increased the |
| 1202 |
length of head and the thickness of the pen to emphasize the effects. |
| 1203 |
\begin{verbatim} |
| 1204 |
\begin{mfpic}{0}{4}{0}{4} |
| 1205 |
\setlength{\headlen}{20pt} |
| 1206 |
\penwd{3pt} |
| 1207 |
\arrow\polyline{(0,3),(4,3)} |
| 1208 |
\headshape{.5}{2}{true} |
| 1209 |
\arrow\polyline{(0,2),(4,2)} |
| 1210 |
\arrow*\polyline{(0,1),(4,1)} |
| 1211 |
\end{mfpic} |
| 1212 |
\end{verbatim} |
| 1213 |
The results are pictured in figure~\ref{fig32}. The first argument to |
| 1214 |
\cs{headshape} sets the ratio of width to height for the head. We have |
| 1215 |
cut it in half here. The second argument sets the tension in the curves |
| 1216 |
that form the sides of the head. This reduces the curvature in the |
| 1217 |
sides. The third argument can be only \texttt{true} or \texttt{false} |
| 1218 |
and determines whether the head is a solid shape, or only the two |
| 1219 |
`barbs'. The defaults correspond to \verb$\headshape{1}{1}{false}$. The |
| 1220 |
filled form does not draw the outline so what we see is the pointy |
| 1221 |
arrowhead on top of a thick line. The *-form tries to erase part of the |
| 1222 |
line so that one sees an actual pointy arrow. |
| 1223 |
\begin{mfpfig}{fig32} |
| 1224 |
\begin{mfpic}{0}{4}{0}{4} |
| 1225 |
\setlength{\headlen}{20pt} |
| 1226 |
\penwd{3pt} |
| 1227 |
\arrow\polyline{(0,3),(4,3)} |
| 1228 |
\headshape{.5}{2}{true} |
| 1229 |
\arrow\polyline{(0,2),(4,2)} |
| 1230 |
\arrow*\polyline{(0,1),(4,1)} |
| 1231 |
\end{mfpic} |
| 1232 |
\end{mfpfig} |
| 1233 |
|
| 1234 |
|
| 1235 |
\chapter{Color} |
| 1236 |
|
| 1237 |
We saw the use of color in earlier sections, and now it's time to be |
| 1238 |
systematic about it. The several rendering commands have a color option; |
| 1239 |
examples are \cs{draw}, \cs{gfill}, \cs{arrow}, and the hatching |
| 1240 |
commands. However, even those commands that don't provide such an option |
| 1241 |
can have the color of their rendering changed. \Mfp{} provides the |
| 1242 |
following commands to change certain colors. Those commands with a |
| 1243 |
color option can be used without that option and then they will the use |
| 1244 |
the appropriate color described here. Each of these color-changing |
| 1245 |
commands takes a mandatory argument containing the color to change to, |
| 1246 |
and an optional argument to be described later. |
| 1247 |
|
| 1248 |
\begin{description} |
| 1249 |
\item[\cs{backgroundcolor}] This sets the color to be used by \cs{gclear}. |
| 1250 |
It is the same color used by \cs{point} for the inside of the |
| 1251 |
points when \cs{pointfillfalse} has been used. In \MP{}, the |
| 1252 |
only way to clear the inside of a region is to cover it up. The |
| 1253 |
default color for this purpose is \mfc{white}. Use this command |
| 1254 |
to change that default. |
| 1255 |
\item[\cs{drawcolor}] This sets the default color used by those rendering |
| 1256 |
commands that draw a path. This includes \cs{draw}, but also |
| 1257 |
includes \cs{dashed}, \cs{dotted}, \cs{plot} and \cs{plotnodes}. |
| 1258 |
It is also used by other commands that produce lines or curves: |
| 1259 |
figure macros used without any rendering prefix, as well as |
| 1260 |
\cs{axes} and related commands. |
| 1261 |
\item[\cs{fillcolor}] This sets the default color used by \cs{gfill}. It |
| 1262 |
is also used by \cs{polkadot} (which has no color option). |
| 1263 |
\item[\cs{hatchcolor}] This sets the default color used by any hatching |
| 1264 |
command. |
| 1265 |
\item[\cs{headcolor}] This sets the default color for arrowheads added |
| 1266 |
by the \cs{arrow} command. It is also the color of |
| 1267 |
arrowheads on any coordinate axis. |
| 1268 |
\item[\cs{pointcolor}] This sets the color used by \cs{point}, \cs{grid}, |
| 1269 |
and \cs{plotsymbol} (the last one will be described later). |
| 1270 |
\item[\cs{tlabelcolor}] This sets the color used for all text labels if |
| 1271 |
the \opt{mplabels} option is turned on. |
| 1272 |
\end{description} |
| 1273 |
|
| 1274 |
The color can be a common name for a color, provided that name is one of |
| 1275 |
the following: \texttt{white}, \texttt{black}, \texttt{red}, |
| 1276 |
\texttt{green}, \texttt{blue}, \texttt{cyan}, \texttt{magenta}, or |
| 1277 |
\texttt{yellow}. We have already seen this usage. It can also be a color |
| 1278 |
name defined in the file \file{dvipsnam.mp} that accompanies \mfp. It can |
| 1279 |
also be an explicit color formula, where color formulas are described in |
| 1280 |
the \mfp{} manual. |
| 1281 |
|
| 1282 |
The optional argument is one of the \emph{color models}. See the manual |
| 1283 |
for details, but the syntax is just like that of the \prog{color} |
| 1284 |
package's \cs{color} command. For example, |
| 1285 |
\begin{verbatim} |
| 1286 |
\pointcolor[rgb]{0,1,0} |
| 1287 |
\end{verbatim} |
| 1288 |
would use the color model \opt{rgb} with parameters 0, 1, and 0 (this is |
| 1289 |
green). After each of these commands a certain color name is assigned a |
| 1290 |
value. For example, a use of the \cs{pointcolor} command assigns a value |
| 1291 |
to the color named \gbc{pointcolor}. Also \cs{drawcolor} sets |
| 1292 |
\gbc{drawcolor} and this pattern is followed for all the color setting |
| 1293 |
commands above except \cs{backgroundcolor}, which assigns its value to |
| 1294 |
the color named \gbc{background}. |
| 1295 |
|
| 1296 |
Color names for \mfp{} use can be defined using the \cs{mfpdefinecolor} |
| 1297 |
command. Here's an example (figure~\ref{fig33}). Note the use of the |
| 1298 |
color name \gbc{pointcolor} to make arrowheads and points have the same |
| 1299 |
color. |
| 1300 |
\begin{verbatim} |
| 1301 |
\begin{mfpic}{0}{3.5}{0}{3.5} |
| 1302 |
\tlabelcolor{red} |
| 1303 |
\pointcolor{rgb(0,1,0)}% green |
| 1304 |
\drawcolor[rgb]{0,0,1} % blue |
| 1305 |
\fillcolor{Goldenrod} % from dvipsnam.mp |
| 1306 |
\headcolor{pointcolor} % will be green after above |
| 1307 |
\mfpdefinecolor{DarkerRed}{rgb}{.67,0,0} |
| 1308 |
\hatchcolor{DarkerRed} |
| 1309 |
\penwd{1pt} |
| 1310 |
\gfill\circle{(1,1),.5} |
| 1311 |
\point[3pt]{(1,.5),(1,1.5),(.5,1),(1.5,1)} |
| 1312 |
\hatch\rect{(2.5,2.5),(3.5,3.5)} |
| 1313 |
\arrow[l 5pt]\polyline{(1,1),(3,3)} |
| 1314 |
\tlabel[cc](1,3){Examples\\of\\colors} |
| 1315 |
\end{mfpic} |
| 1316 |
\end{verbatim} |
| 1317 |
\begin{mfpfig}{fig33} |
| 1318 |
\begin{mfpic}{0}{3.5}{0}{3.5} |
| 1319 |
\tlabelcolor{red} |
| 1320 |
\pointcolor{rgb(0,1,0)}% green |
| 1321 |
\drawcolor[rgb]{0,0,1} % blue |
| 1322 |
\fillcolor{Goldenrod} % from dvipsnam.mp |
| 1323 |
\headcolor{pointcolor} % will be green after above |
| 1324 |
\mfpdefinecolor{DarkerRed}{rgb}{.67,0,0} |
| 1325 |
\hatchcolor{DarkerRed} |
| 1326 |
\penwd{1pt} |
| 1327 |
\gfill\circle{(1,1),.5} |
| 1328 |
\point[3pt]{(1,.5),(1,1.5),(.5,1),(1.5,1)} |
| 1329 |
\hatch\rect{(2.5,2.5),(3.5,3.5)} |
| 1330 |
\arrow[l 5pt]\polyline{(1,1),(3,3)} |
| 1331 |
\tlabel[cc](1,3){Examples\\of\\colors} |
| 1332 |
\end{mfpic} |
| 1333 |
\end{mfpfig} |
| 1334 |
|
| 1335 |
\chapter{Closing paths} |
| 1336 |
|
| 1337 |
There are many different ways to modify a figure. We have already seen |
| 1338 |
\cs{arrow}, which appends an arrowhead, \cs{reverse} which reverses the |
| 1339 |
sense, and several that apply an affine transformation |
| 1340 |
(\cs{rotatepath}, \cs{shiftpath}, etc.). Now we will see the simple |
| 1341 |
operation of closing a path. |
| 1342 |
|
| 1343 |
All methods of closing a path have to connect the end to the start, but |
| 1344 |
simply drawing a connection is not enough. \MP{} has to be told to close |
| 1345 |
the path, and what kind of connection is desired. We have several macros |
| 1346 |
that can do the job, the simplest being \cs{lclosed}, which closes with |
| 1347 |
a straight line. Putting \cs{lclosed} in front of \cs{polyline}, for |
| 1348 |
example, produces the same result as \cs{polygon}. Another macro is |
| 1349 |
\cs{sclosed} which produces a smooth closure. Putting it in front of |
| 1350 |
\cs{curve} gives (almost) the same result as \cs{cyclic}. There is one |
| 1351 |
other useful macro, \cs{bclosed}, which also informs \MP{} to make a |
| 1352 |
smooth closure. The difference between \cs{sclosed} and \cs{bclosed} is |
| 1353 |
that the first modifies slightly the original path (in order to achieve |
| 1354 |
the effect that \cs{sclosed}${}+{}$\cs{curve}${}\approx{}$\cs{cyclic}), |
| 1355 |
the second just asks \MP{} to do its best to connect the ends smoothly. |
| 1356 |
Here's an example comparing the two smooth methods (figure~\ref{fig34}). |
| 1357 |
\begin{verbatim} |
| 1358 |
\begin{mfpic}{0}{4}{0}{4} |
| 1359 |
% an open curve: |
| 1360 |
\curve{(0.49,3),(.5,3.7),(1,4),(1.5,3.7),(1.51,3)} |
| 1361 |
% \sclosed a shifted copy: |
| 1362 |
\draw\gfill[green]\sclosed\shiftpath{(2,0)} |
| 1363 |
\curve{(0.49,3),(.5,3.7),(1,4),(1.5,3.7),(1.51,3)} |
| 1364 |
% \bclosed another copy: |
| 1365 |
\draw\gfill[yellow]\bclosed\shiftpath{(2,-2)} |
| 1366 |
\curve{(0.49,3),(.5,3.7),(1,4),(1.5,3.7),(1.51,3)} |
| 1367 |
% \cyclic with same points, shifted: |
| 1368 |
\draw\gfill[red]\shiftpath{(0,-2)} |
| 1369 |
\cyclic{(0.49,3),(.5,3.7),(1,4),(1.5,3.7),(1.51,3)} |
| 1370 |
\tlabeljustify{bc} |
| 1371 |
\nomplabels |
| 1372 |
\tlabels{ |
| 1373 |
(1,2.4){\cs{curve}} |
| 1374 |
(3,2.4){\cs{sclosed}} |
| 1375 |
(1,0.4){\cs{cyclic}} |
| 1376 |
(3,0.4){\cs{bclosed}} |
| 1377 |
} |
| 1378 |
% Some points to help illustrate |
| 1379 |
\point{(0.49,3),(.5,3.7),(1,4),(1.5,3.7),(1.51,3)} |
| 1380 |
\point{(2.49,3),(2.5,3.7),(3,4),(3.5,3.7),(3.51,3)} |
| 1381 |
\point{(0.49,1),(.5,1.7),(1,2),(1.5,1.7),(1.51,1)} |
| 1382 |
\point{(2.49,1),(2.5,1.7),(3,2),(3.5,1.7),(3.51,1)} |
| 1383 |
\end{mfpic} |
| 1384 |
\end{verbatim} |
| 1385 |
\begin{mfpfig}{fig34} |
| 1386 |
\begin{mfpic}{0}{4}{0}{4} |
| 1387 |
\curve{(0.49,3),(.5,3.7),(1,4),(1.5,3.7),(1.51,3)} |
| 1388 |
\draw\gfill[green]\sclosed\shiftpath{(2,0)} |
| 1389 |
\curve{(0.49,3),(.5,3.7),(1,4),(1.5,3.7),(1.51,3)} |
| 1390 |
\draw\gfill[yellow]\bclosed\shiftpath{(2,-2)} |
| 1391 |
\curve{(0.49,3),(.5,3.7),(1,4),(1.5,3.7),(1.51,3)} |
| 1392 |
\draw\gfill[red]\shiftpath{(0,-2)} |
| 1393 |
\cyclic{(0.49,3),(.5,3.7),(1,4),(1.5,3.7),(1.51,3)} |
| 1394 |
\tlabeljustify{bc} |
| 1395 |
\nomplabels |
| 1396 |
\tlabels{ |
| 1397 |
(1,2.4){\cs{curve}} |
| 1398 |
(3,2.4){\cs{sclosed}} |
| 1399 |
(1,0.4){\cs{cyclic}} |
| 1400 |
(3,0.4){\cs{bclosed}} |
| 1401 |
} |
| 1402 |
\point{(0.49,3),(.5,3.7),(1,4),(1.5,3.7),(1.51,3)} |
| 1403 |
\point{(2.49,3),(2.5,3.7),(3,4),(3.5,3.7),(3.51,3)} |
| 1404 |
\point{(0.49,1),(.5,1.7),(1,2),(1.5,1.7),(1.51,1)} |
| 1405 |
\point{(2.49,1),(2.5,1.7),(3,2),(3.5,1.7),(3.51,1)} |
| 1406 |
\end{mfpic} |
| 1407 |
\end{mfpfig} |
| 1408 |
|
| 1409 |
A word about the labels: we turned off \opt{mplabels} with the command |
| 1410 |
\verb$\nomplabels$, because we used a command (\verb$\cs$) defined for |
| 1411 |
this document and not known to basic \TeX{} or \LaTeX. The labels |
| 1412 |
therefore are positioned by \LaTeX{} while it assembles this document, |
| 1413 |
instead of by \MP{} which would call a separate instance of \TeX{} or |
| 1414 |
\LaTeX{} where \cs{cs} was unknown. We could have kept \opt{mplabels}, |
| 1415 |
provided we had used \verb$\mfpverbtex$ to write the appropriate |
| 1416 |
\LaTeX{} preamble to the \file{.mp} output. It would need to be some |
| 1417 |
subset of the preamble of this document. |
| 1418 |
|
| 1419 |
|
| 1420 |
\chapter*{Appendices} |
| 1421 |
\addcontentsline{toc}{section}{Appendices} |
| 1422 |
|
| 1423 |
In addition to \pdfLaTeX, \Mfp{} works with plain \pdfTeX, \LaTeX, and |
| 1424 |
plain \TeX{}. Instead of \MP{} as the figure processor, \MF{} can also |
| 1425 |
be used. Let's start with the difference between using \mfp{} in a |
| 1426 |
plain~\TeX{} document and using it in a \LaTeX{} document. |
| 1427 |
|
| 1428 |
\renewcommand\thesubsection{\Alph{subsection}} |
| 1429 |
|
| 1430 |
\section{\Mfp{} in plain \TeX} |
| 1431 |
|
| 1432 |
Here is a sample plain \pdfTeX{} document with results the same as our |
| 1433 |
first ``Hello, world'' example. Let's call this file \file{plfirst} |
| 1434 |
\begin{verbatim} |
| 1435 |
\input mfpic |
| 1436 |
\usemetapost |
| 1437 |
\opengraphsfile{myfigs} |
| 1438 |
My first figure: |
| 1439 |
\mfpic[72]{-1}{1}{-1}{1} |
| 1440 |
\ellipse{(0,0),1,.5} |
| 1441 |
\endmfpic |
| 1442 |
\closegraphsfile |
| 1443 |
\end |
| 1444 |
\end{verbatim} |
| 1445 |
The main difference is the lack of \LaTeX{} commands. The crucial |
| 1446 |
difference is in the first two lines. There we simply |
| 1447 |
\verb$\input mfpic$ and we turn on \MP{} support with the |
| 1448 |
\verb$\usemetapost$ command instead of an option to \verb$\usepackage$. |
| 1449 |
|
| 1450 |
Since \verb$\usepackage$ and its options don't exist in plain \TeX{}, |
| 1451 |
all those features that we select with options in \LaTeX{} must be |
| 1452 |
selected by some command in plain. For example, the \opt{mplabels} |
| 1453 |
option is replaced with the command \verb$\usemplabels$ (which can also |
| 1454 |
be used in \LaTeX). |
| 1455 |
|
| 1456 |
Also, plain \TeX{} doesn't have environments, so instead of |
| 1457 |
\verb$\begin{mfpic}$ we just use \verb$\mfpic$ and instead of |
| 1458 |
\verb$\end{mfpic}$ we use \verb$\endmfpic$. |
| 1459 |
|
| 1460 |
The external processing is essentially the same: |
| 1461 |
\begin{verbatim} |
| 1462 |
pdftex plfirst |
| 1463 |
mpost myfigs |
| 1464 |
pdftex plfirst |
| 1465 |
\end{verbatim} |
| 1466 |
should produce \texttt{plfirst.pdf} with the same picture of an ellipse. |
| 1467 |
|
| 1468 |
|
| 1469 |
\section{\Mfp{} without PDF} |
| 1470 |
|
| 1471 |
If we wish to use nonPDF versions of \LaTeX{} or plain \TeX, the only |
| 1472 |
difference is in the processing steps. To process \file{first.tex} with |
| 1473 |
\LaTeX, run the command |
| 1474 |
\begin{verbatim} |
| 1475 |
latex first |
| 1476 |
\end{verbatim} |
| 1477 |
followed by |
| 1478 |
\begin{verbatim} |
| 1479 |
mpost myfigs |
| 1480 |
\end{verbatim} |
| 1481 |
followed by latex again. |
| 1482 |
\begin{verbatim} |
| 1483 |
latex first |
| 1484 |
\end{verbatim} |
| 1485 |
Then run the dvi processor of your choice. It should be one that can |
| 1486 |
successfully handle eps figures (or at least the simple eps produced by |
| 1487 |
\MP). Certainly \prog{dvips} can do it: |
| 1488 |
\begin{verbatim} |
| 1489 |
dvips first |
| 1490 |
\end{verbatim} |
| 1491 |
will produce \file{first.ps}. The file{.ps} file can be viewed with |
| 1492 |
\prog{gsview} or printed, or converted to PDF with some distillation |
| 1493 |
program like \prog{ps2pdf}. Also \prog{dvipdfm} (if properly |
| 1494 |
configured) can be used convert the \file{.dvi} file to PDF. |
| 1495 |
|
| 1496 |
\section{\Mfp{} without \MP} |
| 1497 |
|
| 1498 |
\Mfp{} can produce figures using \MF{} instead of \MP. What it does is |
| 1499 |
work with \MF{} to produce a made-to-order font, where each picture is a |
| 1500 |
large character in that font. |
| 1501 |
|
| 1502 |
Since \pdfTeX{} and \pdfLaTeX{} do not work well with the fonts produced |
| 1503 |
by \MF, and many PDF viewers don't display them well anyway, I do not |
| 1504 |
recommend using \mfp{} to produce PDF without turning on \MP{} support. |
| 1505 |
However, all dvi viewers and \prog{dvips} \emph{do} work well with such |
| 1506 |
fonts, so it can make sense to use \mfp{} with \MF{} \emph{if} you don't |
| 1507 |
need the features that \MP{} enables: color and rotation of labels. One |
| 1508 |
advantage of doing this is the smaller number of files produced. If |
| 1509 |
there are 100 \mfp{} figures in a document, \MP{} produces 100 files |
| 1510 |
(apart from a couple of temporary files and the \file{.log} file), but |
| 1511 |
the \MF{} procedure produces only four files no matter how many figures |
| 1512 |
are present. |
| 1513 |
|
| 1514 |
To use \mfp{} without \MP{}, omit the \opt{metapost} option or the |
| 1515 |
\verb$\usemetapost$ command. If you want a visible reminder of the fact |
| 1516 |
that \MF{} is being used, you can use the \opt{metafont} option or the |
| 1517 |
\verb$\usemetafont$ command. Of course, you may not use \opt{mplabels} |
| 1518 |
without \MP. You may use the color commands and options, but the only |
| 1519 |
colors actually produced will be black and white (and occasionally a |
| 1520 |
pattern of pixels that simulate gray). The processing steps are |
| 1521 |
different. After |
| 1522 |
\begin{ex} |
| 1523 |
\texttt{latex first} \quad(or \texttt{tex plfirst}) |
| 1524 |
\end{ex} |
| 1525 |
run \MF: |
| 1526 |
\begin{ex} |
| 1527 |
\texttt{mf myfigs} |
| 1528 |
\end{ex} |
| 1529 |
This should produce three files: \texttt{myfigs.log}, |
| 1530 |
\texttt{myfigs.tfm}, and \texttt{myfigs.600gf}. The last one (which |
| 1531 |
might have a different number on your system) is called a \emph{generic |
| 1532 |
font} (GF) file and contains the bitmap descriptions. If the file |
| 1533 |
produced is \texttt{myfigs.2602gf}, and the \file{.tfm} is not produced, |
| 1534 |
that indicates a configuration problem with your system that we'll get |
| 1535 |
to later. If this did work, one needs to convert the GF file to a |
| 1536 |
PK font file, the standard format for bitmap fonts in the \TeX{} world. |
| 1537 |
This may be done with |
| 1538 |
\begin{ex} |
| 1539 |
\texttt{gftopk myfigs.600gf} |
| 1540 |
\end{ex} |
| 1541 |
Some systems may require you to name the output file on the command |
| 1542 |
line: |
| 1543 |
\begin{ex} |
| 1544 |
\texttt{gftopk myfigs.600gf myfigs.600pk} |
| 1545 |
\end{ex} |
| 1546 |
And some systems may require the extension to be simply \file{.pk}: |
| 1547 |
\begin{ex} |
| 1548 |
\texttt{gftopk myfigs.600gf myfigs.pk} |
| 1549 |
\end{ex} |
| 1550 |
Finally, some systems may have a \prog{makepk} or \prog{mktexpk} command |
| 1551 |
that can be used in place of the combination of \MF{} and \prog{gftopk}. |
| 1552 |
You'll have to check what your system has and what its usage might be, |
| 1553 |
and what it might do with the PK file produced. |
| 1554 |
|
| 1555 |
After the above, one again runs `\texttt{latex first}' (or `\texttt{tex |
| 1556 |
plfirst}'), and then the \file{.dvi} can be viewed or processed with dvips. |
| 1557 |
The two files \file{myfigs.log} and \file{myfigs.600gf} can be deleted; |
| 1558 |
only \file{myfigs.tfm} and \file{myfigs.600pk} are needed. If the viewed |
| 1559 |
image shows the pictures at a far different size than you expect, this can |
| 1560 |
also indicate a configuration problem. |
| 1561 |
|
| 1562 |
Some systems permit on-the-fly creation of PK files by various |
| 1563 |
\file{.dvi} processing programs. It is not wise to allow this to happen |
| 1564 |
when working with \mfp. The problem is that this automatic creation |
| 1565 |
process is \emph{not} repeated when a figure is edited unless the old PK |
| 1566 |
files are deleted, and it may take some hunting to even locate them. One |
| 1567 |
should \emph{always} follow the \MF{} step with the \prog{gftopk} step. |
| 1568 |
You might even want to write a batch script or makefile to ensure that |
| 1569 |
this happens. |
| 1570 |
|
| 1571 |
Another problem (more an annoyance) that can occur comes from the |
| 1572 |
behavior of most dvi viewers: most will reload a \file{.dvi} file if |
| 1573 |
they detect that it has changed (or if asked to), but none that I know |
| 1574 |
of will reload any fonts even if they have changed. So if one is going |
| 1575 |
through a edit-compile-view cycle involving \mfp{} figures, one usually |
| 1576 |
has to close the viewer and open it again before one can see changes |
| 1577 |
that were made in the figures after starting the viewer. It is also |
| 1578 |
possible that PK fonts are cached and shared by other programs, so you |
| 1579 |
may need to close other programs to ensure the cache is cleared and the |
| 1580 |
new figures loaded. |
| 1581 |
|
| 1582 |
\section{\MF{} configuration problems} |
| 1583 |
|
| 1584 |
To diagnose these problems it important to know something about |
| 1585 |
\emph{printer modes}. \CMF{} produces bitmap images of characters. This |
| 1586 |
means a description of a block of pixels, telling which ones are black |
| 1587 |
and which are white. If the description says that 60 pixels in a row are |
| 1588 |
black, that produces a thin black line. How long that line is depends on |
| 1589 |
the size of a printer's pixels. For the LaserJet IV, there are 600 |
| 1590 |
pixels to the inch, so 60 pixels makes 1/10 of an inch. The LaserJet~II, |
| 1591 |
however, has 300 pixels to the inch, so 60 pixels is 1/5 of an inch |
| 1592 |
long. What \MF{} needs in order to produce an image that is the correct |
| 1593 |
size is (at a minimum) the \emph{resolution} of the intended printer. |
| 1594 |
This is typically reported in DPI (dots per inch) and \MF{} keeps the |
| 1595 |
value in the variable \mfc{pixels_per_inch}. |
| 1596 |
|
| 1597 |
As part of the configuration of your DVI viewer or of \prog{dvips} you |
| 1598 |
may have needed to select a printer from a list, or edit a line in some |
| 1599 |
configuration file (e.g., \file{config.ps}). What was going on then was |
| 1600 |
the assigning of a default \MF{} printer mode. There is a file on most |
| 1601 |
\TeX{} systems named \file{modes.mf} which assigns symbolic names to a |
| 1602 |
set of parameters that enable \MF{} to tune its output to a particular |
| 1603 |
printer. For example, the LaserJet~IV is given the name |
| 1604 |
`\texttt{ljfour}' and that name is associated with the value 600 for |
| 1605 |
\mfc{pixels_per_inch}. In order to tell \MF{} to make output for the |
| 1606 |
LaserJet~IV, one can put that information on the command line: |
| 1607 |
\begin{ex} |
| 1608 |
\texttt{mf \cs{mode}:=ljfour; input myfigs} |
| 1609 |
\end{ex} |
| 1610 |
Your operating system or \TeX{} distribution may require you to quote |
| 1611 |
the backslash in the above command. |
| 1612 |
|
| 1613 |
There is a system for making the selection of the correct mode |
| 1614 |
semi-automatic, not requiring a command line specification. Near the end |
| 1615 |
of \file{modes.mf} is a line similar to |
| 1616 |
\begin{ex} |
| 1617 |
\mfc{localfont:=ljfour;} |
| 1618 |
\end{ex} |
| 1619 |
This is intended to equate the symbolic name \mfc{localfont} with the |
| 1620 |
user's default printer. If the LaserJet~IV is your default printer, the |
| 1621 |
line above would be the correct one. If it is not, then that line should |
| 1622 |
be changed. This can be done with an ordinary text editor, or your |
| 1623 |
\TeX{} system may have a configuration utility to take care of it. |
| 1624 |
|
| 1625 |
If you say ``\texttt{mf myfigs}'' on an \mfp{} file \file{myfigs.mf}, \mfp's |
| 1626 |
internal code will detect that no mode was defined on the command line. |
| 1627 |
It will then check if \mfc{localfont} is defined and if so, use that for |
| 1628 |
the printer mode. If that fails, it will try to select \mfc{ljfour}. |
| 1629 |
If even that is unknown, \mfp{} will define its own generic 600 DPI mode. |
| 1630 |
|
| 1631 |
\Mfp{} doesn't need to know all the parameters associated to a printer |
| 1632 |
mode, only the value of \mfc{pixels_per_inch}. If you get a GF file that |
| 1633 |
indicates an incorrect DPI value for your printer, you should arrange |
| 1634 |
for the line in \file{modes.mf} that sets \mfc{localfont} to be |
| 1635 |
corrected. At the very least it should equate \mfc{localfont} to a name |
| 1636 |
defined in \file{modes.mf} and associated to a printer with the same DPI |
| 1637 |
as yours. After changing \file{modes.mf}, you need to run whatever |
| 1638 |
programs your \TeX{} system requires to remake the \MF{} format. |
| 1639 |
|
| 1640 |
\end{document} |