Feynman diagrams
An online LaTeX editor that’s easy to use. No installation, real-time collaboration, version control, hundreds of LaTeX templates, and more.
/favicon.ico
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, which uses TikZ to draw diagrams, and feynmp-auto which ("behind the scenes") uses MetaPost.

The TikZ-Feynman package

The tikz-feynman package was published in 2016 and uses TikZ in order to generate Feynman diagrams. TikZ-Feynman builds upon the TikZ package and its graph drawing algorithms in order to automate the placement of many vertices. TikZ-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 TikZ-Feynman will always be on the project page and in the package documentation on CTAN.

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. 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.

Loading the Package

After installing the package, the TikZ-Feynman package can be loaded with \usepackage{tikz-feynman} in the preamble. It is recommend that you also specify the version of TikZ-Feynman to use with the compat package option: \usepackage[compat=1.0.0]{tikz-feynman}. This ensures that any new versions of TikZ-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 TikZ and requires a final semi-colon (;) to finish the environment. For example, a simple s-channel diagram is:

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 [<options>]. 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 [<options>]. 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):

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, TikZ-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 TikZ-Feynman package comes with quite a few extra styles for edges and vertices which are all documented over in the package documentation. 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:

In addition to the style keys documented below, style keys from TikZ can be used as well:

For a list of all the various styles that TikZ provides, have a look at the TikZ manual; 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).

Alternative Algorithms

The graph drawing library from TikZ 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.

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. TikZ-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 TikZ-Feynman and declares additional TikZ-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 TikZ, 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 TikZ 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:

Other packages for drawing Feynman diagrams

There are several alternatives to the TikZ-Feynman package:

feynmf: produces bitmap graphics via MetaFont

feynmp (bundled with feynmf) produces vector graphics via MetaPost

feynmp-auto: 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:

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;

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

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

or, for the starred version (fmfgraph*)

where (width,height) defines the size of the diagram expressed in units of \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 of the same size. It supports the use of LaTeX labels.

An example

Let's start with a quick example:

Open this example in Overleaf

This example produces the following output:

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

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:

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

Open this example in Overleaf.

This example now produces a larger diagram:

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:

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:

Labels

As noted above, 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:

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

which produces the updated diagram shown below:

Open this example in Overleaf.

This example produces a Feynman diagram containing labels:

Some more complex examples

The following, more advanced, examples use features of feynmp that we have not discussed: see the feynmp package (feynmf) documentation—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—that page contains further examples you may wish to try.

Example 1

Open this example in Overleaf

This example produces the following diagram:

Example 2

Open this example in Overleaf

This example produces the following diagram:

Example 3

Open this example in Overleaf

This example produces the following diagram:

Line styles

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

Appearance Name(s) gluon, curly dbl_curly dashes scalar, dashes_arrow dbl_dashes dbl_dashes_arrow dots ghost, dots_arrow dbl_dots dbl_dots_arrow phantom phantom_arrow vanilla, plain fermion, electron, quark, plain_arrow double, dbl_plain double_arrow, heavy, dbl_plain_arrow boson, photon, wiggly dbl_wiggly zigzag dbl_zigzag

Further Reading

For more information see: