The following works with pdflatex and feynmp:
\usepackage{feynmp}
\DeclareGraphicsRule{*}{mps}{*}{}
\makeatletter
\def\endfmffile{%
\fmfcmd{\p@rcent\space the end.^^J%
end.^^J%
endinput;}%
\if@fmfio
\immediate\closeout\@outfmf
\fi
\ifnum\pdfshellescape=\@ne
\immediate\write18{mpost \thefmffile}%
\fi}
\makeatother
If you now call pdflatex with the -shell-escape option (-enable-write18 for MiKTeX), the Metapost file is compiled right after the end of the environment and will be used at the next compilation.
NOTE TeX Live 2012 lists mpost among the programs that can be run with "restricted shell escape", so the test above can be
\ifnum\pdfshellescape>\z@
and -shell-escape is not needed any more. Note though that MiKTeX 2.9 doesn't allow mpost in restricted shell escape.
For feynmf it's just the same:
\usepackage{feynmf}
\makeatletter
\def\endfmffile{%
\fmfcmd{\p@rcent\space the end.^^J%
end.^^J%
endinput;}%
\if@fmfio
\immediate\closeout\@outfmf
\fi
\ifnum\pdfshellescape=\@ne
\immediate\write18{mf "\noexpand\mode:=localfont;input \thefmffile"}%
\fi}
\makeatother
Adding -shell-escape to the call of (pdf)latex should be easy in Kile.
I advise to use feynmp that's easier to manage and produces resolution independent output. Moreover it supports color.
Another way, for older systems, is to open an output stream where to write the necessary shell commands.
\usepackage{feynmf}
\makeatletter
\newwrite\@feynmfwr
\immediate\openout\@feynmfwr=\jobname.out
\def\endfmffile{%
\fmfcmd{\p@rcent\space the end.^^J%
end.^^J%
endinput;}%
\if@fmfio
\immediate\closeout\@outfmf
\fi
\immediate\write\@feynmfwr{mf "\noexpand\mode:=localfont;input \thefmffile"}%
}
\makeatother
At the end of the LaTeX run you'll have a file called as your main file, with extension .out that contains the necessary shell commands to run. If the file is main.tex all you have to do is to run from the shell
sh main.out
pdflatexandlatexat the same time? This neat trick results inlatexcomplaining "Can not include graphics of type: mps." (Ifmposthas already run) – Tobias Kienzler May 02 '13 at 12:06feynmp-autoinstead offeynmp? This should work without the need of any trick: thefeynmp-autopackage is just an implementation of the trick and loadsfeynmpautomatically. – egreg May 02 '13 at 16:39-enable-write18switch does the trick for bothpdflatexandlatex, I think you mention that only in this post but not in the package documentation. – Tobias Kienzler May 03 '13 at 07:57feynmp-auto, the already existing.mpfile will not be considered "changed" and thereforempostwon't ever be run. A workaround is deleting all.mpfiles when switching tofeynmp-auto. Maybe the package can check for the existence of processed diagrams as well? – Tobias Kienzler May 03 '13 at 08:04forceoption to disable the checks and run Metapost anyway. It's a pity that MiKTeX doesn't allowmpostin the restricted shell, but it may have something to do with how the program is built. – egreg May 03 '13 at 10:33