This page will teach you how to color lines and other shapes, as well as text in the Feynman diagrams produced with the feynmp
package in LaTeX. Have a look at the “color” tag to see examples of diagrams with color.
Line & shape colors
To color specific line, simply add the following style option
foreground=(❬red❭,,❬green❭,,❬blue❭)
to
\fmf
for lines or \fmfv
for other shapes. You need two commas instead of one so the parser does not get confused between style options. You can abbreviate tof=(❬red❭,,❬green❭,,❬blue❭)
.You specify the color with its normalized RGB code. You can use many online tools like this RGB color picker to find the RGB code for the color you want. Some examples of normalized RGB codes:
foreground=(0,,0,,0)
is purely black, corresponding to (0,0,0).foreground=(1,,1,,1)
is purely white, corresponding to (255,255,255).foreground=(1,,0,,0)
is purely red, corresponding to (255,0,0).foreground=(0,,1,,0)
is purely green, corresponding to (0,255,0).foreground=(0,,0,,1)
is purely blue, corresponding to (0,0,255).foreground=(0,,0,,0.6)
is dark blue, corresponding to (0,0,153).foreground=(1,,0.5,,0)
is orange, corresponding to (255,128,0).
For example:
\documentclass[11pt,border=2pt]{standalone} \usepackage{feynmp-auto} \begin{document} \begin{fmffile}{feyngraph} \begin{fmfgraph*}(90,60) % dimensions (WH) \fmfleft{i2,i1} \fmfright{o2,o1} \fmf{fermion}{i2,v1,i1} % black \fmf{boson,foreground=(1,,0,,0)}{v1,v2} % red \fmf{fermion,f=(0,,0,,1)}{o2,v2,o1} % blue \fmfv{decor.shape=circle,decor.filled=full, decor.size=4,f=(0,,0,,0.6)}{v2} % dark blue \end{fmfgraph*} \end{fmffile} \end{document}
The default line and shape color is black. To color all lines, you can set a global color line via the
\fmfcmd{foreground := (❬red❭,❬green❭,❬blue❭);}
command to set the default
foreground
via MetaPost. This time you do not need two commas.
\documentclass[11pt,border=2pt]{standalone} \usepackage{feynmp-auto} \begin{document} \begin{fmffile}{feyngraph} \begin{fmfgraph*}(70,60) % dimensions (WH) \fmfcmd{foreground:=(0,0,1);} % set blue as default line/shape color \fmfleft{i2,i1} \fmfright{o2,o1} \fmf{fermion}{i2,v1,i1} \fmf{boson}{v1,v2} \fmf{fermion}{o2,v2,o1} \fmfv{decor.shape=circle,decor.filled=full,decor.size=4}{v1} \fmfv{decor.shape=circle,decor.filled=full, decor.size=4,f=(1,,0,,0)}{v2} % override default \end{fmfgraph*} \end{fmffile} \end{document}
You can predefine your own named colors in MetaPost using
\fmfcmd{color ❬colorname❭; ❬colorname❭ := f(❬red❭,❬green❭,❬blue❭);}
.Then you can pass it to the
foreground
style option instead of a normalized RGB code:
\documentclass[11pt,border=2pt]{standalone} \usepackage{feynmp-auto} \begin{document} \begin{fmffile}{feyngraph} \begin{fmfgraph*}(70,60) % dimensions (WH) \fmfcmd{ % define custom named colors color myred; myred := (1,0,0); color myblue; myblue := (0,0,1); color mydarkblue; mydarkblue := (0,0,0.6); } \fmfleft{i2,i1} \fmfright{o2,o1} \fmf{fermion}{i2,v1,i1} % black \fmf{boson,foreground=myred}{v1,v2} % red \fmf{fermion,f=myblue}{o2,v2,o1} % blue \fmfv{decor.shape=circle,decor.filled=full, decor.size=4,f=mydarkblue}{v2} % dark blue \end{fmfgraph*} \end{fmffile} \end{document}
Text colors
To set text color, you can use the xcolor
LaTeX package. There are several ways to define the color, and you can find several excellent tutorials on this Wikibooks page, or this Overleaf page. To use it in Feynman diagrams, simply add it before the text you want to write via the label
style option:
\documentclass[11pt,border=2pt]{standalone} \usepackage{feynmp-auto} \usepackage{xcolor} % for \definecolor & \color \definecolor{myred}{rgb}{1,0,0} % red \definecolor{myblue}{rgb}{0,0,1} % blue \definecolor{mydarkblue}{rgb}{0,0,0.6} % dark blue \begin{document} \fmfframe(0,15)(0,15){ % padding (LT)(RB) \begin{fmffile}{feyngraph} \begin{fmfgraph*}(90,60) % dimensions (WH) \fmfleft{i2,i1} \fmfright{o2,o1} \fmf{fermion}{i2,v1,i1} \fmf{boson,foreground=(1,,0,,0),label=\color{myred}$\gamma$}{v1,v2} \fmf{fermion,foreground=(0,,0,,1)}{o2,v2,o1} \fmflabel{\color{myblue}$q$}{o1} \fmflabel{\color{myblue}$\overline{q}$}{o2} \fmfv{decor.shape=circle,decor.filled=full,decor.size=4, f=mydarkblue,label=\color{mydarkblue}$\alpha$}{v2} % dark blue \end{fmfgraph*} \end{fmffile} } % close \end{document}
You can change all text color with by calling \color
just before \begin{fmfgraph}
:
\documentclass[11pt,border=2pt]{standalone} \usepackage{feynmp-auto} \usepackage{xcolor} % for \definecolor & \color \definecolor{myred}{rgb}{1,0,0} % red \definecolor{myblue}{rgb}{0,0,1} % blue \begin{document} \fmfframe(0,15)(0,15){ % padding (LT)(RB) \begin{fmffile}{feyngraph} \color{myblue} % set blue as default text color \fmfcmd{foreground:=(0,0,1);} % set blue as default line/shape color \begin{fmfgraph*}(90,60) % dimensions (WH) \fmfleft{i2,i1} \fmfright{o2,o1} \fmf{fermion}{i2,v1,i1} \fmf{boson,label=$\gamma$}{v1,v2} \fmf{fermion}{o2,v2,o1} \fmflabel{$q$}{o1} \fmflabel{$\overline{q}$}{o2} \end{fmfgraph*} \end{fmffile} } % close \end{document}