Mlpost manual

There are really two ways of using Mlpost. The first one uses the command line tool mlpost and is more convenient. The second one uses only the API of Mlpost and can be used in situations where the mlpost command does not apply.

Using the Mlpost Tool

  1. Define your figures in an Ocaml file The Mlpost modules are packed in the top module Mlpost, so you probably want to open it right away.
             open Mlpost
    	 let fig_a = ...
    	 let fig_b = ...
    Each figure has type Command.t.
  2. Add some code to emit Metapost code, as follows
    	let () = Metapost.emit "file_a" fig_a
    	let () = Metapost.emit "file_b" fig_b
  3. Then run the mlpost program on this file
    It will create PostScript figures in files file_a.1, file_b.1, etc.


mlpost supports the following options:
creates .mps files instead of .1, for inclusion in LaTeX files compiled with pdflatex (the PostScript file is actually the same, but the suffix is used by pdflatex to identify PostScript produced by Metapost)

-latex main.tex
indicates the main LaTeX file, from which the prelude is extracted to be passed to Metapost (this way you can use macros, fonts and packages from your LaTeX document in your figures). main.tex has to contain at least a documentclass and the line "\begin{document}". The contents of this file are taken into account up to the "\begin{document}" part.

Using only the API

The mlpost tool works on a modified version of your file, and this can be a problem sometimes. The following method is a way out, but you need to do a bit more things by hand.
  1. Follow steps 1 and 2 above.
  2. Instead of running mlpost on your file, add the following additional lines to your program:
    let () = Metapost.dump 
               ~prelude:(Metapost.read_prelude_from_tex_file "document.tex") "somefile"
    Now you can compile your program using the ocaml compiler. The obtained executable will compute your figure, dump the metapost code in and produce the postscript figures, using the specified file document.tex to extract a prelude. The Metapost.dump function has the additional optional arguments pdf and eps, with the same meaning as the options on the command line.

Franšais / English / Deutsch