FPIC

David Hyatt and I are building a language for picture specification on top of Standard ML. It is provided with primitives that are inspired by the language PIC, which was - still is, I suppose - used for picture specification in the troff environment. The main idea is that, once these primitives are defined, the ML language features can be used to create "libraries" of code for drawing various types of pictures.

We have just finished a paper on the system:

Samuel Kamin, David Hyatt, A Special-purpose Language for Picture-Drawing, June 13, 1997, submitted for publication.

This will appear, in revised form, in the DSL '97 conference in Santa Barbara, CA, in October, 1997.

FPIC runs in Standard ML of New Jersey, version 109.29. (It seems to run in Moscow ML also, but I've only tried a couple of simple examples. There is one glitch; look in the file latexboxes.sml for a comment containing "Moscow ML".)

To obtain a preliminary version of the FPIC code in gzip format, click here; for a compressed tar file, click here. Each of these expands to a collection of files, explained in the README file, so they should be uncompressed in a new directory.

FPIC picture specifications are included in Latex documents. Using ML functions described below, each picture produces a file containing pstricks macros. (Pstricks is a package of TeX macros developed by ???.) When the Latex document is run through latex, these files are read and produce the pictures that were specified.

More specifically FPIC is simply a set of definitions in ML, so programming in FPIC is programming in ML. An FPIC specification is an ML expression of type Picture. To obtain a listing of the Picture-forming operations of FPIC, click here. This page explains the two commands used to extract the FPIC specifications from Latex documents and run them.

To incorporate FPIC pictures in Latex documents:

  1. Include the style file fpic.sty, as well as the pstricks files. Normally, this is done in the documentstyle command:
          \documentstyle[fpic,pstricks,...]{...}
    

    Give the SML code for each picture as the second argument to the FPIC command. The first argument is the name of the picture, which must be a valid TeX command name as well as a valid file name (on whatever system you are one); basically, this means that it must contain alphabetic characters only.

           \fpic{picname}{ ...
              ....
           }
    

    The picture to be drawn here must be included as an anonymous Picture-valued expression, the last expression in the brackets. For example,

            \fpic{boxpic}{
            val b1 = box 2.0 4.0;
            b1 hseq (b1 scaleXY 0.5);
            }
    
    is good, and
            \fpic{boxpic}{
            let val b1 = box 2.0 4.0;
            in b1 hseq (b1 scaleXY 0.5)
            end;
            }
    
    is also good, but
            \fpic{boxpic}{
            val b1 = box 2.0 4.0;
            val thebox = b1 hseq (b1 scaleXY 0.5);
            }
    
    is not. (This is because FPIC refers to the picture drawn in each FPIC command as it, which in SML refers to the most recent unnamed value.)

    Note that the final } must be on a new line and must be the only character on that line.

    All the FPIC code will eventually be evaluated in one shot, so you may include definitions in earlier pictures that will be seen by later pictures.

    Reminder: backslashes inside quotes in the FPIC code need to be escaped, that is, doubled.

  2. Before running Latex, load FPIC by starting SML and entering
           use "fpic.sml";
    

    Then enter the expression

           processTeXfile "filename";
    

    where your TeX file is filename.tex.

    This step creates a file named "fpicpics.sml", which is mainly just a listing of all the FPIC code given in \fpic commands.

  3. In FPIC (that is, in ML with FPIC functions loaded), enter
           use "fpicpics.sml";
    

    When evaluated, the expressions in fpicpics.sml create files fpic-pic1.tex, fpic-pic2.tex, etc., where pic1, pic2, ..., are the picture names from the FPIC commands. It also attempts to find the sizes of all the text boxes from the log file; the first time a text box shows up, the log file will have no record of it and FPIC will use an approximation; on subsequent runs, the correct sizes of text boxes will be used.

  4. Run latex on the TeX file. This will include the FPIC pictures. However, it will not correctly calculate the sizes of text boxes.
  5. To correctly calculate the sizes of text boxes, repeat steps 3 and 4. Each time a new picture is added, or a picture is modified so as to include more or different text boxes, steps 2 - 4 must be done, and then steps 3 and 4 repeated. (On the other hand, changes in the TeX file that do not involved pictures do not require that step 2 or 3 be done again.)


    Back to Sam Kamin's DSL research page
    Back to Sam Kamin's home page