Skip to content

Instantly share code, notes, and snippets.

@uwezi
Last active August 17, 2025 11:43
Show Gist options
  • Save uwezi/8b3fd07df9d4d96ca07dda617d4793a3 to your computer and use it in GitHub Desktop.
Save uwezi/8b3fd07df9d4d96ca07dda617d4793a3 to your computer and use it in GitHub Desktop.
[Feynman diagrams] Using LaTeX to create Feynman diagrams in Manim. #manim #feynman #physics
from manim import *
# https://discord.com/channels/581738731934056449/1178561529914871818/1180619063161016390
class feynman(Scene):
def construct(self):
MyTexTemplate = TexTemplate()
MyTexTemplate.add_to_preamble(r"\usepackage{tikz}\usepackage[compat=1.1.0]{tikz-feynman}")
feyn = Tex(r"""
\begin{tikzpicture}
\begin{feynman}
\vertex (a) {\(\mu^{-}\)};
\vertex [right=of a] (b);
\vertex [above right=of b] (f1) {\(\nu_{\mu}\)};
\vertex [below right=of b] (c);
\vertex [above right=of c] (f2) {\(\overline \nu_{e}\)};
\vertex [below right=of c] (f3) {\(e^{-}\)};
\diagram* {
(a) -- [fermion] (b) -- [fermion] (f1),
(b) -- [boson, edge label'=\(W^{-}\)] (c),
(c) -- [anti fermion] (f2),
(c) -- [fermion] (f3),
};
\end{feynman}
\end{tikzpicture}
""",
tex_template=MyTexTemplate,
).set_stroke(width=3)
# uncomment the following lines for the indices
#self.add(feyn)
#self.add(index_labels(feyn[0]).set_color(RED))
self.play(
Write(feyn[0][0:2]),
Write(feyn[0][4:7])
)
feyn[0][16].reverse_points()
self.play(
Create(feyn[0][9:11]),
Create(feyn[0][16:18])
)
self.play(
Create(feyn[0][13]),
Write(feyn[0][14:16])
)
self.play(
Create(feyn[0][11:13]),
Create(feyn[0][18:20]),
Write(feyn[0][2:4]),
Write(feyn[0][7:9])
)
self.wait()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment