Skip to content

feynjs

A JavaScript display engine for Feynman diagrams

Learn more Getting started

Write it, see it

Every diagram below is drawn live by your browser, from the source beside it. Written in syntax inspired by MadGraph and TikZ-Feynman.

Multiple syntax support

Write every line, as in TikZ-Feynman, without a tikzpicture, coordinates or a compile; or name the process, as in MadGraph. Both draw the same diagram, and feynjs places every vertex itself.

TikZ-Feynman edges

```feynman
i1 [e-] -- a -- i2 [e+]
a -- [photon] b
f1 [mu-] -- b -- f2 [mu+]
```

MadGraph process

```feynman
e- e+ > gamma > mu- mu+
```
i1 [e-] -- a -- i2 [e+] a -- [photon] b f1 [mu-] -- b -- f2 [mu+]

Drawn in time order

feynjs knows when each particle lives: the collision, then each decay, left to right, as papers draw them. Every part of the drawing knows its step, so a page can build it up one at a time.

```feynman
p p > H
H > Z Z
Z > l+ l-
```
p p > H H > Z Z Z > l+ l-

Particles draw themselves

A particle's name brings its line, arrow, label and colour: superpartners in red, a W wavy, a Higgs dashed. Over a hundred names are built in.

```feynman
arrows: none
p p > chargino neutralino2
chargino > W neutralino1
neutralino2 > Z neutralino1
W > l nu
Z > l l
```
arrows: none p p > chargino neutralino2 chargino > W neutralino1 neutralino2 > Z neutralino1 W > l nu Z > l l

Loops in braces

Put a particle in braces to run it round a loop: the top-quark triangle of Higgs production by gluon fusion is one line.

```feynman
g g > {t} > H
```
g g > {t} > H

Two layout engines

The force engine balances the diagram until it settles; the grid engine puts every line on a grid. One line switches between them, and the same diagram moves from one to the other.

```feynman
layout: grid
p p > t t~
t > b W+(> e+ ve)
t~ > b~ W-(> d u~)
```
p p > t t~ t > b W+(> e+ ve) t~ > b~ W-(> d u~)

More than lines

The final states a detector sees, drawn as it sees them: large-R jets with what they hold, semi-visible and emerging jets, missing energy.

```feynman
i1 [p] -- pp [blob] -- i2 [p]
pp -- [largejet 1b W(2j)] j1
pp -- [Z'] z
z -- [semivisiblejet] f1
z -- [emergingjet] f2
```
i1 [p] -- pp [blob] -- i2 [p] pp -- [largejet 1b W(2j)] j1 pp -- [Z'] z z -- [semivisiblejet] f1 z -- [emergingjet] f2

Draw the eye

Add pulse to a point, or a line, and a glow beats round it and along every line that meets there: here, the Higgs self-coupling in Higgs pair production.

```feynman
i1 [g] -- a
i2 [g] -- b
a -- [fermion] c -- [fermion] b -- [fermion, label=t] a
c -- [H] v [pulse, label=\lambda_{HHH}]
v -- f1 [H]
v -- f2 [H]
```
i1 [g] -- a i2 [g] -- b a -- [fermion] c -- [fermion] b -- [fermion, label=t] a c -- [H] v [pulse, label=\lambda_{HHH}] v -- f1 [H] v -- f2 [H]

Skills for AI assistants

Ask an assistant for a diagram in plain words, and it writes feynjs: two skills in the repository teach it the syntax, how physicists lay diagrams out, and the physics to check. What comes back is a few lines you can read, edit and keep.

You ask
A stop pair, each stop decaying to a top and a neutralino
It writes
```feynman
p p > t1 t1~, (t1 > t n1), (t1~ > t~ n1)
```

The skills

p p > t1 t1~, (t1 > t n1), (t1~ > t~ n1)

Wherever you write

The same text is a diagram in a Markdown site, in an Obsidian note, on any web page with one script tag, and in a LaTeX paper, where it becomes TikZ-Feynman code.

Getting started Try the playground

```feynman
g g > {t} > H
```
\begin{feynjs}
g g > {t} > H
\end{feynjs}