summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/fmp/fmp.dtx
blob: 9384c0f008a5f374a72481227f0190aa63ee0068 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
% \iffalse meta-comment
%
% Copyright 2001 Marco Kuhlmann
%
% This program is distributed under the conditions of the
% LaTeX Project Public License, which can be found in
% http://www.latex-project.org/lppl.txt
%
% This program consists of the files fmp.ins and fmp.dtx
%
% \fi
%
%
% \CheckSum{260}
%
% \changes{v1.0a}{2001/04/03}{%
%   Initial release.}
%
% \CharacterTable
%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%   Digits        \0\1\2\3\4\5\6\7\8\9
%   Exclamation   \!     Double quote  \"     Hash (number) \#
%   Dollar        \$     Percent       \%     Ampersand     \&
%   Acute accent  \'     Left paren    \(     Right paren   \)
%   Asterisk      \*     Plus          \+     Comma         \,
%   Minus         \-     Point         \.     Solidus       \/
%   Colon         \:     Semicolon     \;     Less than     \<
%   Equals        \=     Greater than  \>     Question mark \?
%   Commercial at \@     Left bracket  \[     Backslash     \\
%   Right bracket \]     Circumflex    \^     Underscore    \_
%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%   Right brace   \}     Tilde         \~}
%
% \title{Functional {\MP} for {\LaTeX}\thanks{%
%     This file has version number \fileversion.}}
% \author{Marco Kuhlmann\thanks{%
%     E-Mail: \texttt{marco.kuhlmann@gmx.net}}}
% \date{\filedate}
% \maketitle
%
%
% \begin{abstract}
%   Functional {\MP} (\FMP) is a powerful frontend to the {\MP}
%   language. This package adds basic {\FMP} support to {\LaTeX},
%   enabling users to keep {\FMP} source code within their
%   documents and, by a two-run mechanism, including
%   automatically generated {\FMP} figures.
% \end{abstract}
%
%
% \section{Introduction}
%
% Functional {\MP} by Joachim Korittky (\cite{Diplomarbeit}) adds
% a high-level interface to the {\MP} language (\cite{MetaPost1},
% \cite{MetaPost2}), enabling the user to program their graphics
% using the Haskell language. Impressive examples of Functional
% {\MP} can be found in Korittky's diploma thesis; some of them
% will be given below. The system and the documentation can be
% downloaded from
% \begin{quote}
%   \texttt{http://www.informatik.uni-bonn.de/\~{}ralf/software.html}
% \end{quote}
%
% Using Functional {\MP} as my standard graphics developing tool,
% I felt a need to write a {\LaTeX} package which smoothly
% integrates {\FMP} into daily work, similar to the |emp| package
% by Thorsten Ohl (\cite{EMP}); this is how |fmp| came to being.
% The earliest version supported only the possibility to
% automatically produce shell-scripts for graphics generation.
% Since then, I have added the possibility to encapsulate {\FMP}
% code -- though I still ask myself if this way of maintaining
% code is as natural for {\FMP} as it is for pure {\MP} in |emp|.
%
% In case you have any questions or comments on this package,
% feel free to send me an email. May |fmp| help {\FMP} to spread
% around the world. \texttt{:-)}
%
%
% \subsection{Examples of Functional {\MP}}
%
% Before I start to present the |fmp| package, let me first give
% you two mouth-watering examples of {\FMP} (the Haskell code for
% them can be found at the end of this document):
% figure~\ref{figure:example1} gives a binominal tree of
% rank~$5$, figure~\ref{figure:example2} shows a simple Venn
% diagram. Among other things, these examples exhibit two
% features in which {\FMP} is superior to many other graphics
% drawing packages around:
% \begin{itemize}
% \item By embedding {\MP} into the Haskell programming language,
%   {\FMP} gives the user (and especially users who have previous
%   experience in functional programming) a great tool to program
%   graphics on a very high-level level of abstraction. This not
%   only helps you to focus on the logical structure rather than
%   on layout questions, but also is especially important if you
%   want to scale and re-use old material.
% \item {\FMP} can be easily extended. For example, for
%   figure~\ref{figure:example1}, the core language has been
%   augmented by tree drawing features, using much better
%   algorithms than those of any other tree drawing package
%   around. This is especially good news for computer scientists,
%   who need trees very often, but did not yet have a package to
%   draw them on such a level of abstraction.
% \end{itemize}
%
% \begin{figure}
%   \begin{center}
%     \fmpfigure{example1}
%   \end{center}
%   \caption{A binominal tree of rank~$5$}
%   \label{figure:example1}
% \end{figure}
%
% \begin{figure}
%   \begin{center}
%     \fmpfigure{example2}
%   \end{center}
%   \caption{A Venn diagram (cf.\ figure~22 in \cite{MetaPost2})}
%   \label{figure:example2}
% \end{figure}
%
% To be able to use {\FMP}, you need a Haskell interpreter, such
% as |hugs|, and the {\MP} program, which should be part of any
% somewhat complete distribution of {\LaTeX}. Having produced a
% Haskell source, you feed it into |hugs| and issue the
% |generate| command provided by {\FMP}. This will translate your
% code into low-level {\MP} commands, and finally produce a
% ready-to use PostScript file.
%
% \subsection{How this package works}
%
% Calling |hugs| and typing in the generation commands is a
% tedious job if you keep more than but a few illustrations
% around. This package offers the |\fmpfigure| command, which
% generates a shell script (at present, this only works for
% $*$n$*$x), which you then can execute to have all the graphics
% files generated at once. At the next run of {\LaTeX}, these
% graphic files will appear at their proper positions.  Besides,
% |fmp| enables you to store Haskell code within a {\LaTeX} file,
% in case you want to have all the code for one document at one
% place.
%
%
% \section{Usage}
%
% \subsection{Including graphics}
%
% \changes{v1.0b}{2001/10/22}{%
%   Documentation: Improvements as suggested by Peter Bartke.}
% Using \verb|fmp| to include graphics from some {\FMP} source is
% straightforward. Let us assume that you keep two {\FMP} figures
% (Haskell values) \verb|example1| and \verb|example2| in a file
% called \verb|fmp-doc.hs|. A minimal document using the package to
% include these two figures would then look like this:
%
% \medskip\noindent\bgroup\small
% \verb|\documentclass{article}|\\
% \verb|\usepackage{fmp}|\\
% \verb|\fmpsourcefilename{fmp-doc}|\\
% \verb|\begin{document}|\\
% \verb|\fmpfigure{example1}|\\
% \verb|\fmpfigure{example2}|\\
% \verb|\end{document}|\\
% \verb|\end{verbatim}|
% \medskip\par\egroup
%
% \DescribeMacro{\fmpfigure} You include a figure into your
% {\LaTeX} document by using the |\fmpfigure| macro. It takes, as
% its mandatory argument, the string identifying the figure in
% the Haskell source, and creates a shell script containing all
% the |hugs| calls needed for the actual generation. After the
% shell script has been written, you can execute it and run
% {\LaTeX} again; if everything went right, the graphics file
% will appear at the place where you issued the |\fmpfigure|
% command.
%
% \changes{v1.1a}{2001/11/19}{%
%   Documentation: Optional arguments to \cs{fmpfigure} are now
%   passed to the \texttt{graphicx} package.}
% Any optional arguments to |\fmpfigure| will be passed to the
% |graphicx| package and interpreted as if they appeared together
% with a |\includegraphics| command. This allows you to change
% the visual appearance of the included figure (e.\,g., the size
% to which the figure shall be scaled). Refer to \cite{graphicx}
% for more information about possible paramters.
%
% \subsection{Including code}
%
% \DescribeEnv{fmp} You can also store your {\FMP} code in the same
% file than your {\LaTeX} source, included within the |fmp|
% environment. During compilation, the contents of this environment
% are written to an external file (see below).
%
% \subsection{Changing file names}
%
% \DescribeMacro{\fmpsourcefilename}
% \DescribeMacro{\fmpscriptfilename}
% \DescribeMacro{\fmpfigurebasename}
% You can control the names of three different files:
% \begin{itemize}
% \item the Haskell source (|\fmpsourcefilename|, defaults to
%   \meta{jobname}|.hs|),
% \item the shell script (|\fmpscriptfilename|, defaults to
%   |fmpgenerate.sh|) and
% \item the graphics file base name (|\fmpfigurebasename|,
%   defaults to |fmpfigure|), which is the base file name of the
%   graphics files that will be generated by |hugs|. (An index
%   number specifying their order in the document will be
%   appended to this name.)
% \end{itemize}
% You can modify all three file names by calling the respective
% macros, each of which takes the new name as its argument.
%
% \subsection{Preamble and postamble}
%
% \DescribeMacro{\fmpsourcepreamble}
% \DescribeMacro{\fmpaddtosourcepreamble}
% \DescribeMacro{\fmpscriptpreamble}
% \DescribeMacro{\fmpaddtoscriptpreamble}
% \DescribeMacro{\fmpsourcepostamble}
% \DescribeMacro{\fmpaddtosourcepostamble}
% \DescribeMacro{\fmpscriptpostamble}
% \DescribeMacro{\fmpaddtoscriptpostamble}
% Before something is written to the source file or the shell
% script file, the package will output a \emph{preamble} to that
% file. The source code preamble could contain everything from
% comments to Haskell module identifications and basic imports,
% while the shell script preamble should probably contain the
% line that calls |hugs| and tells it to input the rest of the
% file as comment. Have a sample run to see the default contents
% of the preamble. If you wish to change the text: you can set a
% new preamble by the |\fmpsourcepreamble| command, and you can
% append a new line to the current preamble calling
% |\fmpaddtosourcepreamble|. (Similar commands are available for
% the shell script preamble.) There is also a postamble, which is
% written as the very last thing to the source code or shell
% script.
%
% \MP\ uses the environment variable \verb|$TEX| to determine which
% \TeX\ it has to call when generating labels etc. On many systems,
% this variable defaults to \verb|tex|, which is certainly not what
% you want in conjunction with \verb|fmp|. One common usage for the
% preamble therefore is to include a line like
% \verb|export TEX=latex| (or something similar, depending on your
% shell) into the generation script.
%
% \subsection{Graphics file formats}
%
% The |graphicx| package is used to handle the inclusion of
% generated {\FMP} figures. If |fmp| is called from within
% |pdflatex|, |graphicx| is loaded with the |pdftex| driver
% option.  In this case, the fall-back behaviour when
% encountering an |\fmpfigure| command is to read the
% corresponding graphics file as |mps| ({\MP} output); it will
% then internally be converted to \textsc{pdf} by |graphicx|.
% When called from within normal |latex|, graphics files are
% handled as |eps| (encapsulated PostScript).  You probably need
% to load a specific PostScript driver for |graphicx| in this
% case -- do so by supplying |fmp| with the same package option
% that you would use for |graphicx| (see the |graphicx| user
% manual for further information on that).
%
%
% \subsection*{Acknowledgements}
%
% The help of Ralf Hinze and the suggestions of Peter Bartke and
% Ferenc Wagner are gratefully acknowledged.
%
%
% \section*{Source code for the examples}
%
% \verbatiminput{fmp-doc.hs}
%
%
% \StopEventually{%
%   \begin{thebibliography}{XXX99}
%   \bibitem[Hob89]{MetaPost1}
%     \textsc{John D.\ Hobby:}
%     \emph{A {\MF}-like System with PostScript Output.}
%     TUGboat vol.~10, no.~2, pp.\ 505--512, 1989
%   \bibitem[Hob92]{MetaPost2}
%     \textsc{John D.\ Hobby:}
%     \emph{A User's manual for {\MP}.}
%     Computing Science Technical Report no.~162, AT\&T Bell
%     Laboratories, Murray Hill, New Jersey, 1992
%   \bibitem[Kor98]{Diplomarbeit}
%     \textsc{Joachim Korittky:}
%     \emph{functional {\MP}. Eine Beschreibungsspra\-che
%       f\"ur Grafiken.}
%     Diplomarbeit an der Rheinischen
%     Friedrich-Wilhelms-Universit\"at Bonn, 1998
%   \bibitem[Ohl97]{EMP}
%     \textsc{Thorsten Ohl:}
%     \emph{EMP: Encapsulated {\MP} for {\LaTeX}.}
%     Technische Hochschule Darmstadt, 1998
%   \bibitem[Car99]{graphicx}
%     \changes{v1.1a}{2001/11/19}{%
%       Added to bibliography: Reference to \texttt{graphicx}
%       package user documentation.}
%     \textsc{David Carlisle:}
%     \emph{Packages in the `graphics' bundle.}
%     User documentation, 1999
%   \end{thebibliography}}
%
%
% \section{The Documentation Driver File}
%
%    \begin{macrocode}
%<*driver>
\documentclass{ltxdoc}
\usepackage{fmp}
\usepackage{mflogo}
\OnlyDescription
\GetFileInfo{fmp.sty}
\newcommand*{\FMP}{\textsc{fmp}}
\fmpsourcefilename{fmp-doc}
\setcounter{topnumber}{1}
\makeatletter
\let\verbatim@oldfont=\verbatim@font
\def\verbatim@font{\small\verbatim@oldfont}
\makeatother
\tolerance=2000
\emergencystretch=20pt
\RecordChanges
\begin{document}
\DocInput{fmp.dtx}
\PrintChanges
\end{document}
%</driver>
%    \end{macrocode}
%
%
% \section{The Implementation}
%
% \subsection{Setup}
%
%    \begin{macrocode}
%<*package>
%    \end{macrocode}
%
% We start with the usual identification procedure. All the
% options that |fmp| cannot cater for itself are passed to the
% |graphicx| package, as they probably are requests for special
% PostScript drivers (see above).
%    \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}[1995/05/16]
\ProvidesPackage{fmp}
[2001/11/19 v1.1a Support for Functional MetaPost]
\DeclareOption*{\PassOptionsToPackage{\CurrentOption}{graphicx}}
\ProcessOptions
%    \end{macrocode}
%
% Depending on whether or not |fmp| is called from within
% |pdflatex|, the |graphicx| package has to be loaded with or
% without the |pdftex| option. A fall-back rule is declared for
% |\includegraphics| commands.
%    \begin{macrocode}
\@ifundefined{pdfoutput}{%
  \RequirePackage{graphicx}[1999/02/16]%
  \DeclareGraphicsRule{*}{eps}{*}{}}{%
  \RequirePackage[pdftex]{graphicx}[1994/12/15]%
  \DeclareGraphicsRule{*}{mps}{*}{}}
%    \end{macrocode}
%
% The |verbatim| package is used for writing the contents of the
% |fmp| environment (see below) into a file.
%    \begin{macrocode}
\RequirePackage{verbatim}
%    \end{macrocode}
%
% We set up new streams |\fmp@sourceout| and |\fmp@scriptout| for
% the Haskell source and the shell script to be written, as well
% as conditionals to remember whether or not we have already
% opened these streams.
%    \begin{macrocode}
\newwrite\fmp@sourceout
\newwrite\fmp@scriptout
\newif\iffmp@sourceio
\fmp@sourceiofalse
\newif\iffmp@scriptio
\fmp@scriptiofalse
%    \end{macrocode}
%
% Finally, we need a counter for the figures that we want to
% generate.
%    \begin{macrocode}
\newcounter{fmpfigure}
%    \end{macrocode}
%
% \subsection{Writing the source code}
%
% \begin{environment}{fmp}
% The |fmp| environment writes its contents into the
% |\fmp@sourceout| stream. This is done in an almost
% ``classical'' way, employing the |verbatim| package.
%    \begin{macrocode}
\newenvironment*{fmp}{}{}
\def\fmp{%
  \begingroup
    \@bsphack
    \let\do\@makeother\dospecials
    \catcode`\^^M\active
    \def\verbatim@processline{\fmp@sourcewrite{\the\verbatim@line}}%
    \verbatim@start}
\def\endfmp{%
    \@esphack
  \endgroup}
%    \end{macrocode}
% \end{environment}
%
% \begin{macro}{\fmp@sourcewrite}
% This is the wrapper used for writing to the source file.  Every
% time it is called, it checks whether or not the
% |\fmp@sourceout| stream has already been opened. If not, it
% calls |\fmp@sourceopen| to do so. (I do so because I want to
% avoid situations like in the |emp| package, where the outstream
% is opened and a file is created, even when at the end nothing
% is written to it. Is this too expensive?)
%    \begin{macrocode}
\def\fmp@sourcewrite#1{%
  \iffmp@sourceio \else \global\fmp@sourceiotrue\fmp@sourceopen \fi%
  \immediate\write\fmp@sourceout{#1}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\fmp@sourceopen}
% Opens the output stream for the source file and writes the
% preamble.
%    \begin{macrocode}
\def\fmp@sourceopen{%
  \immediate\openout\fmp@sourceout\fmp@sourcefilename%
  \edef\@tempa{\the\fmp@sourcepreamble}%
  \immediate\write\fmp@sourceout{\@tempa}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\fmpsourcefilename}
% \begin{macro}{\fmp@sourcefilename}
% Set the filename of the source file.
%    \begin{macrocode}
\newcommand*{\fmpsourcefilename}[1]{%
  \gdef\fmp@sourcefilename{#1}}
\@onlypreamble{\fmpsourcefilename}
\def\fmp@sourcefilename{\jobname.hs}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\fmp@sourcepreamble}
% \begin{macro}{\fmpsourcepreamble}
% \begin{macro}{\fmpaddtosourcepreamble}
% Sets up the preamble for the source file, as well as macros to
% reset them or append new lines to it.
%    \begin{macrocode}
\newtoks\fmp@sourcepreamble
\newcommand*{\fmpsourcepreamble}[1]{%
  \global\fmp@sourcepreamble={#1}}
\@onlypreamble{\fmpsourcepreamble}
\newcommand*{\fmpaddtosourcepreamble}[1]{%
  \fmp@sourcepreamble=\expandafter{\the\fmp@sourcepreamble#1}}
\@onlypreamble{\fmpaddtosourcepreamble}
\fmp@sourcepreamble={-- This is file `\fmp@sourcefilename',
  created automatically. Do not edit!^^J}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\fmp@sourceclose}
% This is added to \LaTeX's |\@enddocumenthook|. It writes the
% postamble to the source file and closes the output stream.
%    \begin{macrocode}
\def\fmp@sourceclose{%
  \iffmp@sourceio
    \edef\@tempa{\the\fmp@sourcepostamble}%
    \fmp@sourcewrite{\@tempa}%
    \immediate\closeout\fmp@sourceout
  \fi}
\AtEndDocument{\fmp@sourceclose}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\fmp@sourcepostamble}
% \begin{macro}{\fmpsourcepostamble}
% \begin{macro}{\fmpaddtosourcepostamble}
% Sets up the postamble for the source file, as well as macros to
% reset and update it.
%    \begin{macrocode}
\newtoks\fmp@sourcepostamble
\newcommand*{\fmpsourcepostamble}[1]{%
  \global\fmp@sourcepostamble={#1}}
\@onlypreamble{\fmpsourcepostamble}
\newcommand*{\fmpaddtosourcepostamble}[1]{%
  \fmp@sourcepostamble=\expandafter{\the\fmp@sourcepostamble#1}}
\@onlypreamble{\fmpaddtosourcepostamble}
\fmp@sourcepostamble={^^J-- End of file `\fmp@sourcefilename'}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \subsection{Writing the shell script}
%
% \begin{macro}{\fmpfigure}
% \changes{v1.1a}{2001/11/19}{%
%   Pass through optional arguments to the \texttt{graphicx}
%   package, as suggested by Ferenc Wagner.}
% Writes a new line to the |\fmp@scriptout| stream, which is
% connected to the generation shell script file, telling |hugs|
% to generate a graphics file with the name specified. Any
% optional argument is passed to the |graphicx| package.
%    \begin{macrocode}
\newcommand*{\fmpfigure}[2][]{%
  \fmp@scriptwrite{%
    generate "\fmp@figurebasename" \thefmpfigure\space #2}%
  \fmp@includegraphics{#1}{\fmp@figurebasename}{\thefmpfigure}%
  \refstepcounter{fmpfigure}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\fmp@scriptwrite}
% Wrapper for writing to the shell script file.
%    \begin{macrocode}
\def\fmp@scriptwrite#1{%
  \iffmp@scriptio \else \global\fmp@scriptiotrue\fmp@scriptopen \fi%
  \immediate\write\fmp@scriptout{#1}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\fmp@scriptopen}
% Opens the output stream for the shell script file and writes
% the preamble.
%    \begin{macrocode}
\def\fmp@scriptopen{%
  \immediate\openout\fmp@scriptout\fmp@scriptfilename%
  \edef\@tempa{\the\fmp@scriptpreamble}%
  \immediate\write\fmp@scriptout{\@tempa}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\fmp@scriptpreamble}
% \begin{macro}{\fmpscriptpreamble}
% \begin{macro}{\fmpaddtoscriptpreamble}
% Set up the preamble for the shell script file as well as macros
% to reset and append information to it.
%    \begin{macrocode}
\newtoks\fmp@scriptpreamble
\newcommand*{\fmpscriptpreamble}[1]{%
  \global\fmp@scriptpreamble={#1}}
\@onlypreamble{\fmpscriptpreamble}
\newcommand*{\fmpaddtoscriptpreamble}[1]{%
  \fmp@scriptpreamble=\expandafter{\the\fmp@scriptpreamble#1}}
\@onlypreamble{\fmpaddtoscriptpreamble}
\fmp@scriptpreamble={hugs \fmp@sourcefilename\space <<!}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\fmpscriptfilename}
% \begin{macro}{\fmp@scriptfilename}
% This sets the filename of the shell script which can be used
% for generation.
%    \begin{macrocode}
\newcommand*{\fmpscriptfilename}[1]{%
  \gdef\fmp@scriptfilename{#1}}
\@onlypreamble{\fmpscriptfilename}
\def\fmp@scriptfilename{fmpgenerate.sh}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\fmpfigurebasename}
% \begin{macro}{\fmp@figurebasename}
% This sets the base name for the graphics files that will be
% created by |hugs|. 
%    \begin{macrocode}
\newcommand*{\fmpfigurebasename}[1]{%
  \gdef\fmp@figurebasename{#1}}
\@onlypreamble{\fmpfigurebasename}
\def\fmp@figurebasename{fmpfigure}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\fmp@includegraphics}
% \changes{v1.1a}{2001/11/19}{%
%   Pass through optional arguments to the \texttt{graphicx}
%   package, as suggested by Ferenc Wagner.}
% This is a wrapper for the |\includegraphics| command. If the
% |graphicx| package has been loaded correctly, it should be able
% to import the graphics file, either directly in |eps| format,
% or after a transformation to |pdf| by the Con{\TeX}t macros
% included in the |pdftex| driver.
%    \begin{macrocode}
\def\fmp@includegraphics#1#2#3{%
  \leavevmode
  \IfFileExists{#2.#3}%
  {\includegraphics[#1]{#2.#3}}%
  {\typeout{fmp: Could not find file #2.#3}}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\fmp@scriptclose}
% Write the shell script postamble and close the output stream.
%    \begin{macrocode}
\def\fmp@scriptclose{%
  \iffmp@scriptio
    \edef\@tempa{\the\fmp@scriptpostamble}%
    \fmp@scriptwrite{\@tempa}%
    \immediate\closeout\fmp@scriptout
  \fi}
\AtEndDocument{\fmp@scriptclose}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\fmp@scriptpostamble}
% \begin{macro}{\fmpscriptpostamble}
% \begin{macro}{\fmpaddtoscriptpostamble}
% Set up the postamble for the shell script file as well as macros
% to reset and append information to it.
%    \begin{macrocode}
\newtoks\fmp@scriptpostamble
\newcommand*{\fmpscriptpostamble}[1]{%
  \global\fmp@scriptpostamble={#1}}
\@onlypreamble{\fmpscriptpostamble}
\newcommand*{\fmpaddtoscriptpostamble}[1]{%
  \fmp@scriptpostamble=\expandafter{\the\fmp@scriptpostamble#1}}
\@onlypreamble{\fmpaddtoscriptpostamble}
\fmp@scriptpostamble={:quit}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
%    \begin{macrocode}
%</package>
%    \end{macrocode}
%
%
% \Finale
%
%
%<*examples>
module FMPDoc where
import FMP
import FMPTree

example1           = binom 5
    where
    ce             = circle empty
    binom 0        = node ce []
    binom n        = node ce [edge (binom i)
                              | i <- [(n-1),(n-2)..0]]
                     #setAlign AlignRight

example2           = box (math "U" |||
                          ooalign [toPicture [cArea a 0.7,
                                              cArea b 0.7,
                                              cArea ab 0.4],
                                   bOverA])
    where
    cArea a c      = toArea a #setColor c
    bOverA         = column [math "B" #setBGColor white,
                             vspace 50,
                             math "A" #setBGColor white]
    a              = transformPath (scaled 30) fullcircle
    b              = transformPath (scaled 30 & shifted (0,-30))
                     fullcircle
    ab             = buildCycle a b
%</examples>