Without knowing anything about the feynmp
or METAPOST, I removed the fbox
and I just tried to put everyting in a TikZ node. Then I did the centering with respect to the baseline of the bounding box of the tikzpicture
and the result is centered. So remaining question is, How robust is this?, and I have no clue. But seemingly, there is no bad box complaints etc. I regret that it's up to you and other proficient METAPOST users to test and try to break this.
\documentclass{article}
\usepackage{feynmp,tikz}
% Needed to interpret generated *.1, *.2 etc. as ps files.
\DeclareGraphicsRule{*}{mps}{*}{}
\setlength{\fboxsep}{0pt}
\begin{document}
To populate this line and to see how far is the equation spacing.
\begin{fmffile}{fgraphs}
\begin{equation}
5\times
\begin{tikzpicture}[baseline=(current bounding box.center)]
\node {
\fmfframe(5,17)(20,17){ % 2: Had to manually guess these.
\begin{fmfgraph*}(40,30)
% Note that the size is given in normal parentheses
% instead of curly brackets in units of \unitlength
% (1pt by default)
\fmfleft{i1,i2} % Define external vertices from bottom to top
\fmfright{o1,o2}
\fmf{fermion}{i1,v1,o1}
\fmf{fermion}{i2,v2,o2}
\fmf{photon,tension=0.3}{v1,v2}
% 3: Blank lines not allowed in fmfframe!
\fmflabel{$\vec{p}$}{i1}
\fmflabel{$\vec{q}$}{i2}
\fmflabel{$\vec{p}+\vec{k}$}{o1}
\fmflabel{$\vec{p}-\vec{k}$}{o2}
\end{fmfgraph*}
}
};
\end{tikzpicture}
= 5i V_k.
\end{equation}
\end{fmffile}
\end{document}
Because I don't know anything I can also try stupid things such as putting the fmffile
environment completely inside the node in other words, nest it inside the tikzpicture
. And that gives the same result. But I feel that the second one is more robust.
Coming back to the manual guessing of the parameters of the \fmfframe
, I can see that if you omit the manually set lines, the bounding box only covers the drawing but not the p,q,p+k
etc. vectors. Hence I just put a invisible rectangle to set the bounding box enlarged by 2.5ex
. Not a wonderful solution but gives you at least a prediction power how much is left out. So I just chose to have 2.5ex
since I know that only a letter with an arrow is sticking out.
\documentclass{article}
\usepackage{feynmp,tikz}
% Needed to interpret generated *.1, *.2 etc. as ps files.
\DeclareGraphicsRule{*}{mps}{*}{}
\begin{document}
To populate this line and to see how far is the equation spacing.
\begin{equation}
5\times
\begin{tikzpicture}[baseline=(current bounding box.center)]
\node {\begin{fmffile}{fgraphs}
\begin{fmfgraph*}(40,30)
\fmfleft{i1,i2} % Define external vertices from bottom to top
\fmfright{o1,o2}
\fmf{fermion}{i1,v1,o1}
\fmf{fermion}{i2,v2,o2}
\fmf{photon,tension=0.3}{v1,v2}
%
\fmflabel{$\vec{p}$}{i1}
\fmflabel{$\vec{q}$}{i2}
\fmflabel{$\vec{p}+\vec{k}$}{o1}
\fmflabel{$\vec{p}-\vec{k}$}{o2}
\end{fmfgraph*}
\end{fmffile}
};
\path[use as bounding box] ([shift={(2.5ex,2.5ex)}]current bounding box.north east) rectangle ([shift={(-2.5ex,-2.5ex)}]current bounding box.south west);
\end{tikzpicture}
= 5i V_k.
\end{equation}
Same thing here... To populate this line and protect it at all costs. Now fmffile is inside the TikZ picture...
\end{document}
As you can see from the image below, I forgot to take into account the horizontal effect so the equal sign is a little to the left than where it should have been. If there is a handle on the bounding box of the Feynman drawing, TikZ can do centering and all other fancy things with ease. Otherwise at least you don't have to recompile the Feynman drawing since the bounding box computation is now on TikZ side and easier to tune since you only add extra shifts instead of hard coding numbers.
Best Answer
Nowadays it's better using
feynmp
rather thanfeynmf
, because it's easier to produce the pictures.feynmp
also has the distinct feature of using Metapost, which producesEPS
vector graphics, while FeynMF uses Metafont, which produces bitmaps. According to Thorsten Ohl, the creator of this package,feynmf
is outdated.In any case you have to tell the package the name of the auxiliary file where the Metapost code is to be written, which is done by opening a
fmffile
environment.After running LaTeX, you have to run
mpost afilename
and then recompile. If you have a fairly recent TeX distribution, you can usefeynmp-auto
:and you'll just have to compile twice (the second LaTeX run is needed only if the code for a Feynman diagram has changed or some new diagram has been added).