MFPIC: Pictures in TEX with Metafont and MetaPost

MFPIC: Pictures in TEX with Metafont and MetaPost MFPIC: Pictures in TEX with Metafont and MetaPost

ftp.isu.edu.tw
from ftp.isu.edu.tw More from this publisher
13.07.2015 Views

CONTENTSiii4.4 Plott<strong>in</strong>g Styles for \plotdata . . . . . . . . . . . . . . . . . . . . . . . . . . . . 654.5 Special Considerations When Us<strong>in</strong>g METAFONT . . . . . . . . . . . . . . . . . . 664.6 Special Considerations When Us<strong>in</strong>g METAPOST . . . . . . . . . . . . . . . . . . . 674.6.1 Required support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 674.6.2 METAPOST is not METAFONT . . . . . . . . . . . . . . . . . . . . . . . . 674.6.3 Graphic <strong>in</strong>clusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 684.7 <strong>MFPIC</strong> <strong>and</strong> the Rest of the World . . . . . . . . . . . . . . . . . . . . . . . . . . . 694.7.1 The literature . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 694.7.2 Other programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 714.8 Index of comm<strong>and</strong>s, options <strong>and</strong> parameters . . . . . . . . . . . . . . . . . . . . . 724.9 List of comm<strong>and</strong>s by type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 764.9.1 Figures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 764.9.2 Figure modifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 764.9.3 Figure renderers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 764.9.4 Lengths . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 774.9.5 Coord<strong>in</strong>ate transformation . . . . . . . . . . . . . . . . . . . . . . . . . . 774.9.6 Symbols, axes, grids, marks . . . . . . . . . . . . . . . . . . . . . . . . . 774.9.7 Sett<strong>in</strong>g options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 774.9.8 Sett<strong>in</strong>g values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 784.9.9 Chang<strong>in</strong>g colors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 784.9.10 Def<strong>in</strong><strong>in</strong>g arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 784.9.11 Chang<strong>in</strong>g behavior . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 784.9.12 Files <strong>and</strong> environments . . . . . . . . . . . . . . . . . . . . . . . . . . . . 784.9.13 Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 794.9.14 Misc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79


1 Introduction1.1 Why?Tom got the idea for <strong>MFPIC</strong> 1 mostly out of a feel<strong>in</strong>g of frustration. Different output mechanismsfor pr<strong>in</strong>t<strong>in</strong>g or view<strong>in</strong>g <strong>TEX</strong> DVI files each have their own ways to <strong>in</strong>clude pictures. More oftenthan not, there are provisions for <strong>in</strong>clud<strong>in</strong>g graphic objects <strong>in</strong>to a DVI file us<strong>in</strong>g <strong>TEX</strong> \special’s.However, this technique seemed far from <strong>TEX</strong>’s ideal of device <strong>in</strong>dependence because different<strong>TEX</strong> output drivers recognize different \special’s, <strong>and</strong> h<strong>and</strong>le them <strong>in</strong> different ways.LA<strong>TEX</strong>’s picture environment has a hopelessly limited supply of available objects to draw—ifyou want to draw a graph of a polynomial curve, you’re out of luck.There was, of course, PIC<strong>TEX</strong>, which was wonderfully flexible <strong>and</strong> general, but its most obviousfeature was its speed—or rather lack of it. Process<strong>in</strong>g a s<strong>in</strong>gle picture <strong>in</strong> PIC<strong>TEX</strong> (<strong>in</strong> those days)could often take several seconds.It occurred to Tom that it might be possible to take advantage of the fact that METAFONT isdesigned for draw<strong>in</strong>g th<strong>in</strong>gs. The result of pursu<strong>in</strong>g this idea is <strong>MFPIC</strong>, a set of macros for <strong>TEX</strong> <strong>and</strong>METAFONT which <strong>in</strong>corporate METAFONT-drawn pictures <strong>in</strong>to a <strong>TEX</strong> file.With the creation of METAPOST by John Hobby, <strong>and</strong> the almost universal availability of freePOSTSCRIPT <strong>in</strong>terpreters like GHOSTSCRIPT, some <strong>MFPIC</strong> users wanted to run their <strong>MFPIC</strong> outputthrough METAPOST, to produce POSTSCRIPT pictures. Moreover, users wanted to be able to usepdf<strong>TEX</strong>, which does not get along well <strong>with</strong> PK fonts, but is quite happy <strong>with</strong> METAPOST pictures.So METAPOST support was added to <strong>MFPIC</strong>. Now, <strong>MFPIC</strong> can produce (nearly) the same picture <strong>in</strong>METAFONT or METAPOST <strong>with</strong> (nearly) the same code. This gets us away from device <strong>in</strong>dependence,but many users were not so much concerned <strong>with</strong> that as <strong>with</strong> hav<strong>in</strong>g a convenient way tohave text <strong>and</strong> pictures described <strong>in</strong> the same document.With the extra capabilities of POSTSCRIPT (e.g., color) <strong>and</strong> the correspond<strong>in</strong>g abilities ofMETAPOST, there was a dem<strong>and</strong> for some <strong>MFPIC</strong> <strong>in</strong>terface to access them. Consequently, switches(options) have been added to access some of them. When these are used, output files may no longerbe compatible <strong>with</strong> METAFONT.1.2 Who?<strong>MFPIC</strong> was written primarily by Tom Leathrum dur<strong>in</strong>g the late (northern hemisphere) spr<strong>in</strong>g <strong>and</strong>summer of 1992, while at Dartmouth College. Different versions were be<strong>in</strong>g written <strong>and</strong> testedfor nearly two years after that, dur<strong>in</strong>g which time Tom f<strong>in</strong>ished his Ph.D. <strong>and</strong> took a job at BerryCollege, <strong>in</strong> Rome, GA. Between fall of 1992 <strong>and</strong> fall of 1993, much of the development was carriedout by others. Those who helped most <strong>in</strong> this process are credited <strong>in</strong> the Acknowledgements.Somewhere <strong>in</strong> the mid 1990’s the development passed to Geoffrey Tob<strong>in</strong> who kept th<strong>in</strong>gs go<strong>in</strong>gfor several years.The addition of METAPOST support was carried out by Dan Lueck<strong>in</strong>g around 1997–99. He isalso responsible for all other additions <strong>and</strong> changes s<strong>in</strong>ce then, <strong>with</strong> help from Geoffrey <strong>and</strong> a fewothers mentioned <strong>in</strong> the Acknowledgements.1 If you’re wonder<strong>in</strong>g how to pronounce ‘<strong>MFPIC</strong>’: I always say ‘em-eff-pick’, speak<strong>in</strong>g the first two letters. —DHL.1


1.4 HOW? 3pr<strong>in</strong>t driver have been set up to be able to f<strong>in</strong>d the PK font generated from pics.mf). You c<strong>and</strong>elete pics.600gf <strong>and</strong> pics.log.If you use <strong>MFPIC</strong> <strong>with</strong> the metapost option (this would require you to edit pictures.tex orlapictures.tex. See chapter 2 for how to do this), then pics.mp is produced, <strong>and</strong> you needto replace the METAFONT/GFTOPK steps <strong>with</strong> the s<strong>in</strong>gle step of runn<strong>in</strong>g METAPOST. (Read yourMETAPOST documentation on how to do this. 4 ) Typically justmpost pics.mp(or possibly mp pics.mp).After reprocess<strong>in</strong>g pictures.tex <strong>with</strong> <strong>TEX</strong> you should then be able to run dvips on the result<strong>in</strong>gDVI file <strong>and</strong> pr<strong>in</strong>t or view its POSTSCRIPT output. If pdf<strong>TEX</strong> is used <strong>in</strong>stead of <strong>TEX</strong> on thesecond run, you should be able to view the result<strong>in</strong>g PDF file <strong>with</strong> the pictures <strong>in</strong>cluded.It is not advisable to rely on automatic font generation to create the .tfm <strong>and</strong> .pk files. (Differentsystems do this <strong>in</strong> different ways, so here I will try to give a generic explanation.) The reason:later edit<strong>in</strong>g of a figure will require new files to be built, <strong>and</strong> most automatic systems will not remakethe files once they have been created. This is not so much a problem <strong>with</strong> the .tfm, as <strong>MFPIC</strong>never tries to load the font if the .tfm is absent <strong>and</strong> therefore no automatic .tfm-mak<strong>in</strong>g shouldever be triggered. However, if you forget to run GFTOPK, then try to view your result<strong>in</strong>g file, youmay have to search your system <strong>and</strong> delete some automatically generated .pk file (they can turnup <strong>in</strong> unpredictable places) before you can see any later changes. It might be wise to write a shellscript (batch file) that (1) runs METAFONT, (2) runs GFTOPK if step 1 returns no error, (3) deletesthe .tfm if the .pk file does not exist. That way, if anyth<strong>in</strong>g goes wrong, the .dvi will not conta<strong>in</strong>the font (<strong>MFPIC</strong> will draw a rectangle <strong>and</strong> the figure number <strong>in</strong> place of the figure).These process<strong>in</strong>g steps—process<strong>in</strong>g <strong>with</strong> <strong>TEX</strong>, process<strong>in</strong>g <strong>with</strong> METAFONT/GFTOPK, <strong>and</strong> reprocess<strong>in</strong>g<strong>with</strong> <strong>TEX</strong>—may not always be necessary. In particular, if you change the <strong>TEX</strong> document<strong>with</strong>out mak<strong>in</strong>g any changes at all to the pictures, then there will be no need to repeat the META-FONT or METAPOST steps.There are also somewhat subtle circumstance under which you can skip the second <strong>TEX</strong> stepafter edit<strong>in</strong>g a figure if the file has already gone through the above process. Del<strong>in</strong>eat<strong>in</strong>g the exactcirumstances is rather <strong>in</strong>volved, so it is recommended that you always repeat the <strong>TEX</strong> step ifchanges have been made to any figure.What makes <strong>MFPIC</strong> work? When you run <strong>TEX</strong> on the file pictures.tex, the <strong>MFPIC</strong> macrosissue <strong>TEX</strong> \write comm<strong>and</strong>s, writ<strong>in</strong>g METAFONT (or METAPOST) comm<strong>and</strong>s to a file pics.mf(or pics.mp). The user should never have to read or change the file pics.mf directly—the <strong>MFPIC</strong>macros take care of it.The enterpris<strong>in</strong>g user can determ<strong>in</strong>e by exam<strong>in</strong><strong>in</strong>g the <strong>MFPIC</strong> source <strong>and</strong> the result<strong>in</strong>g META-FONT file, that <strong>MFPIC</strong> draw<strong>in</strong>g macros translate almost directly <strong>in</strong>to similar METAFONT/METAPOSTcomm<strong>and</strong>s, def<strong>in</strong>ed <strong>in</strong> one of the files grafbase.mf or grafbase.mp. The labels <strong>and</strong> captions,however, are placed on the graph by <strong>TEX</strong> us<strong>in</strong>g box placement techniques similar to those used <strong>in</strong>LA<strong>TEX</strong>’s picture environment (except when option mplabels is <strong>in</strong> effect, <strong>in</strong> which case METAPOSTplaces the labels).4 The document Some experiences on runn<strong>in</strong>g <strong>Metafont</strong> <strong>and</strong> <strong>MetaPost</strong>, by Peter Wilson, can be useful for beg<strong>in</strong>ners.Fetch CTAN/<strong>in</strong>fo/metafp.pdf.


2 Options.There are now several options to the <strong>MFPIC</strong> package. These can be listed <strong>in</strong> the st<strong>and</strong>ard LA<strong>TEX</strong>\usepackage optional argument, or can be turned on <strong>with</strong> certa<strong>in</strong> provided comm<strong>and</strong>s (the onlypossibility for pla<strong>in</strong> <strong>TEX</strong>). Some options can be switched off <strong>and</strong> on throughout the document.Here we merely list them <strong>and</strong> provide a general description of their purpose. More details may befound later <strong>in</strong> the discussion of the features affected. The head<strong>in</strong>gs below give the option name, thealternative macro <strong>and</strong>, if available, the comm<strong>and</strong> for turn<strong>in</strong>g off the option. Any option not amongthose given below will be passed on to the GRAPHICS package, provided the metapost option hasbeen used.If the file mfpic.cfg exists, it will be <strong>in</strong>put just before all options are processed. You cancreate such a file conta<strong>in</strong><strong>in</strong>g an \ExecuteOptions comm<strong>and</strong> to execute any options you wouldlike to have as default. Actual options to \usepackage will override these defaults, of course. Andso will any of the comm<strong>and</strong>s below.If a file named mfpic.usr can be found, it will be <strong>in</strong>put at the end of the load<strong>in</strong>g of <strong>MFPIC</strong>.The user can create such a file conta<strong>in</strong><strong>in</strong>g any of the comm<strong>and</strong>s of this section that he would liketo have as default.F<strong>in</strong>ally, if the file mfppatch.tex can be found, it will be <strong>in</strong>put slightly before the end ofload<strong>in</strong>g <strong>MFPIC</strong>. It is part of the <strong>MFPIC</strong> distribution, <strong>and</strong> will be used to implement m<strong>in</strong>or correctionswhen bugs are found. The user should probably not modify this file unless he really knows whathe is do<strong>in</strong>g.2.1 metapost, \usemetapostSelects METAPOST as the figure processor <strong>and</strong> makes specific features available. It changes the extensionused on the output file to .mp to signal that it can no longer be processed <strong>with</strong> METAFONT.There is also a metafont option (comm<strong>and</strong> \usemetafont), but it is redundant, as METAFONT isthe default. Either comm<strong>and</strong> must come before the \opengraphsfile comm<strong>and</strong> (see section 3.1).They should not be used together <strong>in</strong> the same document. (Actually, they can but one needs to closeone output file <strong>and</strong> open another. Moreover, it hasn’t ever been seriously tested, <strong>and</strong> it wasn’t taken<strong>in</strong>to consideration <strong>in</strong> writ<strong>in</strong>g most of the macros.) If the comm<strong>and</strong> form \usemetapost is used<strong>in</strong> a LA<strong>TEX</strong> 2ε document, it must come <strong>in</strong> the preamble. Because of the tim<strong>in</strong>g of actions by theBABEL package <strong>and</strong> by older versions of supp-pdf.tex (<strong>in</strong>put by pdftex.def <strong>in</strong> the GRAPHICSpackage), when pdfLA<strong>TEX</strong> is used <strong>MFPIC</strong> should be loaded <strong>and</strong> \usemetapost (if used) declaredbefore BABEL is loaded.2.2 mplabels, \usemplabels, \nomplabelsCauses all label creation comm<strong>and</strong>s to write their contents to the output file. It has no effect on the\tcaption comm<strong>and</strong>. In this case labels are h<strong>and</strong>led by METAPOST <strong>and</strong> can be rotated. It requiresMETAPOST, <strong>and</strong> will be be ignored <strong>with</strong>out it (METAFONT cannot h<strong>and</strong>le labels). It may alsoproduce an error either from <strong>TEX</strong> or METAFONT. Otherwise the comm<strong>and</strong>s can come anywhere <strong>and</strong>affect subsequent \tlabel comm<strong>and</strong>s. When this is <strong>in</strong> effect, the labels become part of the figure<strong>and</strong>, <strong>in</strong> the default h<strong>and</strong>l<strong>in</strong>g, they may be clipped off or covered up by later draw<strong>in</strong>g elements.But see the next section on the overlaylabels option. Labels added to a picture contribute to thebound<strong>in</strong>g box even if truebbox is not <strong>in</strong> effect.The user is responsible for add<strong>in</strong>g the appropriate verbatimtex header to the output file if4


2.3 overlaylabels, \overlaylabels, \nooverlaylabels 5necessary. For this purpose, there is the \mfpverbtex comm<strong>and</strong>, see section 3.8. If the label textconta<strong>in</strong>s only valid pla<strong>in</strong> <strong>TEX</strong> macros, there is generally no need for a verbatimtex preamble atall. If you add a verbatimtex preamble of LA<strong>TEX</strong> code take care to make sure METAPOST callsLA<strong>TEX</strong> (for example, by sett<strong>in</strong>g the environmental variable <strong>TEX</strong> to latex <strong>in</strong> the comm<strong>and</strong> shell ofyour operat<strong>in</strong>g system.).2.3 overlaylabels, \overlaylabels, \nooverlaylabelsIn the past, under mplabels all text labels created by \tlabel <strong>and</strong> its relatives were added to thepicture by METAPOST as they occurred. This made them subject to later draw<strong>in</strong>g comm<strong>and</strong>s: theycould be covered up, erased, or clipped. With this option (or after the comm<strong>and</strong> \overlaylabels)text labels are saved <strong>in</strong> a separate place from the rest of a picture. When a picture is completed,the labels that were saved are added on top of it. This is the way labels always behave under themetafont option, because then <strong>TEX</strong> must add the labels <strong>and</strong> there is no possibility for special effects<strong>in</strong>volv<strong>in</strong>g clipp<strong>in</strong>g or eras<strong>in</strong>g (at the METAFONT level).With the metapost option, but <strong>with</strong>out mplabels it has been decided to keep the same behavior(<strong>and</strong> the same code) as under the metafont option. However, when mplabels is used, there is thepossibility for special effects <strong>with</strong> text, <strong>and</strong> it has always been the behavior before this version tosimply place the labels as they occurred. It turns out that plac<strong>in</strong>g the labels at the end is cleaner<strong>and</strong> simpler to code, so I experimented <strong>with</strong> it <strong>and</strong> rejected it as a default, but now offer it as anoption. With this option, <strong>MFPIC</strong> labels have almost the same behavior <strong>with</strong> or <strong>with</strong>out mplabels.2.4 truebbox, \usetruebbox, \notruebboxNormally METAPOST outputs an EPS file <strong>with</strong> the actual bound<strong>in</strong>g box of the figure. By default,<strong>MFPIC</strong> overrides this <strong>and</strong> sets the bound<strong>in</strong>g box to the dimensions specified by the \mfpic comm<strong>and</strong>that produced it. (This used to be needed for <strong>TEX</strong> is to h<strong>and</strong>le \tlabel comm<strong>and</strong>s correctly.Now, it is just for backward compatability, <strong>and</strong> for compatability <strong>with</strong> METAFONT’s behavior.) Itis reasonable to let METAPOST have its way, <strong>and</strong> that is what this option does. If one of the comm<strong>and</strong>forms is used <strong>in</strong> an mfpic environment, it affects only that environment, otherwise it affectsall subsequent figures. This option currently has no effect <strong>with</strong> METAFONT, but should cause noerrors.2.5 clip, \clipmfpic, \noclipmfpicCauses all parts of the figure outside the rectangle specified by the \mfpic comm<strong>and</strong> to be removed.The comm<strong>and</strong>s can come anywhere. If issued <strong>in</strong>side an mfpic environment they affect thecurrent figure only. Otherwise all subsequent figures are affected. Note: this is a rather rudimentaryoption. It has an often unexpected <strong>in</strong>teraction <strong>with</strong> truebbox. When both are <strong>in</strong> effect, METAPOSTwill produce a bound<strong>in</strong>g box that is the <strong>in</strong>tersection of two rectangles: the true one <strong>with</strong>out clipp<strong>in</strong>g,<strong>and</strong> the box specified <strong>in</strong> the \mfpic comm<strong>and</strong>. It is possible that the actual figure will bemuch smaller (even empty!). This is a property of the METAPOST clip comm<strong>and</strong> <strong>and</strong> we know ofno way to avoid it.


2.10 mfpreadlog, \mfpreadlog 7<strong>and</strong> debugged, some time might be saved (<strong>with</strong> either metafont or metapost) by not writ<strong>in</strong>g theoutput file aga<strong>in</strong>, then nowrite can be used.2.10 mfpreadlog, \mfpreadlogFrom version 0.8, there exists a scheme to allow METAFONT or METAPOST to pass <strong>in</strong>formationback to the .tex file. This is done by writ<strong>in</strong>g code to the figure file request<strong>in</strong>g METAFONT toplace that <strong>in</strong>formation <strong>in</strong> the .log file it produces. This option <strong>in</strong>structs <strong>MFPIC</strong> to read throughthat log file l<strong>in</strong>e-by-l<strong>in</strong>e look<strong>in</strong>g for such <strong>in</strong>formation. S<strong>in</strong>ce such log files can be potentially quitelengthy, this is made an option. If the comm<strong>and</strong> form \mfpreadlog is used, it must come beforethe \opengraphsfile comm<strong>and</strong>, s<strong>in</strong>ce that is when the file will be exam<strong>in</strong>ed. At the presenttime, the only <strong>MFPIC</strong> facility that requires this two-way communication is \assignmfvalue (seesubsection 3.13.7). If this is used, the filename given to \opengraphsfile should not be the sameas the <strong>TEX</strong> source file <strong>in</strong> which this occurs, as then the wrong .log may be read.2.11 Option Scop<strong>in</strong>g RulesSome of these options merely change <strong>TEX</strong> behavior, others write <strong>in</strong>formation to the output filefor METAFONT or METAPOST. Changes <strong>in</strong> <strong>TEX</strong> behavior obey the normal <strong>TEX</strong> group<strong>in</strong>g rules,the <strong>in</strong>formation written to the output file obeys METAFONT group<strong>in</strong>g rules. S<strong>in</strong>ce each mfpicenvironment is both a <strong>TEX</strong> group <strong>and</strong> (corresponds to) a METAFONT group, the follow<strong>in</strong>g alwaysholds: use of one of the comm<strong>and</strong> forms <strong>in</strong>side of an mfpic environment makes the change localto that environment.An effort has been made (as of version 0.7) to make this universal. That is, any of the comm<strong>and</strong>slisted above for turn<strong>in</strong>g options on <strong>and</strong> off will be global when issued outside an mfpicenvironment. The debug comm<strong>and</strong>s are exceptions; they obey all <strong>TEX</strong> scop<strong>in</strong>g rules.We have also tried to make all other <strong>MFPIC</strong> comm<strong>and</strong>s for chang<strong>in</strong>g the various parametersfollow this rule: local <strong>in</strong>side mfpic environment, global outside. However, as of this writ<strong>in</strong>g Idon’t claim to have caught every one.The follow<strong>in</strong>g are special: \usemetapost, \usemetafont, \mfpicdraft, \mfpicf<strong>in</strong>al,\mfpicnowrite, <strong>and</strong> \mfpreadlog. Their effects are always global, partly because they shouldoccur prior to the <strong>in</strong>itialization comm<strong>and</strong> \opengraphsfile (described <strong>in</strong> section 3.1). Note that\usemetapost may cause a file of graphic <strong>in</strong>clusion macros to be <strong>in</strong>put. If this comm<strong>and</strong> is issued<strong>in</strong>side a group, some def<strong>in</strong>itions <strong>in</strong> that file may be lost, break<strong>in</strong>g the graphic <strong>in</strong>clusion code.


3 The Macros.In these descriptions we will often refer to ‘METAFONT’ when we really mean ‘METAFONT orMETAPOST’. This will especially be the case whenever we need to refer to comm<strong>and</strong>s <strong>in</strong> thetwo languages which are substantially the same, but occasionally we will even talk about runn<strong>in</strong>g‘METAFONT’ when we mean runn<strong>in</strong>g one or the other to process the figures. If we need todiscrim<strong>in</strong>ate between the two processors, (for example when they have different behavior) we willmake the difference explicit.A similar shorth<strong>and</strong> is used when referr<strong>in</strong>g to ‘<strong>TEX</strong>’. It should not be taken to mean ‘pla<strong>in</strong><strong>TEX</strong>’,but rather whatever version of <strong>TEX</strong> is used to process the source file: pla<strong>in</strong><strong>TEX</strong>, LA<strong>TEX</strong>, pdf<strong>TEX</strong>, orpdfLA<strong>TEX</strong>. Also AMS-<strong>TEX</strong>, EPLAIN <strong>and</strong> some other variants. When last tried, <strong>MFPIC</strong> didn’t work<strong>with</strong> Con<strong>TEX</strong>t.Many of the comm<strong>and</strong>s of <strong>MFPIC</strong> have optional arguments. These are denoted just as <strong>in</strong> LA<strong>TEX</strong>,<strong>with</strong> square brackets. Thus, the comm<strong>and</strong> for draw<strong>in</strong>g a circle can be given\circle{(0,0),1}hav<strong>in</strong>g only the m<strong>and</strong>atory argument, or\circle[p]{(0,0),1}Whenever an optional argument is omitted, the behavior is equivalent to some choice of the optionalargument. In this example, the two forms have exactly the same behavior, draw<strong>in</strong>g a circlecentered at (0,0) <strong>with</strong> radius 1. In this case we will say that [p] is the default. Another exampleis \po<strong>in</strong>t{(1,0)} versus \po<strong>in</strong>t[3pt]{(1,0)}. They both place a dot at the po<strong>in</strong>t (1,0). Thesecond one explicitly request that it have diameter 3pt; the first will exam<strong>in</strong>e the length comm<strong>and</strong>\po<strong>in</strong>tsize, which the user can change, but it is <strong>in</strong>itialized to 2pt. In this case we will say thedefault is the value of \po<strong>in</strong>tsize, <strong>in</strong>itially 2pt.Optional arguments for <strong>MFPIC</strong> comm<strong>and</strong>s may consist of empty brackets (completely empty,no spaces) <strong>and</strong> the default will be used. This is useful only for comm<strong>and</strong>s that have two optionalarguments <strong>and</strong> one only wants to change from the defaults <strong>in</strong> the second one. An optional argumentshould normally not conta<strong>in</strong> any spaces. Even when the argument conta<strong>in</strong>s more than one piece ofdata, spaces should not separate the parts. In many cases (perhaps most) this will cause no harm,but it would be better to avoid do<strong>in</strong>g it altogether.3.1 Files <strong>and</strong> Environments.\opengraphsfile{〈file〉}...\closegraphsfileThese macros open <strong>and</strong> close the METAFONT or METAPOST file which will conta<strong>in</strong> the picturesto be <strong>in</strong>cluded <strong>in</strong> this document. The name of the file will be 〈file〉.mf (or 〈file〉.mp). Do not specifythe extension, which is added automatically.Note: This comm<strong>and</strong> will cause 〈file〉.mf or 〈file〉.mp to be overwritten if it already exists, sobe sure to consider that when select<strong>in</strong>g the name. Repeat<strong>in</strong>g the runn<strong>in</strong>g of <strong>TEX</strong> will overwrite thefile created on previous runs, but that should be harmless. For if no changes are made to mfpic8


3.1 FILES AND ENVIRONMENTS. 9environments, the identical file will be recreated, <strong>and</strong> if changes have been made, then you wantthe file to be replaced <strong>with</strong> the new version.It is possible (but has not been seriously tested) to close one file <strong>and</strong> open another, <strong>and</strong> even tochange between metapost <strong>and</strong> metafont <strong>in</strong> between. If anyth<strong>in</strong>g goes wrong <strong>with</strong> this, contact thema<strong>in</strong>ta<strong>in</strong>er <strong>and</strong> it might be fixed <strong>in</strong> some later version.\mfpic[〈xscale〉][〈yscale〉]{〈xm<strong>in</strong>〉}{〈xmax〉}{〈ym<strong>in</strong>〉}{〈ymax〉}...\endmfpicThese macros open <strong>and</strong> close the mfpic environment <strong>in</strong> which most of the rest of the macrosmake sense. The \mfpic macro also sets up the local coord<strong>in</strong>ate system for the picture. The〈xscale〉 <strong>and</strong> 〈yscale〉 parameters establish the length of a coord<strong>in</strong>ate system unit, as a multipleof the <strong>TEX</strong> dimension \mfpicunit. If neither is specified, both are taken to be 1 (i.e., each coord<strong>in</strong>atesystem unit is 1 \mfpicunit). If only one is specified, then they are assumed to be equal. The〈xm<strong>in</strong>〉 <strong>and</strong> 〈xmax〉 parameters establish the lower <strong>and</strong> upper bounds for the x-axis coord<strong>in</strong>ates;similarly, 〈ym<strong>in</strong>〉 <strong>and</strong> 〈ymax〉 establish the bounds for the y-axis. These bounds are expressed <strong>in</strong>local units—<strong>in</strong> other words, the actual width of the picture will be (〈xmax〉 − 〈xm<strong>in</strong>〉) · 〈xscale〉times \mfpicunit, its height (〈ymax〉 − 〈ym<strong>in</strong>〉) · 〈yscale〉 times \mfpicunit, <strong>and</strong> its depth zero.One can scale all pictures uniformly by chang<strong>in</strong>g \mfpicunit, <strong>and</strong> scale an <strong>in</strong>dividual picture bychang<strong>in</strong>g 〈xscale〉 <strong>and</strong> 〈yscale〉. After load<strong>in</strong>g <strong>MFPIC</strong>, \mfpicunit has the value 1pt. One pt is apr<strong>in</strong>ter’s po<strong>in</strong>t, which equals 1/72.27 <strong>in</strong>ches or 0.35146 millimeters.Note: Chang<strong>in</strong>g \mfpicunit or the optional parameters will scale the coord<strong>in</strong>ate system, butnot the values of certa<strong>in</strong> parameters that are def<strong>in</strong>ed <strong>in</strong> absolute units. Examples of these are thedefault width of the draw<strong>in</strong>g pen, the default lengths of arrowheads, the default sizes of dashes<strong>and</strong> dots, etc. If you wish, you can set these to multiples of \mfpicunit, but it is difficult (<strong>and</strong>probably unwise) to get them to scale along <strong>with</strong> the scale parameters.In addition to establish<strong>in</strong>g the coord<strong>in</strong>ate system, these scales <strong>and</strong> bounds are used to establishthe metric for the METAFONT character or bound<strong>in</strong>g box for the METAPOST figure described<strong>with</strong><strong>in</strong> the environment. If any of these parameters are changed, the .tfm file (METAFONT) or thebound<strong>in</strong>g box (METAPOST) will be affected, so you will have to be sure to reprocess the <strong>TEX</strong> fileafter process<strong>in</strong>g the .mf or .mp file, even if no other changes are made <strong>in</strong> the figure.\mfpicnumber{〈num〉}Normally, \mfpic assigns the number 1 to the first mfpic environment, after which the numberis <strong>in</strong>creased by one for each new mfpic environment. This number is used <strong>in</strong>ternally to <strong>in</strong>clude thepicture. It is also transmitted to the output file where it is used as the argument to a beg<strong>in</strong>mfpiccomm<strong>and</strong>. In METAFONT this number becomes the position of the character <strong>in</strong> the font file, while<strong>in</strong> METAPOST it is the extension on the graphic file that is output. The above comm<strong>and</strong> tells <strong>MFPIC</strong>to ignore this sequence <strong>and</strong> number the next mfpic figure <strong>with</strong> 〈num〉 (<strong>and</strong> the one after that〈num〉 + 1, etc.). It is up to the user to make sure no number is repeated, as no check<strong>in</strong>g is done.Numbers greater than 255 may cause errors, as <strong>TEX</strong> assumes that characters are represented by 8-bit numbers. If the first figure is to be numbered someth<strong>in</strong>g other than 1, then, under the metapostoption, this comm<strong>and</strong> should come before \opengraphsfile, as that comm<strong>and</strong> checks for theexistence of the first numbered figure to determ<strong>in</strong>e if there are figures to be <strong>in</strong>cluded.


3.2 METAFONT DATA TYPES. 10\beg<strong>in</strong>{mfpic}...\end{mfpic}In LA<strong>TEX</strong>, <strong>in</strong>stead of \mfpic <strong>and</strong> \endmfpic, you may prefer to use \beg<strong>in</strong>{mfpic} <strong>and</strong>\end{mfpic}. This is by no means required: <strong>in</strong> LA<strong>TEX</strong> \beg<strong>in</strong>{comm<strong>and</strong>} <strong>in</strong>vokes \comm<strong>and</strong>,<strong>and</strong> \end{comm<strong>and</strong>} <strong>in</strong>vokes \endcomm<strong>and</strong>, for any environment comm<strong>and</strong>.The sample file lapictures.tex provided <strong>with</strong> <strong>MFPIC</strong> illustrates this use of an mfpic environment<strong>in</strong> LA<strong>TEX</strong>.The rest of the <strong>MFPIC</strong> macros do not affect the font metric file (〈file〉.tfm), <strong>and</strong> so if thesecomm<strong>and</strong>s are changed or added <strong>in</strong> your document, you will not have to repeat the third stepof process<strong>in</strong>g (reprocess<strong>in</strong>g <strong>with</strong> <strong>TEX</strong>) to complete your <strong>TEX</strong> document. The same is true whenoption metapost is selected <strong>with</strong>out the truebbox option, except under pdf<strong>TEX</strong> or pdfLA<strong>TEX</strong>. Those<strong>TEX</strong> programs will embed the figures right <strong>in</strong> the .pdf output. For normal LA<strong>TEX</strong> + DVIPS, thefigures are embedded by DVIPS, which must always be repeated.For the rema<strong>in</strong>der of the macros, the numerical parameters are expressed <strong>in</strong> the units of thelocal coord<strong>in</strong>ate system specified by \mfpic, unless otherwise <strong>in</strong>dicated.3.2 METAFONT Data Types.S<strong>in</strong>ce the arguments of most <strong>MFPIC</strong> draw<strong>in</strong>g comm<strong>and</strong>s are sent to METAFONT to be <strong>in</strong>terpreted,it’s useful to know someth<strong>in</strong>g about METAFONT concepts. In this section we will discuss some ofthe data types METAFONT supports. Even the casual user should know how coord<strong>in</strong>ates <strong>and</strong> colorsare treated <strong>and</strong> so should at least skim the next two subsections. The last subsection can be readwhen the user wants to manipulate more complex objects.METAFONT permits several different data types, <strong>and</strong> we will ma<strong>in</strong>ly be concerned <strong>with</strong> six ofthese: numeric, pair, color (METAPOST only), path, picture <strong>and</strong> boolean. 6A variable is a symbolic name such as A or <strong>in</strong>center. Any sequence of letters <strong>and</strong> underscoresis permitted as a variable name. Numeric <strong>in</strong>dexes are also allowed, provided all variables that differonly <strong>in</strong> the <strong>in</strong>dex have the same type. Thus A1, A2, etc., might be variables which are all of typepair. Quite a lot more is permited for variable names, but the rules are rather complex <strong>and</strong> easyto violate. <strong>MFPIC</strong> has comm<strong>and</strong>s for creat<strong>in</strong>g both simple variables <strong>and</strong> <strong>in</strong>dexed variables (calledarrays) but the casual user can get quite a lot of use out of <strong>MFPIC</strong> <strong>with</strong>out ever creat<strong>in</strong>g or us<strong>in</strong>g aMETAFONT variable.METAFONT also has someth<strong>in</strong>g ak<strong>in</strong> to functions. For example, s<strong>in</strong>(1.57) might representa function named s<strong>in</strong> receiv<strong>in</strong>g the parameter 1.57 as <strong>in</strong>put <strong>and</strong> return<strong>in</strong>g the appropriate value.Functions can take any number of parameters <strong>and</strong> return any of the data types that METAFONTsupports. 73.2.1 METAFONT NUMERICS AND PAIRSMETAFONT has numeric quantities. These <strong>in</strong>clude lengths, such as the radius of a circle, as well asdimension units such as <strong>in</strong> (<strong>in</strong>ches) <strong>and</strong> pt (po<strong>in</strong>ts). In fact it underst<strong>and</strong>s all the same units that<strong>TEX</strong> does. Numeric quantities can be constants (explicit numbers) or variables (symbolic names).In fact, <strong>in</strong> <strong>and</strong> pt are symbolic names for numeric quantities.6 For the curious, there are a total of eight types (n<strong>in</strong>e for METAPOST). The other three are str<strong>in</strong>g, transform <strong>and</strong> pen.METAFONTalso permits expressions that produce noth<strong>in</strong>g, which is sometimes called the vacuous type, but doesn’t allowfor (or need) variables of this type.7 Includ<strong>in</strong>g the vacuous type.


3.3 FIGURES. 11METAFONT also has pair objects, which may be constants or variables. Pair constants have theform (x,y) where x <strong>and</strong> y are numbers, for example (0,0). Pairs are two-dimensional quantitiesused for represent<strong>in</strong>g either po<strong>in</strong>ts or vectors <strong>in</strong> a rectangular (Cartesian) coord<strong>in</strong>ate system.In this manual we often represent each pair by a brief name, such as p, v or c, the mean<strong>in</strong>gsof which are usually obvious <strong>in</strong> the context of the macro. These are <strong>in</strong>tended to be replaced <strong>in</strong>actual use by either a pair constant or variable. The succ<strong>in</strong>ctness of this notation helps us to th<strong>in</strong>kgeometrically rather than only of coord<strong>in</strong>ates.3.2.2 METAPOST COLORSMETAPOST has the same concepts as METAFONT, but also has color objects, which may alsobe constants or variables. color constants have the form (r,g,b) where r, g, <strong>and</strong> b are numbersbetween 0 <strong>and</strong> 1 determ<strong>in</strong><strong>in</strong>g the relative proportions of red, green <strong>and</strong> blue <strong>in</strong> the color (the “rgb”model). A color variable is a name, like red, blue (both predef<strong>in</strong>ed by METAPOST) or magenta(predef<strong>in</strong>ed by <strong>MFPIC</strong>).3.2.3 METAFONT PATHS, PICTURES AND BOOLEANSMost of the th<strong>in</strong>gs that <strong>MFPIC</strong> is designed to draw are paths. Examples of paths are circles, rectangles,other polygons, graphs of functions <strong>and</strong> spl<strong>in</strong>es. Because we tend to want to draw these(or fill them, or render them <strong>in</strong> other ways) we call the <strong>MFPIC</strong> comm<strong>and</strong>s that produce them figuremacros. Although they are much more complex than numerics, pairs, or colors, they can still bestored <strong>in</strong> symbolic names.Normally <strong>in</strong> <strong>MFPIC</strong> we want to create a picture, usually by render<strong>in</strong>g one or more paths. It ispossible <strong>in</strong> METAFONT to store a picture <strong>in</strong> a symbolic name <strong>with</strong>out actually draw<strong>in</strong>g it. However,because of their complexity, picture objects require somewhat more care than paths or other datatypes. Do not expect to use stored pictures <strong>in</strong> the same way as stored paths. In fact, one should usepicture variables only <strong>in</strong> those comm<strong>and</strong> that are explicitely designed for them. In <strong>MFPIC</strong> to datethese are only \mfpimage to store a picture <strong>and</strong> \putmfpimage to draw copies of it.The boolean data type is one of the values true or false. Boolean variables are symbolicnames that can take either of these two values. Usually these are used to <strong>in</strong>fluence the behavior ofsome comm<strong>and</strong> by sett<strong>in</strong>g a relevant boolean variable to one or the other value.3.3 Figures.Some comm<strong>and</strong>s depend on the value of separately def<strong>in</strong>ed parameters. all these parameters are<strong>in</strong>itialized when <strong>MFPIC</strong> is loaded. <strong>in</strong> the follow<strong>in</strong>g descriptions we give the <strong>in</strong>itial value of all therelevant parameters. when METAPOST output is selected, figures can be drawn <strong>in</strong> any color. severalof the above mentioned parameters are colors. <strong>MFPIC</strong> provides comm<strong>and</strong>s to change any of theseparameters.3.3.1 POINTS, LINES, AND RECTANGLES.\po<strong>in</strong>tdef{〈name〉}(x,y)Def<strong>in</strong>es a symbolic name for po<strong>in</strong>ts <strong>and</strong> their coord<strong>in</strong>ates. 〈name〉 is any legal <strong>TEX</strong> comm<strong>and</strong>name <strong>with</strong>out the backslash; x <strong>and</strong> y are any numbers. For example, after the comm<strong>and</strong>\po<strong>in</strong>tdef{A}(1,3), \A exp<strong>and</strong>s to (1,3), while \Ax <strong>and</strong> \Ay exp<strong>and</strong> to 1 <strong>and</strong> 3, respectively.Because of the way \tlabel is def<strong>in</strong>ed (see section 3.8 below), one cannot use \A to specify where


3.3 FIGURES. 12to place a label (unless mplabels is <strong>in</strong> effect), but must useone can use \A where a pair or po<strong>in</strong>t is required.(\Ax,\Ay). In most other comm<strong>and</strong>s,\po<strong>in</strong>t[〈ptsize〉]{〈p 0 〉,〈p 1 〉,...}Draws small disks centered at the po<strong>in</strong>ts 〈p 0 〉, 〈p 1 〉, <strong>and</strong> so on. If the optional argument 〈ptsize〉is present, it determ<strong>in</strong>es the diameter of the disks, which otherwise equals the <strong>TEX</strong> dimension\po<strong>in</strong>tsize, <strong>in</strong>itially 2pt. The disks have a filled <strong>in</strong>terior if the comm<strong>and</strong> \po<strong>in</strong>tfilltrue hasbeen issued (the <strong>in</strong>itial value), \po<strong>in</strong>tfillfalse causes subsequent \po<strong>in</strong>t comm<strong>and</strong>s to produceoutl<strong>in</strong>ed circles <strong>with</strong> the <strong>in</strong>teriors erased. The color of the circles is the value of the predef<strong>in</strong>edvariable po<strong>in</strong>tcolor, <strong>and</strong> the <strong>in</strong>side of the open circles is the value of the color background.\plotsymbol[〈size〉]{〈symbol〉}{〈p 0 〉,〈p 1 〉,...}Draws small symbols centered at the po<strong>in</strong>ts 〈p 0 〉, 〈p 1 〉, <strong>and</strong> so on. The symbols must be givenby name, <strong>and</strong> the available symbols are Asterisk, Circle, Diamond, Square, Triangle, Star,SolidCircle, SolidDiamond, SolidSquare, SolidTriangle, SolidStar, Cross <strong>and</strong> Plus.The names should be self-explanatory. Under metapost, symbols are drawn <strong>in</strong> po<strong>in</strong>tcolor. The〈size〉 defaults to \po<strong>in</strong>tsize as <strong>in</strong> \po<strong>in</strong>t above. Asterisk consists of six l<strong>in</strong>e segments whileStar is the st<strong>and</strong>ard closed, ten-sided polygon. The name ‘\plotsymbol’ comes from the fact thatthe \plot comm<strong>and</strong>, which was written first, utilizes these same symbols. The comm<strong>and</strong> \symbolwas already taken (st<strong>and</strong>ard LA<strong>TEX</strong>).The difference between \po<strong>in</strong>tfillfalse\po<strong>in</strong>t... <strong>and</strong> \plotsymbol{Circle}... is thatthe <strong>in</strong>side of the circle will not be erased <strong>in</strong> the second version (i.e., whatever else has already beendrawn <strong>in</strong> that area will rema<strong>in</strong> visible). This is the default (for backward compatibility), but thatcan be changed <strong>with</strong> the comm<strong>and</strong>s below.\clearsymbols\noclearsymbolsAfter the first of these two comm<strong>and</strong>s, subsequent \plotsymbol comm<strong>and</strong>s will draw the opensymbols <strong>with</strong> their <strong>in</strong>teriors erased. After the second, the default behavior (described above) willbe restored. These comm<strong>and</strong>s have no effect on \po<strong>in</strong>t. \plotnodes (see subsection 3.6.1) alsoresponds to the sett<strong>in</strong>gs made by these comm<strong>and</strong>s. The \plot comm<strong>and</strong> (also <strong>in</strong> subsection 3.6.1)does not.\polyl<strong>in</strong>e{〈p 0 〉,〈p 1 〉,...}\l<strong>in</strong>es{〈p 0 〉,〈p 1 〉,...}Draws the l<strong>in</strong>e segment <strong>with</strong> endpo<strong>in</strong>ts at 〈p 0 〉 <strong>and</strong> 〈p 1 〉, then the l<strong>in</strong>e segment <strong>with</strong> endpo<strong>in</strong>tsat 〈p 1 〉 <strong>and</strong> 〈p 2 〉, etc. The result is an open polygonal path through the specified po<strong>in</strong>ts, <strong>in</strong> thespecified order. \polyl<strong>in</strong>e <strong>and</strong> \l<strong>in</strong>es mean the same th<strong>in</strong>g.\polygon{〈p 0 〉,〈p 1 〉,...}Draws a closed polygon <strong>with</strong> vertices at the specified po<strong>in</strong>ts <strong>in</strong> the specified order.\rect{〈p 0 〉,〈p 1 〉}Draws the rectangle specified by the po<strong>in</strong>ts 〈p 0 〉 <strong>and</strong> 〈p 1 〉, these be<strong>in</strong>g either pair of oppositecorners of the rectangle <strong>in</strong> any order.


3.3 FIGURES. 13It is occasionally helpful to know that connected paths like those produced by \polyl<strong>in</strong>e or\rect have a sense (a direction). The sense of \polyl<strong>in</strong>e is the direction determ<strong>in</strong>ed by the orderof the po<strong>in</strong>ts. For \rect the sense may be clockwise or anticlockwise depend<strong>in</strong>g on the cornersused: it beg<strong>in</strong>s at the first of the two po<strong>in</strong>ts <strong>and</strong> goes horizontally from there.\regpolygon{〈num〉}{〈name〉}{〈eqn 1 〉}{〈eqn 2 〉}This produces a regular polygon <strong>with</strong> 〈num〉 sides. The second argument, 〈name〉 is a symbolicname. It can be used to refer to the vertices later. The last two arguments should be equations thatposition two of the vertices or one vertex <strong>and</strong> the center. The center is refered to by 〈name〉0 <strong>and</strong>the vertices by 〈name〉1 〈name〉2, etc., go<strong>in</strong>g anticlockwise around the polygon. The 〈name〉 itself(<strong>with</strong>out a number) will be a METAFONT variable assigned the value of 〈num〉. For example,\regpolygon{5}{Meg}{Meg0=(0,1)}{Meg1=(2,0)}will produce a regular pentagon <strong>with</strong> its center at (0,1) <strong>and</strong> its first vertex at (2,0). One could laterdraw a star <strong>in</strong>side it <strong>with</strong>\polygon{Meg1,Meg3,Meg5,Meg2,Meg4}Moreover, Meg will equal 5. The name given becomes a METAFONT variable <strong>and</strong> care should betaken to make the name dist<strong>in</strong>ctive so as not to redef<strong>in</strong>e some <strong>in</strong>ternal variable.3.3.2 A WORD ABOUT LIST ARGUMENTSWe have seen already four <strong>MFPIC</strong> macros that take a m<strong>and</strong>atory argument consist<strong>in</strong>g of a list ofcoord<strong>in</strong>ate pairs. There are many more, <strong>and</strong> some that take a comma-separated list of other typesof items. If the lists are long, especially if they are generated by a program, it might be moreconvenient if one could simply refer to an external file for the data. This is possible, <strong>and</strong> one doesit the follow<strong>in</strong>g way: <strong>in</strong>stead of \l<strong>in</strong>es{〈list〉}, one can write\l<strong>in</strong>es\datafile{〈filename〉}where 〈filename〉 is the full name of the file conta<strong>in</strong><strong>in</strong>g the data. The required format of this file<strong>and</strong> the details of this usage can be found <strong>in</strong> subsection 3.7.3. This method is available for anycomm<strong>and</strong> that takes a comma-separated list of data as its last argument, <strong>with</strong> the exception of thosecomm<strong>and</strong>s that adds text to the picture. Examples of the latter are \plottext <strong>and</strong> \axislabels(subsection 3.8.1).3.3.3 AXES, AXIS MARKS, AND GRIDS.\axes[〈hlen〉]\xaxis[〈hlen〉]\yaxis[〈hlen〉]These are reta<strong>in</strong>ed for backward compatibility, but there are more flexible alternatives below.They draw x- <strong>and</strong> y-axes for the coord<strong>in</strong>ate system. The comm<strong>and</strong> \axes is equivalent to \xaxisfollowed by \yaxis which produce the obvious. The x- <strong>and</strong> y-axes extend the full width <strong>and</strong>height of the mfpic environment. The optional 〈hlen〉 sets the length of the arrowhead on eachaxis. The default is the value of the <strong>TEX</strong> dimension \axisheadlen, <strong>in</strong>itially 5pt. The shape of thearrowhead is determ<strong>in</strong>ed as <strong>in</strong> the \arrow macro (section 3.5). The color of the head is the valueof headcolor, the shaft is drawcolor.


3.3 FIGURES. 14Unlike other comm<strong>and</strong>s that produce l<strong>in</strong>es or curves, these do not respond to the prefix macrosof sections 3.5 <strong>and</strong> 3.6. They always draw a solid l<strong>in</strong>e (<strong>with</strong> an arrowhead unless \axisheadlenis 0pt). They do respond to changes <strong>in</strong> the pen thickness (see \penwd <strong>in</strong> section 3.12) but that ispretty much the only possibility for variation.\axis[〈hlen〉]{〈one-axis〉}\doaxes[〈hlen〉]{〈axis-list〉}These produce any of 6 different axes. The parameter 〈one-axis〉 can be x or y, to produce(almost) the equivalent of \xaxis <strong>and</strong> \yaxis; or it can be l, b, r, or t to produce an axis onthe border of the picture (left, bottom, right or top, respectively). \doaxes takes a list of any orall of the six letters (<strong>with</strong> either spaces or noth<strong>in</strong>g <strong>in</strong> between) <strong>and</strong> produces the appropriate axes.Example: \doaxes{lbrt}. The optional argument sets the length of the arrowhead. In the case ofaxes on the edges, the default is the value of \sideheadlen, which <strong>MFPIC</strong> <strong>in</strong>itializes to 0pt. Forthe x- <strong>and</strong> y-axis the default is \axisheadlen as <strong>in</strong> \xaxis <strong>and</strong> \yaxis above.The comm<strong>and</strong>s \axis{x}, \axis{y}, <strong>and</strong> \doaxes{xy} differ from the old \xaxis, \yaxis<strong>and</strong> \axes <strong>in</strong> that these new versions respond to changes made by \setrender (see subsection3.6.3). Moreover, prefix macros may be applied to \axis <strong>with</strong>out error (see sections 3.5 <strong>and</strong>3.6): \dotted\axis{x} draws a dotted x-axis, but \dotted\xaxis produces a METAFONT error.A prefix macro applied to \doaxes generates no error, but only the first axis <strong>in</strong> the list will beaffected.The side axes are drawn by default <strong>with</strong> a pen stroke along the very edge of the picture (asdeterm<strong>in</strong>ed by the parameters to \mfpic). This can be changed <strong>with</strong> the comm<strong>and</strong> \axismarg<strong>in</strong>described below.Axes on the edges are drawn so that they don’t cross each other. \doaxes{lbrt}, for example,produces a perfect rectangle. If the x- <strong>and</strong> y-axis are drawn <strong>with</strong> \axis or \doaxes, then they willnot cross the side axes. For this to work properly, all the follow<strong>in</strong>g marg<strong>in</strong> sett<strong>in</strong>gs have to be donebefore the axes are drawn.\axismarg<strong>in</strong>{〈axis〉}{〈num〉}\setaxismarg<strong>in</strong>s{〈num〉}{〈num〉}{〈num〉}{〈num〉}\setallaxismarg<strong>in</strong>s{〈num〉}The 〈axis〉 is one of the letters l, b, r, or t. \axismarg<strong>in</strong> causes the given axis to be shifted<strong>in</strong>ward by the 〈num〉 specified (<strong>in</strong> graph coord<strong>in</strong>ates). The second comm<strong>and</strong> \setaxismarg<strong>in</strong>stakes 4 arguments, us<strong>in</strong>g them to set the marg<strong>in</strong>s start<strong>in</strong>g <strong>with</strong> the left <strong>and</strong> proceed<strong>in</strong>g anticlockwise.The last comm<strong>and</strong> sets all the axis marg<strong>in</strong>s to the same value.A change to an axis marg<strong>in</strong> affects not only the axis at that edge but also the three axes perpendicularto it. For example, if the marg<strong>in</strong>s are M lft , M bot , M rt <strong>and</strong> M top , then \axis b draws a l<strong>in</strong>estart<strong>in</strong>g M lft graph units from the left edge <strong>and</strong> end<strong>in</strong>g M rt units from the right edge. Of course,the entire l<strong>in</strong>e is M bot units above the bottom edge. The marg<strong>in</strong>s are also respected by the x- <strong>and</strong>y-axis, but only when drawn <strong>with</strong> \axis. The old \xaxis, \yaxis <strong>and</strong> \axes ignore them.Special effects can be achieved by ly<strong>in</strong>g to one axis about the other marg<strong>in</strong>s.


3.3 FIGURES. 15\xmarks[〈len〉]{〈numberlist〉}\tmarks[〈len〉]{〈numberlist〉}\bmarks[〈len〉]{〈numberlist〉}\ymarks[〈len〉]{〈numberlist〉}\lmarks[〈len〉]{〈numberlist〉}\rmarks[〈len〉]{〈numberlist〉}\axismarks{〈axis〉}[〈len〉]{〈numberlist〉}These macros place hash marks on the appropriate axes at the places <strong>in</strong>dicated by the values<strong>in</strong> the list. The optional 〈len〉 gives the length of the hash marks. If 〈len〉 is not specified, the <strong>TEX</strong>dimension \hashlen, <strong>in</strong>itially 4pt, is used. The marks on the x- <strong>and</strong> y-axes are centered on therespective axis; the marks on the border axes are drawn to the <strong>in</strong>side. Both these behaviors can bechanged (see below). The comm<strong>and</strong>s may be repeated as often as desired. (The tim<strong>in</strong>g of draw<strong>in</strong>gcomm<strong>and</strong>s can make a difference as outl<strong>in</strong>ed <strong>in</strong> appendix 4.6.) The comm<strong>and</strong> \axismarks{x} isequivalent to \xmarks <strong>and</strong> so on for each of the six axes. (I would have used \marks, but thatname was co-opted by e<strong>TEX</strong>.)The 〈numberlist〉 is normally a comma-separated list of numbers. In place of this, one can givea start<strong>in</strong>g number, an <strong>in</strong>crement <strong>and</strong> an end<strong>in</strong>g number as <strong>in</strong> the follow<strong>in</strong>g example:\xmarks{-2 step 1 until 2}is the equivalent of\xmarks{-2,-1,0,1,2}One must use exactly the words step <strong>and</strong> until. Spaces are not needed unless a variablename is used <strong>in</strong> place of one of the numbers (see subsection 3.13.4). The number of spaces is notsignificant. 8 Users of this syntax should be aware that if any of the numbers are non-<strong>in</strong>tegral thendue to natural round-off effects, the last value might be overshot <strong>and</strong> a mark not pr<strong>in</strong>ted there. Forexample, to ensure that a mark is pr<strong>in</strong>ted at the po<strong>in</strong>t 1.0 on the x-axis, the second l<strong>in</strong>e below isbetter than the first.\xmarks{0 step .2 until 1.0}\xmarks{0 step .2 until 1.1}\setaxismarks{〈axis〉}{〈pos〉}\setbordermarks{〈lpos〉}{〈bpos〉}{〈rpos〉}{〈tpos〉}\setallbordermarks{〈pos〉}\setxmarks{〈pos〉}\setymarks{〈pos〉}These set the placement of the hash marks relative to the axis. The parameter 〈axis〉 is one of theletters x, y, l, b, r, or t, <strong>and</strong> 〈pos〉 must be one of the literal words <strong>in</strong>side, outside, centered,onleft, onright, ontop or onbottom. The second comm<strong>and</strong> takes four arguments <strong>and</strong> sets theposition of the marks on each border. The third comm<strong>and</strong> sets the position on all four border axis8 Experienced METAFONT programmers may recognize that anyth<strong>in</strong>g can be used that is permitted <strong>in</strong> METAFONT’s〈forloop〉 syntax. Thus the given example can also be reworded \xmarks{-2 upto 2}, or even \xmarks{2 downto-2}. See subsection 3.13.6 for more on for-loops <strong>in</strong> <strong>MFPIC</strong>.


3.3 FIGURES. 16to the same value. The last two comm<strong>and</strong>s are abbreviations for \setaxismarks{x}{〈pos〉} <strong>and</strong>\setaxismarks{y}{〈pos〉}, respectively.Not all comb<strong>in</strong>ations make sense (for example, \setaxismarks{r}{ontop}). In these cases,no error message is produced: ontop <strong>and</strong> onleft are considered to be equivalent, as are onbottom<strong>and</strong> onright. The parameters <strong>in</strong>side <strong>and</strong> outside make no sense for the x- <strong>and</strong> y-axes, but ifthey are used then <strong>in</strong>side means ontop for the x-axis <strong>and</strong> onright for the y-axis. These words areactually METAFONT numeric variables def<strong>in</strong>ed <strong>in</strong> the file grafbase.mf, <strong>and</strong> the variables ontop<strong>and</strong> onleft, for example, are given the same value.\grid[〈ptsize〉]{〈xsep〉,〈ysep〉}\gridpo<strong>in</strong>ts[〈ptsize〉]{〈xsep〉,〈ysep〉}\lattice[〈ptsize〉]{〈xsep〉,〈ysep〉}\hgridl<strong>in</strong>es{〈ysep〉}\vgridl<strong>in</strong>es{〈xsep〉}\gridl<strong>in</strong>es{〈xsep〉,〈ysep〉}\grid draws a dot at every po<strong>in</strong>t for which the first coord<strong>in</strong>ate is an <strong>in</strong>teger multiple of the〈xsep〉 <strong>and</strong> the second coord<strong>in</strong>ate is an <strong>in</strong>teger multiple of 〈ysep〉. The diameter of the dot is determ<strong>in</strong>edby 〈ptsize〉. The default is .5bp <strong>and</strong> is hard coded <strong>in</strong> the METAFONT macros that ultimatelydo the draw<strong>in</strong>g. Under the metapost option, the color of the dot is po<strong>in</strong>tcolor. The comm<strong>and</strong>s\gridpo<strong>in</strong>ts <strong>and</strong> \lattice are synonyms for \grid.\hgridl<strong>in</strong>es draws the horizontal <strong>and</strong> \vgridl<strong>in</strong>es the vertical l<strong>in</strong>es through these samepo<strong>in</strong>ts. \gridl<strong>in</strong>es draws both sets of l<strong>in</strong>es. The thickness of the l<strong>in</strong>es is set by \penwd. Authorsare recommended to either reduce the pen width or change drawcolor to a lighter color for grids.Or omit them entirely: well-designed graphs usually don’t need them <strong>and</strong> almost never should bothhorizontals <strong>and</strong> verticals be used.\plrgrid{〈rsep〉,〈anglesep〉}\gridarcs{〈rsep〉}\gridrays{〈anglesep〉}\plrpatch{〈rm<strong>in</strong>〉,〈rmax〉,〈rsep〉,〈tm<strong>in</strong>〉,〈tmax〉,〈tsep〉}\plrgridpo<strong>in</strong>ts{〈rsep〉,〈anglesep〉}\plrgrid fills the graph <strong>with</strong> circular arcs <strong>and</strong> radial l<strong>in</strong>es. \gridarcs draws only the arcs,\gridrays only the radial l<strong>in</strong>es. \plrgridpo<strong>in</strong>ts places a dot at all the places the rays <strong>and</strong> arcswould <strong>in</strong>tersect.The arcs are centered at (0,0) <strong>and</strong> the l<strong>in</strong>es emanate from (0,0) (even if (0,0) is not <strong>in</strong> thegraph space). The correspond<strong>in</strong>g METAFONT comm<strong>and</strong>s actually draw enough to cover the grapharea <strong>and</strong> then clip them to the graph boundaries. If you don’t want them clipped, use \plrpatch.\plrpatch draws arcs <strong>with</strong> radii start<strong>in</strong>g at 〈rm<strong>in</strong>〉, stepp<strong>in</strong>g by 〈rsep〉 <strong>and</strong> end<strong>in</strong>g <strong>with</strong> 〈rmax〉.Each arc goes from angle 〈tm<strong>in</strong>〉 to 〈tmax〉. It also draws radial l<strong>in</strong>es <strong>with</strong> angles start<strong>in</strong>g at 〈tm<strong>in</strong>〉,stepp<strong>in</strong>g by 〈tsep〉 <strong>and</strong> end<strong>in</strong>g <strong>with</strong> 〈tmax〉. Each l<strong>in</strong>e goes from radius 〈rm<strong>in</strong>〉 to 〈rmax〉. If〈rmax〉 − 〈rm<strong>in</strong>〉 doesn’t happen to be a multiple of 〈rsep〉, the arc <strong>with</strong> radius 〈rmax〉 is drawnanyway. The same is true of the l<strong>in</strong>e at angle 〈tmax〉, so that the entire boundary is always drawn.If 〈tsep〉 is larger than 〈tmax〉 − 〈tm<strong>in</strong>〉, then only the boundary rays will be drawn. If 〈rsep〉 islarger than 〈rmax〉 − 〈rm<strong>in</strong>〉, then only the boundary arcs will be drawn.


3.3 FIGURES. 17The color used for rays <strong>and</strong> arcs is drawcolor, <strong>and</strong> for dots po<strong>in</strong>tcolor. The advice about\gridl<strong>in</strong>es holds for \plrgrid as well.3.3.4 CIRCLES AND ELLIPSES.\circle[〈format〉]{〈specification〉}Draws a circle. Start<strong>in</strong>g <strong>with</strong> <strong>MFPIC</strong> version 0.7, there are more than one way to specify acircle. In version 0.8 there are six ways, <strong>and</strong> one selects which one by giv<strong>in</strong>g \circle an optionalargument that signals what data will be specified <strong>in</strong> the m<strong>and</strong>atory argument.\circle[p]{〈c〉,〈r〉}\circle[c]{〈c〉,〈p〉}\circle[t]{〈p 1 〉,〈p 2 〉,〈p 3 〉}\circle[s]{〈p 1 〉,〈p 2 〉,〈θ〉}\circle[r]{〈p 1 〉,〈p 2 〉,〈r〉}\circle[q]{〈p 1 〉,〈p 2 〉,〈r〉}The optional arguments produce circles accord<strong>in</strong>g to the follow<strong>in</strong>g descriptions.[p] The Polar form is the default. The data <strong>in</strong> the m<strong>and</strong>atory argument should then be the center〈c〉 <strong>and</strong> radius 〈r〉 of the circle.[c] The Center-po<strong>in</strong>t form. In this case the data should be the center <strong>and</strong> one po<strong>in</strong>t on the circumference.[t] The Three-po<strong>in</strong>t form. The data are three po<strong>in</strong>ts that do not lie <strong>in</strong> a straight l<strong>in</strong>e.[s] The po<strong>in</strong>t-sweep form. The data are two po<strong>in</strong>ts on the circle, followed by the angle of arcbetween them.[r] The po<strong>in</strong>t-radius form. The data are two po<strong>in</strong>ts on the circle, followed by the radius. Thereare two circles <strong>with</strong> this data. The one that makes the angle from the first to the second po<strong>in</strong>tpositive <strong>and</strong> less than 180 degrees is produced.[q] The alternate po<strong>in</strong>t-radius form. The data are the same as for the [r] case, except the othercircle is produced.These optional arguments are also used <strong>in</strong> the \arc comm<strong>and</strong> (see subsection 3.3.6). The \circlecomm<strong>and</strong> draws the whole circle of which the correspond<strong>in</strong>g \arc comm<strong>and</strong> draws only a part.The sense of the circle produced is anticlockwise except <strong>in</strong> the case [t], where it is the directiondeterm<strong>in</strong>ed by the order of the three po<strong>in</strong>ts, <strong>and</strong> the case [s], where it is determ<strong>in</strong>ed by 〈θ〉:clockwise if negative, anticlockwise if positive. Actually, negative values of 〈r〉 may sometimeswork <strong>and</strong> may reverse the above directions.\ellipse[〈θ〉]{〈c〉,〈r x 〉,〈r y 〉}Draws an ellipse <strong>with</strong> the x radius 〈r x 〉 <strong>and</strong> y radius 〈r y 〉, centered at the po<strong>in</strong>t 〈c〉. The optionalparameter 〈θ〉 provides a way of rotat<strong>in</strong>g the ellipse by 〈θ〉 degrees anticlockwise around its center.Ellipses may also be created by differentially scal<strong>in</strong>g a circle <strong>and</strong> perhaps rotat<strong>in</strong>g the result. Seesubsection 3.11.2.


3.3 FIGURES. 183.3.5 CURVES.\curve[〈tension〉]{〈p 0 〉,〈p 1 〉,...}Draws a smooth path through the specified po<strong>in</strong>ts, <strong>in</strong> the specified order. It is ‘smooth’ <strong>in</strong> twoways: it never changes direction abruptly (no ‘corners’ or ‘cusps’ on the curve), <strong>and</strong> it tries to maketurns that are not too sharp. This latter property is acheived by specify<strong>in</strong>g (to METAFONT) that thetangent to the curve at each listed po<strong>in</strong>t is to be parallel to the l<strong>in</strong>e from that po<strong>in</strong>t’s predecessor toits successor.The optional 〈tension〉 <strong>in</strong>fluences how smooth the curve is. The special value <strong>in</strong>f<strong>in</strong>ity (<strong>in</strong>fact, usually anyth<strong>in</strong>g greater than about 10), makes the curve not visibly different from a polyl<strong>in</strong>e.The higher the value of tension, the sharper the corners on the curve <strong>and</strong> the flatter the portions <strong>in</strong>between. METAFONT requires the tension to be larger than 0.75. The default value of the tensionis 1 when <strong>MFPIC</strong> is loaded, but that can be changed <strong>with</strong> the follow<strong>in</strong>g comm<strong>and</strong>.\settension{〈num〉}This sets the default tension for all comm<strong>and</strong>s that take an optional tension parameter.\cyclic[〈tension〉]{〈p 0 〉,〈p 1 〉,...}Draws a cyclic (i.e., closed) METAFONT Bézier curve through the specified po<strong>in</strong>ts, <strong>in</strong> the specifiedorder. It uses the same procedure as \curve, but treats the first listed po<strong>in</strong>t as hav<strong>in</strong>g the lastas its predecessor <strong>and</strong> the last po<strong>in</strong>t has the first as its successor. The 〈tension〉 is as <strong>in</strong> the \curvecomm<strong>and</strong>.Sometimes one would like a convex set of po<strong>in</strong>ts to produce a convex curve. This will notalways be the case <strong>with</strong> \curve or \cyclic, as shown by the follow<strong>in</strong>g example, where the list ofpo<strong>in</strong>ts traces a rectangle:\cyclic{(0,0),(0,1),(1,1),(2,1),(2,0),(0,0)}To produce a convex curve, use one of the follow<strong>in</strong>g:\convexcurve[〈tension〉]{〈p 0 〉,〈p 1 〉,...}\convexcyclic[〈tension〉]{〈p 0 〉,〈p 1 〉,...}These can be used even if the list of po<strong>in</strong>ts is not convex, <strong>and</strong> the result will be convex wherepossible.Occasionally it is necessary to specify a sequence of po<strong>in</strong>ts <strong>with</strong> <strong>in</strong>creas<strong>in</strong>g x-coord<strong>in</strong>ates <strong>and</strong>draw a curve through them. One would then like the result<strong>in</strong>g curve both to be smooth <strong>and</strong> torepresent a function (that is, the curve always has <strong>in</strong>creas<strong>in</strong>g x coord<strong>in</strong>ate, never turn<strong>in</strong>g leftward).This cannot be guaranteed <strong>with</strong> the \curve comm<strong>and</strong> unless the tension is <strong>in</strong>f<strong>in</strong>ity.\fcncurve[〈tension〉]{(x 0 ,y 0 ),(x 1 ,y 1 ),...}Draws a curve through the po<strong>in</strong>ts specified. If the po<strong>in</strong>ts are listed <strong>with</strong> <strong>in</strong>creas<strong>in</strong>g (or decreas<strong>in</strong>g)x coord<strong>in</strong>ates, the curve will also have <strong>in</strong>creas<strong>in</strong>g (resp., decreas<strong>in</strong>g) x coord<strong>in</strong>ates. The〈tension〉 is a number greater than 1/3 which controls how tightly the curve is drawn. Generally,the larger it is, the closer the curve is to the polyl<strong>in</strong>e through the po<strong>in</strong>ts. The default tension is that


3.3 FIGURES. 19set <strong>with</strong> \settension, <strong>in</strong>itially 1. For those who know someth<strong>in</strong>g about METAFONT, this ‘tension’is not the same as the METAFONT notion of tension, the tension <strong>in</strong> the \curve comm<strong>and</strong>, butit functions <strong>in</strong> a similar fashion. In this case it can actually be any positive number, but only valuesgreater than 1/3 guarantee the property of never doubl<strong>in</strong>g back.3.3.6 CIRCULAR ARCS.\arc[〈format〉]{〈specification〉}Draws a circular arc specified as determ<strong>in</strong>ed by the 〈format〉 optional parameter. This macro<strong>and</strong> \circle are unusual <strong>in</strong> that the optional 〈format〉 parameter determ<strong>in</strong>es the format of the otherparameter, as <strong>in</strong>dicated below. The user is responsible for ensur<strong>in</strong>g that the parameter values makegeometric sense.\arc[s]{〈p 0 〉,〈p 1 〉,〈sweep〉}\arc[t]{〈p 0 〉,〈p 1 〉,〈p 2 〉}\arc[r]{〈p 0 〉,〈p 1 〉,〈r〉}\arc[q]{〈p 0 〉,〈p 1 〉,〈r〉}\arc[p]{〈c〉,〈θ 1 〉,〈θ 2 〉,〈r〉}\arc[a]{〈c〉,〈r〉,〈θ 1 〉,〈θ 2 〉}\arc[c]{〈c〉,〈p 1 〉,〈θ〉}The optional arguments produce arcs accord<strong>in</strong>g to the follow<strong>in</strong>g descriptions.[s] The po<strong>in</strong>t-sweep form is the default format. It draws the circular arc start<strong>in</strong>g from the po<strong>in</strong>t〈p 0 〉, end<strong>in</strong>g at the po<strong>in</strong>t 〈p 1 〉, <strong>and</strong> cover<strong>in</strong>g an arc angle of 〈sweep〉 degrees, measuredanticlockwise around the center of the circle. If, for example, the po<strong>in</strong>ts 〈p 0 〉 <strong>and</strong> 〈p 1 〉 lie ona horizontal l<strong>in</strong>e <strong>with</strong> 〈p 0 〉 to the left, <strong>and</strong> 〈sweep〉 is between 0 <strong>and</strong> 360 (degrees), then thearc will sweep below the horizontal l<strong>in</strong>e (<strong>in</strong> order for the arc to be anticlockwise). A negativevalue of 〈sweep〉 gives a clockwise arc from 〈p 0 〉 to 〈p 1 〉.[t] The three-po<strong>in</strong>t form draws the circular arc which passes through all three po<strong>in</strong>ts given, <strong>in</strong> theorder given. Internally, this is converted to two applications of the po<strong>in</strong>t-sweep form.[r] The po<strong>in</strong>t-radius form draws the circular arc start<strong>in</strong>g at the po<strong>in</strong>t 〈p 0 〉, end<strong>in</strong>g at 〈p 1 〉, <strong>with</strong>radius 〈r〉. Of the four possible arcs on two possible circles, it produces the one that coversan arc angle θ no more than 180 degrees measured anticlockwise around the center of thecircle. To get the similar arc on the other circle, reverse the order of the po<strong>in</strong>ts.[q] The alternate po<strong>in</strong>t-radius form is the same as [r] except it produces the arc that covers anangle θ no less than 180 degrees measured anticlockwise around the center of the circle. Toget the similar arc on the other circle, reverse the order of the po<strong>in</strong>ts.[p] The polar form draws the arc of a circle <strong>with</strong> center 〈c〉 start<strong>in</strong>g at the angle 〈θ 1 〉 <strong>and</strong> end<strong>in</strong>gat the angle 〈θ 2 〉, <strong>with</strong> radius 〈r〉. Both angles are measured anticlockwise from the positivex axis.[a] The alternate polar form draws the arc of a circle <strong>with</strong> center 〈c〉 <strong>and</strong> radius 〈r〉, start<strong>in</strong>g at theangle 〈θ 1 〉 <strong>and</strong> end<strong>in</strong>g at the angle 〈θ 2 〉. Both angles are measured anticlockwise from the


3.3 FIGURES. 20positive x axis. This is provided because it seems a more reasonable order of arguments, <strong>and</strong>matches the order \sector requires (see subsection 3.3.7 below). The p option is reta<strong>in</strong>edfor backward compatibility.[c] The center-po<strong>in</strong>t form draws the circular arc <strong>with</strong> center 〈c〉, start<strong>in</strong>g at the po<strong>in</strong>t 〈p 1 〉, <strong>and</strong>sweep<strong>in</strong>g an angle of 〈θ〉 around the center from that po<strong>in</strong>t. (This <strong>and</strong> the po<strong>in</strong>t sweep formare the basic methods of h<strong>and</strong>l<strong>in</strong>g arcs—the previous three formats are translated to one ofthese two before draw<strong>in</strong>g.)3.3.7 OTHER FIGURES.\turtle{〈p 0 〉,〈v 1 〉,〈v 2 〉,...}Draws a l<strong>in</strong>e segment, start<strong>in</strong>g from the po<strong>in</strong>t 〈p 0 〉, <strong>and</strong> extend<strong>in</strong>g along the (2-dimensionalvector) displacement 〈v 1 〉. It then draws a l<strong>in</strong>e segment from the previous segment’s endpo<strong>in</strong>t,along displacement 〈v 2 〉. This cont<strong>in</strong>ues for all listed displacements, a process similar to ‘turtlegraphics’.\sector{〈c〉,〈r〉,〈θ 1 〉,〈θ 2 〉}Draws the sector, from the angle 〈θ 1 〉 to the angle 〈θ 2 〉 <strong>in</strong>side the circle <strong>with</strong> center at the po<strong>in</strong>t〈c〉 <strong>and</strong> radius 〈r〉, where both angles are measured <strong>in</strong> degrees anticlockwise from the directionparallel to the x axis. The sector forms a closed path. Note: \sector <strong>and</strong> \arc[p] have the sameparameters, but <strong>in</strong> a different order. 9\makesector\arc[〈fmt〉]{〈spec〉}The \sector comm<strong>and</strong> requires the center of the arc as one of its arguments. But if one doesn’tknow that center (say one only knows three po<strong>in</strong>ts the arc connects) then even though the arc canbe drawn, \sector cannot. The \makesector comm<strong>and</strong>, when followed by any \arc comm<strong>and</strong>,will f<strong>in</strong>d the center <strong>and</strong> connect it to the two ends of the arc.3.3.8 BAR CHARTS AND PIE CHARTS.\barchart[〈start〉,〈sep〉,〈r〉]{〈h-or-v〉}{〈list〉}\bargraph...\gantt...\histogram...\chartbar{〈num〉}\graphbar{〈num〉}\histobar{〈num〉}The macro \barchart computes a bar chart or a Gantt chart. It does not draw the bars, but onlydef<strong>in</strong>es their rectangular paths which the user may then draw or fill or both us<strong>in</strong>g the \chartbarmacros (see below). S<strong>in</strong>ce bar charts have many names, \bargraph <strong>and</strong> \histogram are providedas synonyms. The macro \gantt is also a synonym; whether a Gantt chart or bar chart is createddepends on the data.〈h-or-v〉 should be v if you want the ends of the bars to be measured vertically from the x-axis,or h if they should be measured horizontally from the y-axis. 〈list〉 should be a comma-separated list9 This apparently was un<strong>in</strong>tended, but we now have to live <strong>with</strong> it so as not to break exist<strong>in</strong>g .tex files.


3.3 FIGURES. 21of numbers <strong>and</strong>/or pairs giv<strong>in</strong>g the coord<strong>in</strong>ates of the end(s) of each bar. A number c is <strong>in</strong>terpretedas the pair (0,c); a pair (a,b) is <strong>in</strong>terpreted as an <strong>in</strong>terval giv<strong>in</strong>g the ends of the bar (for Ganttdiagrams). The rest of this description refers to the h case; the v case is analogous.By default the bars are 1 graph unit high (thickness), from y = n − 1 to y = n. Their width <strong>and</strong>location are determ<strong>in</strong>ed by the data. The optional parameter consists of three numeric parametersseparated by commas. 〈start〉 is the y-coord<strong>in</strong>ate of the bottom edge of the first bar, 〈sep〉 is thedistance between the bottom edges of successive bars, <strong>and</strong> 〈r〉 is the fraction of 〈sep〉 occupiedby each bar. The default behavior corresponds to [0,1,1]. In general, bar number n will be fromy = 〈start〉 + (n − 1) ∗ 〈sep〉 to y = 〈start〉 + (n − 1 + 〈r〉) ∗ 〈sep〉Notice the bars are numbered <strong>in</strong> order from bottom to top. You can reverse them by mak<strong>in</strong>g〈sep〉 negative, <strong>and</strong> mak<strong>in</strong>g 〈start〉 the top edge of the first bar.The fraction 〈r〉 should be between -1 <strong>and</strong> 1. A negative value reverses the direction from the‘lead<strong>in</strong>g edge’ of the bar to the ‘trail<strong>in</strong>g edge’. For example, if one bar chart is created <strong>with</strong>\barchart[1,1,-.4]{h}{...}<strong>and</strong> another <strong>with</strong>\barchart[1,1,.4]{h}{...}both hav<strong>in</strong>g the same number of bars, then the first will have its first bar from y = 1 to y = 1−.4 =.6, while the second will have its first bar adjacent to that one, from 1 to 1 + .4. Similarly the nextbars will be above <strong>and</strong> below y = 2, etc. This makes it easy to draw bars next to one another forcomparison.The macro \chartbar (synonyms \graphbar, \ganttbar, <strong>and</strong> \histobar) takes a numberfrom 1 to the number of elements <strong>in</strong> the 〈list〉 <strong>and</strong> draws the rectangular path. This behaves justlike any other figure macro, <strong>and</strong> the prefix macros from section 3.6 may be used to give adjacentbars contrast<strong>in</strong>g colors, fills, etc.\piechart[〈dir〉〈angle〉]{〈c〉,〈r〉}{〈list〉}\piewedge[〈spec〉〈trans〉]{〈num〉}The macro \piechart also does not draw anyth<strong>in</strong>g, but computes the \piewedge regionsdescribed below. The first part of the optional parameter, 〈dir〉, is a s<strong>in</strong>gle letter which may be eitherc or a which st<strong>and</strong> for clockwise or anticlockwise, respectively. It is common to draw piecharts <strong>with</strong>the largest wedge start<strong>in</strong>g at 12 o’clock (angle 90 degrees) <strong>and</strong> successive wedges clockwise fromthere. This is the default. You can change the start<strong>in</strong>g angle from 90 <strong>with</strong> the 〈angle〉 parameter,<strong>and</strong> the change the direction to counter-clockwise by specify<strong>in</strong>g a for 〈dir〉. It is also traditional toarrange the wedges from largest to smallest, except there is often a miscellaneous category whichis usually last <strong>and</strong> may be larger than some others. Therefore \piechart makes no attempt tosort the data. The data is entered as a comma separated 〈list〉 of positive numbers <strong>in</strong> the secondrequired parameter. These are only used to determ<strong>in</strong>e the relative sizes of the wedges <strong>and</strong> arenot pr<strong>in</strong>ted anywhere. The first required parameter should conta<strong>in</strong> a pair 〈c〉 for the center <strong>and</strong> apositive number 〈r〉 for the radius, separated by a comma.After a \piechart comm<strong>and</strong> has been issued, the <strong>in</strong>dividual wedges may be drawn, filled,etc., us<strong>in</strong>g \piewedge{1}, \piewedge{2}, etc. Without the optional argument, the wedges arelocated accord<strong>in</strong>g to the arguments of the last \piechart comm<strong>and</strong>. The optional argument to\piewedge can override this. The parameter 〈spec〉 is a s<strong>in</strong>gle letter, which can be x, s or m. The


3.4 COLORS 22x st<strong>and</strong>s for exploded <strong>and</strong> it means the wedge is moved directly out from the center of the pie adistance 〈trans〉. 〈trans〉 should then be a pure number <strong>and</strong> is <strong>in</strong>terpreted as a distance <strong>in</strong> graphunits. The s st<strong>and</strong>s for shifted <strong>and</strong> <strong>in</strong> this case 〈trans〉 should be a pair of the form (〈dx〉,〈dy〉)<strong>in</strong>dicat<strong>in</strong>g the wedge should be shifted 〈dx〉 horizontally <strong>and</strong> 〈dy〉 vertically (<strong>in</strong> graph units). The mst<strong>and</strong>s for move to, <strong>and</strong> 〈trans〉 is then the absolute coord<strong>in</strong>ates (〈x〉,〈y〉) <strong>in</strong> the graph where thepo<strong>in</strong>t of the wedge should be placed.3.3.9 POLAR COORDINATES TO RECTANGULAR.\plr{(〈r 0 〉,〈θ 0 〉), (〈r 1 〉,〈θ 1 〉), ...}Replaces the specified list of polar coord<strong>in</strong>ate pairs by the equivalent list of rectangular (cartesian)coord<strong>in</strong>ate pairs. Through \plr, comm<strong>and</strong>s designed for rectangular coord<strong>in</strong>ates can be appliedto data represented <strong>in</strong> polar coord<strong>in</strong>ates—<strong>and</strong> to data conta<strong>in</strong><strong>in</strong>g both rectangular <strong>and</strong> polarcoord<strong>in</strong>ate pairs.3.4 Colors3.4.1 SETTING THE DEFAULT COLORS.\drawcolor[〈model〉]{〈colorspec〉}\fillcolor...\hatchcolor...\po<strong>in</strong>tcolor...\headcolor...\tlabelcolor...\backgroundcolor...These macros set the default color for various draw<strong>in</strong>g elements. Any curve (<strong>with</strong> one exception,those drawn by \plotdata), whether solid, dashed, dotted, or plotted <strong>in</strong> symbols, will be<strong>in</strong> the color set by \drawcolor. Set the color used by \gfill <strong>with</strong> \fillcolor. For all thehatch<strong>in</strong>g comm<strong>and</strong>s use \hatchcolor. For the \po<strong>in</strong>t, \plotsymbol <strong>and</strong> \grid comm<strong>and</strong>suse \po<strong>in</strong>tcolor, <strong>and</strong> for arrowheads, \headcolor. One can set the color used by \gclear<strong>with</strong> \backgroundcolor (the same color will also be used <strong>in</strong> the <strong>in</strong>terior of unfilled po<strong>in</strong>ts thatare drawn <strong>with</strong> \po<strong>in</strong>t) <strong>and</strong>, when mplabels is <strong>in</strong> effect, the color of labels can be set <strong>with</strong>\tlabelcolor. The optional 〈model〉 may be one of rgb, RGB, cmyk, gray, <strong>and</strong> named. The〈colorspec〉 depends on the model, as outl<strong>in</strong>ed below. Each of these comm<strong>and</strong>s sets a correspond<strong>in</strong>gMETAPOST color variable <strong>with</strong> the same name (except \backgroundcolor sets the colorbackground). Thus one can set the fill<strong>in</strong>g color to the draw<strong>in</strong>g color by issu<strong>in</strong>g the comm<strong>and</strong>\fillcolor{drawcolor}.3.4.2 METAPOST COLORS.If the optional 〈model〉 specification is omitted, the color specification may be any expressionrecognized as a color by METAPOST. In METAPOST, a color is a triple of numbers like (1,.5,.5),<strong>with</strong> the coord<strong>in</strong>ates between 0 <strong>and</strong> 1, represent<strong>in</strong>g red, green <strong>and</strong> blue levels, respectively. Whiteis given by (1,1,1) <strong>and</strong> black by (0,0,0). METAPOST also has color variables <strong>and</strong> severalhave been predef<strong>in</strong>ed: red, green, blue, yellow, cyan, magenta, white, <strong>and</strong> black. All thenames <strong>in</strong> the LA<strong>TEX</strong> COLOR package’s dvipsnam.def are predef<strong>in</strong>ed color variable names. S<strong>in</strong>ce


3.4 COLORS 23METAPOST allows color expressions, colors may be added <strong>and</strong> multiplied by numerics. Moreover,several METAPOST color functions have been def<strong>in</strong>ed <strong>in</strong> grafbase.mp:cmyk(c,m,y,k)Converts a cmyk color specification to METAPOST’s native rgb. For example, the comm<strong>and</strong>cmyk(1,0,0,0) yields (0,1,1), which is the def<strong>in</strong>ition of cyan.RGB(R,G,B)Converts an RGB color specification to rgb. It essentially just divides each component by 255.gray(g)Converts a numeric g (a gray level) to the correspond<strong>in</strong>g multiple of (1,1,1).named(〈name〉), rgb(r,g,b)These are essentially no-ops. However; rgb will truncate the arguments to the 0–1 range, anunknown 〈name〉 is converted to black, <strong>and</strong> an unknown numeric argument is set to 0.As an example of the use of these functions, one could conceivable write:\drawcolor{0.5*RGB(255,0,0)+0.5*cmyk(1,0,0,0)}to have all curves drawn <strong>in</strong> a color halfway between red <strong>and</strong> cyan (which turns out to be the sameas gray(0.5)).3.4.3 COLOR MODELS.When the optional 〈model〉 is specified <strong>in</strong> the color sett<strong>in</strong>g comm<strong>and</strong>s, it determ<strong>in</strong>es the format ofthe color specification:Model:rgbRGBcmykgraynamedSpecification:Three numbers <strong>in</strong> the range 0 to 1 separated by commas.Three numbers <strong>in</strong> the range 0 to 255 separated by commas.Four numbers <strong>in</strong> the range 0 to 1 separated by commas.One number <strong>in</strong> the range 0 to 1, <strong>with</strong> 1 <strong>in</strong>dicat<strong>in</strong>g white, 0 black.A METAPOST color variable name either predef<strong>in</strong>ed by <strong>MFPIC</strong> or by the user.<strong>MFPIC</strong> translates\fillcolor{cmyk}{1,.3,0,.2}<strong>in</strong>to the equivalent of\fillcolor{cmyk(1,.3,0,.2)}.Note that when the optional model is specified, the color specification must not be enclosed <strong>in</strong>parentheses. Note also that each model name is the name of a color function described <strong>in</strong> theprevious subsection. That is how the models are implemented <strong>in</strong>ternally.


3.5 SHAPE-MODIFIER MACROS. 243.4.4 DEFINING A COLOR NAME.\mfpdef<strong>in</strong>ecolor{〈name〉}{〈model〉}{〈colorspec〉}This def<strong>in</strong>es a color variable 〈name〉 for later use, either <strong>in</strong> the comm<strong>and</strong>s \drawcolor, etc.,or <strong>in</strong> the optional parameters to \draw, etc. The name can be used alone or <strong>in</strong> the named model.The m<strong>and</strong>atory 〈model〉 <strong>and</strong> 〈colorspec〉 are as above.A f<strong>in</strong>al caution, the colors of an <strong>MFPIC</strong> figure are stored <strong>in</strong> the .mp output file, <strong>and</strong> are notrelated to colors used or def<strong>in</strong>ed by the LA<strong>TEX</strong> COLOR package. In particular a color def<strong>in</strong>ed only byLA<strong>TEX</strong>’s \def<strong>in</strong>ecolor comm<strong>and</strong> will rema<strong>in</strong> unknown to <strong>MFPIC</strong>. Conversely, LA<strong>TEX</strong> comm<strong>and</strong>swill not recognize any color def<strong>in</strong>ed only by \mfpdef<strong>in</strong>ecolor.3.4.5 COLOR IN METAFONTMETAFONT was never meant to underst<strong>and</strong> colors, but it certa<strong>in</strong>ly can be taught the differencebetween black <strong>and</strong> white <strong>and</strong>, to a limited extent, various grays. Start<strong>in</strong>g <strong>with</strong> version 0.7, <strong>MFPIC</strong>will no longer generate an error when a color-chang<strong>in</strong>g comm<strong>and</strong> is used under the metafont option.Instead, when possible, the variables that represent colors <strong>in</strong> METAPOST will be converted to anumeric value between 0 <strong>and</strong> 1 <strong>in</strong> METAFONT. When possible (for example, when a region isfilled) the numeric will be <strong>in</strong>terpreted as a gray level <strong>and</strong> shad<strong>in</strong>g (see subsection 3.6.2) will beused to approximate the gray. In other cases (draw<strong>in</strong>g or dash<strong>in</strong>g of curves, plac<strong>in</strong>g of po<strong>in</strong>ts orsymbols, fill<strong>in</strong>g <strong>with</strong> a pattern of hatch l<strong>in</strong>es) the number will be <strong>in</strong>terpreted as black or white: avalue less than 1 will cause the figure to be rendered (<strong>in</strong> black), while a value equal to 1 (white)will cause pixels correspond<strong>in</strong>g to the figure to be erased.This is depends on adher<strong>in</strong>g to certa<strong>in</strong> restrictions. METAFONT’s syntax does not recognizea triple of numbers as any sort of data structure, but it does allow comm<strong>and</strong>s to have any numberof parameters <strong>in</strong> parentheses. So colors must be specified us<strong>in</strong>g the color comm<strong>and</strong>s such asrgb(1,1,0) or color names such as yellow, <strong>and</strong> never as a bare triple. Also, as currently written,the color names def<strong>in</strong>ed <strong>in</strong> dvipsnam.mp are not def<strong>in</strong>ed <strong>in</strong> METAFONT. With these provisionsthe same <strong>MFPIC</strong> code can often produce either gray scale METAFONT pictures or METAPOST colorpictures depend<strong>in</strong>g only on the metapost option.The comm<strong>and</strong>s \shade <strong>and</strong> \gfill[gray(.75)] (see subsection 3.6.2 for their mean<strong>in</strong>g)will produce a similar shade of gray, but there is a difference. The first simply adds small dots ontop of whatever is already drawn. The second, however, tries to simulate the METAPOST effect,which is to cover up whatever is previously drawn. Therefore, it first zeros all affected pixelsbefore add<strong>in</strong>g the dots to simulate gray. In particular, \gfill[white] should have the same effectas \gclear.3.5 Shape-Modifier Macros.Some <strong>MFPIC</strong> macros operate as shape-modifier macros—for example, if you want to put an arrowheadon a l<strong>in</strong>e segment, you could write: \arrow\l<strong>in</strong>es{(0,0),(1,0)}. These are alwaysprefixed to some figure draw<strong>in</strong>g comm<strong>and</strong>, <strong>and</strong> apply only to the next follow<strong>in</strong>g figure macro(which can be rather far removed) provided that only other prefix comm<strong>and</strong>s <strong>in</strong>tervene. This is arather long section, but even more modification prefixes are documented <strong>in</strong> subsection 3.11.2.For the purposes of these macros, a dist<strong>in</strong>ction must be made <strong>in</strong> the figure macros between‘open’ <strong>and</strong> ‘closed’ paths. A path that merely returns to its start<strong>in</strong>g po<strong>in</strong>t is not automatically


3.5 SHAPE-MODIFIER MACROS. 25closed; such a path is open, <strong>and</strong> must be explicitly closed, for example by \lclosed (see below).The (already) closed paths are those that have ‘closed’ or ‘cyclic’ <strong>in</strong> their name plus:\belowfcn, \btwnfcn, \btwnplrfcn, \chartbar (along <strong>with</strong> its aliases), \circle, \ellipse,\levelcurve, \makesector, \piewedge, \plrregion, \polygon, \rect, \regpolygon,\sector, \tlabelcircle. \tlabelellipse, \tlabeloval, <strong>and</strong> \tlabelrect,It should be po<strong>in</strong>ted out that the closure macros will leave already closed paths unchanged, soit is always safe to add one when uncerta<strong>in</strong>. Moreover, if the path is not closed but the endpo<strong>in</strong>tsare identical, \lclosed will close it <strong>with</strong>out add<strong>in</strong>g the (trivial) l<strong>in</strong>e segment.3.5.1 CLOSURE OF PATHS.\lclosed...Makes each open path <strong>in</strong>to a closed path by add<strong>in</strong>g a l<strong>in</strong>e segment between the endpo<strong>in</strong>ts ofthe path.\bclosed[〈tens〉]...This macro is similar to \lclosed, except that it closes an open path smoothly by draw<strong>in</strong>ga Bézier curve. A Bézier is METAFONT’s natural way of connect<strong>in</strong>g po<strong>in</strong>ts <strong>in</strong>to a curve, <strong>and</strong>\bclosed is the simplest <strong>and</strong> most efficient closure next to \lclosed. Moreover it usually givesa reasonably aesthetic result. Sometimes, however, one might wish a tighter connection. If that isthe case, use the optional argument <strong>with</strong> a value of the tension 〈tens〉 greater than 1, the default.The comm<strong>and</strong> \settension (see subsection 3.3.5) can be used to change the default.\sclosed[〈tens〉]...This closes the curve by mimick<strong>in</strong>g the def<strong>in</strong>ition of the \curve comm<strong>and</strong>. That comm<strong>and</strong>tries to force the curve to pass through the nth po<strong>in</strong>t <strong>in</strong> a direction parallel to the l<strong>in</strong>e from po<strong>in</strong>t(n − 1) to po<strong>in</strong>t (n + 1). In order to close a curve <strong>in</strong> this way, the direction at the two endpo<strong>in</strong>tsoften has to be changed, <strong>and</strong> this changes the shape of the first <strong>and</strong> last segments of the curve. Use\bclosed if you don’t wish this to happen. However, \sclosed\curve produces a result almostidentical to \cyclic given the same po<strong>in</strong>ts <strong>and</strong> tension values. The optional tension argument isas <strong>in</strong> the \bclosed comm<strong>and</strong>.There are two other closure comm<strong>and</strong>s but, because they are associated <strong>with</strong> particular typesof paths (spl<strong>in</strong>es), we delay their discussion until those are discussed (subsection 3.13.1).3.5.2 REVERSAL, CONNECTION AND OTHER PATH MODIFICATIONS.\reverse...Turns a path around, revers<strong>in</strong>g its sense. This will affect both the direction of arrows (e.g. bidirectionalarrows can be coded <strong>with</strong> \arrow\reverse\arrow..., where the first \arrow modifierapplies to the reversed path), <strong>and</strong> the order of endpo<strong>in</strong>ts for a \connect...\endconnectenvironment (below).\connect ... \endconnectThis pair of macros, act<strong>in</strong>g as an environment, adds l<strong>in</strong>e segments from the trail<strong>in</strong>g endpo<strong>in</strong>tof one path to the lead<strong>in</strong>g endpo<strong>in</strong>t of the next path, <strong>in</strong> the given order. The result is a connected,open path.


3.5 SHAPE-MODIFIER MACROS. 26Note: In LA<strong>TEX</strong>, this pair of macros can be used <strong>in</strong> the form of a LA<strong>TEX</strong>-style environment calledconnect —as <strong>in</strong> \beg<strong>in</strong>{connect}...\end{connect}.\partpath{〈frac1〉,〈frac2〉}. . .\subpath{〈num1〉,〈num2〉}. . .Both produce a part of the follow<strong>in</strong>g path. In \partpath the parameters 〈frac1〉 <strong>and</strong> 〈frac2〉should be numbers between 0 <strong>and</strong> 1. The path produced travels the same course as the path thatfollows, but starts at the po<strong>in</strong>t that is 〈frac1〉 of the orig<strong>in</strong>al length along it, <strong>and</strong> ends at the po<strong>in</strong>t〈frac2〉 of its orig<strong>in</strong>al length. If 〈frac1〉 is greater than 〈frac2〉, the sense of the path is reversed. In\subpath, the two numbers should be between 0 <strong>and</strong> the number of Bézier segments <strong>in</strong> the path.This is ma<strong>in</strong>ly for experienced METAFONTers <strong>and</strong> provides an <strong>MFPIC</strong> <strong>in</strong>terface to METAFONT’s‘subpath’ operation.As an example of \partpath, one can put an arrowhead (see next subsection) <strong>in</strong> the middle ofa path <strong>with</strong> someth<strong>in</strong>g like the follow<strong>in</strong>g.\arrow\partpath{0,.5}\draw. . .See also the example similar to this near the beg<strong>in</strong>n<strong>in</strong>g of section 3.6.\parallelpath〈dist〉...This takes the follow<strong>in</strong>g path <strong>and</strong> returns a path that follows beside it, keep<strong>in</strong>g a fixed distance〈dist〉 to the left. If 〈dist〉 is negative, it keeps to the right. Left or right is from the po<strong>in</strong>t of viewof a traveller follow<strong>in</strong>g the given path from start to f<strong>in</strong>ish. The distance is a pure number <strong>in</strong> graphcoord<strong>in</strong>ates. Note: this should be compared to the first optional argument of \doubledraw (seesubsection 3.6.1), which requires an absolute dimension like 2pt, even though it is implementedus<strong>in</strong>g the <strong>in</strong>ternal code of \parallelpath.The calculation of the parallel path is approximate <strong>and</strong> rather <strong>in</strong>efficient. It is likely to produce<strong>in</strong>explicable small loops where it tries to follow the <strong>in</strong>side of tight turns (radius less than 〈dist〉).Actual corners, (which might be thought of as turns of radius 0) are usually detected <strong>and</strong> dealt <strong>with</strong><strong>in</strong> a reasonable manner. However, if the path is made up of segments of length 〈dist〉 or less, thisis unlikely to work correctly at all.3.5.3 ARROWS.\arrow[l〈headlen〉][r〈rotate〉][b〈backset〉][c〈color〉]...\arrow*[l〈headlen〉][r〈rotate〉][b〈backset〉][c〈color〉]...Draws an arrowhead at the endpo<strong>in</strong>t of the open path (or at the last key po<strong>in</strong>t of the closedpath) that follows. The optional parameter 〈headlen〉 determ<strong>in</strong>es the length of the arrowhead. Thedefault is the value of the <strong>TEX</strong> dimension \headlen, <strong>in</strong>itially 3pt. The optional parameter 〈rotate〉allows the arrowhead to be rotated anticlockwise around its po<strong>in</strong>t an angle of 〈rotate〉 degrees.The default is 0. The optional parameter 〈backset〉 allows the arrowhead to be ‘set back’ fromits orig<strong>in</strong>al po<strong>in</strong>t, thus allow<strong>in</strong>g e.g. double arrowheads. This parameter is <strong>in</strong> the form of a <strong>TEX</strong>dimension—its default value is 0pt. If an arrowhead is both rotated <strong>and</strong> set back, it is set back <strong>in</strong>the direction after the rotation. Actually, except on a straight l<strong>in</strong>e, a better way to set an arrowheadback might be someth<strong>in</strong>g like\arrow\trimpath{0,5pt}\draw. . .


3.6 RENDERING MACROS 27See subsection 3.13.7 for the \trimpath macro (which has its own problems). The optional〈color〉 defaults to headcolor. The optional parameters may appear <strong>in</strong> any order, the <strong>in</strong>dicatedkey character determ<strong>in</strong><strong>in</strong>g the mean<strong>in</strong>g of a parameter.There is also a star-form: If \arrow is called as \arrow*... then any part of the tip of thefollow<strong>in</strong>g curve that lies outside the arrowhead shape is clipped off. Imag<strong>in</strong>e a rectangle <strong>with</strong> oneside connect<strong>in</strong>g the ends of the barbs <strong>and</strong> the opposite side pass<strong>in</strong>g through the tip. Everyth<strong>in</strong>g <strong>in</strong>that rectangle outside the arrowhead is erased, so be careful us<strong>in</strong>g this. At the moment, the only realuse of this is add<strong>in</strong>g an arrowhead to a figure rendered <strong>with</strong> \doubledraw (see the next section)or <strong>with</strong> a rather large pen diameter (see section 3.12).3.6 Render<strong>in</strong>g MacrosWhen <strong>MFPIC</strong> is loaded, the <strong>in</strong>itial way <strong>in</strong> which figures are drawn is <strong>with</strong> a solid outl<strong>in</strong>e. Thatis, \l<strong>in</strong>es{(1,0),(1,1),(0,0)} will draw two solid l<strong>in</strong>es connect<strong>in</strong>g the po<strong>in</strong>ts. When themacros <strong>in</strong> this section are used, any previously established default (see subsection 3.6.3 below) isoverridden.\norender...This causes the follow<strong>in</strong>g path not to be rendered at all. For an example where this might beuseful, consider the follow<strong>in</strong>g:\arrow\partpath{0,.5}\dotted. . .This would add an arrowhead onto the partial path, then, s<strong>in</strong>ce there is no preced<strong>in</strong>g render<strong>in</strong>gprefix, the partial path would be subject to the default render<strong>in</strong>g (normally drawn <strong>with</strong> a solid l<strong>in</strong>e),<strong>and</strong> then the whole path is dotted. If one wanted just the whole dotted path <strong>with</strong> an arrowhead<strong>in</strong> the middle, one needs to turn off the default render<strong>in</strong>g of \partpath. Thus, \norender is arender<strong>in</strong>g macro that does noth<strong>in</strong>g except override the default:\norender\arrow\partpath{0,.5}\dotted. . .3.6.1 DRAWING.\draw[〈color〉]...Draws the subsequent path us<strong>in</strong>g a solid outl<strong>in</strong>e. For an example: to both draw a curve <strong>and</strong>hatch its <strong>in</strong>terior, \draw\hatch must be used. The default for 〈color〉 is drawcolor.To save repetition, the color used for the follow<strong>in</strong>g comm<strong>and</strong>s is also drawcolor: \dashed,\dotted, \doubledraw, \plot, \plotnodes, <strong>and</strong> \gendashed,\doubledraw[〈sep〉][〈color〉]...This draws <strong>with</strong> a double l<strong>in</strong>e. The default separation (distance between centers of the twopenstrokes) is twice the pen diameter. This normally leaves one l<strong>in</strong>e thickness of white spacebetween. You can change this <strong>with</strong> the [〈sep〉] argument. In order to make the space betweenthe l<strong>in</strong>es transparent, this comm<strong>and</strong> is implemented by calculat<strong>in</strong>g two curves that parallel thegiven curve <strong>and</strong> draw<strong>in</strong>g those. For technical reasons, that calculation is rather lengthy so this issomewhat <strong>in</strong>efficient <strong>and</strong> users of slow mach<strong>in</strong>es might want to avoid it. See also comments at\parallelpath <strong>in</strong> subsection 3.5.2.


3.6 RENDERING MACROS 28\dashed[〈length〉,〈space〉]...Draws dashed segments along the path specified. The default length of the dashes is the valueof the <strong>TEX</strong> dimension \dashlen, <strong>in</strong>itially 4pt. The default space between the dashes is the valueof the <strong>TEX</strong> dimension \dashspace, <strong>in</strong>itially 4pt. The dashes <strong>and</strong> the spaces between may be<strong>in</strong>creased or decreased by as much as 1/n of their value, where n is the number of spaces appear<strong>in</strong>g<strong>in</strong> the curve, <strong>in</strong> order to have the proper dashes at the ends. The dashes at the ends are half of\dashlen long.\dotted[〈size〉,〈space〉]...Draws dots along the specified path. The default size of the dots is the value of the <strong>TEX</strong> dimension\dotsize, <strong>in</strong>itially 0.5pt. The default space between the dots is the value of the <strong>TEX</strong>dimension \dotspace, <strong>in</strong>itially 3pt. The size of the spaces may be adjusted as <strong>in</strong> \dashed.\plot[〈size〉,〈space〉]{〈symbol〉}...Similar to \dotted except copies of 〈symbol〉 are drawn along the path. Possible symbols arethose listed under \plotsymbol <strong>in</strong> subsection 3.3.1. The default 〈size〉 is \po<strong>in</strong>tsize (<strong>in</strong>itially2pt) <strong>and</strong> the default 〈space〉 is \symbolspace (<strong>in</strong>itially 5pt).\plotnodes[〈size〉]{〈symbol〉}...This places a symbol (same possibilities as <strong>in</strong> \plotsymbol, see subsection 3.3.1) at each nodeof the path that follows. A node is one of the po<strong>in</strong>ts through which METAFONT draws its curve. Ifone of the macros \polyl<strong>in</strong>e{...} or \curve{...} follows, each of the po<strong>in</strong>ts listed is a node. Inthe \datafile comm<strong>and</strong> (subsection 3.7.3), each of the data po<strong>in</strong>ts <strong>in</strong> the file is. In the functionmacros (below) the po<strong>in</strong>ts correspond<strong>in</strong>g to 〈m<strong>in</strong>〉, 〈max〉 <strong>and</strong> each step <strong>in</strong> between are nodes. Theoptional 〈size〉 defaults to \po<strong>in</strong>tsize. If the comm<strong>and</strong> \clearsymbols has been issued then the<strong>in</strong>teriors of the open symbols are erased. The effect of someth<strong>in</strong>g like the follow<strong>in</strong>g is rather nice:\clearsymbols\plotnodes{Circle}\draw\polyl<strong>in</strong>e{...}This will first draw the polyl<strong>in</strong>e <strong>with</strong> solid l<strong>in</strong>es, <strong>and</strong> then the po<strong>in</strong>ts listed will be plotted as opencircles <strong>with</strong> the portion of the l<strong>in</strong>es <strong>in</strong>side the circles erased. One sees a series of open circlesconnected one to the next by l<strong>in</strong>e segments\dashpattern{〈name〉}{〈len1〉,〈len2〉,...,〈len2k〉}For more general dash patterns than \dashed <strong>and</strong> \dotted provide, <strong>MFPIC</strong> offers a generalizeddash<strong>in</strong>g comm<strong>and</strong>. Before us<strong>in</strong>g it, one must first establish a named dash<strong>in</strong>g pattern <strong>with</strong>the above comm<strong>and</strong>. The 〈name〉 can be any sequence of letters <strong>and</strong> underscores. Try to make itdist<strong>in</strong>ctive to avoid undo<strong>in</strong>g some <strong>in</strong>ternal variable. 〈len1〉 through 〈len2k〉 are an even number oflengths. The odd ones determ<strong>in</strong>e the lengths of dashes, the even ones the lengths of spaces. A dashof length 0pt means a dot. An alternat<strong>in</strong>g dot-dash pattern can be specified <strong>with</strong>\dashpattern{dotdash}{0pt,4pt,3pt,4pt}Note: S<strong>in</strong>ce pens have some thickness, dashes look a little longer, <strong>and</strong> spaces a little shorter, thanthe numbers suggest. If one wants dashes <strong>and</strong> spaces <strong>with</strong> the same length, one needs to take the


3.6 RENDERING MACROS 29size desired <strong>and</strong> <strong>in</strong>crease the spaces by the thickness of the draw<strong>in</strong>g pen (normally 0.5pt) <strong>and</strong>decrease the dashes by the same amount.If \dashpattern is used <strong>with</strong> an odd number of entries, a space of length 0pt is appended.This makes the last dash <strong>in</strong> one copy of the pattern abut the first dash <strong>in</strong> the next copy.\gendashed{〈name〉}...Once a dash<strong>in</strong>g pattern name has been def<strong>in</strong>ed, it can be used <strong>in</strong> this comm<strong>and</strong> to draw thecurve that follows it. Us<strong>in</strong>g a name not previously def<strong>in</strong>ed will cause the curve to be drawn <strong>with</strong>a solid l<strong>in</strong>e, <strong>and</strong> generate a METAFONT warn<strong>in</strong>g, but <strong>TEX</strong> will not compla<strong>in</strong>. If all the dimensions<strong>in</strong> a dash pattern are 0, \gendashed responds by draw<strong>in</strong>g a solid curve. The same is true if thepattern has only one entry.3.6.2 SHADING, FILLING, ERASING, CLIPPING, HATCHING.These macros can all be used to fill (or unfill) the <strong>in</strong>terior of closed paths, even if the paths crossthemselves. Fill<strong>in</strong>g an open curve is technically an error, but the METAFONT code responds bydraw<strong>in</strong>g the path <strong>and</strong> not do<strong>in</strong>g any fill<strong>in</strong>g. These macros replace the default render<strong>in</strong>g: when theyare used the outl<strong>in</strong>e will not be drawn unless an explicit prefix to do so is present.\gfill[〈color〉]...Fills <strong>in</strong> the subsequent closed path. Under METAPOST it fills <strong>with</strong> 〈color〉, which defaults tofillcolor. Under METAFONT it approximates the color <strong>with</strong> a shade of gray, clears the <strong>in</strong>terior,<strong>and</strong> then fills <strong>with</strong> a pattern of black <strong>and</strong> white pixels simulat<strong>in</strong>g gray.\gclear...Erases everyth<strong>in</strong>g <strong>in</strong>side the subsequent closed path (except text labels under some circumstances,see section 2.2 <strong>and</strong> 2.3). Under METAPOST it actually fills <strong>with</strong> the predef<strong>in</strong>ed color namedbackground. S<strong>in</strong>ce background is normally white, <strong>and</strong> so are most actual backgrounds, this isusually <strong>in</strong>dist<strong>in</strong>guishable from clear<strong>in</strong>g.\gclip...Erases everyth<strong>in</strong>g outside the subsequent closed path from the picture (except text labels undersome circumstances, see section 2.2 <strong>and</strong> 2.3).\shade[〈shadesp〉]...Shades the <strong>in</strong>terior of the subsequent closed path <strong>with</strong> dots. The diameter of the dots is theMETAFONT variable shadewd, set by the macro \shadewd{〈size〉}. Normally this is 0.5bp. Theoptional argument specifies the spac<strong>in</strong>g between (the centers of) the dots, which defaults to the<strong>TEX</strong> dimension \shadespace, <strong>in</strong>itially 1pt. If \shadespace is less than shadewd, the closedpath is filled <strong>with</strong> black, as if <strong>with</strong> \gfill. Under METAPOST this macro actually fills the path’s<strong>in</strong>terior <strong>with</strong> a shade of gray. The shade to use is computed based on \shadespace <strong>and</strong> shadewd.The default values of these parameters correspond to a gray level of about 78% of white. 10 TheMETAFONT version attempts to optimize the dots to the pixel grid correspond<strong>in</strong>g to the pr<strong>in</strong>tersresolution (to avoid generat<strong>in</strong>g dither l<strong>in</strong>es). Because this <strong>in</strong>volves round<strong>in</strong>g, it will happen thatvalues of \shadespace that are relatively close <strong>and</strong> at the same time close to shadewd produce10 If \shadewd is w <strong>and</strong> \shadespace is s, then the level of gray is 1 − (.88w/s) 2 , where 0 denotes black <strong>and</strong> 1 white.


3.6 RENDERING MACROS 30exactly the same shade. Most of the time, however, values of \shadespace that differ by at least20% will produce different patterns. The actual behavior for particular values of the parameters<strong>and</strong> particular pr<strong>in</strong>ter resolutions cannot be predicted, <strong>and</strong> we even make no guarantee it will notchange from one version of <strong>MFPIC</strong> to another.\polkadot[〈space〉]...Fills the <strong>in</strong>terior of a closed path <strong>with</strong> large dots. This is almost what \shade does, but thereare several differences. \shade is <strong>in</strong>tended solely to simulate a gray fill <strong>in</strong> METAFONT where theonly color is black. So it is optimized for small dots aligned to the pixel grid (<strong>in</strong> METAFONT).In METAPOST all it does is fill <strong>with</strong> gray <strong>and</strong> is <strong>in</strong>tended merely for compatibility. The macro\polkadot is <strong>in</strong>tended for large dots <strong>in</strong> any color, <strong>and</strong> so it optimizes spac<strong>in</strong>g (a nice hexagonalarray) <strong>and</strong> makes no attempt to align at the pixel level. The 〈space〉 defaults to the <strong>TEX</strong> dimension\polkadotspace, <strong>in</strong>itially 10pt. The diameter of the dots is the value of the METAFONT variablepolkadotwd, which can be set <strong>with</strong> \polkadotwd{〈size〉}, <strong>and</strong> is <strong>in</strong>itially 5bp. The dots arecolored <strong>with</strong> fillcolor. In METAFONT, nonblack values of fillcolor will produce shadeddots.\thatch[〈hatchsp〉,〈angle〉][〈color〉]...Fills a closed path <strong>with</strong> equally spaced parallel l<strong>in</strong>es at the specified angle. The thickness ofthe l<strong>in</strong>es is set by the macro \hatchwd. In the optional argument, 〈hatchsp〉 specifies the spacebetween l<strong>in</strong>es, which defaults to the <strong>TEX</strong> dimension \hatchspace, <strong>in</strong>itially 3pt. The 〈angle〉defaults to 0. The 〈color〉 defaults to hatchcolor. If \hatchspace is less than the l<strong>in</strong>e thickness,the closed path is filled <strong>with</strong> 〈color〉, as if <strong>with</strong> \gfill. If the first optional argument appears,both parts must be present, separated by a comma. For the color argument to be present, the otheroptional argument must also be present. However, if one wishes only to override the default colorone can use an empty first optional argument (completely empty, no spaces or comma).\lhatch[〈hatchsp〉][〈color〉]...Draws l<strong>in</strong>es shad<strong>in</strong>g <strong>in</strong> the subsequent closed path <strong>in</strong> a left-oblique hatched (upper left to lowerright) pattern. It is exactly the same as \thatch[〈hatchsp〉,-45][〈color〉]...\rhatch[〈hatchsp〉][〈color〉]...Draws l<strong>in</strong>es shad<strong>in</strong>g <strong>in</strong> the subsequent closed path <strong>in</strong> a right-oblique hatched (lower left toupper right) pattern. It is exactly the same as \thatch[〈hatchsp〉,45][〈color〉]...\hatch[〈hatchsp〉][〈color〉]...\xhatch[〈hatchsp〉][〈color〉]...Draws l<strong>in</strong>es shad<strong>in</strong>g <strong>in</strong> the subsequent closed path <strong>in</strong> a cross-hatched pattern. It is exactly thesame as \rhatch followed by \lhatch us<strong>in</strong>g the same 〈hatchsp〉 <strong>and</strong> 〈color〉.Hatch<strong>in</strong>g should normally be used very spar<strong>in</strong>gly, or never if alternatives are available (color,shad<strong>in</strong>g). Hatch<strong>in</strong>g at two different angles is, however, almost the only way to fill <strong>in</strong> two regionsthat automatically shows the overlapp<strong>in</strong>g region.3.6.3 CHANGING THE DEFAULT RENDERING.Render<strong>in</strong>g is the process of convert<strong>in</strong>g a geometric description <strong>in</strong>to a draw<strong>in</strong>g. In METAFONT,this means produc<strong>in</strong>g a bitmap (METAFONT stores these <strong>in</strong> picture variables), either by strok<strong>in</strong>g


3.7 FUNCTIONS AND PLOTTING. 31(draw<strong>in</strong>g) a path us<strong>in</strong>g a particular pen), or by fill<strong>in</strong>g a closed path. In METAPOST it means produc<strong>in</strong>ga POSTSCRIPT description of strokes <strong>with</strong> pens, <strong>and</strong> fills\setrender{〈<strong>TEX</strong> comm<strong>and</strong>s〉}Initially, <strong>MFPIC</strong> uses the \draw comm<strong>and</strong> (strok<strong>in</strong>g) as the default operation when a figure isto be rendered. However, this can be changed to any comb<strong>in</strong>ation of <strong>MFPIC</strong> render<strong>in</strong>g comm<strong>and</strong>s<strong>and</strong>/or other <strong>TEX</strong> comm<strong>and</strong>s, by us<strong>in</strong>g the \setrender comm<strong>and</strong>. This redef<strong>in</strong>ition is local <strong>in</strong>sidean mfpic environment, so it can be enclosed <strong>in</strong> braces to restrict its range. Outside an mfpicenvironment it is a global redef<strong>in</strong>ition.For example, after \setrender{\dashed\shade} the comm<strong>and</strong> \circle{(0,0),1} producesa shaded circle <strong>with</strong> a dashed outl<strong>in</strong>e. Any explicit render<strong>in</strong>g prefix overrides this default.3.6.4 EXAMPLES.It may be <strong>in</strong>structive, for the purpose of underst<strong>and</strong><strong>in</strong>g the syntax of shape-modifier <strong>and</strong> render<strong>in</strong>gprefixes, to consider two examples:\draw\shade\lclosed\l<strong>in</strong>es{...}which shades <strong>in</strong>side a polygon <strong>and</strong> draws its outl<strong>in</strong>e; <strong>and</strong>\shade\lclosed\draw\l<strong>in</strong>es{...}which draws all of the outl<strong>in</strong>e except the l<strong>in</strong>e segment supplied by \lclosed, then shades the<strong>in</strong>terior. Thus, <strong>in</strong> the first case the path is def<strong>in</strong>ed (by \l<strong>in</strong>es) then closed, then the result<strong>in</strong>gclosed path is shaded, then drawn; while <strong>in</strong> the second case the order is: def<strong>in</strong>ed, drawn, closed,shaded. In particular, what is drawn <strong>in</strong> the second case is the path not yet closed.3.7 Functions <strong>and</strong> Plott<strong>in</strong>g.In the follow<strong>in</strong>g macros, expressions like f (x), g(t) st<strong>and</strong> for any legal METAFONT expression, <strong>in</strong>which the only unknown variables are those <strong>in</strong>dicated (x <strong>in</strong> the first case, <strong>and</strong> t <strong>in</strong> the second).3.7.1 DEFINING FUNCTIONS\fdef{〈fcn〉}{〈param1〉,〈param2〉,...}{〈mf-expr〉}Def<strong>in</strong>es a METAFONT function 〈fcn〉 of the parameters 〈param1〉, 〈param2〉, ..., by the META-FONT expression 〈mf-expr〉 <strong>in</strong> which the only free parameters are those named. The return type ofthe function is the same as the type of the expression. What is allowed for the function name 〈fcn〉is more restrictive than METAFONT’s rule for variable names. Roughly speak<strong>in</strong>g, it should consistof letters <strong>and</strong> underscore characters only. (In particular, for those that know what this means,the name should have no suffixes.) Try to make the name dist<strong>in</strong>ctive to avoid redef<strong>in</strong><strong>in</strong>g <strong>in</strong>ternalMETAFONT comm<strong>and</strong>s.The expression 〈mf-expr〉 is passed directly <strong>in</strong>to the correspond<strong>in</strong>g METAFONT macro <strong>and</strong> <strong>in</strong>terpretedthere, so METAFONT’s rules for algebraic expressions apply. If \fdef occurs <strong>in</strong>side anmfpic environment, it is local to that environment, otherwise it is available to all subsequent mfpicenvironments.As an example, after \fdef{myfcn}{s,t}{s*t-t}, any place below where a METAFONTexpression is required, you can use myfcn(2,3) to mean 2*3-3 <strong>and</strong> myfcn(x,x) to mean x*x-x.


3.7 FUNCTIONS AND PLOTTING. 32Operations available <strong>in</strong>clude +, -, *, /, <strong>and</strong> ** (x**y= x y ), <strong>with</strong> ( <strong>and</strong> ) for group<strong>in</strong>g. Functionsalready available <strong>in</strong>clude the st<strong>and</strong>ard METAFONT functions round, floor, ceil<strong>in</strong>g, abs, sqrt,s<strong>in</strong>d, cosd, mlog, <strong>and</strong> mexp. Note that <strong>in</strong> METAFONT the operations * <strong>and</strong> ** have the same levelof precedence, so x*y**z means (xy) z . Use parentheses liberally!(Notes: The METAFONT trigonometric functions s<strong>in</strong>d <strong>and</strong> cosd take arguments <strong>in</strong> degrees;mlog(x)= 256lnx, <strong>and</strong> mexp is its <strong>in</strong>verse.) You can also def<strong>in</strong>e the function 〈fcn〉 by cases, us<strong>in</strong>gthe METAFONT conditional expressionif 〈boolean〉: 〈expr〉 elseif 〈boolean〉: ... else: 〈expr〉 fi.Relations available for the 〈boolean〉 part of the expression <strong>in</strong>clude =, , =.Complicated functions can be def<strong>in</strong>ed by a compound expression, which is a series of META-FONT statements, followed by an expression, all enclosed <strong>in</strong> the comm<strong>and</strong>s beg<strong>in</strong>group <strong>and</strong>endgroup. The \fdef comm<strong>and</strong> automatically supplies the group<strong>in</strong>g around the def<strong>in</strong>ition sothe user need not type them if the entire 〈mf-expr〉 is one such compound expression. METAFONTfunctions can call METAFONT functions, even recursively.Many common functions have been predef<strong>in</strong>ed <strong>in</strong> grafbase, which is a package of METAFONTmacros that implement <strong>MFPIC</strong>’s draw<strong>in</strong>g. These <strong>in</strong>clude all the usual trig functions t<strong>and</strong>, cotd,secd, cscd, which take angles <strong>in</strong> degrees, plus variants s<strong>in</strong>, cos, tan, cot, sec, <strong>and</strong> csc, whichtake angles <strong>in</strong> radians. Some <strong>in</strong>verse trig functions are also available, the follow<strong>in</strong>g produce angles<strong>in</strong> degrees: as<strong>in</strong>, acos, <strong>and</strong> atan, <strong>and</strong> the follow<strong>in</strong>g <strong>in</strong> radians: <strong>in</strong>vs<strong>in</strong>, <strong>in</strong>vcos, <strong>in</strong>vtan. Theexponential <strong>and</strong> hyperbolic functions: exp, s<strong>in</strong>h, cosh, tanh, <strong>and</strong> their <strong>in</strong>verses ln (or log),as<strong>in</strong>h, acosh, <strong>and</strong> atanh are also def<strong>in</strong>ed.3.7.2 PLOTTING FUNCTIONSThe plott<strong>in</strong>g macros take two or more arguments. They have an optional first argument, 〈spec〉,which determ<strong>in</strong>es whether a function is drawn smooth (as a METAFONT Bézier curve), or polygonal(as l<strong>in</strong>e segments)—if 〈spec〉 is p, the function will be polygonal. Otherwise the 〈spec〉 should bes, followed by an optional positive number no smaller than 0.75. In this case the function will besmooth <strong>with</strong> a tension equal to the number. See the \curve comm<strong>and</strong> (subsection 3.3.5) for anexplanation of tension. The default 〈spec〉 depends on the purpose of the macro.One compulsory argument conta<strong>in</strong>s three values 〈m<strong>in</strong>〉, 〈max〉 <strong>and</strong> 〈step〉 separated by commas.The <strong>in</strong>dependent variable of a function starts at the value 〈m<strong>in</strong>〉 <strong>and</strong> steps by 〈step〉 until reach<strong>in</strong>g〈max〉. If 〈max〉−〈m<strong>in</strong>〉 is not a whole number of steps, then round((〈max〉−〈m<strong>in</strong>〉)/〈step〉) equalsteps are used. One may have to experiment <strong>with</strong> the size of 〈step〉, s<strong>in</strong>ce METAFONT merelyconnects the po<strong>in</strong>ts correspond<strong>in</strong>g to these steps <strong>with</strong> what it considers to be a smooth curve.Smaller 〈step〉 gives better accuracy, but too small may cause the curve to exceed METAFONT’scapacity or slow down its process<strong>in</strong>g. Increas<strong>in</strong>g the tension may help keep the curve <strong>in</strong> l<strong>in</strong>e, butat the expense of reduced smoothness.There are one or more subsequent arguments, each of which is a METAFONT function or expressionas described above.\function[〈spec〉]{〈x m<strong>in</strong> 〉,〈x max 〉,〈∆x〉}{ f (x)}This plots f (x), a METAFONT numeric function or expression of one numeric argument, whichmust be denoted by a literal x. The default 〈spec〉 is s. For example\function{0,pi,pi/10}{s<strong>in</strong> x}


3.7 FUNCTIONS AND PLOTTING. 33draws the graph of s<strong>in</strong>x between 0 <strong>and</strong> π.\parafcn[〈spec〉]{〈t m<strong>in</strong> 〉,〈t max 〉,〈∆t〉}{(x(t),y(t))}\parafcn[〈spec〉]{〈t m<strong>in</strong> 〉,〈t max 〉,〈∆t〉}{〈pair-fcn〉}Plots the parametric path determ<strong>in</strong>ed by the last argument. This can be a pair of expressionsx(t) <strong>and</strong> y(t) enclosed <strong>in</strong> parentheses <strong>and</strong> separated by a comma, <strong>with</strong> the literal variable t. Alternatively,the last argument can be a METAFONT function or expression <strong>in</strong> t that returns a pair. Thedefault 〈spec〉 is s. For example\parafcn{0,1,.1}{(2t, t+t*t)}plots a smooth parabola from (0,0) to (2,2).\plrfcn[〈spec〉]{〈θ m<strong>in</strong> 〉,〈θ max 〉,〈∆θ〉}{ f (t)}Plots the polar function determ<strong>in</strong>ed by r = f (θ), where f is a METAFONT numeric function orexpression of one numeric argument, <strong>and</strong> θ varies from 〈θ m<strong>in</strong> 〉 to 〈θ max 〉 <strong>in</strong> steps of 〈∆θ〉. Each θvalue is <strong>in</strong>terpreted as an angle measured <strong>in</strong> degrees. In the expression f (t), the unknown t st<strong>and</strong>sfor θ. The default 〈spec〉 is s. For example\plrfcn{0,90,5}{s<strong>in</strong>d (2t)}draws one loop of a 4-petal rosette. If one needs radian measures, use someth<strong>in</strong>g like the follow<strong>in</strong>gto get the same graph:\plrfcn{0,pi/2*radian,pi/36*radian}{s<strong>in</strong> (2t/radian)}\btwnfcn[〈spec〉]{〈x m<strong>in</strong> 〉,〈x max 〉,〈∆x〉}{ f (x)}{g(x)}\btwnplrfcn[〈spec〉]{〈θ m<strong>in</strong> 〉,〈θ max 〉,〈∆θ〉}{ f (t)}{g(t)}The first one def<strong>in</strong>es a closed path surround<strong>in</strong>g the region between the two functions. The secondone does the same for two polar functions. That is (<strong>in</strong> both cases), the path follows the firstfunction (<strong>in</strong> order or <strong>in</strong>creas<strong>in</strong>g x or θ), thence along the straight l<strong>in</strong>e to the end of the second one,thence backwards along the second function (decreas<strong>in</strong>g x or θ) <strong>and</strong> f<strong>in</strong>ally along the straight l<strong>in</strong>e tothe start. The last two m<strong>and</strong>atory arguments, the functions, are specified exactly as <strong>in</strong> \function<strong>and</strong> \plrfcn, be<strong>in</strong>g numeric functions of one numeric argument x or t. Unlike the previous functionmacros, the default 〈spec〉 is p—these macros are <strong>in</strong>tended to be used for shad<strong>in</strong>g betweendrawn functions, a task for which smoothness is usually unnecessary. For example, the first l<strong>in</strong>ebelow\shade\btwnfcn{0,1,.1}{0}{x - x**2}\btwnplrfcn[s]{-30,30,5}{1}{2*cosd 2t}shades the area between the x-axis <strong>and</strong> the given parabola. The second draws the boundary of theregion between the circle r = 1 <strong>and</strong> one loop of the rosette r = 2cos2θ.Note: the effect of \btwnfcn could also be accomplished <strong>with</strong>\lclosed\connect\function{〈x m<strong>in</strong> 〉,〈x max 〉,〈∆x〉}{ f (x)}\reverse\function{〈x m<strong>in</strong> 〉,〈x max 〉,〈∆x〉}{g(x)}\endconnect


3.7 FUNCTIONS AND PLOTTING. 34\lclosed was described <strong>in</strong> subsection 3.5.1 <strong>and</strong> the \connect. . . \endconnect pair was described<strong>in</strong> subsection 3.5.2.\belowfcn[〈spec〉]{〈x m<strong>in</strong> 〉,〈x max 〉,〈∆x〉}{ f (x)}\plrregion[〈spec〉]{〈θ m<strong>in</strong> 〉,〈θ max 〉,〈∆θ〉}{ f (t)}These are essentially more efficient versions of \btwnfcn <strong>and</strong> \btwnplrfcn where the firstfunction is just 0. The first of these, \belowfcn, def<strong>in</strong>es a region bounded by the x-axis, the graphof y = f (x) <strong>and</strong> the two vertical l<strong>in</strong>es x = x m<strong>in</strong> <strong>and</strong> x = x max . (The region is not actually belowy = f (x) unless f (x) ≥ 0 throughout the <strong>in</strong>terval.) The second def<strong>in</strong>es the boundary of the regionbounded by the polar function r = f (θ) <strong>and</strong> the two rays θ = θ m<strong>in</strong> <strong>and</strong> θ = θ max .The arguments of these comm<strong>and</strong> are the same as the correspond<strong>in</strong>g nonclosed versions,\function <strong>and</strong> \plrfcn, except the default for the optional agument is [p]. Aga<strong>in</strong>, this is becauseit is ma<strong>in</strong>ly for shad<strong>in</strong>g. However, draw<strong>in</strong>g the boundary is often needed:\shade\plrregion{0,90,5}{s<strong>in</strong>d (2t)}\plrregion[s]{0,90,5}{s<strong>in</strong>d (2t)}shades one loop of the 4-petal rosette, <strong>and</strong> then draws it..\levelcurve[〈spec〉]{〈seed〉,〈step〉} {〈<strong>in</strong>equality〉}This calculates a level curve of some function F(x,y). There are several requirements forthis to work. To obta<strong>in</strong> the curve F(x,y) = C, the {〈<strong>in</strong>equality〉} must be {F(x,y) > C} or{F(x,y) < C}. 11 The level curve must surround the po<strong>in</strong>t given by 〈seed〉 <strong>and</strong> the <strong>in</strong>equalitymust be true at this seed po<strong>in</strong>t.The comm<strong>and</strong> works by search<strong>in</strong>g rightward from 〈seed〉 until it encounters the first po<strong>in</strong>t onthe level curve. It then tries to f<strong>in</strong>d a nearby po<strong>in</strong>t on the level curve <strong>and</strong> jo<strong>in</strong>s it to the first one,<strong>and</strong> cont<strong>in</strong>ues similarly until it f<strong>in</strong>ds it has returned near the start<strong>in</strong>g po<strong>in</strong>t. The mean<strong>in</strong>g of “nearbypo<strong>in</strong>t on the level curve” is the <strong>in</strong>tersection of the level curve <strong>with</strong> a circle of radius 〈step〉 centeredat the previously found po<strong>in</strong>t. If the region def<strong>in</strong>ed by the <strong>in</strong>equality extends beyond the bounds ofthe picture (as set by the \mfpic comm<strong>and</strong>), the region is truncated <strong>and</strong> the result<strong>in</strong>g curve willfollow along the picture’s border.S<strong>in</strong>ce the algorithm only approximates the level set, a tolerance (how close the po<strong>in</strong>ts are toactually be<strong>in</strong>g on the level curve) is chosen which gives two decimal places more accuracy than〈step〉. The value of 〈step〉 is <strong>in</strong>terpreted <strong>in</strong> graph coord<strong>in</strong>ates <strong>and</strong> so should be a pure number.The [〈spec〉] is either [p], <strong>in</strong> which case the calculated po<strong>in</strong>ts are jo<strong>in</strong>ed <strong>with</strong> straight l<strong>in</strong>es, or[s〈tension〉] as <strong>in</strong> \function. The default is the same as [s]: a smooth curve <strong>with</strong> the currentdefault tension.In general, choos<strong>in</strong>g a 〈step〉 that corresponds to a few millimeters works reasonably well. Forexample, if the graph unit is 1cm (for example, \mfpicunit=1cm <strong>and</strong> no scal<strong>in</strong>g is used), then〈step〉 = 0.5 might be a reasonable first choice. If the level set is reasonably smooth <strong>and</strong> [s] isused, then the result will match the actual curve to <strong>with</strong><strong>in</strong> .005cm, which is approximately .14pt,which is less than half the thickness of the st<strong>and</strong>ard pen used to draw it. If you only <strong>in</strong>tend to fillit, you might want a little more accuracy, say a step of 0.1. There is a lower limit: there should notbe more than 2000 steps <strong>in</strong> the curve. In a figure 10-by-10 graph units, a level curve <strong>with</strong>out too11 A non-strict <strong>in</strong>equality such as >= can be used, but the result will not be significantly different.


3.7 FUNCTIONS AND PLOTTING. 35much oscillation could be about 80 units <strong>in</strong> length <strong>and</strong> a step size of .04 would produce about 2000steps.As a special case, if 〈step〉 is 0, the maximum of width <strong>and</strong> height of the figure (as given by thearguments to the mfpic environment) is divided by 100. For example, <strong>in</strong> a 5-by-10 graph, giv<strong>in</strong>ga step size of 0 will actually select 〈step〉 = 10/100 = 0.1.The algorithm used will produce <strong>in</strong>correct results if parts of the curve that are distant (as measuredalong the curve) are closer than 〈step〉 <strong>in</strong> actual distance.3.7.3 PLOTTING EXTERNAL DATA FILES\datafile[〈spec〉]{〈file〉}\smoothdata[〈tension〉]\unsmoothdata\datafile def<strong>in</strong>es a curve connect<strong>in</strong>g the po<strong>in</strong>ts listed <strong>in</strong> the file 〈file〉. (The context makes itclear whether this mean<strong>in</strong>g of \datafile or that of subsection 3.3.2 is meant.) The 〈spec〉 may bep to produce a polygonal path, or s followed by a tension value (as <strong>in</strong> \curve) to produce a smoothpath. If no 〈spec〉 is given, the default is <strong>in</strong>itially p, but \smoothdata may be used to change this.Thus, after the comm<strong>and</strong> \smoothdata[〈tension〉] the default 〈spec〉 is changed to s〈tension〉.If the tension parameter is not supplied it defaults to 1.0 (or the value set by the \settensioncomm<strong>and</strong> if one has been used).The comm<strong>and</strong> \unsmoothdata restores the default 〈spec〉 to p.By default, each non-blank l<strong>in</strong>e <strong>in</strong> the file is assumed to conta<strong>in</strong> at least two numbers, separatedby whitespace (blanks or tabs). The first two numbers on each l<strong>in</strong>e are assumed to represent the x-<strong>and</strong> y-coord<strong>in</strong>ates of a po<strong>in</strong>t. Initial blank l<strong>in</strong>es <strong>in</strong> the file are ignored, as are comments. The commentcharacter <strong>in</strong> the data file is assumed to be %, but it can be reset us<strong>in</strong>g \mfpdatacomment (below).Any blank l<strong>in</strong>e other than at the start of the file causes the curve to term<strong>in</strong>ate. The \datafilecomm<strong>and</strong> may be preceded by any of the prefix comm<strong>and</strong>s, so that, for example, a closed curvecould be formed <strong>with</strong> \lclosed\datafile{data.dat}.The \datafile comm<strong>and</strong> has another use, <strong>in</strong>dependent of the above description. We saw <strong>in</strong>subsection 3.3.2 that any <strong>MFPIC</strong> comm<strong>and</strong> (other than one that pr<strong>in</strong>ts text labels) that takes as itslast argument a list of po<strong>in</strong>ts (or numerical values) separated by commas, can have that list replaced<strong>with</strong> a reference to an external data file. For example, if a file ptlist.dat conta<strong>in</strong>s two or morenumerical values per l<strong>in</strong>e separated by whitespace, then one can draw a dot at each of the po<strong>in</strong>tscorrespond<strong>in</strong>g to the first pair of numbers on each l<strong>in</strong>e <strong>with</strong> the follow<strong>in</strong>g.\po<strong>in</strong>t\datafile{ptlist.dat}In fact there is no essential difference between ‘\datafile[p]’ <strong>and</strong> ‘\polyl<strong>in</strong>e\datafile’,<strong>and</strong> no difference between ‘\datafile[s]’ <strong>and</strong> ‘\curve\datafile’.Here is the full list of <strong>MFPIC</strong> macros that allow this usage of \datafile:• Numeric data: \piechart, \barchart, \numericarray, <strong>and</strong> all the axis markscomm<strong>and</strong>s.• Po<strong>in</strong>t or vector data: \po<strong>in</strong>t, \plotsymbol, \polyl<strong>in</strong>e, \polygon, \fcncurve,\curve, \cyclic, \convexcurve, \convexcyclic, \turtle, \qspl<strong>in</strong>e,\closedqspl<strong>in</strong>e, \cspl<strong>in</strong>e, \closedcspl<strong>in</strong>e, \mfbezier, \closedmfbezier,


3.7 FUNCTIONS AND PLOTTING. 36\qbeziers, \closedqbeziers, \pairarray, \computedspl<strong>in</strong>e,\closedcomputedspl<strong>in</strong>e, \fcnspl<strong>in</strong>e <strong>and</strong> \periodicfcnspl<strong>in</strong>e.\mfpdatacomment\〈char〉Changes 〈char〉 to a comment character <strong>and</strong> changes the usual <strong>TEX</strong> comment character % to anord<strong>in</strong>ary character while read<strong>in</strong>g a datafile for draw<strong>in</strong>g.\us<strong>in</strong>g{〈<strong>in</strong>-pattern〉}{〈out-pattern〉}Used to change the assumptions about the format of the data file. For example, if there arefour numbers on each l<strong>in</strong>e separated by commas, to plot the third aga<strong>in</strong>st the second (<strong>in</strong> that order)you can say \us<strong>in</strong>g{#1,#2,#3,#4}{(#3,#2)}. This means the follow<strong>in</strong>g: Everyth<strong>in</strong>g ona l<strong>in</strong>e up to the first comma is assigned to parameter #1, everyth<strong>in</strong>g from there up to the secondcomma is assigned to parameter #2, etc. Everyth<strong>in</strong>g from the third comma to the end of l<strong>in</strong>e isassigned to #4. When the l<strong>in</strong>e is processed by <strong>TEX</strong> a METAFONT pair is produced represent<strong>in</strong>ga po<strong>in</strong>t on the curve. METAFONT pair expressions can be used <strong>in</strong> the output portion of \us<strong>in</strong>g.For example \us<strong>in</strong>g{#1,#2,#3}{(#2,#1)/10} or even \us<strong>in</strong>g{#1 #2 #3}{polar(#1,#2)}if the data are polar coord<strong>in</strong>ates. The default assumptions of the \datafile comm<strong>and</strong> (i.e., spaceseparated numbers, the first two determ<strong>in</strong><strong>in</strong>g each po<strong>in</strong>t) correspond to the sett<strong>in</strong>g\us<strong>in</strong>g{#1 #2 #3}{(#1,#2)}The \us<strong>in</strong>g comm<strong>and</strong> cannot normally be used <strong>in</strong> the replacement text of another comm<strong>and</strong>. Orrather, it can be so used, but then each # has to be doubled. If a \us<strong>in</strong>g declaration occurs <strong>in</strong> anmfpic environment it is local to that environment. Otherwise it affects all subsequent ones.\sequenceAs a special case, you can plot any number aga<strong>in</strong>st its sequence position, <strong>with</strong> someth<strong>in</strong>g like\us<strong>in</strong>g{#1 #2}{(\sequence,#1)}. Here, the macro \sequence will take on the values 1, 2,etc. as l<strong>in</strong>es are read from the file.\us<strong>in</strong>gpairdefault\us<strong>in</strong>gnumericdefaultThe comm<strong>and</strong> \us<strong>in</strong>gpairdefault restores the above default for pair data. The comm<strong>and</strong>\us<strong>in</strong>gnumericdefault is the equivalent of \us<strong>in</strong>g{#1 #2}{#1}.Note that the default value of \us<strong>in</strong>g appears to reference three arguments. If there are onlytwo numbers on a l<strong>in</strong>e separated by whitespace, this will still work because of <strong>TEX</strong>’s argumentmatch<strong>in</strong>g rules. <strong>TEX</strong>’s file read<strong>in</strong>g mechanism normally converts the EOL to a space, but thereare exceptions so <strong>MFPIC</strong> <strong>in</strong>ternally adds a space at the end of each l<strong>in</strong>e read <strong>in</strong> to be on the safeside. Then the default def<strong>in</strong>ition of \us<strong>in</strong>g reads everyth<strong>in</strong>g up to the first space as #1 (whitespaceis normally compressed to a s<strong>in</strong>gle space by <strong>TEX</strong>’s read<strong>in</strong>g mechanism), then everyth<strong>in</strong>g to thesecond space (the one added at the end of the l<strong>in</strong>e, perhaps) is #2, then everyth<strong>in</strong>g to the EOL is#3. This might assign an empty argument to #3, but it is discarded anyway.If the numerical data conta<strong>in</strong> percentages <strong>with</strong> explicit % signs, then choose another commentcharacter <strong>with</strong> \mfpdatacomment. This will change % to an ord<strong>in</strong>ary character <strong>in</strong> the data file.However, <strong>in</strong> your \us<strong>in</strong>g comm<strong>and</strong> it would still be read as a comment. The follow<strong>in</strong>g exampleshows how to overcome this:


3.7 FUNCTIONS AND PLOTTING. 37\makepercentother\us<strong>in</strong>g{#1% #2 #3}{(#1/100,#2)}\makepercentcommentHere is an analysis of the mean<strong>in</strong>g of this example: everyth<strong>in</strong>g <strong>in</strong> a l<strong>in</strong>e, up to the first percentfollowed by a space is assigned to parameter #1, everyth<strong>in</strong>g from there to the next space isassigned to #2 <strong>and</strong> the rest of the l<strong>in</strong>e (which may be empty) is #3. On the output side <strong>in</strong> theabove example, the percentage is divided by 100 to convert it to a fraction, <strong>and</strong> plotted aga<strong>in</strong>st thesecond parameter. Note: normal comments should not be used between \makepercentother <strong>and</strong>\makepercentcomment, for obvious reasons. Moreover, the above construction will fail <strong>in</strong>sidethe argument of another comm<strong>and</strong>.\plotdata[〈spec〉]{〈file〉}This plots several curves from a s<strong>in</strong>gle file. The 〈spec〉 <strong>and</strong> the comm<strong>and</strong> \smoothdata havethe same effect on each curve as <strong>in</strong> the \datafile comm<strong>and</strong>. The data for each curve is a successionof nonblank l<strong>in</strong>es separated from the data for the next curve by a s<strong>in</strong>gle blank l<strong>in</strong>e. A pair ofsuccessive blank l<strong>in</strong>es is treated as the end of the data. No prefix macros are permitted <strong>in</strong> front of\plotdata.Each successive curve <strong>in</strong> the data file is drawn differently. By default, the first is drawn as a solidl<strong>in</strong>e the next dashed, the third dotted, etc., through a total of six different l<strong>in</strong>e types. A \gendashedcomm<strong>and</strong> is used <strong>with</strong> predef<strong>in</strong>ed dash patterns named dashtype0 through dashtype5. This behaviorcan be changed <strong>with</strong>:\coloredl<strong>in</strong>es\po<strong>in</strong>tedl<strong>in</strong>es\datapo<strong>in</strong>tsonly\dashedl<strong>in</strong>esThe comm<strong>and</strong> \coloredl<strong>in</strong>es changes to cycl<strong>in</strong>g through eight different colors start<strong>in</strong>g <strong>with</strong>black (hey, black is a color too). This has an effect only for METAPOST. The sole exceptionto the general rule that all curves are drawn <strong>in</strong> drawcolor is the \plotdata comm<strong>and</strong> after\coloredl<strong>in</strong>es has been issued. The comm<strong>and</strong> \po<strong>in</strong>tedl<strong>in</strong>es causes \plotdata to use therender<strong>in</strong>g comm<strong>and</strong> \plot, cycl<strong>in</strong>g through n<strong>in</strong>e symbols. The comm<strong>and</strong> \datapo<strong>in</strong>tsonlycauses \plotdata to use \plotnodes{〈symbol〉} comm<strong>and</strong>s to plot the data po<strong>in</strong>ts only. (Seethe Appendix for more details.) The comm<strong>and</strong> \dashedl<strong>in</strong>es restores the default. The comm<strong>and</strong>\coloredl<strong>in</strong>es will produce a warn<strong>in</strong>g under the metafont option <strong>and</strong> substitute \dashedl<strong>in</strong>es.If, for some reason, you do not like the default start<strong>in</strong>g l<strong>in</strong>e style (say you want to start <strong>with</strong> acolor other than black), you can use one of the follow<strong>in</strong>g comm<strong>and</strong>s.\mfpl<strong>in</strong>etype{〈num〉}, or\mfpl<strong>in</strong>estyle{〈num〉}Here 〈num〉 is a non-negative number, less than the number of different draw<strong>in</strong>g types available.The four previous comm<strong>and</strong>s reset the number to 0, so if you use one of them, issue \mfpl<strong>in</strong>etypeafter it. The different l<strong>in</strong>e styles are numbered start<strong>in</strong>g from 0. If two or more \plotdata comm<strong>and</strong>sare used <strong>in</strong> the same mfpic environment, the number<strong>in</strong>g <strong>in</strong> each cont<strong>in</strong>ues where the onebefore left off (unless you issue one of the comm<strong>and</strong>s above <strong>in</strong> between). \mfpl<strong>in</strong>estyle means


3.8 LABELS AND CAPTIONS. 38the same as \mfpl<strong>in</strong>etype, <strong>and</strong> is <strong>in</strong>cluded for compatibility. See the Appendix to f<strong>in</strong>d out whatdash pattern, color or symbol corresponds to each number by default. The comm<strong>and</strong>s below canbe used to change the default dashes, colors, or symbols.\reconfigureplot{dashes}{〈pat 1 〉,...,〈pat n 〉}\reconfigureplot{colors}{〈clr 1 〉,...,〈clr n 〉}\reconfigureplot{symbols}{〈symb 1 〉,...,〈symb n 〉}The first argument of \reconfigureplot is the render<strong>in</strong>g method to be changed: dashes,colors, or symbols. The second argument is a list of dash patterns, colors, or symbols. The dashpatterns should be names of patterns def<strong>in</strong>ed through the use of \dashpattern. The colors canbe any color names already known to METAPOST, or def<strong>in</strong>ed through \mfpdef<strong>in</strong>ecolor. Thesymbols can be any of those listed <strong>with</strong> the \plotsymbol comm<strong>and</strong> (see subsection 3.3.1), or anyknown METAFONT path variable. The colors can also be METAPOST expressions of type color, <strong>and</strong>the symbols can be expressions of type path. With<strong>in</strong> a mfpic environment, the changes made arelocal to that environment. Outside, they affect all subsequent environments.Us<strong>in</strong>g \reconfigureplot{colors} under the metafont option will have no effect, but mayproduce an error from METAFONT unless the colors used conform to the guidel<strong>in</strong>es <strong>in</strong> subsection3.4.5. This also holds for \defaultplot{colors} (below).\defaultplot{dashes}\defaultplot{colors}\defaultplot{symbols}The comm<strong>and</strong> \defaultplot restores the built-<strong>in</strong> defaults for the <strong>in</strong>dicated method of render<strong>in</strong>g<strong>in</strong> \plotdata.The comm<strong>and</strong>s \us<strong>in</strong>g, \mfpdatacomment <strong>and</strong> \sequence have the same mean<strong>in</strong>g here (for\plotdata) as they do for \datafile (above). The sequence number<strong>in</strong>g for \sequence startsover <strong>with</strong> each new curve.3.8 Labels <strong>and</strong> Captions.3.8.1 SETTING <strong>TEX</strong>T.If option metafont is <strong>in</strong> effect macros \tlabel, \tlabels, \axislabels <strong>and</strong> \tcaption do notaffect the METAFONT file (〈file〉.mf) at all, but are added to the picture by <strong>TEX</strong>. If metapost is <strong>in</strong>effect but mplabels is not, they do not affect the METAPOST file. In these cases, if these macrosare the only changes or additions to your document, there is no need to repeat the process<strong>in</strong>g <strong>with</strong>METAFONT or METAPOST nor the reprocess<strong>in</strong>g <strong>with</strong> <strong>TEX</strong> <strong>in</strong> order to complete your <strong>TEX</strong> document.\tlabel[〈just〉](〈x〉,〈y〉){〈labeltext〉}\tlabel[〈just〉]{〈pair-list〉}{〈label text〉}\tlabels{〈params 1 〉 〈params 2 〉 ...}Places <strong>TEX</strong> labels on the graph. (Not to be confused <strong>with</strong> LA<strong>TEX</strong>’s \label comm<strong>and</strong>.) Thespecial form \tlabels (note the plural) essentially just applies \tlabel to each set of parameterslisted <strong>in</strong> its argument. That is, each 〈params k 〉 is a valid set of parameters for a \tlabel comm<strong>and</strong>.These can be separated by spaces, newl<strong>in</strong>es, or noth<strong>in</strong>g at all. They should not be separated byblank l<strong>in</strong>es.


3.8 LABELS AND CAPTIONS. 39The last required parameter is ord<strong>in</strong>ary <strong>TEX</strong> text. The pair (〈x〉,〈y〉) gives the coord<strong>in</strong>ates of apo<strong>in</strong>t <strong>in</strong> the graph where the text will be placed. It may optionally be enclosed <strong>in</strong> braces. In fact, thesecond syntax may be used if mplabels is <strong>in</strong> effect, where 〈pair-list〉 is any expression recognizedas a pair by METAPOST, or a comma-separated list of such pairs.The optional parameter [〈just〉] specifies the justification, the relative placement of the label<strong>with</strong> respect to the po<strong>in</strong>t (〈x〉,〈y〉). It is a two-character sequence where the first character is oneof t (top), c (center), b (bottom), or B (Basel<strong>in</strong>e), to specify vertical placement, <strong>and</strong> the secondcharacter is one of l (left), c (center), or r (right), to specify horizontal placement. These lettersspecify what part of the text is to be placed at the given po<strong>in</strong>t, so r puts the right end of the textthere—which means the text will be left of the po<strong>in</strong>t. The default justification is [Bl].When mplabels is <strong>in</strong> effect, the two characters may optionally be followed by a number, specify<strong>in</strong>gan angle <strong>in</strong> degrees to rotate the text about the po<strong>in</strong>t (〈x〉,〈y〉). If the angle is supplied<strong>with</strong>out mplabels it is ignored after a warn<strong>in</strong>g. If the angle is absent, there is no rotation. Note thatthe rotation takes place after the placement <strong>and</strong> uses the given po<strong>in</strong>t as the center of rotation. Forexample, [cr] will place the text left of the po<strong>in</strong>t, while [cr180] will rotate it around to the rightside of the po<strong>in</strong>t (<strong>and</strong> upsidedown, of course).There should be no spaces before, between, or after the first two characters. However the number,if present, is only required to be a valid METAPOST numerical expression conta<strong>in</strong><strong>in</strong>g no bracketcharacters; as such, it may conta<strong>in</strong> some spaces (e.g., around operations as <strong>in</strong> 45 + 30).A multil<strong>in</strong>e \tlabel may be specified by explicit l<strong>in</strong>e breaks, which are <strong>in</strong>dicated by the \\comm<strong>and</strong> or the \cr comm<strong>and</strong>. This is a very rudimentary feature. By default it left justifies thel<strong>in</strong>es <strong>and</strong> causes \tlabel to redef<strong>in</strong>e \\. One can center a l<strong>in</strong>e by putt<strong>in</strong>g \hfil as the first th<strong>in</strong>g<strong>in</strong> the l<strong>in</strong>e, <strong>and</strong> right justify by putt<strong>in</strong>g \hfill there (these are <strong>TEX</strong> primitives). Redef<strong>in</strong><strong>in</strong>g \\can <strong>in</strong>terfere <strong>with</strong> LA<strong>TEX</strong>’s def<strong>in</strong>ition. For better control <strong>in</strong> LA<strong>TEX</strong> use \shortstack <strong>in</strong>side the label(or a tabular environment or some other environment which always <strong>in</strong>itializes \\ <strong>with</strong> its owndef<strong>in</strong>ition).If the label goes beyond the bounds of the graph <strong>in</strong> any direction, the space reserved for thegraph is exp<strong>and</strong>ed to make room for it. (Note: this behavior is very much different from that of theLA<strong>TEX</strong> picture environment.)If the mplabels option is <strong>in</strong> effect, \tlabel will write a btex ... etex group to the outputfile, allow<strong>in</strong>g METAPOST to arrange for typesett<strong>in</strong>g the label. Normally, the label becomes part ofthe picture, rather than be<strong>in</strong>g laid on top of it, <strong>and</strong> can be covered up by any fill<strong>in</strong>g macros thatfollow, or clipped off by \gclear or \gclip. However, under the overlaylabels option (or after thecomm<strong>and</strong> \overlaylabels), labels are saved <strong>and</strong> added to the picture at the very end. This mayprevent some special effects, but it makes the behavior of labels much more consistent through allthe 12 permissable sett<strong>in</strong>gs of the options metapost, mplabels, clip, <strong>and</strong> truebbox.\everytlabel{〈<strong>TEX</strong>-code〉}One problem <strong>with</strong> multi-l<strong>in</strong>e \tlabels is that each l<strong>in</strong>e of their contents constitutes a separategroup. This makes it difficult to change the \basel<strong>in</strong>eskip (for example) <strong>in</strong>side a label. Thecomm<strong>and</strong> \everytlabel saves it’s contents <strong>in</strong> a token register <strong>and</strong> the code is issued <strong>in</strong> each\tlabel, as the last th<strong>in</strong>g before the actual l<strong>in</strong>e(s) of text. Any switch you want to apply to everyl<strong>in</strong>e can be supplied. For example\everytlabel{\bf\basel<strong>in</strong>eskip 10pt}


3.8 LABELS AND CAPTIONS. 40will make every l<strong>in</strong>e of every \tlabel’s text come out bold <strong>with</strong> 10 po<strong>in</strong>t basel<strong>in</strong>es. The effect of\everytlabel is local to the mfpic environment, if it is issued <strong>in</strong>side one. Note that each l<strong>in</strong>e ofa tlabel is wrapped <strong>in</strong> a box, but the comm<strong>and</strong>s of \everytlabel are outside all of them, so noactual text should be produced by the contents of \everytlabel.Us<strong>in</strong>g \tlabel <strong>with</strong>out an optional argument is equivalent to specify<strong>in</strong>g [Bl]. Use the follow<strong>in</strong>gcomm<strong>and</strong> to change this behavior.\tlabeljustify{〈just〉}After this comm<strong>and</strong> the placement of all subsequent labels <strong>with</strong>out optional argument will beas specified <strong>in</strong> this comm<strong>and</strong>. For example, \tlabeljustify{cr45} would cause all subsequent\tlabel comm<strong>and</strong>s lack<strong>in</strong>g an optional argument to be placed as if the argument [cr45] wereused <strong>in</strong> each. If mplabels is not <strong>in</strong> effect at the time of this comm<strong>and</strong>, the rotation part will be saved<strong>in</strong> case that option is turned on later, but a warn<strong>in</strong>g message will be issued. Without mplabels, therotation is ignored by \tlabel .\tlabeloffset{〈hlen〉}{〈vlen〉}\tlpo<strong>in</strong>tsep{〈len〉}\tlpathsep{〈len〉}\tlabelsep{〈len〉}The first comm<strong>and</strong> causes all subsequent \tlabel comm<strong>and</strong>s to shift the label right by 〈hlen〉<strong>and</strong> up by 〈vlen〉 (negative lengths cause it to be shifted left <strong>and</strong> down, respectively).The \tlpo<strong>in</strong>tsep comm<strong>and</strong> causes labels to be shifted by the given amount <strong>in</strong> a directionthat depends on the optional position<strong>in</strong>g parameter. For example, if the first letter is t the label isshifted down by the amount 〈len〉 <strong>and</strong> if the second letter is l it is also shifted right. In all cases itis shifted away from the po<strong>in</strong>t of placement (unless the dimension is negative). If c or B is the firstparameter, no vertical shift takes place, <strong>and</strong> if c is the second, there is no horizontal shift. This is<strong>in</strong>tended to be used <strong>in</strong> cases where someth<strong>in</strong>g has been drawn at that particular po<strong>in</strong>t, <strong>in</strong> order toseparate the text from the draw<strong>in</strong>g.Prior to version 0.8, this separation also def<strong>in</strong>ed the separation between the label <strong>and</strong> thosecurves designed to frame the label such as \tlabelrect (subsection 3.8.2). Now the two separationsare <strong>in</strong>dependent <strong>and</strong> \tlpathsep is used to set the separation between the label <strong>and</strong> suchpaths.For backward compatability, the comm<strong>and</strong> \tlabelsep is still available <strong>and</strong> sets both separationsto the same value.\axislabels{〈axis〉}[〈just〉]{{〈text 1 〉}〈n 1 〉,{〈text 2 〉}〈n 2 〉,...}This comm<strong>and</strong> places the given <strong>TEX</strong> text (〈text k 〉) at the given positions (〈n k 〉) on the givenaxis, 〈axis〉, which must be a s<strong>in</strong>gle letter <strong>and</strong> one of l, b, r, t, x, or y. The text is placed as<strong>in</strong> \tlabels (<strong>in</strong>clud<strong>in</strong>g the tak<strong>in</strong>g <strong>in</strong>to account of \tlpo<strong>in</strong>tsep <strong>and</strong> \tlableoffset), exceptthat the default justification depends on the axis (the sett<strong>in</strong>gs of \tlabeljustify are ignored).In the case of the border axes, the default is to place the label outside the axis <strong>and</strong> centered. So,for example, for the bottom axis it is [tc]. The defaults for the x- <strong>and</strong> y-axis are below <strong>and</strong>left, respectively. The optional 〈just〉 can be used to change this. For example, to place the labels<strong>in</strong>side the left border axis, use [cl]. If mplabels is <strong>in</strong> effect, rotations can be <strong>in</strong>cluded <strong>in</strong> thejustification parameter. For example, to place the text str<strong>in</strong>gs ‘first’, ‘second’ <strong>and</strong> ‘third’ just below


3.8 LABELS AND CAPTIONS. 41the positions 1, 2 <strong>and</strong> 3 on the x-axis, rotated so they read upwards at a 90 degree angle, one canuse \axislabels{x}[cr90]{{first}1, {second}2, {third}3}.\plottext[〈just〉]{〈text〉}{(x 0 ,y 0 ), (x 1 ,y 1 ), ...}Similar <strong>in</strong> effect to \po<strong>in</strong>t <strong>and</strong> \plotsymbol (but <strong>with</strong>out requir<strong>in</strong>g METAFONT), \plottextplaces a copy of 〈text〉 at each of the listed po<strong>in</strong>ts. It simply issues multiple \tlabel comm<strong>and</strong>s<strong>with</strong> the same text <strong>and</strong> optional parameter, but at the different po<strong>in</strong>ts listed. This is <strong>in</strong>tended to plota set of po<strong>in</strong>ts <strong>with</strong> a s<strong>in</strong>gle letter or font symbol (<strong>in</strong>stead of a METAFONT generated shape). Like\axislabels, this does not respond to the sett<strong>in</strong>g of \tlabeljustify. It has a default sett<strong>in</strong>gof [cc] if the optional argument is omitted. The po<strong>in</strong>ts may be <strong>MetaPost</strong> pair expressions undermplabels, but they must not be <strong>in</strong>dividually enclosed <strong>in</strong> braces. (This requirement is new <strong>with</strong>version 0.7; prior to that pairs <strong>in</strong> braces didn’t work reliably anyway.) This comm<strong>and</strong> is actuallyunnecessary under mplabels as the pla<strong>in</strong> \tlabel comm<strong>and</strong> can then be given a list of po<strong>in</strong>ts. The\tlabel comm<strong>and</strong> is more efficient, <strong>and</strong> \plottext is converted to it <strong>in</strong>ternally.\mfpverbtex{〈<strong>TEX</strong>-cmds〉}This writes a verbatimtex block to the .mp file. It makes sense only if the mplabels optionis used <strong>and</strong> so only for METAPOST. The 〈<strong>TEX</strong>-cmds〉 <strong>in</strong> the argument are written to the .mp file,preceded by the METAPOST comm<strong>and</strong> verbatimtex <strong>and</strong> followed by etex. L<strong>in</strong>e breaks <strong>with</strong><strong>in</strong>the 〈<strong>TEX</strong>-cmd〉 are preserved. The \mfpverbtex comm<strong>and</strong> must come before any \tlabel that isto be affected by it. Any sett<strong>in</strong>gs common to all mfpic environments should be <strong>in</strong> a \mfpverbtexcomm<strong>and</strong> preced<strong>in</strong>g all such environments. It may be issued at any po<strong>in</strong>t after <strong>MFPIC</strong> is loaded, <strong>and</strong>any number of times. If it is issued before \opengraphsfile, its contents are saved <strong>and</strong> writtenby that comm<strong>and</strong>. Therefore, it should occur only once before the \opengraphsfile comm<strong>and</strong>.Because of the way METAPOST h<strong>and</strong>les verbatimtex material, the effects cannot be constra<strong>in</strong>edby any group<strong>in</strong>g unless one places <strong>TEX</strong> group<strong>in</strong>g comm<strong>and</strong>s <strong>with</strong><strong>in</strong> 〈<strong>TEX</strong>-cmds〉. However,<strong>MFPIC</strong> itself places group<strong>in</strong>g comm<strong>and</strong>s <strong>in</strong>to the output file at the beg<strong>in</strong>n<strong>in</strong>g <strong>and</strong> end of each picture,so def<strong>in</strong>itions written by a \mfpverbtex are local to any picture <strong>in</strong> which it occurs. Priorto version 0.8, <strong>MFPIC</strong> did not write comments that occured <strong>with</strong><strong>in</strong> the 〈<strong>TEX</strong>-cmds〉. Now they willbe preserved, <strong>and</strong> can be used to place the %&latex l<strong>in</strong>e that some <strong>TEX</strong> distributions permit as asignal that latex should be run to produce the labels.This comm<strong>and</strong>s attempts a near-verbatim writ<strong>in</strong>g of the 〈<strong>TEX</strong>-cmds〉 <strong>and</strong>, as <strong>with</strong> all verbatimlikecomm<strong>and</strong>s, it should not be used <strong>in</strong> the argument of another comm<strong>and</strong>.\tcaption[〈maxwd〉,〈l<strong>in</strong>ewd〉]{〈caption text〉}Places a <strong>TEX</strong> caption at the bottom of the graph. (Not to be confused <strong>with</strong> LA<strong>TEX</strong>’s similar\caption comm<strong>and</strong>.) The macro will automatically break l<strong>in</strong>es which are too much wider thanthe graph—if the \tcaption l<strong>in</strong>e exceeds 〈maxwd〉 times the width of the graph, then l<strong>in</strong>es willbe broken to form l<strong>in</strong>es at most 〈l<strong>in</strong>ewd〉 times the width of the graph. The default sett<strong>in</strong>gs for〈maxwd〉 <strong>and</strong> 〈l<strong>in</strong>ewd〉 are 1.2 <strong>and</strong> 1.0, respectively. \tcaption typesets its argument twice (asdoes LA<strong>TEX</strong>’s \caption), the first time to test its width, the second time for real. Therefore, theuser is advised not to <strong>in</strong>clude any global assignments <strong>in</strong> the caption text.If the \tcaption <strong>and</strong> graph have different widths, the two are centered relative to each other.If the \tcaption takes multiple l<strong>in</strong>es, then the l<strong>in</strong>es are both left- <strong>and</strong> right-justified (except for


3.8 LABELS AND CAPTIONS. 42the last l<strong>in</strong>e), but the first l<strong>in</strong>e is not <strong>in</strong>dented. If the option centeredcaptions is <strong>in</strong> effect, each l<strong>in</strong>eof the caption will be centered.In a \tcaption, explicit l<strong>in</strong>e breaks may be specified by us<strong>in</strong>g the \\ comm<strong>and</strong>. The separationbetween the bottom of the picture <strong>and</strong> the caption can be changed by <strong>in</strong>creas<strong>in</strong>g or decreas<strong>in</strong>gthe skip \mfpiccaptionskip (a ‘rubber’ length <strong>in</strong> Lamport’s term<strong>in</strong>ology).Many <strong>MFPIC</strong> users f<strong>in</strong>d the \tcaption comm<strong>and</strong> too limit<strong>in</strong>g (one cannot, for example,place the caption to the side of the figure). It is common to use some other method (such asLA<strong>TEX</strong>’s \caption comm<strong>and</strong> <strong>in</strong> a figure environment). The dimensions \mfpicheight <strong>and</strong>\mfpicwidth (see section 3.12) might be a convenience for pla<strong>in</strong> <strong>TEX</strong> users who want to rolltheir own caption macros.3.8.2 CURVES SURROUNDING <strong>TEX</strong>T\tlabelrect[〈rad〉][〈just〉]〈pair〉{〈text〉}\tlabelrect*...This <strong>and</strong> the follow<strong>in</strong>g two methods of suround<strong>in</strong>g a bit of text <strong>with</strong> a curve share some commoncharacteristics which will be described here. The comm<strong>and</strong>s all take an optional argumentthat can modify the shape of the curve. After that come arguments exactly as for the \tlabelcomm<strong>and</strong> except that only a s<strong>in</strong>gle po<strong>in</strong>t is permitted, not a list. (So 〈pair〉 is either of the form(〈x〉,〈y〉) or the same enclosed <strong>in</strong> braces, or for mplabels a pair expression <strong>in</strong> braces.) After process<strong>in</strong>gthe surround<strong>in</strong>g curve, a \tlabel is applied to those arguments unless a * is present. Inorder for the second optional argument to be recognized as the second, the first optional argumentmust also be present. An empty first optional argument is permitted, caus<strong>in</strong>g the default value to beused. The default for the justification parameter is cc, for compatibility <strong>with</strong> past <strong>MFPIC</strong> versions<strong>in</strong> which these comm<strong>and</strong>s all centered the figure around the po<strong>in</strong>t <strong>and</strong> no justification parameterexisted. This default can be changed <strong>with</strong> the \tlpathjustify comm<strong>and</strong> below.The pla<strong>in</strong> rectangle version produces a frame separated from the text on all sides by the amountdef<strong>in</strong>ed <strong>with</strong> \tlpathsep. All other versions produce the smallest described curve that conta<strong>in</strong>sthis rectangle.These comm<strong>and</strong>s may be preceded by prefix macros (see the sections 3.5 <strong>and</strong> 3.6, above).They all have a ‘*-form’ which produces the curve but omits plac<strong>in</strong>g the text. All have the effect ofrender<strong>in</strong>g the path before plac<strong>in</strong>g any text. For example, \gclear\tlabelrect. . . will clear therectangle <strong>and</strong> then place the follow<strong>in</strong>g text <strong>in</strong> the cleared space.The optional argument of \tlabelrect, 〈rad〉, is a dimension, default<strong>in</strong>g to 0pt, that producesrounded corners made from quarter-circles of the given radius. If the corners are rounded, the sidesare exp<strong>and</strong>ed slightly so the result<strong>in</strong>g shape still encompasses the rectangle mentioned above.There is one special case for the optional argument 〈rad〉: if the keyword ‘roundends’ is used<strong>in</strong>stead of a dimension, the radius will be chosen to make the nearest quarter circles just meet, sothe narrow side of the rectangle is a half circle.\tlabeloval[〈mult〉][〈just〉]〈pair〉{〈text〉}\tlabeloval*...This is similar to \tlabelrect, except it draws an ellipse. The ellipse is calculated to have thesame ratio of width to height as the rectangle mentioned above. The optional 〈mult〉 is a multiplierthat <strong>in</strong>creases or decreases this ratio. Values of 〈mult〉 larger than 1 <strong>in</strong>crease the width <strong>and</strong> decrease


3.9 SAVING AND REUSING AN <strong>MFPIC</strong> PICTURE. 43the height.\tlabelellipse[〈ratio〉][〈just〉]〈pair〉{〈text〉}\tlabelellipse*...\tlabelcircle[〈just〉]〈pair〉{〈text〉}\tlabelcircle*...Draws the smallest ellipse centered at the po<strong>in</strong>t that encompasses the rectangle def<strong>in</strong>ed above,<strong>and</strong> that has a ratio of width to height equal to 〈ratio〉, then places the text. The default ratio is1, which produces a circle. We also provide the comm<strong>and</strong> \tlabelcircle, which take only the[〈just〉] optional argument. Internally, it just processes any * <strong>and</strong> calls \tlabelellipse <strong>with</strong>parameter 1.In the above \tlabel... curves, the optional parameter should be positive. If it is zero, allthe curves silently revert to \tlabelrect. If it is negative, it is silently accepted. In the case of\tlabelrect this causes the quarter-circles at the corners to be <strong>in</strong>dented rather than convex. Inthe other cases, there is no visible effect, but <strong>in</strong> all cases the sense of the curve is reversed.\tlpathjustify{〈just〉}This can be used to change the default justification for \tlabelrect <strong>and</strong> friends. The 〈just〉parameter is exactly as <strong>in</strong> \tlabeljustify <strong>in</strong> subsection 3.8.1.3.9 Sav<strong>in</strong>g <strong>and</strong> Reus<strong>in</strong>g an <strong>MFPIC</strong> Picture.These comm<strong>and</strong>s have been changed from versions prior to 0.3.14 <strong>in</strong> order to behave more like theLA<strong>TEX</strong>’s \savebox, <strong>and</strong> also to allow the reuse of an allocated box. Past files that use \savepicwill have to be edited to add \newsavepic comm<strong>and</strong>s that allocate the <strong>TEX</strong> boxes.\newsavepic{〈picname〉}\savepic{〈picname〉}\usepic{〈picname〉}\newsavepic allocates a box (like LA<strong>TEX</strong>’s \newsavebox) <strong>in</strong> which to save a picture. As <strong>in</strong>\newsavebox, 〈picname〉 is a control sequence. Example: \newsavepic{\foo}. In a LA<strong>TEX</strong> document,\newsavepic is actually def<strong>in</strong>ed to be \newsavebox.\savepic saves the next \mfpic picture <strong>in</strong> the named box, which should have been previouslyallocated <strong>with</strong> \newsavepic. (This comm<strong>and</strong> should not be used <strong>in</strong>side an mfpic environment.)The next picture will not be placed, but saved <strong>in</strong> the box for later use. This is primarily <strong>in</strong>tended asa convenience. One could use\savebox{〈picname〉}{〈entire mfpic environment〉},but \savepic avoids hav<strong>in</strong>g to place the mfpic environment <strong>in</strong> braces, <strong>and</strong> avoids one extra levelof <strong>TEX</strong> group<strong>in</strong>g. It also avoids read<strong>in</strong>g the entire mfpic environment as a parameter, which wouldnullify <strong>MFPIC</strong>’s efforts to preserve l<strong>in</strong>e breaks <strong>in</strong> parameters written to the METAFONT output file.If you repeat \savepic <strong>with</strong> the same 〈picname〉, the old contents are replaced <strong>with</strong> the nextpicture.\usepic copies the picture that had been saved <strong>in</strong> the named box. This may be repeated asoften as liked to create multiple copies of one picture. The \usepic comm<strong>and</strong> is essentially aclone of the LA<strong>TEX</strong> \usebox comm<strong>and</strong>. S<strong>in</strong>ce the contents of the saved picture are only def<strong>in</strong>ed


3.10 PICTURE FRAMES. 44dur<strong>in</strong>g the <strong>TEX</strong> run, \usebox cannot be used <strong>in</strong> the <strong>TEX</strong>-comm<strong>and</strong>s argument of the \tlabelcomm<strong>and</strong> while mplabels is <strong>in</strong> effect.3.10 Picture Frames.When <strong>TEX</strong> is run but before METAFONT or METAPOST has been run on the output file, <strong>MFPIC</strong>detects that the .tfm file is miss<strong>in</strong>g or that the first METAPOST figure file 〈file〉.1 is miss<strong>in</strong>g. Inthese cases, the mfpic environment draws only a rectangular frame <strong>with</strong> dimensions equal to thenom<strong>in</strong>al size of the picture, conta<strong>in</strong><strong>in</strong>g the figure name <strong>and</strong> number (<strong>and</strong> any <strong>TEX</strong> labels). Thecomm<strong>and</strong>(s) used <strong>in</strong>ternally to do this are made available to the user.\mfpframe[〈fsep〉]〈 material-to-be-framed 〉\endmfpframe\mfpframed[〈fsep〉]{〈material-to-be-framed〉}These surround their contents <strong>with</strong> a rectangular frame consist<strong>in</strong>g of l<strong>in</strong>es <strong>with</strong> thickness\mfpframethickness separated from the contents by the 〈fsep〉 if specified, otherwise by thevalue of the dimension \mfpframesep. The default value of the <strong>TEX</strong> dimensions \mfpframesep<strong>and</strong> \mfpframethickness are 2pt <strong>and</strong> 0.4pt, respectively. The \mfpframe ... \endmfpframeversion is preferred around mfpic environments or verbatim material s<strong>in</strong>ce it avoids read<strong>in</strong>g theenclosed material before appropriate \catcode changes go <strong>in</strong>to effect. In LA<strong>TEX</strong>, one can also usethe \beg<strong>in</strong>{mfpframe} ... \end{mfpframe} syntax.An alternative way to frame mfpic pictures is to save them <strong>with</strong> \savepic (see previoussection) <strong>and</strong> issue a correspond<strong>in</strong>g \usepic comm<strong>and</strong> <strong>in</strong>side any fram<strong>in</strong>g environment/comm<strong>and</strong>of the user’s choice or devis<strong>in</strong>g.3.11 Aff<strong>in</strong>e Transforms.Coord<strong>in</strong>ate transformations that keep parallel l<strong>in</strong>es <strong>in</strong> parallel are called aff<strong>in</strong>e transforms. These<strong>in</strong>clude translation, rotation, reflection, scal<strong>in</strong>g <strong>and</strong> skew<strong>in</strong>g (slant<strong>in</strong>g). For the METAFONT coord<strong>in</strong>atesystem only—that is, for paths, but not for \tlabel’s (let alone \tcaption’s)—<strong>MFPIC</strong>provides the ability to apply METAFONT aff<strong>in</strong>e transforms.3.11.1 TRANSFORMING THE METAFONT COORDINATE SYSTEM.\coords ... \endcoordsAll aff<strong>in</strong>e transforms are restricted to the <strong>in</strong>nermost enclos<strong>in</strong>g \coords...\endcoords pair. Ifthere is no such enclosure, then the transforms will apply to the rest of the mfpic environmentNote: In LA<strong>TEX</strong>, a coords environment may be used.Transforms provided by <strong>MFPIC</strong>.\rotate{〈θ〉}Rotates around orig<strong>in</strong> by 〈θ〉 degrees.\rotatearound{〈po<strong>in</strong>t〉}{〈θ〉} Rotates around po<strong>in</strong>t 〈po<strong>in</strong>t〉 by 〈θ〉 degrees.\turn[〈po<strong>in</strong>t〉]{〈θ〉}Rotates around po<strong>in</strong>t 〈po<strong>in</strong>t〉 (orig<strong>in</strong> is default) by 〈θ〉.\mirror{〈p 1 〉}{〈p 2 〉} Same as \reflectabout.\reflectabout{〈p 1 〉}{〈p 1 〉} Reflect about the l<strong>in</strong>e 〈p 1 〉--〈p 2 〉.\shift{〈pair〉}Shifts orig<strong>in</strong> by the vector 〈pair〉.\scale{〈s〉}Scales uniformly by a factor of 〈s〉.\xscale{〈s〉}Scales only the x coord<strong>in</strong>ates by a factor of 〈s〉.


3.11 AFFINE TRANSFORMS. 45\yscale{〈s〉}Scales only the y coord<strong>in</strong>ates by a factor of 〈s〉.\zscale{〈pair〉}Scales uniformly by magnitude of 〈pair〉, <strong>and</strong> rotates by angle of 〈pair〉.\xslant{〈s〉} Skew <strong>in</strong> x direction by the multiple 〈s〉 of y.\yslant{〈s〉} Skew <strong>in</strong> y direction by the multiple 〈s〉 of x.\zslant{〈pair〉}See zslanted <strong>in</strong> grafbase.dtx.\boost{〈χ〉}Special relativity boost by χ, see boost <strong>in</strong> grafbase.dtx.\xyswap Exchanges the values of x <strong>and</strong> y.An arbitrary METAFONT transformation can be implemented <strong>with</strong>\applyT{〈transformer〉}This is ma<strong>in</strong>ly for METAFONT hackers. This applies the METAFONT 〈transformer〉 to thecurrent coord<strong>in</strong>ate system. For example, the <strong>MFPIC</strong> <strong>TEX</strong> macro \zslant#1 is implemented as\applyT{zslanted #1} where the argument #1 is a METAFONT pair, such as (x,y). Any codethat satisfies METAFONT’s syntax for a 〈transformer〉 (see D. E. Knuth, “The METAFONTbook”)is permitted, although no effort is made to correctly write <strong>TEX</strong> special characters nor to preservel<strong>in</strong>ebreaks <strong>in</strong> the code.When any of these comm<strong>and</strong>s is issued, the effect is to transform all subsequent figures (<strong>with</strong><strong>in</strong>the enclos<strong>in</strong>g coords or mfpic environment). In particular, attention may need to be paid towhether these transformations move (part of) the figure outside the space allotted by the \mfpiccomm<strong>and</strong> parameters.A not-so-obvious po<strong>in</strong>t is that if several of these transformations are applied <strong>in</strong> succession,then the most recent is applied first, so that figures are transformed as if the transformations wereapplied <strong>in</strong> the reverse order of their occurrence. This is similar to the application of prefix macros(as well as application of transformations <strong>in</strong> mathematics: ST z usually means to apply S to theresult of T z).3.11.2 TRANSFORMING PATHS.In the previous section we discussed transformations of the METAFONT coord<strong>in</strong>ate system. Thosemacros affect the draw<strong>in</strong>g of paths <strong>and</strong> other figures, but do not change the actual paths. We willexpla<strong>in</strong> the dist<strong>in</strong>ction after <strong>in</strong>troduc<strong>in</strong>g two macros for stor<strong>in</strong>g <strong>and</strong> reus<strong>in</strong>g figures.\store{〈path variable〉}{〈path〉}\store{〈path variable〉}〈path〉This stores the follow<strong>in</strong>g 〈path〉 <strong>in</strong> the specified METAFONT 〈path variable〉. Any valid META-FONT symbolic token will do, <strong>in</strong> particular, any sequence of letters or underscores. You should becareful to make the name dist<strong>in</strong>ctive to avoid overwrit<strong>in</strong>g the def<strong>in</strong>ition of some <strong>in</strong>ternal variable.The stored path may later be used as a figure macro us<strong>in</strong>g \mfobj (below). The 〈path〉 may be anyof the figure macros (such as \curve{(0,0),(1,0),(1,1)}) or the result of modify<strong>in</strong>g it. Forexample.\store{pth}\lclosed\reverse\curve{(0,0),(1,0),(1,1)}In fact, \store is a prefix macro that does noth<strong>in</strong>g to the follow<strong>in</strong>g curve except store it. It actsas a render<strong>in</strong>g macro <strong>with</strong> a null render<strong>in</strong>g, so the curve is not made visible unless other render<strong>in</strong>gmacros appear before or after it. It is special <strong>in</strong> that it is the only prefix macro that allows the


3.11 AFFINE TRANSFORMS. 46follow<strong>in</strong>g path to be an argument, that is, enclosed <strong>in</strong> braces. This is solely to support past <strong>MFPIC</strong>versions <strong>in</strong> which \store was not def<strong>in</strong>ed as a prefix macro.\mfobj{〈path expression〉}\mpobj{〈path expression〉}The 〈path expression〉 is a previously stored path variable, or a valid METAFONT (or META-POST) expression comb<strong>in</strong><strong>in</strong>g such variables <strong>and</strong>/or constant paths. This allows the use of pathvariables or expressions as figure macros, permitt<strong>in</strong>g all prefix operations, etc.. Here’s some oversimplifieduses of \store <strong>and</strong> \mfobj:\store{my_f}{\circle{...}}% Store a circle.\dotted\mfobj{my_f}% Now draw it dotted,\hatch\mfobj{my_f}% <strong>and</strong> hatch its <strong>in</strong>terior% Store two curves:\store{my_f}{\curve{...}}\store{my_g}{\curve{...}}% Store two comb<strong>in</strong>ations of them:\store{my_h}{\mfobj{my_f--my_g--cycle}} % a MF path expression\store{my_k}{%\lclosed\connect% a comb<strong>in</strong>ation path created\mfobj{my_f}\mfobj{my_g} % from mfpic comm<strong>and</strong>s.\endconnect}\dotted\mfobj{my_f}% Draw the first dotted,\dotted\mfobj{my_g}% then the second.\shade\mfobj{my_h}% Now shade one comb<strong>in</strong>ation.\hatch\mfobj{my_k}% <strong>and</strong> hatch the otherThe two forms \mfobj <strong>and</strong> \mpobj are absolutely equivalent; they differ only <strong>in</strong> spell<strong>in</strong>g.It should be noted that every <strong>MFPIC</strong> figure is implicitly stored <strong>in</strong> the object curpath. So youcan use \mfobj{curpath} <strong>and</strong> get the path def<strong>in</strong>ed by the most recent sequence of prefix macros<strong>and</strong> figure.Gett<strong>in</strong>g back to coord<strong>in</strong>ate transforms, if one changes the coord<strong>in</strong>ate system <strong>and</strong> then stores<strong>and</strong> draws a curve, say by\coords\rotate{45 deg}\store{xx}{\rect{(0,0),(1,1)}}\dashed\mfobj{xx}\endcoordsone will get a transformed picture, but the object \mfobj{xx} will conta<strong>in</strong> the simple, unrotatedrectangular path <strong>and</strong> draw<strong>in</strong>g it later (outside the coords environment) will prove that. This isbecause the coords environment works at the draw<strong>in</strong>g level, not at the def<strong>in</strong>ition level. In oversimplifiedterms, \dashed <strong>in</strong>vokes the transformation, but not \store. More precisely, <strong>MFPIC</strong>prefix macros have an <strong>in</strong>put <strong>and</strong> an output <strong>and</strong> a side effect. The <strong>in</strong>put is the output of whateverfollows it, the output can be the same as the <strong>in</strong>put (the case for render<strong>in</strong>g prefixes) or modified


3.11 AFFINE TRANSFORMS. 47version of that (the closure prefixes). The side effect is the draw<strong>in</strong>g (dash<strong>in</strong>g, fill<strong>in</strong>g) of the path,append<strong>in</strong>g of an arrowhead, etc.. These side effects have to know where to place their marks, soa computation is <strong>in</strong>voked that converts the user’s graph coord<strong>in</strong>ates <strong>in</strong>to METAFONT’s draw<strong>in</strong>gcoord<strong>in</strong>ates. The previous transformation macros work by modify<strong>in</strong>g the parameters used <strong>in</strong> thiscomputation.The follow<strong>in</strong>g transformation prefixes provide a means of actually creat<strong>in</strong>g <strong>and</strong> stor<strong>in</strong>g a transformedpath. In the terms just discussed, their <strong>in</strong>put is a path, their output is the transformed path,<strong>and</strong> they have no side effects (other than <strong>in</strong>vok<strong>in</strong>g the default render<strong>in</strong>g if no render<strong>in</strong>g prefix waspreviously provided).\rotatepath{(〈x〉,〈y〉),〈θ〉}...\shiftpath{(〈dx〉,〈dy〉)}...\scalepath{(〈x〉,〈y〉),〈s〉}...\xscalepath{〈x〉,〈s〉}...\yscalepath{〈y〉,〈s〉}...\slantpath{〈y〉,〈s〉}...\xslantpath{〈y〉,〈s〉}...\yslantpath{〈x〉,〈s〉}...\reflectpath{〈p 1 〉,〈p 2 〉}...\xyswappath...\transformpath{〈transformer〉}...\rotatepath rotates the follow<strong>in</strong>g path by 〈θ〉 degrees about po<strong>in</strong>t (〈x〉,〈y〉). After the comm<strong>and</strong>s:\store{xx}\rotatepath{(0,0), 45}\rect{(0,0),(1,1)}the object \mfobj{xx} conta<strong>in</strong>s an actual rotated rectangle, as draw<strong>in</strong>g it will prove. The abovemacro, <strong>and</strong> the five that follow are extremely useful (<strong>and</strong> better than coords environments) if oneneeds to draw a figure, together <strong>with</strong> many slightly different versions of it.\shiftpath shifts the follow<strong>in</strong>g path by the horizontal amount 〈dx〉 <strong>and</strong> the vertical amount〈dy〉.\scalepath scales (magnifies or shr<strong>in</strong>ks) the follow<strong>in</strong>g path by the factor 〈s〉, <strong>in</strong> such a waythat the po<strong>in</strong>t (〈x〉,〈y〉) is kept fixed. That is\scalepath{(0,0),2}\rect{(0,0),(1,1)}is essentially the same as \rect{(0,0),(2,2)}, while\scalepath{(1,1),2}\rect{(0,0),(1,1)}is the same as \rect{(-1,-1),(1,1)}. In both cases the rectangle is doubled <strong>in</strong> size. In the firstcase the lower left corner stays the same, while <strong>in</strong> the second case the the upper right corner staysthe same.\xscalepath is similar to \scalepath, but only the x-direction is scaled, <strong>and</strong> all po<strong>in</strong>ts <strong>with</strong>first coord<strong>in</strong>ate equal to 〈x〉 rema<strong>in</strong> fixed. \yscalepath is similar, except the y-direction is affected.


3.12 PARAMETERS. 48\slantpath applies a slant transformation to the follow<strong>in</strong>g path, keep<strong>in</strong>g po<strong>in</strong>ts <strong>with</strong> secondcoord<strong>in</strong>ate equal to 〈y〉 fixed. That is, a po<strong>in</strong>t p on the path is moved right by an amount proportionalto the height of p above the l<strong>in</strong>e y = 〈y〉, <strong>with</strong> s be<strong>in</strong>g the proportionality factor. Vertical l<strong>in</strong>es <strong>in</strong>the path will acquire a slope of 1/s, while horizontal l<strong>in</strong>es stay horizontal.\xslantpath is an alias for \slantpath\yslantpath is similar to \xslantpath, but exchanges the roles of x <strong>and</strong> y coord<strong>in</strong>ates.\reflectpath returns the mirror image of the follow<strong>in</strong>g path, where the l<strong>in</strong>e determ<strong>in</strong>ed bythe po<strong>in</strong>ts 〈p 1 〉 <strong>and</strong> 〈p 2 〉 is the mirror.\xyswappath returns the path <strong>with</strong> the roles of x <strong>and</strong> y exchanged. This is similar <strong>in</strong> somerespects to \reflectpath{(0,0),(1,1)}, <strong>and</strong> produces the same result if the x <strong>and</strong> y scales ofthe picture are the same. However, \reflectpath compensates for such different scales (so thepath shape rema<strong>in</strong>s the same), while \xyswappath does not (so that after a swap, verticals becomehorizontal <strong>and</strong> horizontals become vertical). One cannot have both when the scales are different.This compensation for different scales is also done for \rotatepath, so the result<strong>in</strong>g pathalways has the same shape after the rotation as before. None of the other path transformationprefixes compensate for different scales, <strong>and</strong> none of the coord<strong>in</strong>ate system transformations of theprevious subsection do it.For METAFONT or METAPOST power users, \transformpath can take any ‘transformer’ <strong>and</strong>transform the follow<strong>in</strong>g path <strong>with</strong> it. Here, a transformer is the same as <strong>in</strong> the previous section.Examples are scaled, shifted(1,1), <strong>and</strong> rotatedabout(0,1).All these prefixes change only the path that follows, not any render<strong>in</strong>g of it that follows. Forexample:\gfill\rotatepath{(0,0),90}\dashed\rect{(0,0),(1,1)}will not produce a rotated dashed rectangle. Rather the orig<strong>in</strong>al rectangle will be dashed, <strong>and</strong> therotated rectangle will be filled.3.12 Parameters.There are many parameters <strong>in</strong> <strong>MFPIC</strong> which the user can modify to obta<strong>in</strong> different effects, suchas different arrowhead size or shape. Most of these parameters have been described already <strong>in</strong> thecontext of macros they modify, but they are all described together here.Many of the parameters are stored by <strong>TEX</strong> as dimensions, <strong>and</strong> so are available even if there isno METAFONT file open; changes to them are not subject to the usual <strong>TEX</strong> rules of scope however:they are local to only to mfpic environments if set <strong>in</strong>side one, otherwise they are global. This is forconsistency: other parameters are stored by METAFONT (so the macros to change them will haveno effect unless a METAFONT file is open) <strong>and</strong> the changes are subject to METAFONT’s rules ofscope—to the <strong>MFPIC</strong> user, this means that changes <strong>in</strong>side the \mfpic ... \endmfpic environmentare local to that environment, but other <strong>TEX</strong> group<strong>in</strong>gs have no effect on scope. Some comm<strong>and</strong>s(notably those that set the axismarg<strong>in</strong>s <strong>and</strong> \tlabel parameters) change both <strong>TEX</strong> parameters <strong>and</strong>METAFONT parameters, <strong>and</strong> it is important to keep them consistent.There are a few parameters that do obey <strong>TEX</strong> group<strong>in</strong>g, but only <strong>in</strong>side mfpic environments.These are noted where the parameter is described.\mfpicunitThis <strong>TEX</strong> dimension stores the basic unit length for <strong>MFPIC</strong> pictures—the x <strong>and</strong> y scales <strong>in</strong> the


3.12 PARAMETERS. 49\mfpic macro are multiples of this unit. The default value is 1pt.\po<strong>in</strong>tsizeThis <strong>TEX</strong> dimension stores the diameter of the circle drawn by the \po<strong>in</strong>t macro <strong>and</strong> thediameter of the symbols drawn by \plot, \plotsymbol <strong>and</strong> \plotnodes. The default value is2pt.\po<strong>in</strong>tfilltrue <strong>and</strong> \po<strong>in</strong>tfillfalseThis <strong>TEX</strong> boolean switch determ<strong>in</strong>es whether the circle drawn by \po<strong>in</strong>t will be filled or open(outl<strong>in</strong>e drawn, <strong>in</strong>side erased). The default is true: filled. This value is local to any <strong>TEX</strong> group<strong>in</strong>side an mfpic environment. Outside such it is global.\pen{〈drawpensize〉}\drawpen{〈drawpensize〉}\penwd{〈drawpensize〉}Establishes the width of the normal draw<strong>in</strong>g pen. The default is 0.5pt. This width is stored byMETAFONT. The shad<strong>in</strong>g dots <strong>and</strong> hatch<strong>in</strong>g pen are unaffected by this. There exist three aliases forthis comm<strong>and</strong>, the first two to ma<strong>in</strong>ta<strong>in</strong> backward compatibility, the last one for consistency <strong>with</strong>other dimension chang<strong>in</strong>g comm<strong>and</strong>s. Publishers generally recommended authors to use at least awidth of one-half po<strong>in</strong>t for draw<strong>in</strong>gs submitted for publication.\shadewd{〈dotdiam〉}Sets the diameter of the dots used <strong>in</strong> the shad<strong>in</strong>g macro. The draw<strong>in</strong>g <strong>and</strong> hatch<strong>in</strong>g pens areunaffected by this. The default is 0.5bp, <strong>and</strong> the value is stored by METAFONT.\hatchwd{〈hatchpensize〉}Sets the l<strong>in</strong>e thickness used <strong>in</strong> the hatch<strong>in</strong>g macros. The draw<strong>in</strong>g pen <strong>and</strong> shad<strong>in</strong>g dots areunaffected by this. The default is 0.5bp, <strong>and</strong> the value is stored by METAFONT.\polkadotwd{〈polkadotdiam〉}Sets the diameter of the dots used <strong>in</strong> the \polkadot macro. The default is 5bp, <strong>and</strong> the valueis stored by METAFONT.\headlenThis <strong>TEX</strong> dimension stores the length of the arrowhead drawn by the \arrow macro. Thedefault value is 3pt.\axisheadlenThis <strong>TEX</strong> dimension stores the length of the arrowhead drawn by the \axes, \xaxis <strong>and</strong>\yaxis macros, <strong>and</strong> by the macros \axis <strong>and</strong> \doaxes when applied to the parameters x <strong>and</strong> y.\sideheadlenThis <strong>TEX</strong> dimension stores the length of the arrowhead drawn by the \axis <strong>and</strong> \doaxesmacros when applied to l, b, r or t. The default value is 0pt (that is, the default is not to putarrowheads on border axes).


3.12 PARAMETERS. 50\headshape{〈hdwdr〉}{〈hdten〉}{〈hfilled〉}Establishes the shape of the arrowhead drawn by the \arrow <strong>and</strong> \axes macros. The value of〈hdwdr〉 is the ratio of the width of the arrowhead to its length; 〈hdten〉 is the tension of the Béziercurves; <strong>and</strong> 〈hfilled〉 is a METAFONT boolean value <strong>in</strong>dicat<strong>in</strong>g whether the arrowheads are to befilled (if true) or open. The default values are 1, 1, false, respectively. The 〈hdwdr〉, 〈hdten〉 <strong>and</strong>〈hfilled〉 values are stored by METAFONT. Sett<strong>in</strong>g 〈hdten〉 to ‘<strong>in</strong>f<strong>in</strong>ity’ will make the sides ofthe arrowheads straight l<strong>in</strong>es. These values are all stored by METAFONT.\dashlen, \dashspaceThese <strong>TEX</strong> dimensions store, respectively, the length of dashes <strong>and</strong> the length of spaces betweendashes, for l<strong>in</strong>es drawn by the \dashed macro. The \dashed macro may adjust the dashes <strong>and</strong>the spaces between by as much as 1/n of their value, where n is the number of spaces appear<strong>in</strong>g<strong>in</strong> the curve, <strong>in</strong> order not to have partial dashes at the ends. The default values are both 4pt. Thedashes will actually be longer (<strong>and</strong> the spaces shorter) by the thickness of the pen used when theyare drawn.\dashl<strong>in</strong>eset, \dotl<strong>in</strong>esetThese macros provide shorth<strong>and</strong>s for certa<strong>in</strong> sett<strong>in</strong>gs of the \dashlen <strong>and</strong> \dashspace dimensions.The macro \dashl<strong>in</strong>eset sets both values to 4pt, while \dotl<strong>in</strong>eset sets \dashlento 1pt <strong>and</strong> \dashspace to 2pt. They are kept ma<strong>in</strong>ly for backward compatibility.\hashlenThis <strong>TEX</strong> dimension stores the length of the axis hash marks drawn by the \xmarks <strong>and</strong>\ymarks macros. The default value is 4pt.\shadespaceThis <strong>TEX</strong> dimension establishes the spac<strong>in</strong>g between dots drawn by the \shade macro. Thedefault value is 1pt.\darkershade, \lightershadeThese macros both multiply the \shadespace dimension by constant factors, 5/6 = .833333<strong>and</strong> 6/5 = 1.2 respectively, to provide convenient st<strong>and</strong>ard sett<strong>in</strong>gs for several levels of shad<strong>in</strong>g.Under METAFONT it is possible that us<strong>in</strong>g one of these macros can have no visible effect. See thediscussion of the \shade macro <strong>in</strong> subsection 3.6.2.\polkadotspaceThis <strong>TEX</strong> dimension establishes the spac<strong>in</strong>g between the centers of the dots used <strong>in</strong> the macro\polkadot. The default is 10pt.\dotsize, \dotspaceThese <strong>TEX</strong> dimensions establishes the size <strong>and</strong> spac<strong>in</strong>g between the centers of the dots used <strong>in</strong>the \dotted macro. The defaults are 0.5pt <strong>and</strong> 3pt.


3.12 PARAMETERS. 51\symbolspaceSimilar to \dotspace, this <strong>TEX</strong> dimension establishes the space between the centers of symbolsplaced by the macro \plot{〈symbol〉}.... Its default is 5pt.\hatchspaceThis <strong>TEX</strong> dimension establishes the spac<strong>in</strong>g between l<strong>in</strong>es drawn by the \hatch macro. Thedefault value is 3pt.\tlpo<strong>in</strong>tsep{〈separation〉}\tlpathsep{〈separation〉}\tlabelsep{〈separation〉}The first macro establishes the separation between a label <strong>and</strong> its nom<strong>in</strong>al position. It affectstext written <strong>with</strong> any of the comm<strong>and</strong>s \tlabel, \tlabels, \axislabels or \plottext. Thesecond sets the separation between the text <strong>and</strong> the curve def<strong>in</strong>ed by the comm<strong>and</strong>s \tlabelrect,\tlabeloval or \tlabelellipse. The third sets both of these separations to the same value.It is for backward compatibility when there was only one dimension used for both purposes. Thedefault separation is 0pt. The values are stored by both <strong>TEX</strong> <strong>and</strong> METAFONT.\tlabeloffset{〈hlen〉}{〈vlen〉}This macro establishes a uniform offset that applies to all labels. It affects text written <strong>with</strong> anyof the comm<strong>and</strong>s \tlabel, \tlabels, \axislabels or \plottext. The default is to have bothhorizontal <strong>and</strong> vertical offsets of 0pt. The values are stored by both <strong>TEX</strong> <strong>and</strong> METAFONT.\mfpdataperl<strong>in</strong>eWhen <strong>MFPIC</strong> is read<strong>in</strong>g data from files <strong>and</strong> writ<strong>in</strong>g it to the output file, this macro stores themaximum number of po<strong>in</strong>ts that will be written on a s<strong>in</strong>gle l<strong>in</strong>e <strong>in</strong> the output file. Its defaultis def<strong>in</strong>ed by \def\mfpdataperl<strong>in</strong>e{5}. Any such def<strong>in</strong>ition (or redef<strong>in</strong>ition) obeys all <strong>TEX</strong>group<strong>in</strong>gs.\mfpicheight, \mfpicwidthThese <strong>TEX</strong> dimensions store the height <strong>and</strong> width of the figure created by the most recentlycompleted mfpic environment. This might perhaps be of <strong>in</strong>terest to hackers or to aid <strong>in</strong> preciseposition<strong>in</strong>g of the graphics. They are meant to be read-only: the \endmfpic comm<strong>and</strong> globallysets them equal to the height <strong>and</strong> width of the picture. But <strong>MFPIC</strong> does not otherwise make anyuse of them. As they are not to be changed, group<strong>in</strong>g is irrelevent, but when <strong>MFPIC</strong> sets them, itdoes so globally. These are set even if the picture is saved <strong>with</strong> \savepic, so if another mfpic<strong>in</strong>tervenes before the correspond<strong>in</strong>g \usepic <strong>and</strong> these values are needed, they need to be saved<strong>in</strong> another <strong>TEX</strong> dimension comm<strong>and</strong>.


3.13 FOR ADVANCED USERS. 523.13 For Advanced Users.3.13.1 SPLINES\qspl<strong>in</strong>e{〈list〉}\closedqspl<strong>in</strong>e{〈list〉}\cspl<strong>in</strong>e{〈list〉}\closedcspl<strong>in</strong>e{〈list〉}These are alternate ways of def<strong>in</strong><strong>in</strong>g curves. In each case, 〈list〉 is a comma separated list ofpo<strong>in</strong>ts. These represent not the po<strong>in</strong>ts the curve passes through, but the control po<strong>in</strong>ts. The first twoproduce quadratic B-spl<strong>in</strong>es <strong>and</strong> the last two produce cubic B-spl<strong>in</strong>es. If you don’t know what B-spl<strong>in</strong>es are, or don’t know what control po<strong>in</strong>ts are, it is recommended you not use these comm<strong>and</strong>s.For \qspl<strong>in</strong>e, the curve will pass through the midpo<strong>in</strong>ts of the l<strong>in</strong>e segments jo<strong>in</strong><strong>in</strong>g the po<strong>in</strong>ts<strong>in</strong> the list, tangent to that l<strong>in</strong>e segment.For the \cspl<strong>in</strong>e, the list also def<strong>in</strong>es l<strong>in</strong>e segments. Divide these <strong>in</strong> thirds at two po<strong>in</strong>ts oneach segment. Connect these division po<strong>in</strong>ts only to obta<strong>in</strong> l<strong>in</strong>e segments. Each odd numberedsegment is the middle third of one of the orig<strong>in</strong>al l<strong>in</strong>e segments. The \cspl<strong>in</strong>e curve passesthrough the midpo<strong>in</strong>t of each even numbered l<strong>in</strong>e segment, tangent to it.\computedspl<strong>in</strong>e{〈list〉}\closedcomputedspl<strong>in</strong>e{〈list〉}These are both cubic spl<strong>in</strong>es. For these you do provide the list of po<strong>in</strong>ts the curves are to passthrough. They become the nodes <strong>and</strong> the control po<strong>in</strong>ts are computed from them. The nodes do notuniquely determ<strong>in</strong>e the control po<strong>in</strong>ts so extra equations are required. For the first version, the extraequations give the path zero curvature at the endpo<strong>in</strong>ts (a relaxed spl<strong>in</strong>e). For the closed version,the extra equations are those that close the curve smoothly.\fcnspl<strong>in</strong>e{〈list〉}\periodicfcnspl<strong>in</strong>e{〈list〉}These comm<strong>and</strong>s use cubic spl<strong>in</strong>e equations to produce a smooth graph of a function basedon a list of po<strong>in</strong>ts <strong>with</strong> <strong>in</strong>creas<strong>in</strong>g x-values. See \fcncurve <strong>in</strong> section 3.3.5 for another way todo this. As <strong>in</strong> the computed spl<strong>in</strong>es, above, the spl<strong>in</strong>e equations at the nodes do not provide sufficient<strong>in</strong>formation to compute all control po<strong>in</strong>ts. In the basic version, \fcnspl<strong>in</strong>e, extra equationsproduce a graph <strong>with</strong> zero curvature at the endpo<strong>in</strong>ts (a relaxed spl<strong>in</strong>e), while the periodic versionuses equations that make the first <strong>and</strong> second derivatives at the last po<strong>in</strong>t match those at the firstpo<strong>in</strong>t.\cbclosed...\qbclosed...These are prefix macros for clos<strong>in</strong>g curves. The first closes <strong>with</strong> a cubic B-spl<strong>in</strong>e, the second<strong>with</strong> a quadratic B-spl<strong>in</strong>e. They will close any given curve, but the comm<strong>and</strong> \cbclosed is meantto close a cubic B-spl<strong>in</strong>e (see above). That is, \cbclosed\cspl<strong>in</strong>e should produce the sameresult as \closedcspl<strong>in</strong>e <strong>with</strong> the same argument. The correspond<strong>in</strong>g statements are true of\qbclosed: it is meant to close a quadratic B-spl<strong>in</strong>e <strong>and</strong> \qbclosed\qspl<strong>in</strong>e should producethe same result as \closedqspl<strong>in</strong>e <strong>with</strong> the same argument.


3.13 FOR ADVANCED USERS. 533.13.2 BÉZIERSThe power user, hav<strong>in</strong>g noticed that \curve <strong>and</strong> \cyclic <strong>in</strong>sert some direction modifiers <strong>in</strong>to thepath created, may have decided that there is no <strong>MFPIC</strong> comm<strong>and</strong> to create a simple METAFONTdefault style path, for example (1,1)..(0,1)..(0,0)..cycle. If so, he or she has forgottenabout \mfobj: the comm<strong>and</strong>\mfobj{(1,1)..(0,1)..(0,0)..cycle}will produce, <strong>in</strong> the .mf file, exactly this path, but surround it <strong>with</strong> the <strong>TEX</strong> wrapp<strong>in</strong>g needed tomake <strong>MFPIC</strong>’s prefix macro system work. However, the syntax of more complicated paths can beextremely lengthy, so we offer this <strong>in</strong>terface:\mfbezier[〈tens〉]{〈list〉}\closedmfbezier[〈tens〉]{〈list〉}This uses the path jo<strong>in</strong> operator ..tension 〈tens〉.. to connect the po<strong>in</strong>ts <strong>in</strong> the list. If thetension option [〈tens〉] is omitted, the value set by \settension (<strong>in</strong>itially 1) is used. One can geta cyclic path by prepend<strong>in</strong>g \bclosed (<strong>with</strong> match<strong>in</strong>g tension option), but it will not produce thesame result as \closedmfbezier. These are cubic Bézier’s (but you know that if you are a poweruser). Quadratic Béziers (as <strong>in</strong> LA<strong>TEX</strong>’s picture environment) can be obta<strong>in</strong>ed <strong>with</strong> the follow<strong>in</strong>g:\qbeziers[〈tens〉]{〈list〉}\closedqbeziers[〈tens〉]{〈list〉}Note the plural to dist<strong>in</strong>guish the first from the LA<strong>TEX</strong> comm<strong>and</strong>, <strong>and</strong> to <strong>in</strong>dicate that they willdraw a series of quadratic Béziers. In the 〈list〉, the first, third, fifth, etc., are the po<strong>in</strong>ts to connect,while the second, fourth, etc., are the control po<strong>in</strong>ts. The open version requires an end<strong>in</strong>g po<strong>in</strong>t,<strong>and</strong> so needs an odd number of po<strong>in</strong>ts <strong>in</strong> the list. The closed version assumes the first po<strong>in</strong>t is theend<strong>in</strong>g, <strong>and</strong> so requires an even number <strong>in</strong> the list. The curve will not automatically be smooth.That depends on the choice of the control po<strong>in</strong>ts.3.13.3 VERBATIM METAFONT CODE\mfsrc{〈metafont code〉}\mfcmd{〈metafont code〉}\mflist{〈metafont code〉}These all write the 〈metafont code〉 directly to the METAFONT file, us<strong>in</strong>g a <strong>TEX</strong> \write comm<strong>and</strong>.L<strong>in</strong>e breaks <strong>with</strong><strong>in</strong> 〈metafont code〉 are preserved. 12 Almost all the <strong>MFPIC</strong> draw<strong>in</strong>g macros<strong>in</strong>voke one of these. Because of the way <strong>TEX</strong> reads <strong>and</strong> processes macro arguments, not all draw<strong>in</strong>gmacros preserve l<strong>in</strong>e breaks (nor do they all need to). However, the ones that operate on long listsof pair or numeric data (for example, \po<strong>in</strong>t, \curve, etc.), do preserve l<strong>in</strong>e breaks <strong>in</strong> that data.The difference <strong>in</strong> these is m<strong>in</strong>or: \mfsrc writes its argument <strong>with</strong>out change, \mfcmd appendsa semicolon (‘;’) to the code, while \mflist surrounds its argument <strong>with</strong> parentheses <strong>and</strong> thenappends a semicolon.Us<strong>in</strong>g these can have some rather bizarre consequences, though, so it is not recommended tothe unwary. It is, however, currently the only way to make use of METAFONT’s equation solv<strong>in</strong>gability. Here’s an oversimplified example:12 Under most circumstances, but not if the comm<strong>and</strong> (plus its argument) is part of the argument of another macro.


3.13 FOR ADVANCED USERS. 54\mfpic[20]{-0.5}{1.5}{0}{1.5}\mfsrc{z1=(0,0);z2-z3=(1,2);z2+2z3=(1,-1);} % z2=(1,1), z3=(0,-1)\arc[t]{z1,z2,z3}\endmfpicCheck out the sample forfun.tex for a more extensive example.3.13.4 CREATING METAFONT VARIABLES\setmfvariable{〈type〉}{〈name〉}{〈value〉}\setmpvariable{〈type〉}{〈name〉}{〈value〉}\globalsetvariable{〈type〉}{〈name〉}{〈value〉}\setmfnumeric{〈name〉}{〈value〉}\setmfpair {〈name〉}{〈value〉}\setmfboolean{〈name〉}{〈value〉}\setmfcolor {〈name〉}{〈value〉}These formerly <strong>in</strong>ternal <strong>MFPIC</strong> macros can be use to def<strong>in</strong>e symbolic names for any META-FONT or METAPOST variable type. The first two are <strong>in</strong>terchangeable; you can use either one<strong>with</strong> or <strong>with</strong>out the metapost option. The rema<strong>in</strong><strong>in</strong>g four are just abbreviations. For example,\setmfpair{X}{(2,0)} is the same as \setmfvariable{pair}{X}{(2,0)}. Note that theseoverwrite any variable <strong>with</strong> the specified 〈name〉. For certa<strong>in</strong> <strong>in</strong>ternal names, METAFONT will issuean error, but usually the variable is silently redef<strong>in</strong>ed. For the four abbreviations, there is no “mp”version, but they may be used <strong>with</strong> either the metapost or metafont options.As an example of their use, s<strong>in</strong>ce dimensions are numeric data types <strong>in</strong> METAFONT, the comm<strong>and</strong>\setmfnumeric{my_dim}{7pt}would set the METAFONT variable my_dim to the value 7pt. After that, my_dim can be used <strong>in</strong> anydraw<strong>in</strong>g comm<strong>and</strong> where a dimension is required:\plotsymbol[my_dim]{Triangle}\rect{(0,0),(1,1)}will plot the rectangle <strong>with</strong> small triangles spaced 7pt apart.You can def<strong>in</strong>e paths this way (\setmfpath{X}{(0,0)..(1,1)..(0,1)}), but the 〈value〉has to be valid METAFONT path construction syntax, not someth<strong>in</strong>g like \rect{...}. You need\store if you want to set a variable to an <strong>MFPIC</strong> path. However, def<strong>in</strong>ed either way, they can beused <strong>in</strong> \mfobj.With the obvious exception of \globalsetvariable comm<strong>and</strong>, these comm<strong>and</strong>s def<strong>in</strong>e thevariable locally. That is, the variable will revert to any previous def<strong>in</strong>ition (or become undef<strong>in</strong>ed)at the end of the mfpic environment it is def<strong>in</strong>ed <strong>in</strong>. It is <strong>in</strong> fact local to any METAFONT group.In <strong>MFPIC</strong>, only \connect . . . \endconnect, \mfpimage . . . \endmfpimage, <strong>and</strong> \mfpic . . .\endmfpic create METAFONT groups <strong>in</strong> the graph file.


3.13 FOR ADVANCED USERS. 55\patharr{〈pv〉}...\endpatharrThis pair of macros, act<strong>in</strong>g as an environment, accumulate all enclos<strong>in</strong>g paths, <strong>in</strong> order, <strong>in</strong>to apath array named 〈pv〉. A path array is a collection of paths <strong>with</strong> a common base name <strong>in</strong>dexed by<strong>in</strong>tegers from 1 to the number of paths. Any path <strong>in</strong> the array can be accessed by means of \mfobj.For example, after\patharr{pa}\rect{(0,0),(1,1)} \circle{(.5,.5), .5}\endpatharrthen \mfobj{pa[1]} refers to the rectangle <strong>and</strong> \mfobj{pa[2]} refers to the circle. In caseexplicit numbers are used, METAFONT allows pa1 as an abbreviation for pa[1]. However, if anumeric variable or some expression is used (e.g., pa[n+1]) the square brackets are required.This comm<strong>and</strong> can only be used <strong>in</strong> an mfpic environment. For this reason, the def<strong>in</strong>itions itmakes are global.Note: In LA<strong>TEX</strong>, this pair of macros can be used <strong>in</strong> the form of a LA<strong>TEX</strong>-style environment calledpatharr—as <strong>in</strong> \beg<strong>in</strong>{patharr}...\end{patharr}.\setmfarray{〈type〉}{〈var〉}{〈list〉}\setmparray{〈type〉}{〈var〉}{〈list〉}\pairarray{〈var〉}{〈list-of-po<strong>in</strong>ts〉}\numericarray{〈var〉}{〈list-of-numbers〉}\colorarray{〈var〉}{〈list-of-colors〉}These enable the simultaneous def<strong>in</strong>ition of variables. For example, after\pairarray{X}{(0,1),(1,1),(0,0),(1,0)}the variables X1, X2, X3, <strong>and</strong> X4 are equal to the given po<strong>in</strong>ts <strong>in</strong> that order. And then\polyl<strong>in</strong>e{X1,X2,X3,X4}will draw the l<strong>in</strong>es connect<strong>in</strong>g these four po<strong>in</strong>ts. The <strong>in</strong>dex may optionally be put <strong>in</strong> square brackets<strong>and</strong> may be separated from the name by any number of spaces. If a numeric expression is used<strong>in</strong>stead of an explicit number, square brackets must surround it: X[1+1], X[2], X2 <strong>and</strong> X 2 areall the same. The arrays are def<strong>in</strong>ed locally if these comm<strong>and</strong>s occur <strong>in</strong> an mfpic environment,global otherwise. For all the array comm<strong>and</strong>s, the variable X by itself (not followed by any digit orbrackets) becomes a numeric variable equal to the number of elements <strong>in</strong> the array.Array variables may be used only where the values are processed only by METAFONT or META-POST, they are unknown to <strong>TEX</strong>. In particular, they cannot be used <strong>in</strong> comm<strong>and</strong>s that position textunless mplabels is <strong>in</strong> effect. Variables may be used <strong>in</strong> the 〈list〉 parameters of comm<strong>and</strong>s, but theymust have been previously def<strong>in</strong>ed or otherwise known to METAFONT.Several comm<strong>and</strong>s <strong>in</strong> <strong>MFPIC</strong> def<strong>in</strong>e arrays of objects that can be used <strong>in</strong> other comm<strong>and</strong>s. Thema<strong>in</strong> ones are \piechart <strong>and</strong> \barchart. These arrays are always global. Us<strong>in</strong>g \piechartcauses the follow<strong>in</strong>g arrays to become def<strong>in</strong>ed (or redef<strong>in</strong>ed):• piewedge, a path array describ<strong>in</strong>g the wedges of the chart. To access piewedge[1], forexample, one could use \mfobj{piewedge[1]}. This almost exactly the same as the <strong>MFPIC</strong>comm<strong>and</strong> \piewdge{1} <strong>with</strong>out optional arguments.


3.13 FOR ADVANCED USERS. 56• pieangle, a numeric array, gives the start<strong>in</strong>g angles of the wedges.• piedirection, a pair array, gives the unit vectors po<strong>in</strong>t<strong>in</strong>g from the center of the piechartthrough middles of the wedges. If \pieangle1 is 0 <strong>and</strong> pieangle2 is 90 degrees, thenpiedirection1 is (cos45,s<strong>in</strong>45).Us<strong>in</strong>g \barchart causes the follow<strong>in</strong>g arrays to become def<strong>in</strong>ed (or redef<strong>in</strong>ed). The exactmean<strong>in</strong>g depends on whether bars are horizontal or vertical. The follow<strong>in</strong>g describes horizontalbars; exchange the roles of x <strong>and</strong> y if they are vertical:• barstart, a numeric array, gives the position on the y-axis of the lead<strong>in</strong>g edge of the bars.• barbeg<strong>in</strong>, numeric, gives the x-coord<strong>in</strong>ate of the leftmost end of the bars.• barend, numeric, gives the x-coord<strong>in</strong>ate of the rightmost end of the bars.• chartbar, a path array, gives the actual bars. For example, chartbar1 is the rectangle <strong>with</strong>opposite corners (barbeg<strong>in</strong>1,barstart1) <strong>and</strong> (barend1,barstart+barwd), where thenumeric variable barwd is the width (thickness) of the bar.• barlength, the same as barend. This is for backward compatibility; the name was chosenat a time when all the bars had one side on an axis (i.e., barbeg<strong>in</strong>[n] = 0 for all n).3.13.5 MANIPULATING METAFONT PICTURE VARIABLES\tile{〈tilename〉,〈unit〉,〈wd〉,〈ht〉,〈clip〉}〈<strong>MFPIC</strong> draw<strong>in</strong>g comm<strong>and</strong>s〉\endtileIn this environment, all draw<strong>in</strong>g comm<strong>and</strong>s contribute to a tile. A tile is a rectangular picturewhich may be used to fill the <strong>in</strong>terior of closed paths. Actually, a tile is a composite object. After\tile{fred, ... } ... \endtile a picture variable fred.pic is created as well as numericvariable fred.wd <strong>and</strong> fred.ht. These are needed by the \tess comm<strong>and</strong>, below.The units of draw<strong>in</strong>g are given by 〈unit〉, which should be a dimension (like 1pt or 2<strong>in</strong>). Thetile’s horizontal dimensions are 0 to 〈wd〉 · 〈unit〉 <strong>and</strong> its vertical dimensions 0 to 〈ht〉 · 〈unit〉, so〈wd〉 <strong>and</strong> 〈ht〉 should be pure numbers. If 〈clip〉 is true then the draw<strong>in</strong>g is clipped to be <strong>with</strong><strong>in</strong>the tile’s boundary.By us<strong>in</strong>g this macro, you can design your own fill patterns (to use them, see the \tess macrobelow), but please take some care <strong>with</strong> the æsthetics, <strong>and</strong> see the warn<strong>in</strong>g about memory use bythe \tess comm<strong>and</strong>. The 〈tilename〉 is globally def<strong>in</strong>ed by this comm<strong>and</strong>.\tess{〈tilename〉}...Tile the <strong>in</strong>terior of a closed path <strong>with</strong> a tessellation comprised of copies of the tile specified by〈tilename〉. The tile must have been previously created by \tile{〈tilename〉, ... }. Til<strong>in</strong>g anopen curve is technically an error, but the METAFONT code responds by draw<strong>in</strong>g the path <strong>and</strong> notdo<strong>in</strong>g any til<strong>in</strong>g. The METAFONT code places shifted copies of the tile picture <strong>in</strong> a rectangular gridsufficient to cover the region, then clips it to the closed path before draw<strong>in</strong>g it.Til<strong>in</strong>g large regions <strong>with</strong> complicated tiles can exceed the capacity of some versions of META-POST. There is less of a problem <strong>with</strong> METAFONT. This is not because METAFONT has greatercapacity, but because of the natural difference between bitmaps <strong>and</strong> vector graphics.


3.13 FOR ADVANCED USERS. 57In METAPOST, the tiles are copied <strong>with</strong> whatever color they are given when they are def<strong>in</strong>ed.They can be multicolored.Before version 0.8, \tile was the only way to create a picture variable, <strong>and</strong> the only way todraw this picture was <strong>with</strong> the \tess comm<strong>and</strong>. Now we have the follow<strong>in</strong>g comm<strong>and</strong> to placemultiple copies of a picture:\putmfpimage{〈name〉}〈list〉This take the name of a picture variable <strong>and</strong> copies the picture at each location <strong>in</strong> the 〈list〉,which should be a comma-separated list of coord<strong>in</strong>ate pairs <strong>in</strong> graph coorc<strong>in</strong>ates. The picture iscopied so that its reference po<strong>in</strong>t is placed at each of the locations. The reference po<strong>in</strong>t of a picturecreated <strong>with</strong> \tile is its lower left corner.\mfpimage[〈refpt〉]{〈picname〉}〈<strong>MFPIC</strong> draw<strong>in</strong>g comm<strong>and</strong>s〉\endmfpimageThis is another way to create a picture variable. The draw<strong>in</strong>g comm<strong>and</strong>s <strong>with</strong><strong>in</strong> the mfpimageenvironment contribute not to the current <strong>MFPIC</strong> picture, but rather to the picture variable named <strong>in</strong>〈picname〉. Otherwise, they operate exactly as they would outside this environment, us<strong>in</strong>g the samecoord<strong>in</strong>ate system <strong>and</strong> the same default values of all parameters, etc. (unlike the tile environment,which def<strong>in</strong>es its own coord<strong>in</strong>ate system). The picture is created <strong>with</strong> its reference po<strong>in</strong>t at the po<strong>in</strong>t〈refpt〉 given <strong>in</strong> the optional argument. The default is (0,0). For example:\mfpimage[(1,1)]{fred}\fill\rect{(0,0),(1,1)}\fill\rect{(1,1),(2,2)}\rect{(0,0),(2,2)}\endmfpimageproduces a simple 2-by-2 chessboard <strong>with</strong> its reference po<strong>in</strong>t at the center po<strong>in</strong>t (1,1). One canthen write someth<strong>in</strong>g like\putmfpimage{fred}{(1,1),(3,1),(1,3),(3,3)}to get a 4-by-4 chessboard: the picture fred copied <strong>with</strong> its center at each of the listed po<strong>in</strong>ts.The behavior of \tlabel s <strong>in</strong> an mfpimage environment depends on the current sett<strong>in</strong>g of twooptions. If mplabels is turned off, then labels are added by <strong>TEX</strong> <strong>and</strong> are not <strong>in</strong>cluded as part of thenamed METAFONT or METAPOST picture variable. If mplabels is turned on <strong>and</strong> overlaylabels isalso turned on, then the labels will be saved <strong>and</strong> placed when the mfpic environment ends <strong>and</strong> notadded to the named picture variable. Thus, to <strong>in</strong>clude text labels <strong>in</strong> the named picture variable, youmust have mplabels on <strong>and</strong> overlaylabels off.The picture created by \mfpimage is locally def<strong>in</strong>ed. That is, it becomes undef<strong>in</strong>ed at the endof the current mfpic environment. If one needs it to be global, one can use \globalsetvariable(see subsection 3.13.4) to copy it to another variable. For example. the comm<strong>and</strong>\globalsetvariable{picture}{wilma}{fred}


3.13 FOR ADVANCED USERS. 58would make wilma globally def<strong>in</strong>ed to be equal to the current value of the picture fred.You can use \putmfpimage <strong>in</strong>side a mfpimage environment, provided the picture be<strong>in</strong>g placedhas been previously def<strong>in</strong>ed. Nest<strong>in</strong>g a mfpimage <strong>in</strong>side another has not been completely tested<strong>and</strong> is not recommended. One can use the LA<strong>TEX</strong> environment construct \beg<strong>in</strong>{mfpimage} ...\end{mfpimage} <strong>in</strong> a LaTeX document <strong>in</strong>stead of \mfpimage ... \endmfpimage.3.13.6 METAFONT LOOPS\mfpfor{〈for-loop header〉}〈<strong>MFPIC</strong> comm<strong>and</strong>s〉\endmfpforThis creates a loop <strong>in</strong> the METAFONT output file. From the po<strong>in</strong>t of view of <strong>TEX</strong> the comm<strong>and</strong>sbetween \mfpfor <strong>and</strong> \endmfpfor are executed only once, but any code they write to the outputfile is executed repeatedly by METAFONT, accord<strong>in</strong>g to the <strong>in</strong>formation <strong>in</strong> 〈for-loop header〉. Thereare two types of header possible, illustrated by the follow<strong>in</strong>g examples.\mfpfor{center = (0,0), (1,0), (0,1)}\gfill\circle{center,1}\endmfpforThis example will fill three circles of radius 1 <strong>with</strong> centers at the three given po<strong>in</strong>ts. This type ofheader has the format〈variable〉 = 〈list〉where 〈variable〉 should be a simple variable name <strong>and</strong> 〈list〉 is a comma separated list of items ofthe appropriate data type. In the above, center needs coord<strong>in</strong>ate pairs, but <strong>in</strong> the follow<strong>in</strong>g\mfpfor{radius = 1,3,4}\dotted\circle{(0,0),radius}\endmfpforradius needs numeric data. The other type of header is for a stepped variable:\mfpfor{level = 3 step 2 until 9}\circle{(0,0),sqrt(level)}\endmfpforThis will cause level to step through the values 3, 5, 7 <strong>and</strong> 9 <strong>and</strong> the circles <strong>with</strong> radius √ 3, √ 5,etc. will be drawn. This type of header has the format〈variable〉 = 〈start〉 step 〈delta〉 until 〈stop〉where 〈variable〉 is as before, while 〈start〉, 〈delta〉 <strong>and</strong> 〈stop〉 are numeric values. If 〈delta〉 ispositive the loop is skipped entirely if 〈stop〉 is less than 〈start〉. Otherwise the loop is executedsuccessively <strong>with</strong> the variable equal to 〈start〉, then 〈start〉+〈delta〉 then 〈start〉+2〈delta〉, etc., aslong as the variable is not greater than 〈stop〉. The behavior is similar if 〈delta〉 is negative, exceptthe loop is repeated only as long as the variable is not less than 〈stop〉. If 〈delta〉 is 0, then theMETAFONT run will generate an error..The s<strong>in</strong>gle word “upto” can be used as an abbreviation for “step 1 until” <strong>and</strong> “downto”for “step -1 until” <strong>in</strong> for-loop headers. Spaces are not significant <strong>in</strong> for-loop headers.


3.13 FOR ADVANCED USERS. 59\mfpwhile{〈condition〉}〈<strong>MFPIC</strong> comm<strong>and</strong>s〉\endmfpwhileThe 〈condition〉 should be an expression that can be either true or false about a METAFONTvariable that changes at some time dur<strong>in</strong>g the loop body. The loop body is executed (by META-FONT) as long as the condition is true. Example:\setmfvariable{numeric}{R}{20}\mfpwhile{R > 1}\rect{(0,0), (R,3R)}\mfcmd{R:=R/2}\endmfpwhileThere are almost no <strong>MFPIC</strong> comm<strong>and</strong> to systematically change a variable, so <strong>in</strong> this example wehave resorted to directly writ<strong>in</strong>g a METAFONT assignment comm<strong>and</strong> via \mfcmd (see subsection3.13.3 above) that reduces R by half. The loop will be executed <strong>with</strong> R hav<strong>in</strong>g the successivevalues 20, 10, 5, 2.5, <strong>and</strong> 1.25.\mfploop〈<strong>MFPIC</strong> comm<strong>and</strong>s〉\mfpuntil{〈condition〉}〈<strong>MFPIC</strong> comm<strong>and</strong>s〉\endmfploopThe body of this loop will be repeated until the 〈condition〉 becomes true. The conditionshould be some expression that can be either true or false about a variable that changes dur<strong>in</strong>gthe loop execution. It should eventually become true. If an mfploop environment does not conta<strong>in</strong>an \mfpuntil comm<strong>and</strong>, then the \endmfploop comm<strong>and</strong> will generate a warn<strong>in</strong>g message. Ifthe warn<strong>in</strong>g is ignored, <strong>and</strong> the user has not otherwise arranged for loop term<strong>in</strong>ation, 13 the .mfwill conta<strong>in</strong> an <strong>in</strong>f<strong>in</strong>ite loop. The \mfpuntil comm<strong>and</strong> will break the loop at whatever po<strong>in</strong>t itoccurs. Example:\setmfvariable{numeric}{R}{20}\mfploop\mfcmd{R:=R/2}\mfpuntil{R


3.13 FOR ADVANCED USERS. 60\beg<strong>in</strong>{mfpfor}{radius = 1,3,4}\circle{(0,0),radius}\end{mfpfor}3.13.7 MISCELLANEOUS\noship\stopshipp<strong>in</strong>g\resumeshipp<strong>in</strong>g\stopshipp<strong>in</strong>g turns off character shipp<strong>in</strong>g (by METAFONT to the TFM <strong>and</strong> GF files, orby METAPOST to appropriate EPS output file) until \resumeshipp<strong>in</strong>g occurs. If you want justone character not shipped, just use \noship <strong>in</strong>side the mfpic environment. This is useful if allone wishes to do <strong>in</strong> the current mfpic environment is to make tiles (see above) or def<strong>in</strong>e picturevariables <strong>with</strong> \mfpimage. While the latter def<strong>in</strong>es the picture locally, one can globally copy it toanother variable <strong>with</strong> \globalsetvariable (see subsection 3.13.4).\assignmfvalue{〈<strong>TEX</strong>-macro〉}{〈MF-expr〉}\assignmpvalue{〈<strong>TEX</strong>-macro〉}{〈MP-expr〉}These two comm<strong>and</strong>s differ only <strong>in</strong> spell<strong>in</strong>g; either may be substituted for the other <strong>in</strong> any document.This comm<strong>and</strong> causes the 〈MF-expr〉 to be passed to METAFONT for evaluation, which thenwrites the value to the figure’s .log file. On the next <strong>TEX</strong> run, if mfpreadlog (see section 2.10) is <strong>in</strong>effect, the macro 〈<strong>TEX</strong>-macro〉 will be def<strong>in</strong>ed to produce the result<strong>in</strong>g value. Before METAFONT isrun to evaluate the expression, the macro produces ‘???’. Thus, it cannot be used <strong>in</strong> places where anumber is needed (as <strong>in</strong> the position arguments of a \tlabel comm<strong>and</strong>). For example:\setmfvariable{numeric}{s}{3}\assignmfvalue{\val}{2*s+1}\tlabel(1,2){$\val$}After METAFONT is run <strong>and</strong> then <strong>TEX</strong> run a second time, \val will acquire the def<strong>in</strong>ition ‘7’ (thevalue of 2s + 1 when s = 3). If mplabels is <strong>in</strong> effect, the correct label is written to the figure fileonly dur<strong>in</strong>g this second run, <strong>and</strong> a second METAPOST run will be required. In many cases (whenus<strong>in</strong>g pdf<strong>TEX</strong>, for example, or when the label changes the figure dimensions), a third <strong>TEX</strong> run willbe required to make the figure correct when it is <strong>in</strong>cluded <strong>in</strong> the document.Note well that if a comm<strong>and</strong> def<strong>in</strong>ed by \assignmfvalue is used <strong>in</strong> a tlabel <strong>with</strong> mplabels <strong>in</strong>effect, then mplabels must be <strong>in</strong> effect dur<strong>in</strong>g the \assignmfvalue comm<strong>and</strong> as well.As usual, if the def<strong>in</strong>ition is <strong>in</strong>side a <strong>TEX</strong> group, the macro will become undef<strong>in</strong>ed when thegroup ends. You can put\global\assignmfvalueto override this. It is possible to use the same macro name <strong>in</strong> different mfpic environments, eachgett<strong>in</strong>g the correct value. However, because of the asynchronous nature of the def<strong>in</strong>ition, it willnot work to use \assignmfvalue <strong>with</strong> the same macro name more than once <strong>in</strong> the same mfpicenvironment, nor more than once outside mfpic environments. Moreover, the def<strong>in</strong>ition is actuallyattached to the number of the mfpic environment, so reorder<strong>in</strong>g the environments or add<strong>in</strong>g onemeans another <strong>TEX</strong>-METAFONT-<strong>TEX</strong> sequence is required.If the 〈<strong>TEX</strong>-macro〉 is already def<strong>in</strong>ed, no warn<strong>in</strong>g will be issued <strong>and</strong> the comm<strong>and</strong> will beredef<strong>in</strong>ed, so be careful <strong>in</strong> the name chosen. If mplabels is turned off when \assignmfvalue is


3.13 FOR ADVANCED USERS. 61used, but turned on before the 〈<strong>TEX</strong>-macro〉 is used <strong>in</strong> a \tlabel comm<strong>and</strong>, the macro def<strong>in</strong>itionwill not be written to the .mp file, <strong>and</strong> either an error message, or <strong>in</strong>correct label will result whenMETAPOST tries to make the tlabel.The concept <strong>and</strong> much of the code for \assignmfvalue came from Werner Lemberg.\cutoffafter{〈obj〉}. . .\cutoffbefore{〈obj〉}. . .\trimpath{〈dim 1 〉,〈dim 2 〉}. . .\trimpath{〈dim 1 〉}. . .These are prefix macros. The first two take an ‘object’ (a variable <strong>in</strong> which a path was previouslystored us<strong>in</strong>g \store) <strong>and</strong> uses it to trim one end off the follow<strong>in</strong>g path. \cutoffbeforecuts off the part of the path before its first <strong>in</strong>tersection <strong>with</strong> the object, while \cutoffafter cutsoff the part after the last <strong>in</strong>tersection. If the path does not <strong>in</strong>tersect the object, noth<strong>in</strong>g is cut off. Ifthe object <strong>and</strong> the path <strong>in</strong>tersect <strong>in</strong> more than one po<strong>in</strong>t, as little as possible (usually 14 ) is cut off.This is completely reliably only when there is only one po<strong>in</strong>t of <strong>in</strong>tersection.The \trimpath macro takes two dimensions separated by commas <strong>and</strong> trims those lengthsoff the <strong>in</strong>itial <strong>and</strong> term<strong>in</strong>al ends of the path. If only one dimension is given, that is used at bothends. This macro is essentially equivalent to apply<strong>in</strong>g a comb<strong>in</strong>ation of the first two comm<strong>and</strong>s,us<strong>in</strong>g as the objects circles which have radii equal to the given dimensions <strong>and</strong> which are centeredat the endpo<strong>in</strong>ts of the path. Consequently, if the path is shorter than either dimension, it will not<strong>in</strong>tersect either circle <strong>and</strong> noth<strong>in</strong>g will be trimmed. Similarly, if the result of the first cut is too shortthe second cut may not cut anyth<strong>in</strong>g off. If the path <strong>in</strong>tersects one of these circles more than once,it is not predictable at which po<strong>in</strong>t the cut will be made.The first two macros can be used to create a curve that starts or ends right at another figure<strong>with</strong>out hav<strong>in</strong>g to f<strong>in</strong>d the po<strong>in</strong>t where the two curves <strong>in</strong>tersect. The third one can be used on theresult to produce a curve that stops just short of the po<strong>in</strong>t of <strong>in</strong>tersection.\mftitle{〈title〉}Write the str<strong>in</strong>g 〈title〉 to the METAFONT file, <strong>and</strong> use it as a METAFONT message. (See TheMETAFONTbook, chapter 22, page 187, for two uses of this.)\tmtitle{〈title〉}Write the text 〈title〉 to the <strong>TEX</strong> document, <strong>and</strong> to the log file, <strong>and</strong> use it implicitly <strong>in</strong> \mftitle.This macro forms a local group around its argument.S<strong>in</strong>ce <strong>TEX</strong> is limited to 256 dimension registers, <strong>and</strong> s<strong>in</strong>ce dimensions are so important to typesett<strong>in</strong>g<strong>and</strong> draw<strong>in</strong>g, it is common to use up all 256 when draw<strong>in</strong>g packages are loaded. Therefore<strong>MFPIC</strong> uses font dimensions to store dimension values. The follow<strong>in</strong>g is the comm<strong>and</strong> that h<strong>and</strong>lesthe allocation of these dimensions.\newfdim{〈fdim〉}This create a new global font dimension named 〈fdim〉, which is a <strong>TEX</strong> control sequence (<strong>with</strong>backslash). It can be used almost like an ord<strong>in</strong>ary <strong>TEX</strong> dimension. One exception is that the <strong>TEX</strong>comm<strong>and</strong>s \advance, \multiply <strong>and</strong> \divide cannot be applied directly to font dimensions14 METAFONT’s methods for f<strong>in</strong>d<strong>in</strong>g the ‘first’ po<strong>in</strong>t of <strong>in</strong>tersection do not always f<strong>in</strong>d the actual first one.


3.13 FOR ADVANCED USERS. 62(nor LA<strong>TEX</strong>’s \addtolength); however, the font dimension can be copied to a temporary <strong>TEX</strong>dimension register, which can then be manipulated <strong>and</strong> copied back (us<strong>in</strong>g \setlength <strong>in</strong> LA<strong>TEX</strong>,if desired). Another exception is that all changes to a font dimension are global <strong>in</strong> scope. Alsobeware that \newfdim uses font dimensions from a s<strong>in</strong>gle font, the dummy font, which most <strong>TEX</strong>systems ought to have. (You’ll know if yours doesn’t, because <strong>MFPIC</strong> will fail upon load<strong>in</strong>g!)Also, implementations of <strong>TEX</strong> differ <strong>in</strong> the number of font dimensions allowed per font. Hopefully,<strong>MFPIC</strong> won’t exceed your local <strong>TEX</strong>’s limit.All of <strong>MFPIC</strong>’s basic dimension parameters are font dimensions. We have lied slightly when wecalled them ‘<strong>TEX</strong> dimensions’. We arrange for them to be local to mfpic environments by sav<strong>in</strong>gtheir values at the start <strong>and</strong> restor<strong>in</strong>g them at the end.\setmfpicgraphic{〈filename〉}This is the comm<strong>and</strong> that is <strong>in</strong>voked to place the graphic created. See appendix 4.6.3 for adiscussion of its use <strong>and</strong> its default def<strong>in</strong>ition. It is a user-level macro so that it can be redef<strong>in</strong>ed <strong>in</strong>unusual cases. It operates on the output of the follow<strong>in</strong>g macro:\setfilename{〈file〉}{〈num〉}<strong>MFPIC</strong>’s figure <strong>in</strong>clusion code ultimately executes \setmfpicgraphic on the result of apply<strong>in</strong>g\setfilename to two arguments: the file name specified <strong>in</strong> the \opengraphsfile comm<strong>and</strong><strong>and</strong> the number of the current picture. Normally \setfilename just puts them together<strong>with</strong> the ‘.’ separator (because that is usually the way METAPOST names its output), but thiscan be redef<strong>in</strong>ed if the METAPOST output undergoes further process<strong>in</strong>g or conversion to anotherformat <strong>in</strong> which the name is changed. Any redef<strong>in</strong>ition of \setfilename must come before\opengraphsfile because that comm<strong>and</strong> tests for the existence of the first figure. After anyredef<strong>in</strong>ition, \setfilename must be a macro <strong>with</strong> two arguments that creates the actual filenamefrom the above two parts. It should also be completely exp<strong>and</strong>able. See the appendices, subsection4.6.3 for further dicussion.\preparemfpicgraphic{〈filename〉}This comm<strong>and</strong> is automatically <strong>in</strong>voked before \setmfpicgraphic to make any preparationsneeded. The default def<strong>in</strong>ition is to do noth<strong>in</strong>g except when the GRAPHICS package is used. Thatpackage provides no clean way to determ<strong>in</strong>e the bound<strong>in</strong>g box of the graphic after it is <strong>in</strong>cluded.S<strong>in</strong>ce <strong>MFPIC</strong> needs this <strong>in</strong>formation, this comm<strong>and</strong> redef<strong>in</strong>es an <strong>in</strong>ternal comm<strong>and</strong> of the graphicspackage to make the data available. If \setmfpicgraphic is redef<strong>in</strong>ed then this may also have tobe redef<strong>in</strong>ed.\getmfpicoffset{〈filename〉}This comm<strong>and</strong> is automatically <strong>in</strong>voked after \setmfpicgraphic to store the offset of thelower left corner of the figure <strong>in</strong> the macros \mfpicllx <strong>and</strong> \mfpiclly. If \setmfpicgraphicis redef<strong>in</strong>ed then this may also have to be redef<strong>in</strong>ed.\ifmfpmpostUsers wish<strong>in</strong>g to write code that adjusts its behavior to the graph file processor can use thisto test which option is <strong>in</strong> effect. The macro \usemetapost sets it true <strong>and</strong> \usemetafont sets itfalse. There are no comm<strong>and</strong>s \mfpmposttrue nor \mfpmpostfalse, s<strong>in</strong>ce the user should not


3.13 FOR ADVANCED USERS. 63be chang<strong>in</strong>g the sett<strong>in</strong>g once it is set: a great deal of <strong>MFPIC</strong> <strong>in</strong>ternal code depends on them, <strong>and</strong> onkeep<strong>in</strong>g them consistent <strong>with</strong> the \opengraphsfile comm<strong>and</strong>s read<strong>in</strong>g of these booleans.\mfpicversionThis exp<strong>and</strong>s to the current <strong>MFPIC</strong> version multiplied by 100. At this writ<strong>in</strong>g, it produces ‘80’because the version is 0.80a. It can be used to test the version:\ifx\mfpicversion\undef<strong>in</strong>ed \def\mfpicversion{0}\fi\ifnum\mfpicversion>70 ... \else ... \fi\mfpicversion was added <strong>in</strong> version 0.7.Most of <strong>MFPIC</strong>’s comm<strong>and</strong>s have arguments <strong>with</strong> parts delimited by commas <strong>and</strong> parentheses.In most cases this is no problem because they are written unchanged to the .mf <strong>and</strong> there theyare parsed just f<strong>in</strong>e. Some comm<strong>and</strong>s’ arguments, however, have to be parsed by both <strong>TEX</strong> <strong>and</strong>METAFONT. Examples are \tlabel (sometimes, under mplabels), <strong>and</strong> \po<strong>in</strong>tdef. One might betempted to use METAPOST expressions there <strong>and</strong> that works f<strong>in</strong>e as long as they do not conta<strong>in</strong>commas or parentheses. In such cases, they can sometimes be enclosed <strong>in</strong> braces to prevent <strong>TEX</strong>see<strong>in</strong>g these elements as delimiters, but sometimes these braces might get written to the .mf (or.mp) output <strong>and</strong> cause a METAFONT (METAPOST) error. In such cases the follow<strong>in</strong>g work-aroundmight be possible:\def\identity#1{#1}\po<strong>in</strong>tdef{A}(\identity{angle (1,2)},3)\rect{(0,0),\A}The braces prevent <strong>TEX</strong>’s argument pars<strong>in</strong>g from see<strong>in</strong>g the first comma as a delimiter, butupon writ<strong>in</strong>g to the .mf, the \identity comm<strong>and</strong>s are exp<strong>and</strong>ed <strong>and</strong> only the contents appear <strong>in</strong>the output. (<strong>TEX</strong> parses the argument to assign mean<strong>in</strong>gs to \Ax <strong>and</strong> \Ay.)


4 Appendices4.1 Acknowledgements.Tom would like to thank all of the people at Dartmouth as well as out <strong>in</strong> the network world fortest<strong>in</strong>g <strong>MFPIC</strong> <strong>and</strong> send<strong>in</strong>g him back comments. He would particularly like to thank:Geoffrey Tob<strong>in</strong> for his many suggestions, especially about clean<strong>in</strong>g up the METAFONT code,enforc<strong>in</strong>g dimensions, fix<strong>in</strong>g the dotted l<strong>in</strong>e computations, <strong>and</strong> speed<strong>in</strong>g up the shad<strong>in</strong>g rout<strong>in</strong>es(through this process, Geoffrey <strong>and</strong> Tom managed to teach each other many of the subtleties ofMETAFONT), <strong>and</strong> for keep<strong>in</strong>g track of <strong>MFPIC</strong> for nearly a year while Tom f<strong>in</strong>ished his thesis;Bryan Green for his many suggestions, some of which (<strong>in</strong>clud<strong>in</strong>g his rewrit<strong>in</strong>g the \tcaptionmacro) ultimately led to the current version’s ability to put graphs <strong>in</strong>-l<strong>in</strong>e or side-by-side; <strong>and</strong>Uwe Bonnes <strong>and</strong> Jaromír Kuben, who worked out rewrites of <strong>MFPIC</strong> dur<strong>in</strong>g Tom’s work<strong>in</strong>ghiatus <strong>and</strong> who each contributed several valuable ideas.Some credit also belongs to Anthony Stark, whose work on a FIG to METAFONT converter hashad a serious impact on the development of many of <strong>MFPIC</strong>’s capabilities.F<strong>in</strong>ally, Tom would like to thank Alan Vlach, the other <strong>TEX</strong>nician at Berry College, for help<strong>in</strong>ghim decide on the format of many of the macros, <strong>and</strong> for help<strong>in</strong>g <strong>with</strong> test<strong>in</strong>g.Dan Lueck<strong>in</strong>g would like to echo Tom’s thanks to all of the above, especially Geoffrey Tob<strong>in</strong><strong>and</strong> Jaromír Kuben. And to add the names Taco Hoekwater, for comments, advice <strong>and</strong> suggestions,Werner Lemberg, for the \assignmfvalue, <strong>and</strong> Zaimi Sami Alex for suggestions.But mostly, he’d like to thank Tom Leathrum for start<strong>in</strong>g it all.4.2 Changes History.See the file changes.txt for a somewhat sporadic <strong>and</strong> rambl<strong>in</strong>g history of changes to <strong>MFPIC</strong>(through the previous version). See the file new.txt for changes s<strong>in</strong>ce the previous version. Seethe file README for any known problems.4.3 Summary of OptionsUnless otherwise stated, any of the comm<strong>and</strong> forms will be local to the current mfpic environmentif used <strong>in</strong>side. Otherwise it will affect all later environments.OPTION: COMMAND FORM(S): RESTRICTIONS:metapost \usemetapost Comm<strong>and</strong> must come before\opengraphsfile. Incompatible <strong>with</strong>metafont option.metafont \usemetafont The default. Comm<strong>and</strong> must come before\opengraphsfile. Incompatible <strong>with</strong>metapost option.mplabels\usemplabels,\nomplabelsRequires metapost. If comm<strong>and</strong> is used<strong>in</strong>side an mfpic environment, it shouldcome before \tlabel comm<strong>and</strong>s to beaffected.64


4 APPENDICES 65overlaylabelstruebboxclipclearsymbolscenteredcaptionsdebugdraftf<strong>in</strong>alnowrite\overlaylabels,\nooverlaylabels\usetruebbox,\notruebbox\clipmfpic,\noclipmfpic\clearsymbols,\noclearsymbols\usecenteredcaptions,\nocenteredcaptions\mfpicdebugtrue,\mfpicdebugfalse\mfpicdraft\mfpicf<strong>in</strong>al\mfpicnowriteHas no effect <strong>with</strong>out metapost.Has no effect <strong>with</strong>out metapost.No restrictions.No restrictions.If comm<strong>and</strong> is used <strong>in</strong>side an mfpicenvironment, it should come before the\tcaption comm<strong>and</strong>.To turn on debugg<strong>in</strong>g while mfpic.tex isload<strong>in</strong>g, issue \def\mfpicdebug{true}.Should not be used together. Comm<strong>and</strong>forms should come before\opengraphsfilemfpreadlog \mfpreadlog Needed for \assignmfvalue. Must occurbefore \opengraphsfile.4.4 Plott<strong>in</strong>g Styles for \plotdataWhen \plotdata passes from one curve to the next, it <strong>in</strong>crements a counter <strong>and</strong> uses that counterto select a dash pattern, color, or symbol. It uses predef<strong>in</strong>ed dash pattern names dashtype0 throughdashtype5, or predef<strong>in</strong>ed color names colortype0 through colortype7, or predef<strong>in</strong>ed symbolspo<strong>in</strong>ttype0 through po<strong>in</strong>ttype8. Here follows a description of each of these variables. Thesevariables must not be used <strong>in</strong> the second argument of \reconfigureplot, whose purpose is toredef<strong>in</strong>e these variables.Under \dashedl<strong>in</strong>es, we have the follow<strong>in</strong>g dash patterns:NAME PATTERN MEANINGdashtype0 0bp solid l<strong>in</strong>edashtype1 3bp,4bp dashesdashtype2 0bp,4bp dotsdashtype3 0bp,4bp,3bp,4bp dot-dashdashtype4 0bp,4bp,3bp,4bp,0bp,4bp dot-dash-dotdashtype5 0bp,4bp,3bp,4bp,3bp,4bp dot-dash-dashUnder \coloredl<strong>in</strong>es, we have the follow<strong>in</strong>g colors. Except for black <strong>and</strong> red, each coloris altered as <strong>in</strong>dicated. This is an attempt to make the colors more equal <strong>in</strong> visibility aga<strong>in</strong>st a whitebackground. (The success of this attempt varies greatly <strong>with</strong> the output or display device.)


4 APPENDICES 66NAME COLOR (R,G,B)colortype0 black (0,0,0)colortype1 red (1,0,0)colortype2 blue (.2,.2,1)colortype3 orange (.66,.34,0)colortype4 green (0,.8,0)colortype5 magenta (.85,0,.85)colortype6 cyan (0,.85,.85)colortype7 yellow (.85,.85,0)Under \po<strong>in</strong>tedl<strong>in</strong>es <strong>and</strong> \datapo<strong>in</strong>tsonly, the follow<strong>in</strong>g symbols are used. Internallyeach is referred to by the numeric name, but they are identical to the more descriptive name.Syntactically, all are METAFONT path variables. (The order changed between versions 0.6 <strong>and</strong>0.7.)NAMEpo<strong>in</strong>ttype0po<strong>in</strong>ttype1po<strong>in</strong>ttype2po<strong>in</strong>ttype3po<strong>in</strong>ttype4po<strong>in</strong>ttype5po<strong>in</strong>ttype6po<strong>in</strong>ttype7po<strong>in</strong>ttype8DESCRIPTIONCircleCrossSolidDiamondSquarePlusTriangleSolidCircleStarSolidTriangle4.5 Special Considerations When Us<strong>in</strong>g METAFONTThe most important restriction <strong>in</strong> METAFONT is on the size of a picture. Coord<strong>in</strong>ates <strong>in</strong> METAFONTultimately refer to pixel units <strong>in</strong> the font that is output. These are required to be less than 4096,so an absolute limit on the size of a picture is whatever length a row of 4095 pixels is. In fontsprepared for a LaserJet4 (600 DPI), this means 6.825 <strong>in</strong>ches (17.3355cm). For a 1200 DPI pronter,the limit is 3.4125 <strong>in</strong>ches.A similar limit holds for numbers <strong>in</strong>put, <strong>and</strong> the values of variables: METAFONT will returnan error for s<strong>in</strong> 4096. Intermediate values can be greater (s<strong>in</strong> (2*2048) will cause no error),but f<strong>in</strong>al, stored results are subject to the limit. An <strong>MFPIC</strong> example that generated an error recentlywas:\mfpicunit 1mm\mfpic[10]{-3}{7}{-3.5}{5}\function{-4.5,4,.1}{x*x}\endmfpicThe problem was the value of 4.5 ∗ 4.5 = 20.25 <strong>in</strong> pixel units (after multiply<strong>in</strong>g by the \mfpicscal<strong>in</strong>g factor the \mfpicunit <strong>in</strong> <strong>in</strong>ches <strong>and</strong> the DPI value): 20.25 × 10 × 0.03937 × 600 > 4783.The error did not occur at the po<strong>in</strong>t of creat<strong>in</strong>g the font, but merely at the po<strong>in</strong>t of stor<strong>in</strong>g the path<strong>in</strong> an <strong>in</strong>ternal variable for manipulation <strong>and</strong> draw<strong>in</strong>g.


4 APPENDICES 67In METAPOST, the limit on numeric values is only 4 times as high: 32768. However, that is<strong>in</strong>dependent of pr<strong>in</strong>ter resolution <strong>and</strong> is <strong>in</strong>terpreted as POSTSCRIPT po<strong>in</strong>ts (<strong>TEX</strong>’s ‘big po<strong>in</strong>ts’). At72 po<strong>in</strong>ts to the <strong>in</strong>ch, this allows figures to be about 12.6 yards (11.56m).4.6 Special Considerations When Us<strong>in</strong>g METAPOST4.6.1 REQUIRED SUPPORTTo use <strong>MFPIC</strong> <strong>with</strong> METAPOST, the follow<strong>in</strong>g support is needed (besides a work<strong>in</strong>g METAPOST<strong>in</strong>stallation):Under pla<strong>in</strong><strong>TEX</strong>Under LA<strong>TEX</strong>209Under LA<strong>TEX</strong>Under pdfLA<strong>TEX</strong>Under pla<strong>in</strong> pdf<strong>TEX</strong>In all casesThe file epsf.tex(No longer supported)The package GRAPHICS or GRAPHICXThe package GRAPHICS or GRAPHICX <strong>with</strong> option pdftexThe files supp-pdf.tex <strong>and</strong> supp-mis.texThe files grafbase.mp <strong>and</strong> dvipsnam.mp plus, of course, mfpic.tex (<strong>and</strong>mfpic.sty for LA<strong>TEX</strong>)The files grafbase.mp <strong>and</strong> dvipsnam.mp should be <strong>in</strong> a directory searched by METAPOST.The rema<strong>in</strong><strong>in</strong>g files should be <strong>in</strong> directories searched by the appropriate <strong>TEX</strong> variant. If METAPOSTcannot f<strong>in</strong>d the file grafbase.mp, then by default it will try to <strong>in</strong>put grafbase.mf, which isgenerally futile (or fatal).In case pdfLA<strong>TEX</strong> is used, the graphics package is given the pdftex option. This option requiresthe file pdftex.def which currently <strong>in</strong>puts the files supp-pdf.tex <strong>and</strong> supp-mis.tex. The filepdftex.def is supplied <strong>with</strong> the GRAPHICS package. The other two are usually supplied <strong>with</strong> apdf<strong>TEX</strong> distribution, <strong>and</strong> are def<strong>in</strong>itely part of the Con<strong>TEX</strong>t distribution. 15 Older versions had somebugs <strong>in</strong> connection <strong>with</strong> the BABEL package. One workaround was to load the GRAPHICS package<strong>and</strong> <strong>MFPIC</strong> before BABEL.If the user loads one of the above required files or packages before the <strong>MFPIC</strong> macros areloaded then <strong>MFPIC</strong> will not reload them. If they have not been <strong>in</strong>put, <strong>MFPIC</strong> will load whicheverone it decides is required. In the LA<strong>TEX</strong> 2ε case, <strong>MFPIC</strong> will load the GRAPHICS package. If the userwishes GRAPHICX, then that package must be loaded before <strong>MFPIC</strong>.4.6.2 METAPOST IS NOT METAFONTPOSTSCRIPT is not a pixel oriented language <strong>and</strong> so neither is METAPOST. The model for draw<strong>in</strong>gobjects is completely different between METAFONT <strong>and</strong> METAPOST, <strong>and</strong> so one cannot alwaysexpect the same results. METAPOST support <strong>in</strong> <strong>MFPIC</strong> was carefully written so that files successfullypr<strong>in</strong>ted <strong>with</strong> <strong>MFPIC</strong> us<strong>in</strong>g METAFONT would be just as successfully pr<strong>in</strong>ted us<strong>in</strong>g METAPOST.Nevertheless, it frequently choke on files that make use of the \mfsrc comm<strong>and</strong> for writ<strong>in</strong>g codedirectly to the .mf file. While grafbase.mp is closely based on grafbase.mf, some of the codehad to be completely rewritten.<strong>Pictures</strong> <strong>in</strong> METAPOST are stored as (possibly nested) sequences of objects, where objects areth<strong>in</strong>gs like po<strong>in</strong>ts, paths, contours, sub-pictures, etc. In METAFONT, pictures are stored as a grid ofpixels. <strong>Pictures</strong> that are relatively simple <strong>in</strong> one program might be very complex <strong>in</strong> the other <strong>and</strong>15 At this writ<strong>in</strong>g, the file CTAN/macros/context/cont-mpd.zip conta<strong>in</strong>s these two support files, plus a few othersfor work<strong>in</strong>g <strong>with</strong> METAPOST.


4 APPENDICES 68even exceed memory allocated for their storage. Two examples are the \polkadot <strong>and</strong> \hatchcomm<strong>and</strong>s. When the polkadot space <strong>and</strong> size are both too small, a \polkadot-ed region has beenknown to exceed METAPOST capacity, while be<strong>in</strong>g well <strong>with</strong><strong>in</strong> METAFONT capacity. In METAPOSTthe memory consumed by \hatch goes up <strong>in</strong> direct proportion to the l<strong>in</strong>ear dimensions of thefigure be<strong>in</strong>g hatched, while <strong>in</strong> METAFONT it goes up <strong>in</strong> proportion to the area (except <strong>in</strong> horizontalhatch<strong>in</strong>g), <strong>and</strong> then the reverse can happen, <strong>with</strong> METAFONT’s capacity exeeded far sooner thatMETAPOST’s.In METAPOST it is important to note that each prefix modifies the result of the entire follow<strong>in</strong>gsequence. In essence prefixes can be viewed as be<strong>in</strong>g applied <strong>in</strong> the opposite order to theiroccurrence. Example:\dashed\gfill\rect{(0,0),(1,1)}This adds the dashed outl<strong>in</strong>e to the filled rectangle. That is, first the rectangle is def<strong>in</strong>ed, then it isfilled, then the outl<strong>in</strong>e is drawn <strong>in</strong> dashed l<strong>in</strong>es. This makes a difference when colors other thanblack are used. Draw<strong>in</strong>g is done <strong>with</strong> the center of the virtual pen stroked down the middle of theboundary, so half of its width falls <strong>in</strong>side the rectangle. On the other h<strong>and</strong>, fill<strong>in</strong>g is done right upto the boundary. In this example, the dashed l<strong>in</strong>es are drawn on top of part of the fill. In the reverseorder, the fill would cover part of the dashed outl<strong>in</strong>e.4.6.3 GRAPHIC INCLUSIONIt may be impossible to completely cater to all possible methods of graphic <strong>in</strong>clusions <strong>with</strong> automatictests. The macro that is <strong>in</strong>voked to <strong>in</strong>clude the POSTSCRIPT graphic is \setmfpicgraphic<strong>and</strong> the user may (carefully!) redef<strong>in</strong>e this to suit special circumstances. Actually, <strong>MFPIC</strong> runs thefollow<strong>in</strong>g sequence:\preparemfpicgraphic{〈filename〉}\setmfpicgraphic{〈filename〉}\getmfpicoffset{〈filename〉}The follow<strong>in</strong>g are the default def<strong>in</strong>itions for \setmfpicgraphic:In pla<strong>in</strong> <strong>TEX</strong>:In LA<strong>TEX</strong>209:In LA<strong>TEX</strong>:In pdfLA<strong>TEX</strong>:In pdf<strong>TEX</strong>:\def\setmfpicgraphic#1{\epsfbox{#1}}(No longer supported)\def\setmfpicgraphic#1{\<strong>in</strong>cludegraphics{#1}}\def\setmfpicgraphic#1{\<strong>in</strong>cludegraphics{#1}}\def\setmfpicgraphic#1{\convertMPtoPDF{#1}{1}{1}}Moreover, s<strong>in</strong>ce METAPOST by default writes files <strong>with</strong> numeric extensions, we add code toeach figure, so that these graphics are correctly recognized as EPS or MPS. For example, to thefigure <strong>with</strong> extension .1, we add the equivalent of one of the follow<strong>in</strong>g\DeclareGraphicsRule{.1}{eps}{.1}{} <strong>in</strong> LA<strong>TEX</strong> 2ε.\DeclareGraphicsRule{.1}{mps}{.1}{} <strong>in</strong> pdfLA<strong>TEX</strong>.After runn<strong>in</strong>g the comm<strong>and</strong> \setmfpicgraphic, <strong>MFPIC</strong> runs \getmfpicoffset to store thelower left corner of the bound<strong>in</strong>g box of the figure <strong>in</strong> two macros \mfpicllx <strong>and</strong> \mfpiclly.


4 APPENDICES 69All the above versions of \setmfpicgraphic (except \<strong>in</strong>cludegraphics) make this <strong>in</strong>formationavailable; the def<strong>in</strong>ition of \getmfpicoffset merely copies it <strong>in</strong>to these two macros. What<strong>MFPIC</strong> does <strong>in</strong> the case of \<strong>in</strong>cludegraphics is to modify (locally) the def<strong>in</strong>ition of an <strong>in</strong>ternalcomm<strong>and</strong> of the graphics package so that it copies the <strong>in</strong>formation to those macros, <strong>and</strong>then \getmfpicoffset does noth<strong>in</strong>g. This <strong>in</strong>ternal modification is accomplished by the macro\preparemfpicgraphic. Changes to \setmfpicgraphic might require chang<strong>in</strong>g either or bothof \preparemfpicgraphic <strong>and</strong> \getmfpicoffset. All three of these comm<strong>and</strong>s are fed thegraphic’s file name as the only argument, although only \setmfpicgraphic currently does anyth<strong>in</strong>g<strong>with</strong> it.One possible reason for want<strong>in</strong>g to redef<strong>in</strong>e \setmfpicgraphic might be to rescale all pictures.This is def<strong>in</strong>itely not a good idea <strong>with</strong>out the option mplabels s<strong>in</strong>ce the <strong>MFPIC</strong> code forplac<strong>in</strong>g labels <strong>and</strong> captions <strong>and</strong> reserv<strong>in</strong>g space for the picture relies on the picture hav<strong>in</strong>g thedimensions given by the arguments to the \mfpic comm<strong>and</strong>. With mplabels plus truebbox it willprobably work, but (i) it has not been considered <strong>in</strong> writ<strong>in</strong>g the <strong>MFPIC</strong> code, (ii) it will then scaleall the text as well as the figure, <strong>and</strong> (iii) it will scale all l<strong>in</strong>e thickness, which should normally bea design choice <strong>in</strong>dependent of the size of a picture. To rescale all pictures, one need only change\mfpicunit <strong>and</strong> rerun <strong>TEX</strong> <strong>and</strong> METAPOST.A better reason might be to allow the conversion of your METAPOST figures to some otherformat. Then redef<strong>in</strong><strong>in</strong>g \setmfpicgraphic could enable <strong>in</strong>clud<strong>in</strong>g the appropriate file <strong>in</strong> theappropriate format.The filename argument mentioned above is actually the result obta<strong>in</strong>ed by runn<strong>in</strong>g the macro\setfilename. The comm<strong>and</strong> \setfilename gets two arguments: the name of the METAPOSToutput file (set <strong>in</strong> the \opengraphsfile comm<strong>and</strong>) <strong>with</strong>out extension, <strong>and</strong> the number of the picture.The default def<strong>in</strong>ition of \setfilename merely <strong>in</strong>serts a dot between the two arguments. Thatis \setfilename{fig}{1} produces fig.1. You can redef<strong>in</strong>e this behavior also. Any changes to\setfilename must come after the <strong>MFPIC</strong> macros are <strong>in</strong>put <strong>and</strong> before the \opengraphsfilecomm<strong>and</strong>. Any changes to \setmfpicgraphic must come after the <strong>MFPIC</strong> macros are <strong>in</strong>put <strong>and</strong>before any \mfpic comm<strong>and</strong>s, but it is best to place it before the \opengraphsfile comm<strong>and</strong>.As <strong>MFPIC</strong> is currently written, \setfilename must be completely exp<strong>and</strong>able, which means itshould conta<strong>in</strong> no def<strong>in</strong>itions, no assignments such as \setcounter, <strong>and</strong> no calculations. To testwhether a proposed def<strong>in</strong>ition is completely exp<strong>and</strong>able, put\message{***\setfilename{file}{1}***}after the def<strong>in</strong>ition <strong>in</strong> a .tex file <strong>and</strong> view the result on the term<strong>in</strong>al or <strong>in</strong> the .log file. You shouldsee only your expected filename between the asterisks.4.7 <strong>MFPIC</strong> <strong>and</strong> the Rest of the World4.7.1 THE LITERATUREThis author has personal knowledge of only one mathematical article which def<strong>in</strong>itely uses <strong>MFPIC</strong>to create diagrams, <strong>and</strong> that is this author’s jo<strong>in</strong>t paper <strong>with</strong> J. Duncan <strong>and</strong> C. M. McGregor: Onthe value of pi for norms <strong>in</strong> R 2 <strong>in</strong> the College Mathematics Journal, vol. 35, pages 84–92.There are at least two major publications where <strong>MFPIC</strong> has garnered more than a cursory mention.The most up-to-date is a section <strong>in</strong> The LA<strong>TEX</strong> Graphics Companion by Michel Goossens,Sebastian Rahtz <strong>and</strong> Frank Mittelbach. It describes a version prior to the <strong>in</strong>troduction of META-POST support, but it correctly describes a subset of its current comm<strong>and</strong>s <strong>and</strong> abilities. The LA<strong>TEX</strong>


4 APPENDICES 70Companion (Second Edition) mentions <strong>MFPIC</strong>, but only <strong>in</strong> its annotation of the bibliography entryfor <strong>TEX</strong> Unbound (see below).The other is <strong>TEX</strong> Unbound by Alan Hoenig, which conta<strong>in</strong>s a chapter on <strong>MFPIC</strong>. Unfortunately,it describes a version that was replaced <strong>in</strong> 1996 <strong>with</strong> version 0.2.10.9. The follow<strong>in</strong>g summarizesthe differences between the description 16 found <strong>in</strong> Chapter 15 <strong>and</strong> <strong>MFPIC</strong> versions 0.2.10.9 throughthe current one:\wedge is now renamed \sector to avoid conflict <strong>with</strong> the <strong>TEX</strong> comm<strong>and</strong> of the same name.The syntax is slightly different from that given for \wedge:\sector{(〈x〉,〈y〉), 〈radius〉, 〈angle1〉, 〈angle2〉}The macro \plr{(〈r 0 〉,〈θ 0 〉),(〈r 1 〉,〈θ 1 〉),...} is used to convert polar coord<strong>in</strong>ate pairs torectangular coord<strong>in</strong>ates, so the comm<strong>and</strong>s \plrcurve, \plrcyclic, \plrl<strong>in</strong>es <strong>and</strong> \plrpo<strong>in</strong>twere dropped from <strong>MFPIC</strong>. Now use<strong>in</strong>stead of\curve{\plr{(〈r 0 〉,〈θ 0 〉),(〈r 1 〉,〈θ 1 〉),...}}\plrcurve{(〈r 0 〉,〈θ 0 〉),(〈r 1 〉,〈θ 1 〉),...}<strong>and</strong> similarly for \cyclic, \l<strong>in</strong>es <strong>and</strong> \po<strong>in</strong>t <strong>with</strong> respect to \plrcyclic, \plrl<strong>in</strong>es <strong>and</strong>\plrpo<strong>in</strong>t.\fill is now renamed \gfill to avoid conflict <strong>with</strong> the LA<strong>TEX</strong> comm<strong>and</strong> of the same name.\rotate, which rotates a follow<strong>in</strong>g figure about a po<strong>in</strong>t, is now renamed \rotatepath toavoid confusion <strong>with</strong> a similar name for a transformation (see below).\white is now renamed \gclear because \white is too likely to be chosen for, or confused<strong>with</strong>, a color comm<strong>and</strong>.The follow<strong>in</strong>g aff<strong>in</strong>e transform comm<strong>and</strong>s were changed from a third person <strong>in</strong>dicative form(which could be confused <strong>with</strong> a plural noun) to an imperative form:Old name:\boosts\reflectsabout\rotatesaround\rotates\scales\shifts\xscales\xslants\xyswaps\yscales\yslants\zscales\zslantsNew name:\boost\reflectabout\rotatearound\rotate\scale\shift\xscale\xslant\xyswap\yscale\yslant\zscale\zslant16 While I’m at it: <strong>TEX</strong> Unbound occasionally refers to <strong>MFPIC</strong> us<strong>in</strong>g a logo-like formatt<strong>in</strong>g <strong>in</strong> which the ‘MF’ is <strong>in</strong> aspecial font <strong>and</strong> the ‘I’ is lowered. This ‘logo’ may suggest a relationship between <strong>MFPIC</strong> <strong>and</strong> PIC<strong>TEX</strong>. There is no suchrelationship, <strong>and</strong> there is no official logo-like designation for <strong>MFPIC</strong>.


4 APPENDICES 71\caption <strong>and</strong> \label are now renamed \tcaption <strong>and</strong> \tlabel to avoid conflict <strong>with</strong> theLA<strong>TEX</strong> comm<strong>and</strong>s.\mfcmd was renamed \mfsrc for clarity, <strong>and</strong> (<strong>in</strong> version 0.7) a new \mfcmd was def<strong>in</strong>ed, whichis pretty much the same except it appends a semicolon to its argument.There is a mispr<strong>in</strong>t: \axisheadl<strong>in</strong> should be \axisheadlen.F<strong>in</strong>ally, <strong>in</strong> the LA<strong>TEX</strong> template on page 496: <strong>MFPIC</strong> now supports the \usepackage method ofload<strong>in</strong>g.4.7.2 OTHER PROGRAMSThere exists a program, FIG2<strong>MFPIC</strong> that produces <strong>MFPIC</strong> code as output. The code produced (asof this writ<strong>in</strong>g) is somewhat old <strong>and</strong> mostly <strong>in</strong>compatible <strong>with</strong> the description <strong>in</strong> this manual.Fortunately, it is accompanied by the appropriate versions of files mfpic.tex <strong>and</strong> grafbase.mf.Unfortunately, the names conflict <strong>with</strong> the current filenames <strong>and</strong> so they should only be used <strong>in</strong>circumstances where no substitution will occur, say <strong>in</strong> a local directory <strong>with</strong> the other sources forthe document be<strong>in</strong>g produced. Moreover, the documentation <strong>in</strong> this manual may not apply to thecode produced. However the <strong>in</strong>formation <strong>in</strong> <strong>TEX</strong> Unbound may apply.There exist a package, CIRCUIT_MACROS, that can produce a variety of output formats, one ofwhich is <strong>MFPIC</strong> code. One writes a file (don’t ask me what it consists of) <strong>and</strong> apparently processes it<strong>with</strong> M4 <strong>and</strong> then DPIC to produce the output. The <strong>MFPIC</strong> code produced appears to be compatible<strong>with</strong> the current <strong>MFPIC</strong>.


4 APPENDICES 724.8 Index of comm<strong>and</strong>s, options <strong>and</strong> parameters\applyT, 45\arc, 19\arrow, 26\assignmfvalue, 60\assignmpvalue, 60Asterisk, 12\axes, 13\axis, 14\axisheadlen, 49\axislabels, 40\axismarg<strong>in</strong>, 14\axismarks, 15\backgroundcolor, 22\barchart, 20\bargraph, 20\bclosed, 25\beg<strong>in</strong>{mfpic}, 10\bmarks, 15\boost, 45\btwnfcn, 33\btwnplrfcn, 33\cbclosed, 52centeredcaptions, 6\chartbar, 20Circle, 12\circle, 17\clearsymbols, 6, 12clearsymbols, 6clip, 5\clipmfpic, 5\closedcomputedspl<strong>in</strong>e, 52\closedcspl<strong>in</strong>e, 52\closedmfbezier, 53\closedqbeziers, 53\closedqspl<strong>in</strong>e, 52\closegraphsfile, 8cmyk(c,m,y,k), 23\colorarray, 55\coloredl<strong>in</strong>es, 37\computedspl<strong>in</strong>e, 52\connect, 25\convexcurve, 18\convexcyclic, 18\coords, 44Cross, 12\cspl<strong>in</strong>e, 52\curve, 18\cutoffafter, 61\cutoffbefore, 61\cyclic, 18\darkershade, 50\dashed, 28\dashedl<strong>in</strong>es, 37\dashlen, 50\dashl<strong>in</strong>eset, 50\dashpattern, 28\datafile, 13, 35\datapo<strong>in</strong>tsonly, 37debug, 6\defaultplot, 38Diamond, 12\doaxes, 14\dotl<strong>in</strong>eset, 50\dotsize, 50\dotspace, 50\dotted, 28\doubledraw, 27draft, 6\draw, 27\drawcolor, 22\drawpen, 49\ellipse, 17\endconnect, 25\endcoords, 44\endmfpfor, 58\endmfpframe, 44\endmfpic, 9\endmfpimage, 57\endmfploop, 59\endmfpwhile, 59\endpatharr, 55\endtile, 56


4 APPENDICES 73\everytlabel, 39\fcncurve, 18\fcnspl<strong>in</strong>e, 52\fdef, 31\fillcolor, 22fillcolor, 29, 30f<strong>in</strong>al, 6\function, 32\gclear, 29\gclip, 29\gendashed, 29\getmfpicoffset, 62, 68\gfill, 29\globalsetvariable, 54\graphbar, 20gray(g), 23\grid, 16\gridarcs, 16\gridl<strong>in</strong>es, 16\gridpo<strong>in</strong>ts, 16\gridrays, 16\hashlen, 50\hatch, 30\hatchcolor, 22\hatchspace, 51\hatchwd, 49\headcolor, 22\headlen, 49\headshape, 50\hgridl<strong>in</strong>es, 16\histobar, 20\histogram, 20\ifmfpmpost, 62\lattice, 16\lclosed, 25\levelcurve, 34\lhatch, 30\lightershade, 50\l<strong>in</strong>es, 12\lmarks, 15\makepercentcomment, 37\makepercentother, 37\makesector, 20metapost, 4\mfbezier, 53\mfcmd, 53\mflist, 53\mfobj, 46\mfpdatacomment, 36\mfpdataperl<strong>in</strong>e, 51\mfpdef<strong>in</strong>ecolor, 24\mfpfor, 58\mfpframe, 44\mfpframed, 44\mfpic, 9\mfpiccaptionskip, 42\mfpicdebugfalse, 6\mfpicdebugtrue, 6\mfpicdraft, 6, 7\mfpicf<strong>in</strong>al, 6, 7\mfpicheight, 51\mfpicnowrite, 6, 7\mfpicnumber, 9\mfpicunit, 48\mfpicversion, 63\mfpicwidth, 51\mfpimage, 57\mfpl<strong>in</strong>estyle, 37\mfpl<strong>in</strong>etype, 37\mfploop, 59\mfpreadlog, 7mfpreadlog, 7\mfpuntil, 59\mfpverbtex, 41\mfpwhile, 59\mfsrc, 53\mftitle, 61\mirror, 44mplabels, 4\mpobj, 46named(〈name〉), 23\newfdim, 61\newsavepic, 43\nocenteredcaptions, 6


4 APPENDICES 74\noclearsymbols, 6, 12\noclipmfpic, 5\nomplabels, 4\nooverlaylabels, 5\norender, 27\noship, 60\notruebbox, 5nowrite, 6\numericarray, 55\opengraphsfile, 8\overlaylabels, 5overlaylabels, 5\pairarray, 55\parafcn, 33\parallelpath, 26\partpath, 26\patharr, 55\pen, 49\penwd, 49\periodicfcnspl<strong>in</strong>e, 52\piechart, 21\piewedge, 21\plot, 28\plotdata, 37\plotnodes, 28\plotsymbol, 12\plottext, 41\plr, 22\plrfcn, 33\plrgrid, 16\plrgridpo<strong>in</strong>ts, 16\plrpatch, 16\plrregion, 34Plus, 12\po<strong>in</strong>t, 12\po<strong>in</strong>tcolor, 22\po<strong>in</strong>tdef, 11\po<strong>in</strong>tedl<strong>in</strong>es, 37\po<strong>in</strong>tfillfalse, 49\po<strong>in</strong>tfilltrue, 49\po<strong>in</strong>tsize, 49\polkadot, 30\polkadotspace, 50\polkadotwd, 49\polygon, 12\polyl<strong>in</strong>e, 12\preparemfpicgraphic, 62, 68\putmfpimage, 57\qbclosed, 52\qbeziers, 53\qspl<strong>in</strong>e, 52\reconfigureplot, 38\rect, 12\reflectabout, 44\reflectpath, 47\regpolygon, 13\resumeshipp<strong>in</strong>g, 60\reverse, 25RGB(R,G,B), 23rgb(r,g,b), 23\rhatch, 30\rmarks, 15\rotate, 44\rotatearound, 44\rotatepath, 47\savepic, 43\scale, 44\scalepath, 47\sclosed, 25\sector, 20\sequence, 36\setallaxismarg<strong>in</strong>s, 14\setallbordermarks, 15\setaxismarg<strong>in</strong>s, 14\setaxismarks, 15\setbordermarks, 15\setfilename, 62, 69\setmfarray, 55\setmfboolean, 54\setmfcolor, 54\setmfnumeric, 54\setmfpair, 54\setmfpicgraphic, 62, 68\setmfvariable, 54\setmparray, 55


4 APPENDICES 75\setmpvariable, 54\setrender, 31\settension, 18\setxmarks, 15\setymarks, 15\shade, 29\shadespace, 50\shadewd, 49\shift, 44\shiftpath, 47\sideheadlen, 49\slantpath, 47\smoothdata, 35SolidCircle, 12SolidDiamond, 12SolidSquare, 12SolidStar, 12SolidTriangle, 12Square, 12Star, 12\stopshipp<strong>in</strong>g, 60\store, 45\subpath, 26\symbolspace, 51\tcaption, 41\tess, 56\thatch, 30\tile, 56\tlabel, 38\tlabelcircle, 43\tlabelcolor, 22\tlabelellipse, 43\tlabeljustify, 40\tlabeloffset, 40, 51\tlabeloval, 42\tlabelrect, 42\tlabels, 38\tlabelsep, 40, 51\tlpathjustify, 43\tlpathsep, 40, 51\tlpo<strong>in</strong>tsep, 40, 51\tmarks, 15\tmtitle, 61\transformpath, 47Triangle, 12\trimpath, 61truebbox, 5\turn, 44\turtle, 20\unsmoothdata, 35\usecenteredcaptions, 6\usemetafont, 7\usemetapost, 4, 7\usemplabels, 4\usepic, 43\usetruebbox, 5\us<strong>in</strong>g, 36\us<strong>in</strong>gnumericdefault, 36\us<strong>in</strong>gpairdefault, 36\vgridl<strong>in</strong>es, 16\xaxis, 13\xhatch, 30\xmarks, 15\xscale, 44\xscalepath, 47\xslant, 45\xslantpath, 47\xyswap, 45\xyswappath, 47\yaxis, 13\ymarks, 15\yscale, 45\yscalepath, 47\yslant, 45\yslantpath, 47\zscale, 45\zslant, 45


4 APPENDICES 764.9 List of comm<strong>and</strong>s by type4.9.1 FIGURES\arc\axis\btwnfcn\chartbar\circle\computedspl<strong>in</strong>e,\closedcomputedspl<strong>in</strong>e\convexcurve\convexcyclic\cspl<strong>in</strong>e, \closedcspl<strong>in</strong>e\curve\cyclic\datafile\ellipse\fcncurve\fcnspl<strong>in</strong>e\function\graphbar\histobar\levelcurve\l<strong>in</strong>es\mfbezier, \closedmfbezier\mfobj\mpobj\parafcn\periodicfcnspl<strong>in</strong>e\piewedge\plrfcn\plrregion\polygon\polyl<strong>in</strong>e\qbeziers, \closedqbeziers\qspl<strong>in</strong>e \closedqspl<strong>in</strong>e\rect\regpolygon\sector\tlabelcircle\tlabelellipse\tlabeloval\tlabelrect\turtle4.9.2 FIGURE MODIFIERS\arrow\bclosed\cbclosed\connect, \endconnect\cutoffafter\cutoffbefore\lclosed\makesector\parallelpath\partpath\qbclosed\reflectpath\reverse\rotatepath\scalepath\sclosed\shiftpath\slantpath\subpath\transformpath\trimpath\xscalepath\xslantpath\xyswappath\yscalepath\yslantpath4.9.3 FIGURE RENDERERS\dashed\dotted\doubledraw\draw\gclear\gclip\gendashed\gfill\hatch\lhatch\plot\plotdata (sort of)\plotnodes\polkadot


4 APPENDICES 77\rhatch\shade\tess\thatch\xhatch4.9.4 LENGTHS\axisheadlen\dashlen\dotsize\dotspace\hashlen\hatchspace\headlen\mfpiccaptionskip\mfpicheight\mfpicunit\mfpicwidth\po<strong>in</strong>tsize\polkadotspace\shadespace\sideheadlen\symbolspace4.9.5 COORDINATE TRANSFORMATION\applyT\boost\coords, \endcoords\mirror\reflectabout\rotate\rotatearound\scale\shift\turn\xscale\xslant\xyswap\yscale\yslant\zscale\zslant4.9.6 SYMBOLS, AXES, GRIDS, MARKS\axes\axis\axismarks\bmarks\doaxes\grid\gridarcs\gridl<strong>in</strong>es\gridpo<strong>in</strong>ts\gridrays\hgridl<strong>in</strong>es\lattice\lmarks\plotsymbol\plrgridpo<strong>in</strong>ts\plrgrid\plrpatch\po<strong>in</strong>t\putmfpimage\rmarks\tmarks\vgridl<strong>in</strong>es\xaxis\xmarks\yaxis\ymarks4.9.7 SETTING OPTIONS\clearsymbols\clipmfpic\mfpicdebugfalse\mfpicdebugtrue\mfpicdraft\mfpicf<strong>in</strong>al\mfpicnowrite\mfpreadlog\nocenteredcaptions\noclearsymbols\noclipmfpic\nomplabels\nooverlaylabels\noship\notruebbox\overlaylabels\resumeshipp<strong>in</strong>g\stopshipp<strong>in</strong>g


4 APPENDICES 78\usecenteredcaptions\usemetafont\usemetapost\usemplabels\usetruebbox4.9.8 SETTING VALUES\axismarg<strong>in</strong>\darkershade\dashl<strong>in</strong>eset\dashpattern\dotl<strong>in</strong>eset\drawpen\hatchwd\headshape\lightershade\mfpicnumber\mfpl<strong>in</strong>estyle\mfpl<strong>in</strong>etype\pen\penwd\polkadotwd\setallaxismarg<strong>in</strong>s\setallbordermarks\setaxismarg<strong>in</strong>s\setaxismarks\setbordermarks\setmfvariable\setmpvariable\settension\setxmarks\setymarks\shadewd4.9.9 CHANGING COLORS\backgroundcolor\drawcolor\fillcolor\hatchcolor\headcolor\mfpdef<strong>in</strong>ecolor\po<strong>in</strong>tcolor\tlabelcolor4.9.10 DEFINING ARRAYS\barchart\bargraph\colorarray\histogram\numericarray\pairarray\patharr, \endpatharr\piechart\setmfarray\setmparray4.9.11 CHANGING BEHAVIOR\clearsymbols\coloredl<strong>in</strong>es\dashedl<strong>in</strong>es\datapo<strong>in</strong>tsonly\defaultplot\everytlabel\makepercentcomment\makepercentother\mfpdatacomment\mfpdataperl<strong>in</strong>e\mfpverbtex\noclearsymbols\po<strong>in</strong>tedl<strong>in</strong>es\po<strong>in</strong>tfillfalse\po<strong>in</strong>tfilltrue\reconfigureplot\setrender\smoothdata\tlabeljustify\tlabeloffset\tlabelsep\tlpathjustify\tlpathsep\tlpo<strong>in</strong>tsep\unsmoothdata\us<strong>in</strong>g\us<strong>in</strong>gnumericdefault\us<strong>in</strong>gpairdefault4.9.12 FILES AND ENVIRONMENTS\closegraphsfile\mfpframe, \endmfpframe\mfpic, \endmfpic\opengraphsfile


4 APPENDICES 794.9.13 <strong>TEX</strong>T\axislabels\plottext\tcaption\tlabel\tlabels4.9.14 MISC\assignmfvalue\assignmpvalue\fdef\getmfpicoffset\ifmfpmpost\mfcmd\mflist\mfpfor, \endmfpfor\mfpframed\mfpicversion\mfpimage, \endmfpimage\mfploop, \endmfploop\mfpuntil\mfpwhile, \endmfpwhile\mfsrc\mftitle\newfdim\newsavepic\plr\po<strong>in</strong>tdef\preparemfpicgraphic\savepic\sequence\setfilename\setmfpicgraphic\store\tile, \endtile\tmtitle\usepic

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!