PyFeynGen

Generate Feynman TikZ diagrams from a single line of text.

Examples

More info

Documentation

Simple Syntax

PyFeynGen uses a natural syntax to describe processes. No need to handle complex coordinates.

  • Use > to separate the initial state from the final state.
  • Particle names are automatically converted (e.g.: mu-\mu^-).
  • Intermediate propagators are inferred or specified by a second >.

Complete Core Syntax

The library parses a reaction string and maps it to a graph structure. The syntax is designed to be readable and mimics the flow of physical processes.

Component Syntax Description
Propagation > Connects states from left to right.
Simple Particle e-, Z0, gamma Standard particle names (mapped in physics.py).
Branching ( ... ) Creates a decay or a split from the current vertex.
Multi-line Loop [p1 p2 ...] Creates parallel edges between two vertices.
Anchor @name Names a vertex to link it later to another vertex.
Style Attribute {style} Applies a style (like blob) to a vertex or particle.
Advanced Features

Branching & Cascades

To represent a particle decaying into multiple others, use parentheses. You can nest these indefinitely.

Example: H > (Z0 > e+ e-) (Z0 > mu+ mu-) Result: A Higgs boson splitting into two Z bosons, each subsequently decaying into lepton pairs.

Effective Interactions (Blobs)

To represent a contact interaction or non-resolved vertex, use the {blob} attribute on an anchor.

Example: n > @v1{blob} > p e- nubar_e Result: An interaction where the central vertex is rendered as a large shaded disk.

Anchors & Vertex Linking

Anchors allow you to connect two separate parts of a diagram without a direct flow.

Example: e+ e- > (mu+ @a > ...) (mu- @a > ...) Result: If two vertices share the same @a name, the library automatically draws a photon (default) or a specified particle between them.
Smart Particle/Label Detection

The library features smart detection of particle names and automatic LaTeX label generation. If a particle name is not found in the default or user dictionary, the system will attempt to intelligently parse the name and deduce its style and LaTeX label.

How it works:

  • Recognizes common patterns such as Greek letters, charge modifiers (+, -, 0), bars (antiparticles), and indices (e.g., _e).
  • Automatically generates the correct LaTeX label, e.g.:
    • mu+\mu^{+}
    • ubar\bar{u}
    • alpha_e\alpha_{e}
    • phi-\phi^{-}
  • Deduces the particle style (fermion, boson, scalar, etc.) based on the base name.
  • If the name cannot be parsed, a warning is logged and a generic style/label is used.