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
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";
Possibly the same trick can work also with emp
, but, for obvious reasons, I prefer gmp
. ;-)
\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[shellescape,latex]{gmp}
\gmpoptions{everymp={input expressg;}}
\catcode`#=12
\mpxcommands{\newcommand\stack [1]{\vbox {\halign {\hfil ##\hfil \cr #1\crcr }}}}
\catcode`#=6
\begin{document}
\title{Gmp Package Test}
\author{Author}
\maketitle
\section{Emp Package Test}
This is a test trying to get a macro properly added to the verbatimtex section
of the generated metapost file.
\begin{figure}[htp]
\centering
\begin{mpost}
z0 = origin;
drawroundedbox(0, 2.5cm, 3cm, 5mm)(\btex \stack{Domain\cr Name\cr Service} etex);
\end{mpost}
\caption{Example using embeded MetaPost}\label{fig:emp}
\end{figure}
\end{document}
It needs running the file with -shell-escape
(it's possible that a new version will avoid it, as now mpost
is in the list of “safe” programs for the restricted shell escape).
However, the simplest workaround is to create a small .tex
file, say mpmacros.tex
with
\newcommand\stack[1]{\vbox{\halign{\hfil##\hfil\cr#1\crcr}}}
in it and simply doing
\mpxcommands{\input{mpmacros}}
On the other hand, you can simply avoid this with
\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[shellescape,latex]{gmp}
\gmpoptions{everymp={input expressg;}}
\begin{document}
\title{Gmp Package Test}
\author{Author}
\maketitle
\section{Emp Package Test}
This is a test trying to get a macro properly added to the verbatimtex section
of the generated metapost file.
\begin{figure}[htp]
\centering
\begin{mpost}
z0 = origin;
drawroundedbox(0, 2.5cm, 3cm, 5mm)(
\btex {\begin{tabular}{@{}c@{}}Domain\\ Name\\ Service\end{tabular}} etex
);
\end{mpost}
\caption{Example using embeded MetaPost}\label{fig:emp}
\end{figure}
\end{document}
Best Answer
I have never tried to include the source directly inside the .tex file but in case your trouble is with the metapost code it may help to start with a known-good stand-alone source.
I did this recently, so I suspect that it still works (although I have edited out some stuff I think is not needed so do let me know if it fails). Here is the input file. It draws the Venn diagram for the union.
At a (Linux) command line I ran the four commands
mpost set.mp
followed bytex mproof set-00.mps
followed bydvips -Pwww -omproof.ps mproof
finally followed bygv mproof.ps
;this last pops up a viewer for the figure.
To include it in my doc I used this.
This is inside Beamer. I don't see that I did anything special to get the graphicx system to recognize the .mps ending but I may have forgot the details; let me know.
(Edit: someone changed what I wrote and in particular dropped the necessary initial paragraph. I added something like it back.)