Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Background

When labels are shown with feynmp, they extend beyond the box of the graph. One can use \fmfframe to allocate an invisible frame to accommodate these, but it seems like you need to manually adjust all of the parameters.

Question

Is there an easy way of automatically placing ones Feynman graphs in an appropriate frame?

Specifically, I would like to be able to use graphs naturally in equations with minimal manual intervention. The following example works, but has the following issues:

  1. I use \raisebox{-0.5\height}{} to vertically center the graph, but this does not quite work properly. How do I fix this?
  2. One can use \fmfframe(<left>,<top>)(<right>,<bottom>){} to "pad" the graph, but the only way I can see to get these values is to manually adjust (using a frame with \fbox so I can see what I am doing).

    Note: All the numbers in () are in terms of the \unitlength defined by feynmp (default is 1pt).

  3. One ugly "feature" of \fmfframe is that is precludes blank lines in its argument (which can be useful for spacing out one's graph definitions). Any easy fix?

Here is a minimal working example:

\documentclass{minimal}
\usepackage{feynmp}

% Needed to interpret generated *.1, *.2 etc. as ps files.
\DeclareGraphicsRule{*}{mps}{*}{} 

\setlength{\fboxsep}{0pt}
\begin{document}
\begin{fmffile}{fgraphs}
\begin{equation}
  5\times
  \raisebox{-0.5\height}{     % 1: center vertically -- does not quite work.
    \fbox{                    % Draw fram so we can tweak the fmfframe
      \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*}
      }
    }
  }
  = 5i V_k.
\end{equation}
\end{fmffile}
\end{document}

Compile this with:

pdflatex tst
mpost fgraphs
pdflatex tst
pdflatex tst

to get:

Output of example.

share|improve this question

1 Answer 1

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}

enter image description here

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.

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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