Functional MetaPost in 5 Steps

Previous Topic Next Topic
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view

Functional MetaPost in 5 Steps

Jared Updike
I'm interested in using Functional MetaPost on Mac OS X (or FreeBSD).
I'm looking for a tutorial like:

but for FMP. I can't even get a simple example to show up in a PDF file:
import FMP
... (see full code below)
myPicture = text "Hello World"
main = do
   print $ emit $ metaPost 1 myPicture params
When run, this emits MetaPost, which, after running through my shell
script, below, won't show up in my PDF... (this same TeX file will
show an .eps figure I made with PyX, the Python equivalent of FMP,
when I change includegraphics to use that file instead of test.1)

What am I missing? If I can get this working I will gladly write the
FMP 5 Step Tutorial. I like the idea of using FMP but I can't for the
life of me understand why running a toy example is so non-trivial.
(Not to mention undocumented... the manual and tutorials are very
compelling but they don't mention how to get a viewable PDF out of any
of the otherwise enticing examples.)


Relevant almost working code:


import FMP

params = Parameters {
  prolog = "verbatimtex\n\
             \input boxes\n\
             \input FuncMP\n\n",
  epilog= "\n\n\\end",

  defaultDX= 3,
  defaultDY= 3,
  textDX= 2,
  textDY= 2,

  newmp= True,

  funcmpRTS= "IGNORE", --"+RTS -H40m -K3M -RTS",
  funcmpBin= "IGNORE", -- "~/FuncMP-1.2/FuncMP",

   mpBin= "IGNORE" -- "MPINPUTS=:~/FuncMP-1.2 TEX=latex mpost "

myPicture = text "blah"

main = do
   print $ emit $ metaPost 1 myPicture params









shell script:

ghc --make Test.hs && \
  ./Test > && \
  mpost && \
  latex test.tex && \
  latex test.tex && \
  dvipdfm test.dvi && \
  open test.pdf   # MacOS X runs my pdf in preview
Haskell-Cafe mailing list
[hidden email]
Reply | Threaded
Open this post in threaded view

Re: Functional MetaPost in 5 Steps

On Thu, 23 Oct 2008 22:13:10 -0700
"Jared Updike" <[hidden email]> wrote:

> I can't even get a simple example to show up in a PDF file

I can't even get my simple example to show up anywhere, period. PDF,
DVI, PS - anything.

No matter which way I try, and I've tried lots, I always hit some kind
of PostScript or TeX error. My Haskell file is attached.

I asked about it on the tex-live mailing list, and I got this
response, advising me to speak to the author:

From: Taco Hoekwater <[hidden email]>
To: Robin Green <[hidden email]>
CC: [hidden email]
Subject: Re: [tex-live] Missing \endcsname errors when trying to insert
MetaPost graphic into PDF Date: Fri, 24 Oct 2008 10:28:20 +0200
User-Agent: Thunderbird (X11/20080305)

Hi Robin,

Robin Green wrote:
> No, it was generated by MetaPost. Here are the sequence of commands I
> used: is the culprit here. It alters MetaPost's output via
explicit special command so that it is no longer acceptable
to the mptopdf converter.

>> I suggest you rename the file to figure1.eps (and run
>> epstopdf on it before inclusion in your latex document)  
> "epstopdf figure1.eps" outputs this error:
> Error: /undefined in cmmi10  

If the document was was 'plain' metapost input, it would actually
have been possible to fix this in texlive 2008 by adding


at the top of the file.

However, has redefined (via specials) the PostScript commands
like /fshow etc,. so this won't work. Also, it seems to be altering
the label typesetting so that it uses metafont bitmap (pk) fonts
instead of type1.

My advice is to look into the functional metapost documentation or
ask its author for help and guidelines on how to use the result
images in pdftex (as opposed to dvips/xdvi).

Best wishes,
Haskell-Cafe mailing list
[hidden email]

Figure1.hs (503 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view

Re: Functional MetaPost in 5 Steps

Peter Simons
Hi Robin,

> [FuncMP problems with pdflatex]

I have no experience whatsoever with pdflatex, I'm sorry, Funcmp works
just fine for me in normal LaTeX, though. That's not exactly what you
need, but from the sound of it, it might be step forward anyway.

First of all, try writing the MetaPost files with the following
function, toMPFile, rather than the standard 'generate':

  toMPFile        :: (IsPicture a) => a -> FilePath -> IO ()
  toMPFile pic f  = writeFile f (show $ toMetaPost pic)

  toMetaPost      :: (IsPicture a) => a -> Doc
  toMetaPost a    = emit $ metaPost 0 (toPicture a) params
      params      =  Parameters
                     { mpBin      = undefined
                     , funcmpBin  = undefined
                     , funcmpRTS  = undefined
                     , defaultDX  = 3
                     , defaultDY  = 3
                     , textDX     = 2
                     , textDY     = 2
                     , prolog     = myprolog
                     , epilog     = "\\end"
                     , newmp      = False
      myprolog    = "verbatimtex\n"
                    ++ "\\documentclass[11pt]{report}\n"
                    ++ "\\begin{document}\n"
                    ++ "etex\n\n"
                    ++ "input boxes\n"
                    ++ "input FuncMP\n"

The resulting .mp file has to be run through mpost with the $MPINPUTS
variable pointing to the directory that contains from.  This
will give you an EPS file, which in turn can be included in any LaTeX
document with, say \epsfig{}.

This whole process ought to work fine with texlive of tetex.

I hope this helps,
Haskell-Cafe mailing list
[hidden email]
Reply | Threaded
Open this post in threaded view

Re: Functional MetaPost in 5 Steps

Stefan Endrullis
This post was updated on .
I have the same problem with FuncMP.

I've also replaced the "generate" function by a custom "toMPFile" as you suggested, but mpost still generates only an empty white sheet. I've used the simple example posted in the first message of this thread. The generated .mp file is also relatively simple (see attachment

The only problem is the line "input FuncMP", which produces additional code in the ps file and causes the white page. If you remove this line everything is fine again and you can see the text "blah".

Here's the additional code FuncMP produces in the .ps file:
/xdvi$run where {pop errordict begin /undefined {} bind def end} if
/fmp1 /fmp1 def /fmp8 /fmp8 def /fmp24 /fmp24 def
/bitline1 {gsave pop dup scale dup length 8 mul 1 true currentpoint translate
   [66.66666 0 0 66.66666 0 0] 4 index imagemask pop grestore} bind def
/bitline8 {gsave pop dup scale dup length 1 8 currentpoint translate
    [2.8 0 0 2.8 0 0] 4 index image pop grestore} bind def
/bitline24 {gsave pop dup scale dup length 3 idiv 1 8 currentpoint translate
    [2.777777 0 0 2.777777 0 0] 4 index false 3 colorimage pop grestore} bind def
/XDVIfshow  {findfont exch scalefont setfont show} bind def
/DVIPSfshow {exch gsave 72 TeXDict /Resolution get div -72 TeXDict
     /VResolution get div scale 1 DVImag div dup scale get cvx exec
     show grestore} bind def
   {/xdvi$run where {pop XDVIfshow} {DVIPSfshow} ifelse} def
/fshow { exch dup
          /fmp1 eq {bitline1}
                   {dup /fmp8 eq {bitline8}
                                 {dup /fmp24 eq {bitline24}
          ifelse}       ifelse}       ifelse} def

You can also fix the .ps file by removing the "/fshow ..." part from the file and the text "blah" will appear in your ghostscript viewer.

Well, this is my first test with FuncMP and that's why I'm asking this silly question now: Is the "fshow" function really necessary or can I remove it from every generated .ps file without problems? :)

Or you know another solution?
Does your generated .ps files also contain this code? If no, what version of FuncMP do you use?