> For the complete documentation index, see [llms.txt](https://overleaf-pro.ayaka.space/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://overleaf-pro.ayaka.space/latex/field-specific/03-feynman-diagrams.md).

# Feynman diagrams

## Introduction

This help article explores LaTeX packages for drawing Feynman diagrams, a very compact and intuitive way of representing interactions between particles. We'll explore the [`tikz-feynman` package](https://ctan.org/pkg/tikz-feynman?lang=en), which uses TikZ to draw diagrams, and [`feynmp-auto`](#other-packages-for-drawing-feynman-diagrams) which ("behind the scenes") uses MetaPost.

## The TikZ-Feynman package

The [`tikz-feynman` package](https://ctan.org/pkg/tikz-feynman?lang=en) was published in 2016 and uses Ti*k*Z in order to generate Feynman diagrams. Ti*k*Z-Feynman builds upon the Ti*k*Z package and its graph drawing algorithms in order to automate the placement of many vertices. Ti*k*Z-Feynman still allows fine-tuned placement of vertices so that even complex diagrams can be generated with ease. The most up-to-date information for Ti*k*Z-Feynman will always be on the [project page](http://www.jpellis.me/projects/tikz-feynman/) and in the [package documentation](http://mirrors.ctan.org/graphics/pgf/contrib/tikz-feynman/tikz-feynman.pdf) on CTAN.

### Update (9 November 2022)

**IMPORTANT post-publication update** (9 November 2022): At the time of updating this page, the **TikZ-Feynman package remains incompatible with TeX Live versions later than TeX Live 2018**—which is the TeX Live version used in the [Overleaf project accompanying this help article.](https://www.overleaf.com/project/new/template/26607?id=114366276\&templateName=Examples+using+the+TikZ-Feynman+package\&latexEngine=lualatex\&texImage=texlive-full%3A2018.1\&mainFile=) All TikZ-Feynman examples listed below will need to be compiled in an Overleaf project with the **TeX Live version** set to `2018 (legacy)`. For further information see [this issue reported on GitHub](https://github.com/JP-Ellis/tikz-feynman/issues/73#issue-942615833).

### Loading the Package

After installing the package, the Ti*k*Z-Feynman package can be loaded with `\usepackage{tikz-feynman}` in the preamble. It is recommend that you also specify the version of Ti*k*Z-Feynman to use with the `compat` package option: `\usepackage[compat=1.0.0]{tikz-feynman}`. This ensures that any new versions of Ti*k*Z-Feynman do not produce any undesirable changes without warning.

### A First Diagram

Feynman diagrams can be declared with the `\feynmandiagram` command. It is analogous to the `\tikz` command from Ti*k*Z and requires a final semi-colon (`;`) to finish the environment. For example, a simple *s*-channel diagram is:

```
\feynmandiagram [horizontal=a to b] {
  i1 -- [fermion] a -- [fermion] i2,
  a -- [photon] b,
  f1 -- [fermion] b -- [fermion] f2,
};
```

![S-channel.png](/files/C2rTMXJAPy3wGIdP7XTC)

Let's go through this example line by line:

**Line 1**

\feynmandiagram introduces the Feynman diagram and allows for optional arguments to be given in the brackets \[]. In this instance, horizontal=a to b orients the algorithm outputs such that the line through vertices a and b is horizontal.

**Line 2**

The left fermion line is drawn by declaring three vertices (i1, a and i2) and connecting them with edges --. Just like the \feynmandiagram command above, each edge also take optional arguments specified in brackets \[]. In this instance, we want these edges to have arrows to indicate that they are fermion lines, so we add the fermion style to them. As you will see later on, optional arguments can also be given to the vertices in exactly the same way.

**Line 3**

This edge connects vertices a and b with an edge styled as a photon. Since there is already a vertex labelled a, the algorithm will connect it to a new vertex labeled b.

**Line 4**

This line is analogous to line 2 and introduces two new vertices, f1 and f2. It re-uses the previously labelled b vertex.

**Line 5**

Finish the declaration of the Feynman diagram. The final semi-colon (;) is important.

The name given to each vertex in the graph does not matter. So in this example, `i1`, `i2` denote the initial particles; `f1`, `f2` denotes the final particles; and `a`, `b` are the end points of the propagator. The only important aspect is that what we called `a` in line 2 is also `a` in line 3 so that the underlying algorithm treats them as the same vertex.

The order in which vertices are declared does not matter as the default algorithm re-arranges everything. For example, one might prefer to draw the fermion lines all at once, as with the following example (note also that the way we named vertices is completely different):

```
\feynmandiagram [horizontal=f2 to f3] {
  f1 -- [fermion] f2 -- [fermion] f3 -- [fermion] f4,
  f2 -- [photon] p1,
  f3 -- [photon] p2,
};
```

![Photon-scattering.png](/files/L48QsZW5pOXjsYJ7NdjB)

As a final remark, the calculation of where vertices should be placed is usually done through an algorithm written in Lua. As a result, LuaTeX is required in order to make use of these algorithms. If LuaTeX is not used, Ti*k*Z-Feynman will default to a more rudimentary algorithm and will warn the user instead.

### Adding Styles

So far, the examples have only used the `photon` and `fermion` styles. The Ti*k*Z-Feynman package comes with quite a few extra styles for edges and vertices which are all documented over in the [package documentation](http://mirrors.ctan.org/graphics/pgf/contrib/tikz-feynman/tikz-feynman.pdf). For example, it is possible to add momentum arrows with `momentum=<text>`, and in the case of end vertices, the particle can be labelled with `particle=<text>`. To demonstrate how they are used, we take the generic *s*-channel diagram from earlier and make it a electron-positron pairs annihilating into muons:

```
\feynmandiagram [horizontal=a to b] {
  i1 [particle=\(e^{-}\)] -- [fermion] a -- [fermion] i2 [particle=\(e^{+}\)],
  a -- [photon, edge label=\(\gamma\), momentum'=\(k\)] b,
  f1 [particle=\(\mu^{+}\)] -- [fermion] b -- [fermion] f2 [particle=\(\mu^{-}\)],
};
```

![S-channel-labelled.png](/files/mR7Feai07fi58ZBwJ0wm)

In addition to the style keys documented below, style keys from Ti*k*Z can be used as well:

```
\feynmandiagram [horizontal=a to b] {
  i1 [particle=\(e^{-}\)] -- [fermion, very thick] a -- [fermion, opacity=0.2] i2 [particle=\(e^{+}\)],
  a -- [red, photon, edge label=\(\gamma\), momentum'={[arrow style=red]\(k\)}] b,
  f1 [particle=\(\mu^{+}\)] -- [fermion, opacity=0.2] b -- [fermion, very thick] f2 [particle=\(\mu^{-}\)],
};
```

![S-channel-labelled-styled.png](/files/Gasqj0YRfM9hXvOAHLau)

For a list of all the various styles that Ti*k*Z provides, have a look at the [Ti*k*Z manual](http://mirrors.ctan.org/graphics/pgf/base/doc/pgfmanual.pdf); it is extremely thorough and provides many usage examples.

### When the Algorithm Isn't Enough

By default, the `\feynmandiagram` and `\diagram` commands use the `spring layout` algorithm to place all the edges. The `spring layout` algorithm attempts to \`spread out' the diagram as much as possible which—for most simpler diagrams—gives a satisfactory result; however in some cases, this does not produce the best diagram and this section will look at alternatives. There are three main alternatives:

**Add invisible edges**

While still using the default algorithm, it is possible to force certain vertices to be closer together by adding extra edges and making them invisible through draw=none. The algorithm will treat these extra edges in the same way, but they are simply not drawn at the end;

**Use a different algorithm**

In some circumstances, other algorithms may be better suited. Some of the other graph layout algorithms are listed in the package documentation, and an exhaustive list of all algorithms and their parameters is given in the TikZ manual;

**Manual placement**

As a last resort, very complicated or unusual diagrams will require each vertex to be manually placed.

#### Invisible Edges

The underlying algorithm treats all edges in exactly the same way when calculating where to place all the vertices, and the actual drawing of the diagram (after the placements have been calculated) is done separately. Consequently, it is possible to add edges to the algorithm, but prevent them from being drawn by adding `draw=none` to the edge style.

This is particularly useful if you want to ensure that the initial or final states remain closer together than they would have otherwise as illustrated in the following example (note that `opacity=0.2` is used instead of `draw=none` to illustrate where exactly the edge is located).

```
% No invisible to keep the two photons together
\feynmandiagram [small, horizontal=a to t1] {
  a [particle=\(\pi^{0}\)] -- [scalar] t1 -- t2 -- t3 -- t1,
  t2 -- [photon] p1 [particle=\(\gamma\)],
  t3 -- [photon] p2 [particle=\(\gamma\)],
};
```

![Invisible-edge-before.png](/files/RZfIuAtauYalNljugk1s)

```
% Invisible edge ensures photons are parallel
\feynmandiagram [small, horizontal=a to t1] {
  a [particle=\(\pi^{0}\)] -- [scalar] t1 -- t2 -- t3 -- t1,
  t2 -- [photon] p1 [particle=\(\gamma\)],
  t3 -- [photon] p2 [particle=\(\gamma\)],
  p1 -- [opacity=0.2] p2,
};
```

![Invisible-edge-after.png](/files/ZdzMDuxix6jeec1VBEyz)

#### Alternative Algorithms

The graph drawing library from Ti*k*Z has several different algorithms to position the vertices. By default, `\diagram` and `\feynmandiagram` use the `spring layout` algorithm to place the vertices. The `spring layout` attempts to spread everything out as much as possible which, in most cases, gives a nice diagram; however, there are certain cases where this does not work. A good example where the `spring layout` doesn't work are decays where we have the decaying particle on the left and all the daughter particles on the right.

```
% Using the default spring layout
\feynmandiagram [horizontal=a to b] {
  a [particle=\(\mu^{-}\)] -- [fermion] b -- [fermion] f1 [particle=\(\nu_{\mu}\)],
  b -- [boson, edge label=\(W^{-}\)] c,
  f2 [particle=\(\overline \nu_{e}\)] -- [fermion] c -- [fermion] f3 [particle=\(e^{-}\)],
};
```

![Spring-layout.png](/files/VjDUqxL7w83jaPXIsbJr)

```
% Using the layered layout
\feynmandiagram [layered layout, horizontal=a to b] {
  a [particle=\(\mu^{-}\)] -- [fermion] b -- [fermion] f1 [particle=\(\nu_{\mu}\)],
  b -- [boson, edge label'=\(W^{-}\)] c,
  c -- [anti fermion] f2 [particle=\(\overline \nu_{e}\)],
  c -- [fermion] f3 [particle=\(e^{-}\)],
};
```

![Layered-layout.png](/files/J1L8GeEx9wiHZ9Izt7Xw)

You may notice that in addition to adding the `layered layout` style to `\feynmandiagram`, we also changed the order in which we specify the vertices. This is because the `layered layout` algorithm does pay attention to the order in which vertices are declared (unlike the default `spring layout`); as a result, `c--f2, c--f3` has a different meaning to `f2--c--f3`. In the former case, `f2` and `f3` are both on the layer below `c` as desired; whilst the latter case places `f2` on the layer above `c` (that, the same layer as where the W-boson originates).

#### Manual Placement

In more complicated diagrams, it is quite likely that none of the algorithms work, no matter how many invisible edges are added. In such cases, the vertices have to be placed manually. Ti*k*Z-Feynman allows for vertices to be manually placed by using the `\vertex` command.

The `\vertex` command is available only within the `feynman` environment (which itself is only available inside a `tikzpicture`). The `feynman` environment loads all the relevant styles from Ti*k*Z-Feynman and declares additional Ti*k*Z-Feynman-specific commands such as `\vertex` and `\diagram`. This is inspired from PGFPlots and its use of the `axis` environment.

The `\vertex` command is very much analogous to the `\node` command from Ti*k*Z, with the notable exception that the vertex contents are optional; that is, you need not have `{<text>}` at the end. In the case where `{}` is specified, the vertex automatically is given the `particle` style, and otherwise it is a usual (zero-sized) vertex.

To specify where the vertices go, it is possible to give explicit coordinates though it is probably easiest to use the `positioning` library from Ti*k*Z which allows vertices to be placed relative to existing vertices. By using relative placements, it is possible to easily tweak one part of the graph and everything will adjust accordingly—the alternative being to manually adjust the coordinates of every affected vertex.

Finally, once all the vertices have been specified, the `\diagram*` command is used to specify all the edges. This works in much the same way as `\diagram` (and also `\feynmandiagram`), except that it uses an very basic algorithm to place new nodes and allows existing (named) nodes to be included. In order to refer to an existing node, the node must be given in parentheses.

This whole process of specifying the nodes and then drawing the edges between them is shown below for the muon decay:

```
\begin{tikzpicture}
  \begin{feynman}
    \vertex (a) {\(\mu^{-}\)};
    \vertex [right=of a] (b);
    \vertex [above right=of b] (f1) {\(\nu_{\mu}\)};
    \vertex [below right=of b] (c);
    \vertex [above right=of c] (f2) {\(\overline \nu_{e}\)};
    \vertex [below right=of c] (f3) {\(e^{-}\)};

    \diagram* {
      (a) -- [fermion] (b) -- [fermion] (f1),
      (b) -- [boson, edge label'=\(W^{-}\)] (c),
      (c) -- [anti fermion] (f2),
      (c) -- [fermion] (f3),
    };
  \end{feynman}
\end{tikzpicture}
```

![Manual-positioning.png](/files/1GRbiWUZKBMhfrgVjKMg)

## Other packages for drawing Feynman diagrams

There are several alternatives to the TikZ-Feynman package:

* [`feynmf`](https://ctan.org/pkg/feynmf): produces bitmap graphics via [MetaFont](https://ctan.org/pkg/metafont)
* [`feynmp`](https://ctan.org/pkg/feynmf) (bundled with `feynmf`) produces vector graphics via [MetaPost](https://ctan.org/pkg/metapost)
* [`feynmp-auto`](https://ctan.org/pkg/feynmp-auto?lang=en): derived from `feynmp`

The `feynmp-auto` package is, in effect, an extension of the `feynmp` package designed to automate the conversion of MetaPost's PostScript code to PDF data for use in pdfTeX, LuaTeX and XeTeX. The following examples all use `feynmp-auto`.

### Introduction

The `feynmf`, `feynmp` and `feynmp-auto` packages let you easily draw Feynman diagrams by specifying the vertices, particles and their labels, then automatically performing the layout to draw your diagram.

#### An overview of using the feynmf-based packages

To create Feynman diagrams you need to:

1. create an `fmfile` environment to contain one or more diagrams, each enclosed within an `fmfgraph` or `fmfgraph*` environment—the difference between the starred and non-starred form is [explained below](#fmfgraph-and-fmfgraph);
2. use each `fmfgraph` or `fmfgraph*` environment to contain the drawing instructions required to create an individual Feynman diagram.

The `fmfile` environment has the following form

```latex
\begin{fmffile}{file-name}

% Diagram 1
\begin{fmfgraph}(width,height)
...
\end{fmfgraph}

% Diagram 2
\begin{fmfgraph*}(width,height)
...
\end{fmfgraph*}

\end{fmffile}
```

where `file-name` is the name of a file that will be used to contain the MetaPost code descriptions of the individual drawings defined within `fmfgraph`/`fmfgraph*` environments.

Each drawing takes the form

```latex
\begin{fmfgraph}(width,height)

% drawing instructions

\end{fmfgraph}
```

or, for the starred version (`fmfgraph*`)

```latex
\begin{fmfgraph*}(width,height)

% drawing instructions

\end{fmfgraph*}
```

where `(width,height)` defines the size of the diagram expressed in units of [`\unitlength`](#note-on-unitlength).

The MetaPost code in `file-name` is processed to create the graphic(s) representing your Feynman diagram(s). An `fmfile` environment can contain up to 256 individual drawings.

#### fmfgraph and fmfgraph\*

* `fmfgraph`: this environment contains the drawing instructions (description) of a single Feynman diagram. It will be placed *at the location of the environment*. This environment does not support labels, use `fmfgraph*` to include labels in your diagrams.
* `fmfgraph*` same as `fmfgraph`, but enclosed in a [`picture` environment](/latex/figures-and-tables/04-picture-environment.md) of the same size. It supports the use of LaTeX labels.

### An example

Let's start with a quick example:

```latex
\documentclass{article}
\usepackage{feynmp-auto}
\begin{document}
\begin{fmffile}{first-diagram}
 \begin{fmfgraph}(120,80)
   \fmfleft{i1,i2}
   \fmfright{o1,o2}
   \fmf{fermion}{i1,v1,o1}
   \fmf{fermion}{i2,v2,o2}
   \fmf{photon}{v1,v2}
 \end{fmfgraph}
\end{fmffile}
\end{document}
```

[Open this example in Overleaf](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=feynmf+package+example+1\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%7Bfeynmp-auto%7D%0A%5Cbegin%7Bdocument%7D%0A%5Cbegin%7Bfmffile%7D%7Bfirst-diagram%7D%0A+%5Cbegin%7Bfmfgraph%7D%28120%2C80%29%0A+++%5Cfmfleft%7Bi1%2Ci2%7D%0A+++%5Cfmfright%7Bo1%2Co2%7D%0A+++%5Cfmf%7Bfermion%7D%7Bi1%2Cv1%2Co1%7D%0A+++%5Cfmf%7Bfermion%7D%7Bi2%2Cv2%2Co2%7D%0A+++%5Cfmf%7Bphoton%7D%7Bv1%2Cv2%7D%0A+%5Cend%7Bfmfgraph%7D%0A%5Cend%7Bfmffile%7D%0A%5Cend%7Bdocument%7D)

This example produces the following output:

![](/files/cdmL5pDEfP77O8GjUnNw)

In this example the `fmfgraph` environment sets the drawing's width and height to 120 and 80 respectively:

```latex
\begin{fmfgraph}(120,80)
```

using units determined by the value of `\unitlength`, which has a default value of 1pt; consequently, this diagram is allocated a width of 120pt and a height of 80pt.

#### Note on \unitlength

Because `\unitlength` is a LaTeX dimension you can change its value using the `\setlength` command; for example, to define the width and height of drawings in units of cm you can write:

```latex
\setlength{\unitlength}{1cm}
```

Reproducing the example above, the diagram below now has a width of `8cm` and height of `5cm`:

```latex
\documentclass{article}
\usepackage{feynmp-auto}
\begin{document}
\setlength{\unitlength}{1cm}
\begin{fmffile}{first-diagram}
 \begin{fmfgraph}(8,5)% units are now in cm
   \fmfleft{i1,i2}
   \fmfright{o1,o2}
   \fmf{fermion}{i1,v1,o1}
   \fmf{fermion}{i2,v2,o2}
   \fmf{photon}{v1,v2}
 \end{fmfgraph}
\end{fmffile}
\end{document}
```

[Open this example in Overleaf.](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Setting+units+to+draw+Feynman+diagrams\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%7Bfeynmp-auto%7D%0A%5Cbegin%7Bdocument%7D%0A%5Csetlength%7B%5Cunitlength%7D%7B1cm%7D%0A%5Cbegin%7Bfmffile%7D%7Bfirst-diagram%7D%0A+%5Cbegin%7Bfmfgraph%7D%288%2C5%29%25+units+are+now+in+cm%0A+++%5Cfmfleft%7Bi1%2Ci2%7D%0A+++%5Cfmfright%7Bo1%2Co2%7D%0A+++%5Cfmf%7Bfermion%7D%7Bi1%2Cv1%2Co1%7D%0A+++%5Cfmf%7Bfermion%7D%7Bi2%2Cv2%2Co2%7D%0A+++%5Cfmf%7Bphoton%7D%7Bv1%2Cv2%7D%0A+%5Cend%7Bfmfgraph%7D%0A%5Cend%7Bfmffile%7D%0A%5Cend%7Bdocument%7D)

This example now produces a larger diagram:

![](/files/YbgZ1ny9UkAA9r1qLR2w)

### Vertices

The first thing you need to do is specify your external vertices, and where they should be positioned. You can name your vertices anything you like, and say where they should be positioned with the commands `\fmfleft`, `\fmfright`, `\fmftop`, `\fmfbottom`.

As used in the examples above:

```latex
% Creates two vertices on the left called i1 and i2
\fmfleft{i1,i2}

% Creates two vertices on the right called o1 and o2
\fmfright{o1,o2}
```

You can connect vertices with the `\fmf`, which will create new vertices if you pass in names that haven't been created yet. Also as used in the examples above:

```latex
% Will create a fermion line between i1 and
% the newly created v1, and between v1 and o1.
\fmf{fermion}{i1,v1,o1}

% Will create a photon line between v1 and the newly created v2
\fmf{photon}{v1,v2}
```

### Labels

As [noted above](#fmfgraph-and-fmfgraph), to use labels the drawing must be created using the `fmfgraph*` form of the drawing environment.

Use the `\fmflabel` command to place a label on a vertex:

```latex
\fmflabel{label-content}{diagram-vertex}
```

where:

* `label-content` is the label to apply to the chosen vertex;
* `diagram-vertex` is the name of the vertex to label.

Note that `label-content` can include mathematical material.

We can re-use the previous example to add the following labels

```latex
   \fmflabel{$v_1$}{v1}
   \fmflabel{$v_2$}{v2}
```

which produces the updated diagram shown below:

```latex
\documentclass{article}
\usepackage{feynmp-auto}
\begin{document}
\begin{fmffile}{first-diagram}
 \begin{fmfgraph*}(120,80) %NOTE the fmfgraph* environment
   \fmfleft{i1,i2}
   \fmfright{o1,o2}
   \fmf{fermion}{i1,v1,o1}
   \fmf{fermion}{i2,v2,o2}
   \fmf{photon}{v1,v2}
   % Add our labels
   \fmflabel{$v_1$}{v1}
   \fmflabel{$v_2$}{v2}
 \end{fmfgraph*}
\end{fmffile}
\end{document}
```

[Open this example in Overleaf.](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Adding+labels+to+Feynman+diagrams\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%7Bfeynmp-auto%7D%0A%5Cbegin%7Bdocument%7D%0A%5Cbegin%7Bfmffile%7D%7Bfirst-diagram%7D%0A+%5Cbegin%7Bfmfgraph%2A%7D%28120%2C80%29+%25NOTE+the+fmfgraph%2A+environment%0A+++%5Cfmfleft%7Bi1%2Ci2%7D%0A+++%5Cfmfright%7Bo1%2Co2%7D%0A+++%5Cfmf%7Bfermion%7D%7Bi1%2Cv1%2Co1%7D%0A+++%5Cfmf%7Bfermion%7D%7Bi2%2Cv2%2Co2%7D%0A+++%5Cfmf%7Bphoton%7D%7Bv1%2Cv2%7D%0A+++%25+Add+our+labels%0A+++%5Cfmflabel%7B%24v_1%24%7D%7Bv1%7D%0A+++%5Cfmflabel%7B%24v_2%24%7D%7Bv2%7D%0A+%5Cend%7Bfmfgraph%2A%7D%0A%5Cend%7Bfmffile%7D%0A%5Cend%7Bdocument%7D)

This example produces a Feynman diagram containing labels:

![](/files/JY31tmrck1EJfLyDBRZx)

### Some more complex examples

The following, more advanced, examples use features of `feynmp` that we have not discussed: see the [`feynmp` package (`feynmf`) documentation](https://mirror.ox.ac.uk/sites/ctan.org/macros/latex/contrib/feynmf/fmfman.pdf)—which also contains numerous additional examples. These diagrams were originally published in an Overleaf template containing LaTeX code reproduced from a CERN web page which is now only accessible via [Wayback Machine](https://web.archive.org/web/20141015023615/http://szczypka.web.cern.ch:80/szczypka/guides/latex/feynmp.html)—that page contains further examples you may wish to try.

#### Example 1

```latex
\documentclass{article}
\usepackage{feynmp-auto}
\begin{document}
\begin{fmffile}{complex-a}
\begin{fmfgraph*}(100,100)
    \fmfleft{i1}
    \fmfright{o1,o2}
    \fmf{fermion,label=$u$}{i1,w1}
    \fmf{fermion,label=$d$}{w1,o1}
    \fmf{photon,label=$W^{+}$}{w1,o2}
    \fmfv{lab=$V^{\ast}_{ud}$,lab.dist=0.05w}{w1}
\end{fmfgraph*}
\end{fmffile}
\end{document}
```

[Open this example in Overleaf](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=feynmf+package+example+1\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%7Bfeynmp-auto%7D%0A%5Cbegin%7Bdocument%7D%0A%5Cbegin%7Bfmffile%7D%7Bcomplex-a%7D%0A%5Cbegin%7Bfmfgraph%2A%7D%28100%2C100%29%0A++++%5Cfmfleft%7Bi1%7D%0A++++%5Cfmfright%7Bo1%2Co2%7D%0A++++%5Cfmf%7Bfermion%2Clabel%3D%24u%24%7D%7Bi1%2Cw1%7D%0A++++%5Cfmf%7Bfermion%2Clabel%3D%24d%24%7D%7Bw1%2Co1%7D%0A++++%5Cfmf%7Bphoton%2Clabel%3D%24W%5E%7B%2B%7D%24%7D%7Bw1%2Co2%7D%0A++++%5Cfmfv%7Blab%3D%24V%5E%7B%5Cast%7D_%7Bud%7D%24%2Clab.dist%3D0.05w%7D%7Bw1%7D%0A%5Cend%7Bfmfgraph%2A%7D%0A%5Cend%7Bfmffile%7D%0A%5Cend%7Bdocument%7D)

This example produces the following diagram:

![](/files/zoac3pUrNqubT0J19LaW)

#### Example 2

```latex
\documentclass{article}
\usepackage{feynmp-auto}
\begin{document}
\begin{fmffile}{complex-b}
\begin{fmfgraph*}(200,200)
    % bottom and top verticies
    \fmfstraight
    \fmfleft{i0,i1,i2,id1,id2,i3,i4,i5}
    \fmfright{o0,o1,o2,od1,od2,o3,o4,o5}
    % incoming proton to gluon vertices
    \fmf{fermion,label=$d$}{i1,o1}
    % tension shifts vertex to one side
    \fmf{fermion,tension=1.5,label=$\overline{b}$}{v2,i4}
    \fmf{fermion,label=$\overline{c}$}{o4,v2}
    \fmffreeze
    \fmf{fermion}{o2,v3,o3}
    \fmf{fermion,label=$\overline{s}$}{o2,v3}
    \fmf{fermion,label=$c$}{v3,o3}
    \fmf{photon, tension=2,label=$W^{+}$}{v2,v3}
    % phantom centres the W->cs vertex
    \fmf{phantom,tension=1.5}{i1,v3}

    \fmfv{lab=$V_{cb}^{\ast}$}{v2}
    \fmfv{lab=$V_{cs}$,lab.dist=-.1w}{v3}
\end{fmfgraph*}
\end{fmffile}
\end{document}
```

[Open this example in Overleaf](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=feynmf+package+example+1\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%7Bfeynmp-auto%7D%0A%5Cbegin%7Bdocument%7D%0A%5Cbegin%7Bfmffile%7D%7Bcomplex-b%7D%0A%5Cbegin%7Bfmfgraph%2A%7D%28200%2C200%29%0A++++%25+bottom+and+top+verticies%0A++++%5Cfmfstraight%0A++++%5Cfmfleft%7Bi0%2Ci1%2Ci2%2Cid1%2Cid2%2Ci3%2Ci4%2Ci5%7D%0A++++%5Cfmfright%7Bo0%2Co1%2Co2%2Cod1%2Cod2%2Co3%2Co4%2Co5%7D%0A++++%25+incoming+proton+to+gluon+vertices%0A++++%5Cfmf%7Bfermion%2Clabel%3D%24d%24%7D%7Bi1%2Co1%7D%0A++++%25+tension+shifts+vertex+to+one+side%0A++++%5Cfmf%7Bfermion%2Ctension%3D1.5%2Clabel%3D%24%5Coverline%7Bb%7D%24%7D%7Bv2%2Ci4%7D%0A++++%5Cfmf%7Bfermion%2Clabel%3D%24%5Coverline%7Bc%7D%24%7D%7Bo4%2Cv2%7D%0A++++%5Cfmffreeze%0A++++%5Cfmf%7Bfermion%7D%7Bo2%2Cv3%2Co3%7D%0A++++%5Cfmf%7Bfermion%2Clabel%3D%24%5Coverline%7Bs%7D%24%7D%7Bo2%2Cv3%7D%0A++++%5Cfmf%7Bfermion%2Clabel%3D%24c%24%7D%7Bv3%2Co3%7D%0A++++%5Cfmf%7Bphoton%2C+tension%3D2%2Clabel%3D%24W%5E%7B%2B%7D%24%7D%7Bv2%2Cv3%7D%0A++++%25+phantom+centres+the+W-%3Ecs+vertex%0A++++%5Cfmf%7Bphantom%2Ctension%3D1.5%7D%7Bi1%2Cv3%7D%0A%0A++++%5Cfmfv%7Blab%3D%24V_%7Bcb%7D%5E%7B%5Cast%7D%24%7D%7Bv2%7D%0A++++%5Cfmfv%7Blab%3D%24V_%7Bcs%7D%24%2Clab.dist%3D-.1w%7D%7Bv3%7D%0A%5Cend%7Bfmfgraph%2A%7D%0A%5Cend%7Bfmffile%7D%0A%5Cend%7Bdocument%7D)

This example produces the following diagram:

![](/files/4kBhyAMIkjhKcyy54Msx)

#### Example 3

```latex
\documentclass{article}
\usepackage{feynmp-auto}
\begin{document}
\begin{fmffile}{complex-c}
\begin{fmfgraph*}(200,200)
    %bottom and top verticies
    \fmfbottom{P1,P2}
    \fmftop{P1',b,bbar,P2'}
    %incoming protons to gluon vertices
    \fmf{fermion,tension=2,lab=$P_1$}{P1,g1}
    \fmf{fermion,tension=2,lab=$P_2$}{P2,g2}
    %blobs at gluon vertices, 0.16w is the size of blob
    \fmfblob{.16w}{g1,g2}
    %gluon from P1 to vertex1
    \fmf{gluon,lab.side=right,lab=$x_{1}P_{1}$}{g1,v1}
    %gluon from P2 to vertex2 - note change of order!
    \fmf{gluon,lab.side=right,lab=$x_{2}P_{2}$}{v2,g2}
    %quark loop was here
    \fmf{fermion, tension=.6, lab.side=right,lab=$b$}{v1,b}
    \fmf{fermion, tension=1.2}{v2,v1}
    \fmf{fermion, tension=.6, lab.side=right,lab=$\overline{b}$}{bbar,v2}
    %outgoing protons
    \fmf{fermion}{g1,P1'}
    \fmf{fermion}{g2,P2'}
    %freeze everything in place
    \fmffreeze
    \renewcommand{\P}[3]{\fmfi{plain}{%
        vpath(__#1,__#2) shifted (thick*(#3))}}
    %lines on P1
    \P{P1}{g1}{2,0}
    \P{P1}{g1}{-2,1}
    %lines on p2
    \P{P2}{g2}{2,1}
    \P{P2}{g2}{-2,0}
    %lines on P1'
    \P{g1}{P1'}{-2,-1}
    \P{g1}{P1'}{2,0}
    %lines on P2'
    \P{g2}{P2'}{-2,0}
    \P{g2}{P2'}{2,-1}
\end{fmfgraph*}
\end{fmffile}
\end{document}
```

[Open this example in Overleaf](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=feynmf+package+example+1\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%7Bfeynmp-auto%7D%0A%5Cbegin%7Bdocument%7D%0A%5Cbegin%7Bfmffile%7D%7Bcomplex-c%7D%0A%5Cbegin%7Bfmfgraph%2A%7D%28200%2C200%29%0A++++%25bottom+and+top+verticies%0A++++%5Cfmfbottom%7BP1%2CP2%7D%0A++++%5Cfmftop%7BP1%27%2Cb%2Cbbar%2CP2%27%7D%0A++++%25incoming+protons+to+gluon+vertices%0A++++%5Cfmf%7Bfermion%2Ctension%3D2%2Clab%3D%24P_1%24%7D%7BP1%2Cg1%7D%0A++++%5Cfmf%7Bfermion%2Ctension%3D2%2Clab%3D%24P_2%24%7D%7BP2%2Cg2%7D%0A++++%25blobs+at+gluon+vertices%2C+0.16w+is+the+size+of+blob%0A++++%5Cfmfblob%7B.16w%7D%7Bg1%2Cg2%7D%0A++++%25gluon+from+P1+to+vertex1%0A++++%5Cfmf%7Bgluon%2Clab.side%3Dright%2Clab%3D%24x_%7B1%7DP_%7B1%7D%24%7D%7Bg1%2Cv1%7D%0A++++%25gluon+from+P2+to+vertex2+-+note+change+of+order%21%0A++++%5Cfmf%7Bgluon%2Clab.side%3Dright%2Clab%3D%24x_%7B2%7DP_%7B2%7D%24%7D%7Bv2%2Cg2%7D%0A++++%25quark+loop+was+here%0A++++%5Cfmf%7Bfermion%2C+tension%3D.6%2C+lab.side%3Dright%2Clab%3D%24b%24%7D%7Bv1%2Cb%7D%0A++++%5Cfmf%7Bfermion%2C+tension%3D1.2%7D%7Bv2%2Cv1%7D%0A++++%5Cfmf%7Bfermion%2C+tension%3D.6%2C+lab.side%3Dright%2Clab%3D%24%5Coverline%7Bb%7D%24%7D%7Bbbar%2Cv2%7D%0A++++%25outgoing+protons%0A++++%5Cfmf%7Bfermion%7D%7Bg1%2CP1%27%7D%0A++++%5Cfmf%7Bfermion%7D%7Bg2%2CP2%27%7D%0A++++%25freeze+everything+in+place%0A++++%5Cfmffreeze%0A++++%5Crenewcommand%7B%5CP%7D%5B3%5D%7B%5Cfmfi%7Bplain%7D%7B%25%0A++++++++vpath%28__%231%2C__%232%29+shifted+%28thick%2A%28%233%29%29%7D%7D%0A++++%25lines+on+P1%0A++++%5CP%7BP1%7D%7Bg1%7D%7B2%2C0%7D%0A++++%5CP%7BP1%7D%7Bg1%7D%7B-2%2C1%7D%0A++++%25lines+on+p2%0A++++%5CP%7BP2%7D%7Bg2%7D%7B2%2C1%7D%0A++++%5CP%7BP2%7D%7Bg2%7D%7B-2%2C0%7D%0A++++%25lines+on+P1%27%0A++++%5CP%7Bg1%7D%7BP1%27%7D%7B-2%2C-1%7D%0A++++%5CP%7Bg1%7D%7BP1%27%7D%7B2%2C0%7D%0A++++%25lines+on+P2%27%0A++++%5CP%7Bg2%7D%7BP2%27%7D%7B-2%2C0%7D%0A++++%5CP%7Bg2%7D%7BP2%27%7D%7B2%2C-1%7D%0A%5Cend%7Bfmfgraph%2A%7D%0A%5Cend%7Bfmffile%7D%0A%5Cend%7Bdocument%7D)

This example produces the following diagram:

![](/files/uFq8NVZ7PbGLXxb3zq3C)

### Line styles

We've seen the `photon` and `fermion` line styles above, but the `feynmp` package supports many more.

| Appearance                                                       | Name(s)                                 |
| ---------------------------------------------------------------- | --------------------------------------- |
| ![Feynmf-line-curly.png](/files/3oQZQ457Yfh0DJD9P9OC)            | gluon, curly                            |
| ![Feynmf-line-dbl-curly.png](/files/mSHxmhTs98uIXvTItbgo)        | dbl\_curly                              |
| ![Feynmf-line-dashes.png](/files/i88OR6hBCktwb0wSZP9s)           | dashes                                  |
| ![Feynmf-line-dashed-arrow.png](/files/sG3YiZGqHEcZkOUQICW5)     | scalar, dashes\_arrow                   |
| ![Feynmf-line-dbl-dashes.png](/files/c2VvK4kkuanRGMtSTOCc)       | dbl\_dashes                             |
| ![Feynmf-line-dbl-dashes-arrow.png](/files/2vohIhMh0wzMnWydnzaS) | dbl\_dashes\_arrow                      |
| ![Feynmf-line-dots.png](/files/wGGG9K6LC6H4FqT35CeU)             | dots                                    |
| ![Feynmf-line-dots-arrow.png](/files/888Db5L2vO6olqZkzhpt)       | ghost, dots\_arrow                      |
| ![Feynmf-line-dbl-dots.png](/files/Yph1KvDOX7FTY0kp1nUL)         | dbl\_dots                               |
| ![Feynmf-line-dbl-dots-arrow.png](/files/cnlKLjoBS6rkYR1sbLnR)   | dbl\_dots\_arrow                        |
|                                                                  | phantom                                 |
| ![Feynmf-line-phantom-arrow.png](/files/mXQ6y465Bo2opJPsqaFp)    | phantom\_arrow                          |
| ![Feynmf-line-plain.png](/files/CSzquFpBvgOngPFBWvm1)            | vanilla, plain                          |
| ![Feynmf-line-plain-arrow.png](/files/g6ck6ArLXiQob0DBjmN1)      | fermion, electron, quark, plain\_arrow  |
| ![Feynmf-line-dbl-plain.png](/files/KgAha1KI16OYsDNPNhW7)        | double, dbl\_plain                      |
| ![Feynmf-line-dbl-plain-arrow.png](/files/s1Z8Z1beKjNAG6sBBraM)  | double\_arrow, heavy, dbl\_plain\_arrow |
| ![Feynmf-line-wiggly.png](/files/byShUYsfHJ1UvAxnYQFj)           | boson, photon, wiggly                   |
| ![Feynmf-line-dbl-wiggly.png](/files/8CZxxcyTqi7ZmUqSY2vs)       | dbl\_wiggly                             |
| ![Feynmf-line-zigzag.png](/files/QsSqweWO3J0233X7fYsh)           | zigzag                                  |
| ![Feynmf-line-dbl-zigzag.png](/files/zORRB8WZubQBcZNbfiYn)       | dbl\_zigzag                             |

## Further Reading

For more information see:

* [Chemistry formulae](/latex/field-specific/02-chemistry-formulae.md)
* [Molecular orbital diagrams](/latex/field-specific/04-molecular-orbital-diagrams.md)
* [TikZ package](/latex/figures-and-tables/05-tikz-package.md)
* [Drawing Diagrams Directly in LaTeX](/latex/figures-and-tables/04-picture-environment.md)
* [Inserting Images](/latex/more-topics/27-inserting-images.md)
* [List of Greek letters and math symbols](/latex/mathematics/11-list-of-greek-letters-and-math-symbols.md)
* [The **feynmf** package documentation](http://mirrors.ctan.org/macros/latex/contrib/feynmf/fmfman.pdf).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://overleaf-pro.ayaka.space/latex/field-specific/03-feynman-diagrams.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
