[Tex/LaTex] Configuring Texmaker to run mpost for FeynMP Graphics

feynmftexmaker

This question led to a new package:
feynmp-auto

What is the command line to be placed in the User

Quick Build Command of Texmaker to get:

LaTeX + mpost + dvips + ps2pdf + ViewPDF

That's to say, in order to avoid manually running mpost run on file.mp every time I run LaTeX command, is there anyway TeXMaker will do it for me?

I used TexMaker's own Wizard, which produced following command line:

latex -interaction=nonstopmode %.tex|mpost --interaction nonstopmode |dvips -o %.ps %.dvi|ps2pdf %.ps|"C:/Program Files (x86)/Adobe/Reader 10.0/Reader/AcroRd32.exe" %.pdf

It looks fine, but when I run a file.tex file it takes indefinite time with no result.

Best Answer

With an updated TeX Live 2012 there's no need to call mpost from the command line, since this program is allowed to be called during the LaTeX run. Just modify the definition of \endfmffile to do the Metapost run.

\documentclass{article}
\usepackage{feynmp}

\usepackage{ifpdf}
\ifpdf
  \DeclareGraphicsRule{*}{mps}{*}{}
\fi

\makeatletter
\def\endfmffile{%
  \fmfcmd{\p@rcent\space the end.^^J%
          end.^^J%
          endinput;}%
  \if@fmfio
    \immediate\closeout\@outfmf
  \fi
  \IfFileExists{\thefmffile.mp}{\immediate\write18{mpost \thefmffile}}{}
  \let\thefmffile\relax
}
\makeatother

\begin{document}

\begin{fmffile}{abc}
\begin{fmfgraph}(40,25) 
\fmfpen{thick}
\fmfleft{i1,i2} 
\fmfright{o1,o2}
\fmf{fermion}{i1,v1,v3,o1}
\fmf{fermion}{o2,v4,v2,i2}
\fmf{photon}{v1,v2} 
\fmf{photon}{v3,v4}
\fmfdotn{v}{4} 
\end{fmfgraph} 
\end{fmffile}

\end{document}

This will produce abc.1 that will be included on the next run, with the usual command line call.

With MiKTeX it might not work, depending if mpost is allowed in the "restricted shell".

Related Question