Caml drawings in PostScript
Pierre Weis
1 What is GraphPS ?
GraphPs is an Objective Caml library used to generate PostScript files from
Caml graphics drawings.
GraphPs provides a module similar to the usual graphics drawings
module Graphics of the regular Caml distribution. This module,
also named Graphics, has (almost) the same signature as the
original Graphics module. Thus, using the GraphPs Graphics
module, your Caml drawing programs transparently generate PostScript
files (that can be encapsulated into TeX or LATEX files), instead of
drawing graphics directly onto the screen.
2 Using GraphPS
Intended usage of this library could be seen as a three phases process:
- write a regular Caml program (either batch or interactive) using
the regular Graphics library.
- use the GraphPS library instead of the regular Graphics
library (for instance you can just change the Caml library load path
to obtain linking of GraphPS in place of Graphics). Recompile
your Caml program to obtain a new executable that produces PostScript
commands instead of Graphics commands.
- run the new executable to produce a PostScript file that exactly
corresponds to the drawing produced by your Caml program.
A PostScript program corresponding to your Graphics sequence of
commands is printed to the standard output of the program, when
close_graph () is evaluated, or alternatively when the normal
termination of the Caml program is reached. You can thus redirect the
output to whichever file you want. GraphPS generates encapusulated PostScript files, which means that a so-called bounding box (that gives the size of the drawing) is calculated and
inserted at the beginning of the PostScript file to help LATEX to
insert it into the document. Hence you should produce a .eps
suffixed file.
3 Using the PostScript files produced by GraphPS
3.1 Direct visualization
You can visualize directly the files using any PostScript visualizers,
for instance ghostview or gs or gv.
3.2 Including PostScript files into your LATEX files
This is not exactly a GraphPS problem, but a simple example may help
to solve this LATEX problem.
A very simple way to include your caml_drawings.eps file, is as
follows:
For instance, the following line will draw the drawings of the file
euro.eps, centered in the current line.
\centerline{\includegraphics[width=10cm]{euro.eps}}
4 Trouble shooting
4.1 Caml problems
Most of the time, your original Caml program should work just fine
with no modification when using the Graphics module provided by
GraphPs.
However, some Graphics commands are not supported by the GraphPS
library, since they have no meaning for PostScript files (e.g. mouse
events handling commands). If the original program uses such commands,
you should remove them.
4.2 PostScript problems
To ensure proper inclusion of generated PostScript files, GraphPS does
not add any showpage order at the end of the file.
If you want to send the produced PostScript file directly to a
PostScript printer, you may be obliged to add a showpage order
at the end of the file.
This document was translated from LATEX by
HEVEA.