12

I use the old MetaPost program to create graphics.

My problem is that, to see the result of my MetaPost figures, I have to compile first the .mp file and then the .tex file where I've inserted them. I find it quite boring.

I've found the online MetaPost Previewer but I have to copy and paste my code there and this is even a further waste of time.

I've also tried to add the lines

prologues:=3;
filenametemplate "%j-%3c.eps";

in my .mp files to generate .eps files, but, when I open them with GSView, sometimes I'm able to see my proper figures and sometimes not.

So, the question is: does anyone knows a program which is able to open the output generated by MetaPost? Or any package that can let me generate viewable images? Or any other trick that make me save some time (even an editor feature)?

If this can help, I use MiKTeX 2.9 in Windows XP. My main editor is TeXMaker (v4), but I have WinEdt (v8) installed as well.

2
  • Welcome to TeX.SX! You can have a look on our starter guide to familiarize yourself further with our format. Commented Jun 8, 2013 at 7:56
  • Did you setup GSview to clip pictures to the bounding box as described in section 14.2.1 in the MetaPost manual? Commented Jun 8, 2013 at 10:21

5 Answers 5

6

This solution won't let you open your MetaPost images with a double-click of the mouse, but probably will let you save a lot of time.

Since you have WinEdt 8 installed, download the add-on MetaPreview (choose the right version) and install it in WinEdt.

Note that the add-on provides a previewer for MetaPost output as well as one for MetaFont output. You can choose only the first one if you are not interested in MetaFont preview.

Once you've installed it, you will find a drop-down button in the toolbar which contains two buttons, as shown in the following image

enter image description here

To have these buttons enabled, you have to compile your .mp file first.

Once you've compiled your .mp file, with the first command ('MetaPost Preview All') you will be able to preview all the generated images, while with the other ('MetaPost Preview One') you will be prompted to choose the image you want to preview (useful when you're working on an image and want to preview only that one).

Just one remark: the add-on works regardless of the prologue but needs the generated output to be in the format .1, .2, etc., so delete the line

filenametemplate "%j-%3c.eps";

from your .mp files.


UPDATE

A new version of MetaPreview is available.

The limitation described above has been overcome. Now it can be used even when your .mp file contains

filenametemplate "%j-%c.mps";

or

outputtemplate := "%j-%c.mps";
3
  • Thanks for your answer. I'll try the add-on you've mentioned.
    – Sterry
    Commented Jun 8, 2013 at 8:23
  • I have to thank you very much. I've tried MPPreview as you suggested and it is just the tool I was looking for! Just have to click a button to preview my images in my favourite PDF viewer is awesome. Thanks again.
    – Sterry
    Commented Jun 8, 2013 at 14:41
  • 1
    The filenametemplate primitive is deprecated since MetaPost version 1.200. It has been replaced by a new internal variable outputtemplate. Please update your MetaPost distribution. Commented Jun 8, 2013 at 16:52
8

If you're not opposed to compiling with lualatex, then you could make use of the luamplib package to bypass the preview step altogether and compile the images in-document:

\documentclass{article}
\usepackage{luamplib}
\begin{document}
Your usual document.
\begin{mplibcode}

%your metapost code here

\end{mplibcode}
The rest of your document.
\end{document}
5
  • Does luamplib support TeX labels?
    – Aditya
    Commented Jun 8, 2013 at 18:16
  • 2
    @aditya It does now it seems. The patch pointed out here seems to have been implemented if the documentation is to be believed. The github listed as the homepage may no longer be where the actual package code resides.
    – Scott H.
    Commented Jun 8, 2013 at 18:20
  • Scott, @Aditya: The patch is in the CTAN version of luamplib, but I think it can't yet be in Texlive or Miktex. Commented Jun 10, 2013 at 20:00
  • @charlesstewart. Ah, thanks for pointing that out. Do you have an idea of how long it might take?
    – Scott H.
    Commented Jun 11, 2013 at 6:09
  • 2
    @ScottH. I tried the new luamplib in CTAN with TeX Live 2013/pretest and it seems to work with labels. We have only to wait for the release and the package will be updated soon.
    – egreg
    Commented Jun 11, 2013 at 10:30
8

If you have ConTeXt standalone installed, then you can just run:

context filename.mp

which will generate filename.pdf.

6

The MetaPost manual describes various ways for previewing MetaPost graphics. To quote from a section titled Previewing PostScript Output:

Previewing MetaPost’s PostScript output is not difficult, but there are some catches that one should know about. This section deals with the following questions: How can graphics be clipped to their true bounding box in the PostScript viewer application? Why are my text labels rendered with an ugly font (or not at all) and how to avoid that? How can several graphics be combined into a multi-page document that can be previewed within one instance of the viewer application?

It then discusses these tools

  • GSview
  • mproof.tex
  • mpsproof.tex

and mentions

as additional alternatives.

Side note: I happen to have written the work-flow and preview related stuff in the MetaPost manual. If you think there's anything missing or unclear and could be improved, please drop me a line.

11
  • Finally I'm able to see my MetaPost graphics in GSView! I did it by activating 'EPS Clip' in Options. Thanks! However I prefer to see them in my PDF viewer thanks to karlkoeller's suggestion.
    – Sterry
    Commented Jun 8, 2013 at 14:35
  • That is really easy with the mpsproof.tex script, which is part of the MetaPost distribution. Use it like pdftex mpsproof *.mps after setting the file extension of MetaPost output to mps by putting the line outputtemplate := "%j-%c.mps"; in the preamble of the source file. Commented Jun 8, 2013 at 16:49
  • @StephanHennig So you are involved in MetaPost development. I'm using MiKTeX 2.9 and the MetaPost version that is shipped with it is still 1.504... This version does not even contain mpsproof.tex and most of the things you've written in this post are not even contemplated in the 1.504 manual. Any chance you convince C.Schenk to update MetaPost in MiKTeX distribution? Commented Jun 9, 2013 at 7:16
  • The MetaPost binary in MiKTeX 2.9 Portable seems to be of version 1.504, which is OK, but the manal is of version 1.005. Please complain to the distributor. The mpsproof.tex script has been added to the MetaPost distribution in version 1.100. You can find it at CTAN. Commented Jun 9, 2013 at 12:11
  • Or try another TeX distribution. TeX Live works well on Windows. Commented Jun 9, 2013 at 12:21
3

You can use gmp:

\documentclass{article}
\usepackage[shellescape]{gmp}
\begin{document}
\begin{mpost}
%beginfig(1};
a=3cm; b=2cm;
z0=(0,0);
z1=-z3=(a,0);
z2=-z4=(0,b);
draw z1..z2..z3..z4..cycle;
draw z1--z0--z2;
label.top(btex $a$ etex, .5[z0,z1]);
label.lft(btex $b$ etex, .5[z0,z2]);
dotlabel.bot(btex $(0,0)$ etex, z0);
%endfig;
\end{mpost}
\end{document}

Just comment out the beginfig and endfig lines and compile with the -shell-escape option active.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .