3

When compiled with pdflatex -shell-escape, the following MCVE (shamelessly taken from another answer and adapted to my problem) fails with an empty mp file, and mpost wait for user input. I have to manually type end to continue the compilation, only after that a non-empty mp file is generated but mpost is not automatically executed again for the non-empty file.

\documentclass{article}
 \usepackage[force]{feynmp-auto}
 \usepackage{amsmath}
 \begin{document}
 \begin{align}
 \begin{fmffile}{simple_labels}
 \begin{fmfgraph*}(40,25)
 \fmfleft{i1,i2}
 \fmfright{o1,o2}
 \fmflabel{$e^-$}{i1}
 \fmflabel{$e^+$}{i2}
 \fmflabel{$e^+,\mu^+$}{o1}
 \fmflabel{$e^-,\mu^-$}{o2}
 \fmflabel{$i\sqrt{\alpha}$}{v1}
 \fmflabel{$i\sqrt{\alpha}$}{v2}
 \fmf{fermion}{i1,v1,i2}
 \fmf{fermion}{o1,v2,o2}
 \fmf{photon,label=$\gamma,,Z^0$}{v1,v2}
 \end{fmfgraph*}
 \end{fmffile}
 &=\text{foobar}\notag\\
 foo&=bar
 \end{align}
 \end{document}

Output in screen (at this time, the mp file is still empty)

(./mpFockLOE.tex [MP to PDF] (./mpFockLOE.1)This is MetaPost, version 2.000 (TeX Live 2017) (kpathsea version 6.2.3)
(/usr/local/texlive/2017/texmf-dist/metapost/base/mpost.mp
(/usr/local/texlive/2017/texmf-dist/metapost/base/plain.mp
Preloading the plain mem file, version 1.005) ) (./mpFockLOE.mp)
*

Then I type end and the non-empty mp file is written.

2

Put \begin{fmffile} and \end{fmffile} outside align. I added\fmfframe` to fix the bounding box.

\documentclass{article}
\usepackage[force]{feynmp-auto}
\usepackage{amsmath}

\usepackage{lipsum} % for context

\begin{document}

\lipsum[1][1-4]
\begin{fmffile}{simple_labels}
\begin{align}
\fmfframe(15,12)(30,12){%
  \begin{fmfgraph*}(80,50)
  \fmfleft{i1,i2}
  \fmfright{o1,o2}
  \fmflabel{$e^-$}{i1}
  \fmflabel{$e^+$}{i2}
  \fmflabel{$e^+,\mu^+$}{o1}
  \fmflabel{$e^-,\mu^-$}{o2}
  \fmflabel{$i\sqrt{\alpha}$}{v1}
  \fmflabel{$i\sqrt{\alpha}$}{v2}
  \fmf{fermion}{i1,v1,i2}
  \fmf{fermion}{o1,v2,o2}
  \fmf{photon,label=$\gamma,,Z^0$}{v1,v2}
  \end{fmfgraph*}%
}
 &=\text{foobar}\notag\\
 foo&=bar
\end{align}
\end{fmffile}

\end{document}

enter image description here

  • Thank you. It seems my MWE is oversimplified. I have multiple fmfgraphs in the align environment – Weijun Zhou Apr 27 at 21:14
  • @WeijunZhou As far as I know, you don't need a file for each graph: the documentation of feynmp says that “Up to 255 graphs can be placed into one METAFONT file” and the same is true for METAPOST. I tried with three and it works. I guess that you can open the file at the beginning of the document and close it at the end, if you don't have too many graphs. – egreg Apr 27 at 21:24
  • There seems to be a bug in my Makefile. Sorry about it. I am accepting it for now and will come back to you if there are any problems. – Weijun Zhou Apr 27 at 21:28
0

I suppose this is related to how the align environment in AMS collects its parameter. A temporary fix I use is replacing it with aligned,

\documentclass{article}
 \usepackage[force]{feynmp-auto}
 \usepackage{amsmath}
 \begin{document}
 \begin{equation}
 \begin{aligned}
 \begin{fmffile}{simple_labels}
 \begin{fmfgraph*}(40,25)
 \fmfleft{i1,i2}
 \fmfright{o1,o2}
 \fmflabel{$e^-$}{i1}
 \fmflabel{$e^+$}{i2}
 \fmflabel{$e^+,\mu^+$}{o1}
 \fmflabel{$e^-,\mu^-$}{o2}
 \fmflabel{$i\sqrt{\alpha}$}{v1}
 \fmflabel{$i\sqrt{\alpha}$}{v2}
 \fmf{fermion}{i1,v1,i2}
 \fmf{fermion}{o1,v2,o2}
 \fmf{photon,label=$\gamma,,Z^0$}{v1,v2}
 \end{fmfgraph*}
 \end{fmffile}
 &=\text{foobar}\\
 foo&=bar
 \end{aligned}
 \end{equation}
 \end{document}

Another solution is patching all related macros and remove the \if@fmfio check,

\documentclass{article}
 \usepackage[force]{feynmp-auto}
 \usepackage{amsmath}
 \makeatletter
\def\fmfcmd#1{%                                                                                                                                                                                             
  %\if@fmfio
    \immediate\write\@outfmf{#1}%
  %\fi
  \ignorespaces}
\def\fmffile#1{%
  \def\thefmffile{#1}%
  \equaltojobname{\thefmffile}{%
    \PackageError{feynmp}
      {The argument of \fmffile MUST NOT be identical\MessageBreak
       to the name of your main input file!  I will use fmfdefault.mf\MessageBreak
       this time around, but you'd better fix your code now!}%
      {Invalid argument to \string\fmffile!}%
    \def\thefmffile{fmfdefault}}{}%
  %\if@fmfio
    \fnmpa@gethash % Added
    \@ifundefined{ifmeasuring@}%
      {}% 
      {\def\if@fmfio{\ifmeasuring@\else}}%
    \immediate\openout\@outfmf=\thefmffile.mp\relax
    \fmfcmd{\p@rcent\space \thefmffile.mp -- do not edit, %
            generated automatically by \jobname.tex^^J%
            input feynmp^^J%
            require_RCS_revision "\fmf@revision";}%
  %\fi
  \setcounter{fmfgraph}{0}}
\def\endfmffile{%
  \fmfcmd{\p@rcent\space the end.^^J%
          end.^^J%
          endinput;}%
  %\if@fmfio
    \immediate\closeout\@outfmf
  %\fi
  \fnmpa@processmp % Added
  \let\thefmffile\relax
}
 \makeatother
 \begin{document}
 \begin{align}
 \begin{fmffile}{simple_labels}
 \begin{fmfgraph*}(40,25)
 \fmfleft{i1,i2}
 \fmfright{o1,o2}
 \fmflabel{$e^-$}{i1}
 \fmflabel{$e^+$}{i2}
 \fmflabel{$e^+,\mu^+$}{o1}
 \fmflabel{$e^-,\mu^-$}{o2}
 \fmflabel{$i\sqrt{\alpha}$}{v1}
 \fmflabel{$i\sqrt{\alpha}$}{v2}
 \fmf{fermion}{i1,v1,i2}
 \fmf{fermion}{o1,v2,o2}
 \fmf{photon,label=$\gamma,,Z^0$}{v1,v2}
 \end{fmfgraph*}
 \end{fmffile}
 &=\text{foobar}\\
 foo&=bar
 \end{align}
 \end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.