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