# Use Feynmf and glossaries together

I am using the package glossaries for a collection of terms, definitions, explanations to various subjects loosely related to my phd thesis. In some entries I also want to include feynman diagrams that I currently create with feynmp.

The problem is, that in order to generate the diagrams I need to put the code into a

\begin{fmffile}{name}
\end{fmffile}


environment that, in order to be compiled by latex, has to be inside of the

\begin{document}
\end{document}


environment.

However, all entries for glossaries are in the preamble before the \begin{document} .

With fmfkeep and fmfreuse I can still generate the feynman diagrams within the document and then refer to them in the entries in glossaries. But this means that I have some extra pages where I have all Feynman diagrams - at the moment I need to do this in order to have the Feynman diagrams in an entry...

In order to write the diagrams directly at the place of the entry I would have to create and use a new *.mp file in each entry in the glossary. With dozens of entries and much more diagrams it will be way to complicated since it means that each time I run latex I would have to mpost each *.mp file individually...

As far as I understand feynmf safes the diagrams as eps files. Is there any way that I can convert the diagrams to eps and then include them with \includegraphics ? In that case I would probably loose all labels, since they are stored in a different file.

Are there other possibilities such that I don't have these extra pages with Feynman diagrams?

Are there other packages that are more compatible with glossaries that I can use to generate the Feynman Diagrams? Or are there other packages to generate a glossary that are more compatible with feynmf? But I suppose with feynmf and glossaries I already have the two most widely used packages for these purposes?

Ok, here is the MWE. I added a bit of text and hope it is not disturbing but rather explaining the problem I have...

\documentclass{article}
\usepackage{feynmp}
\listfiles
\usepackage{datatool}
\usepackage{glossaries}
\makeglossaries

\longnewglossaryentry{minimal}{name={minimal}}{I would like to have a Feynman diagram here :) \\

I can either open fmffile here \\~\\

\begin{fmffile}{minimal01}
\begin{fmfgraph*}(125,100)
\fmfkeep{directphoton01}\fmfleftn{l}{2} \fmfrightn{r}{2}
\fmf{fermion,tension=1.5}{v1,l1}\fmf{fermion,tension=1.5}{l2,v2}\fmf{fermion,tension=2}{v2,v1}
\fmf{phantom,tension=1.5}{v1,r1}
\fmf{photon,tension=1.5}{r2,v2}\fmflabel{$$\bar{q}$$}{l1} \fmflabel{$$q$$}{l2} \fmflabel{$$\gamma$$}{r2} \fmflabel{$$g$$}{r1}
\fmfdotn{v}{2}
\fmffreeze \fmf{plain,tension=4}{v1,m1}\fmf{gluon,tension=0.5}{m1,m2}\fmf{plain,tension=4}{m2,r1}
\end{fmfgraph*}
\end{fmffile}

~\\~\\ and then close it here which means one fmffile for each entry... \\

Or I can use fmfreuse{directphoton02} which allows me to have all diagrams in one fmffile, but generates that additional diagram above header Glossary, which is part of the maintext, since glossary is put at the end of the document...\\~\\

\fmfreuse{directphoton02}
}

\begin{document}

\begin{fmffile}{minimal02}
\begin{fmfgraph*}(125,100)
\fmfkeep{directphoton02}\fmfleftn{l}{2} \fmfrightn{r}{2}
\fmf{fermion,tension=1.5}{v1,l1}\fmf{fermion,tension=1.5}{l2,v2}\fmf{fermion,tension=2}{v2,v1}
\fmf{phantom,tension=1.5}{v1,r1}
\fmf{photon,tension=1.5}{r2,v2}\fmflabel{$$\bar{q}$$}{l1} \fmflabel{$$q$$}{l2} \fmflabel{$$\gamma$$}{r2} \fmflabel{$$g$$}{r1}
\fmfdotn{v}{2}
\fmffreeze \fmf{plain,tension=4}{v1,m1}\fmf{gluon,tension=0.5}{m1,m2}\fmf{plain,tension=4}{m2,r1}
\end{fmfgraph*}
\end{fmffile}

\printglossaries
\end{document}

• Welcome to TeX.SX! Please help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation when we see compilable code, starting with \documentclass{...} and ending with \end{document}. In particular, how do you generate the glossary entries? There are ways (with glossaries) to do this outside of the preamble, but there might be other issues. – Paul Gessler Jul 7 '14 at 20:04
• @PaulGessler Thank you for your answer. I added the MWE. How can I work with glossaries outside of the preamble (inside the document environment?) what other issues will then be there? – user3526475 Jul 7 '14 at 20:37

I don't know if this is what you want; the preamblefmffile environment has the same role as fmffile, but typesets nothing and should be before \begin{document}; you can have another file, say preamblediagrams.tex that collects all these diagrams and say \input{preamblediagrams} before \begin{document} if you don't want to fill your preamble with diagrams.

I use feynmp-auto because it makes life easier. If you don't have it, because your TeX distribution is old, then use feynmp and compile by hand the Metapost files.

\documentclass{article}
\usepackage{feynmp-auto}
\usepackage{glossaries}
\usepackage{environ}
\makeglossaries

\NewEnviron{preamblefmffile}[1]{%
\begingroup\edef\x{\endgroup
\noexpand\AtBeginDocument{\setbox0=\vbox{
\noexpand\begin{fmffile}{#1}
\unexpanded\expandafter{\BODY}
\noexpand\end{fmffile}
}}}\x
}

\begin{preamblefmffile}{minimal01}
\begin{fmfgraph*}(125,100)
\fmfkeep{directphoton01}
\fmfleftn{l}{2} \fmfrightn{r}{2}
\fmf{fermion,tension=1.5}{v1,l1}
\fmf{fermion,tension=1.5}{l2,v2}\fmf{fermion,tension=2}{v2,v1}
\fmf{phantom,tension=1.5}{v1,r1}
\fmf{photon,tension=1.5}{r2,v2}
\fmflabel{$$\bar{q}$$}{l1}
\fmflabel{$$q$$}{l2}
\fmflabel{$$\gamma$$}{r2}
\fmflabel{$$g$$}{r1}
\fmfdotn{v}{2}
\fmffreeze
\fmf{plain,tension=4}{v1,m1}
\fmf{gluon,tension=0.5}{m1,m2}
\fmf{plain,tension=4}{m2,r1}
\end{fmfgraph*}
\end{preamblefmffile}

\longnewglossaryentry{minimal}{name={minimal}}{I would like to have a Feynman diagram here\\[3ex]
\fmfreuse{directphoton01}
}

\begin{document}

Some text