Introduction to Feynman Diagrams in LaTeX
Feynman diagrams are essential tools in theoretical physics, used to represent the mathematical expressions describing the behavior of subatomic particles. While you could draw these using general-purpose graphics software, generating them directly in LaTeX ensures that your diagrams are consistent with your document's fonts, mathematically precise, and easy to edit.
The gold standard for creating these diagrams in modern LaTeX is the tikz-feynman package. It builds upon the powerful TikZ graphics library but provides a simplified, physics-oriented syntax that makes complex particle interactions easy to describe.
Setting Up Your Environment
Before we dive into drawing, we need to load the package and understand a crucial technical requirement regarding how LaTeX processes these diagrams.
Loading the Package
To get started, add the following to your document preamble:
\usepackage[compat=1.1.0]{tikz-feynman}A Note on Compilers (LuaLaTeX vs. pdfLaTeX)
One of the most powerful features of tikz-feynman is its "automatic layout" algorithm, which positions vertices for you. However, this specific feature requires LuaLaTeX.
- If you use LuaLaTeX: You can use advanced positioning like
\feynmandiagram [spring layout]. - If you use pdfLaTeX: You must position your vertices manually or use a fixed grid.
Note: For beginners, we recommend starting with manual positioning or simple directional keys (like
horizontal) to ensure your code works across all LaTeX compilers.
Basic Syntax and Your First Diagram
The most common way to create a diagram is using the \feynmandiagram command. The syntax uses a "connect-the-dots" logic: you define vertices (points) and connect them using lines with specific styles.
Let's look at a simple electron-photon vertex:
\begin{center}
\feynmandiagram [horizontal=a to b] {
i1 [particle=\(e^{-}\)] -- [fermion] a -- [fermion] i2 [particle=\(e^{-}\)],
a -- [photon] b [particle=\(\gamma\)],
};
\end{center}Breaking Down the Code:
horizontal=a to b: This tells LaTeX to align the path from pointato pointbon a horizontal axis.i1 [particle=\(e^{-}\)]: This creates a point namedi1and labels it as an electron.-- [fermion]: This draws a line with an arrow in the middle, signifying a fermion.a: This is a central vertex where the three lines meet.,: Commas are used to separate different chains of connections.
Common Line Styles and Particle Types
In Feynman diagrams, the style of the line conveys what type of particle is being represented. The tikz-feynman package provides intuitive keywords for these styles.
Standard Styles:
fermion: A solid line with an arrow pointing forward.anti fermion: A solid line with an arrow pointing backward.photon: A wavy (sinusoidal) line.gluon: A coiled/loopy line.scalar: A dashed line (often used for Higgs bosons).ghost: A dotted line.
Example: Electron-Positron Annihilation
This example demonstrates how to combine different line styles to show an interaction.
\begin{tikzpicture}
\begin{feynman}
\vertex (i1) {\(e^{-}\)};
\vertex [below=2cm of i1] (i2) {\(e^{+}\)};
\vertex [right=2cm of i1] (a);
\vertex [right=2cm of i2] (b);
\vertex [right=2cm of a] (f1) {\(\mu^{-}\)};
\vertex [right=2cm of b] (f2) {\(\mu^{+}\)};
\diagram* {
(i1) -- [fermion] (a) -- [fermion] (i2),
(a) -- [photon, label=\(\gamma\)] (b),
(f1) -- [fermion] (b) -- [fermion] (f2),
};
\end{feynman}
\end{tikzpicture}Tip: Notice the use of the
\vertexcommand inside atikzpictureenvironment. This is often more stable for complex documents than the shorthand\feynmandiagramcommand.
Adding Momentum and Labels
To make diagrams scientifically useful, you often need to indicate the direction of momentum or label specific propagators.
Momentum Arrows
You can add momentum arrows alongside any line using the momentum key.
\feynmandiagram [horizontal=a to b] {
i1 -- [fermion, momentum=\(p\)] a -- [photon, momentum=\(k\)] b,
};External Labels
Labels can be placed at any vertex. You can adjust their position using keys like label=above:Text or label=180:Text (using degrees).
\feynmandiagram [vertical=a to b] {
a [label=left:\(V_{ub}\)] -- [gluon] b,
};Advanced Layouts and Best Practices
As your diagrams grow in complexity (like Penguin diagrams or Box diagrams), positioning becomes critical.
Using "Relative" Positioning
Instead of guessing coordinates, tell LaTeX where a vertex is relative to another. Use right=of, above right=of, etc.
\begin{tikzpicture}
\begin{feynman}
\vertex (a);
\vertex [right=of a] (b);
\vertex [above left=of a] (i1) {\(q_{1}\)};
\vertex [below left=of a] (i2) {\(q_{2}\)};
\vertex [above right=of b] (f1) {\(q_{3}\)};
\vertex [below right=of b] (f2) {\(q_{4}\)};
\diagram* {
(i1) -- [fermion] (a) -- [fermion] (i2),
(a) -- [gluon, edge label=\(g\)] (b),
(f1) -- [fermion] (b) -- [fermion] (f2),
};
\end{feynman}
\end{tikzpicture}Best Practices:
- Keep it Consistent: Always use the same distance units (e.g.,
2cm) for vertices to keep your diagrams uniform throughout a paper. - Use the
*in\diagram*: When using manual positioning, the*prevents TikZ from trying to override your placement with its own algorithms. - Group your Code: Place your vertices first, then define the connections in the
\diagramblock. This makes debugging much easier.
Common Pitfalls to Avoid
- Missing Semicolons: Like standard TikZ, many commands in
tikz-feynmanrequire a semicolon at the end of the line or the end of the diagram block. - Overlapping Labels: If your particle labels overlap with lines, use the
inner sepornudgeoptions to push them away. - Math Mode: Remember that particle names (like
\gammaore^-) should be wrapped in math mode\( \)or$ $even inside theparticle={...}argument. - Compiler Confusion: If you see an error like
Package tikz-feynman Error: The LuaTeX engine is required for the graph drawing library, it means you've used an automatic layout feature (likespring layout) while compiling with pdfLaTeX. Switch your compiler to LuaLaTeX or use manual vertex positioning.
