Skip to content

Writing diagrams

A diagram is written as edges, line by line. Several diagrams can share one block as panels, and switches set options for a whole diagram.

In a page or a note, a diagram is a ```feynman code block; ```feynjs works the same.

Edges, as in TikZ-Feynman

i1 [e-] -- a -- i2 [e+] a -- [gamma] b f1 [mu-] -- b -- f2 [mu+]
i1 [e-] -- a -- i2 [e+]
a -- [gamma] b
f1 [mu-] -- b -- f2 [mu+]

The edge syntax writes a diagram line by line: name the points, join them, say what each line is. It follows TikZ-Feynman's \diagram* notation, so a -- [photon] b means what it means there.

Chains

A chain joins vertices with --. A vertex is any name you choose: a, v1, top. A chain can be as long as you like, and a vertex can appear in as many chains as you like:

i1 -- a -- b -- f1        one chain, three lines
a -- c                    a fourth line from a

Statements end at a new line; a semicolon or a comma also ends one, as in TikZ-Feynman. %, # and // start a comment.

Vertices

Options for a vertex go in square brackets right after its name.

Write Meaning
i1 [e-] an external leg, labelled as an electron; its line takes the electron's style
f1 [\tilde\chi^0_1] an external leg with any TeX label
v [dot] a vertex drawn as a dot; see Vertices and blobs for the other shapes
v [dot, label=\kappa_\lambda] a coupling label beside the vertex
v at (2, 1) fix a vertex in place by hand (in propagator lengths, y up); see Placing points by hand

Lines

Options for a line go in square brackets right after its --.

Write Meaning
a -- b a plain line, or the style of the labelled external leg at its end
a -- [fermion] b a generic style, named as in TikZ-Feynman; see Lines and particles
a -- [W+] b a particle: sets the style, the arrow and the label
a -- [photon, label=\gamma^*] b your own label; label'= puts it on the right of the line's direction, as in TikZ
a -- [fermion, momentum=p] b a momentum arrow beside the line
a -- [gluon, half left] b a curved line: half left/right, quarter left/right, bend left/right, bend=30
a -- [scalar, color=blue] b a colour, by name or any CSS colour
a -- [hidden] b joins two vertices for the layout without drawing anything

A misspelt name stops with a suggestion: line 1: unknown line style or particle "glunio" (did you mean "gluino"?).

Arrows follow the order you write: a -- [fermion] b points from a to b. For an external particle you rarely need to think about it: i2 [e+] already knows a positron's arrow runs against its direction of travel.

What comes in, what goes out

feynjs decides which legs enter (on the left) and which leave (on the right):

  • Names starting with i (i1, i2, ...) enter; names starting with f leave.
  • For other names, a leg written at the start of a chain enters and one at the end leaves.
  • in: a b and out: c d say it outright, and fix the order of the legs from top to bottom.
in: i1 i2 out: f2 f1 i1 [qbar'] -- a -- f1 [Z] i2 [q] -- b -- f2 [W] b -- [fermion, label=q'] a
in: i1 i2
out: f2 f1
i1 [qbar'] -- a -- f1 [Z]
i2 [q] -- b -- f2 [W]
b -- [fermion, label=q'] a

The order in out: is kept even when lines cross. That is how a u-channel diagram swaps its final states, as above.

Two lines between the same points

Two lines between the same pair of vertices bow apart into a loop by themselves:

i1 -- [photon, momentum=q] a a -- [fermion] b b -- [fermion] a b -- [photon] f1
i1 -- [photon, momentum=q] a
a -- [fermion] b
b -- [fermion] a
b -- [photon] f1

Panels and switches

--- (a) a photon i1 [e-] -- a -- i2 [e+] a -- [gamma] b f1 [mu-] -- b -- f2 [mu+] --- (b) a Z i1 [e-] -- a -- i2 [e+] a -- [Z] b f1 [mu-] -- b -- f2 [mu+]
--- (a) a photon
i1 [e-] -- a -- i2 [e+]
a -- [gamma] b
f1 [mu-] -- b -- f2 [mu+]
--- (b) a Z
i1 [e-] -- a -- i2 [e+]
a -- [Z] b
f1 [mu-] -- b -- f2 [mu+]

Several diagrams side by side

A line of three or more dashes starts a new panel. Text after the dashes is that panel's caption. Without it, panels are lettered (a), (b), ©. Panels sit three to a row; the panelsPerRow option of render changes that.

Each panel is a diagram of its own: vertex names can repeat, and panels can use either syntax.

Joining panels

A joiner in brackets after the dashes stands between that panel and the one before. Joined panels make one figure, so they sit in one row and are not lettered.

Write Between the panels
---[x] × (two scatterings at once, double parton scattering)
---[otimes] ⊗
---[+], ---[=], ---[to] +, =, → (a sum of diagrams, an identity)
---[cut] a dashed cut line: an amplitude beside its conjugate
---[step: words], on a line of its own a step: a tall box of words, an arrow in from the panel before and out to the next
---[step: words \| one, two] the step with labelled arrows into it, one for each, the words flat above each arrow
---[into: words] after a step: a bar over this panel and those after it in the row, the words on it, an arrow down to each

A step and a fan-out make one figure, its flow said in words for a screen reader ("A jet, then flavour tagging, classify into b-jet, c-jet and light jet."):

--- jet a [circle=j] -- [jet, color=#8a919c, no label, impact] f ---[step: Jet flavour-tagging algorithms] ---[into: Classify into] b-jet a [circle=b] -- [bjet, no label] f --- c-jet a [circle=c] -- [cjet, no label] f --- light jet a [circle=l] -- [lightjet, no label] f
i1 [g] -- a i2 [g] -- a a -- [H] f1 ---[cut] f1 [H] -- a a -- i1 [g] a -- i2 [g]
i1 [g] -- a
i2 [g] -- a
a -- [H] f1
---[cut]
f1 [H] -- a
a -- i1 [g]
a -- i2 [g]

Switches

A line name: value sets something for the whole diagram (or panel).

Write Effect
in: i1 i2 / out: f2 f1 which legs enter and leave, in order top to bottom (Edges)
arrows: none no fermion arrows, as many SUSY papers draw them
dots: all a dot on every vertex where lines meet
scale: 1.5 the whole diagram 1.5 times larger, as a zoom
size: small an optical size: small, tiny, large or any number (1 is normal); see Styling
title: ... a title, shown as a tooltip and read by screen readers
colour flow: on draw the colour lines beside quarks and gluons (Colour flow)
charge colour: on colour charged lines by the sign of their charge (Styling)
reveal: 2 draw the first two steps in time as usual and the rest faint and grey (Step by step)
meson:, baryon:, hadron: group legs into a hadron (Hadrons)

Every diagram already carries a summary and a description for screen readers, written from its process (see explain): aria-label="Feynman diagram of an electron and a positron annihilating into a muon pair, through a photon". title: adds a title of your own as well.

Step by step

reveal: n draws the first n steps in time as usual and everything after them faint and grey, so a reader sees where the diagram is going. Put the same diagram in a row of panels with reveal: 1, reveal: 2, ... to build it up one step at a time, in a talk or a lesson:

--- step 1 reveal: 1 p p > gluino gluino gluino > q q neutralino2 neutralino2 > Z neutralino1 --- step 2 reveal: 2 p p > gluino gluino gluino > q q neutralino2 neutralino2 > Z neutralino1 --- step 3 reveal: 3 p p > gluino gluino gluino > q q neutralino2 neutralino2 > Z neutralino1
--- step 1
reveal: 1
p p > gluino gluino
gluino > q q neutralino2
neutralino2 > Z neutralino1
--- step 2
reveal: 2
...

A step is how far a part is from the incoming particles. The parts still to come carry the class feynjs-ahead, so a page can restyle them, or fade them in. render(source, { reveal: 2 }) does the same from JavaScript, and levels: true tags every part with its step without fading anything.

Next