| 1 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2 |
% |
| 3 |
% TikZ-Feynman |
| 4 |
% Feynman Diagrams with TikZ |
| 5 |
% Copyright (C) 2015 Joshua Ellis |
| 6 |
% |
| 7 |
% |
| 8 |
% This work may be distributed and/or modified under the conditions of the LaTeX |
| 9 |
% Project Public License, either version 1.3 of this license or (at your option) |
| 10 |
% any later version. |
| 11 |
% |
| 12 |
% This work has the LPPL maintenance status `maintained'. |
| 13 |
% |
| 14 |
% The Current Maintainer of this work is Joshua Ellis. |
| 15 |
% |
| 16 |
% This program is distributed in the hope that it will be useful, but WITHOUT |
| 17 |
% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 18 |
% FOR A PARTICULAR PURPOSE. See the LaTeX Project Public License for more |
| 19 |
% details. |
| 20 |
% |
| 21 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 22 |
|
| 23 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 24 |
%% Pre-requisites |
| 25 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 26 |
\usetikzlibrary{ |
| 27 |
arrows.meta, |
| 28 |
calc, |
| 29 |
decorations, |
| 30 |
decorations.markings, |
| 31 |
decorations.pathmorphing, |
| 32 |
decorations.pathreplacing, |
| 33 |
graphs, |
| 34 |
patterns, |
| 35 |
positioning, |
| 36 |
shapes.geometric, |
| 37 |
} |
| 38 |
\ifluatex |
| 39 |
\usetikzlibrary{ |
| 40 |
graphdrawing |
| 41 |
} |
| 42 |
\usegdlibrary{ |
| 43 |
circular, |
| 44 |
force, |
| 45 |
layered, |
| 46 |
trees |
| 47 |
} |
| 48 |
\fi |
| 49 |
|
| 50 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 51 |
%% Function definitions |
| 52 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 53 |
|
| 54 |
%% Miscellaneous functions |
| 55 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 56 |
\def\tikzfeynman@empty{} |
| 57 |
|
| 58 |
%% Key Manager |
| 59 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 60 |
%% Setup the tikz-feynman key family |
| 61 |
\pgfkeys{ |
| 62 |
/tikzfeynman/.is family, |
| 63 |
/tikzfeynman/.search also={/tikz}, |
| 64 |
} |
| 65 |
|
| 66 |
%% |\tikzfeynmanset| allows keys that belong with tikz-feynman to be easily set. |
| 67 |
\def\tikzfeynmanset{\pgfqkeys{/tikzfeynman}} |
| 68 |
|
| 69 |
%% Luatex Waring |
| 70 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 71 |
%% Check if we are using luatex |
| 72 |
\newif\iftikzfeynman@warn@luatex% |
| 73 |
\tikzfeynmanset{ |
| 74 |
warn luatex/.is if=tikzfeynman@warn@luatex, |
| 75 |
warn luatex=true, |
| 76 |
} |
| 77 |
|
| 78 |
\AtBeginDocument{ |
| 79 |
\ifluatex\else |
| 80 |
\iftikzfeynman@warn@luatex |
| 81 |
\PackageWarning{tikz-feynman}{LuaTeX is required if you wish to have vertices automatically placed. You can disable this warning by setting /tikzfeynman/warn luatex=false} |
| 82 |
\fi |
| 83 |
\fi |
| 84 |
} |
| 85 |
|
| 86 |
%% Version check |
| 87 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 88 |
%% Check which version is expected and which is installed |
| 89 |
\def\tikzfeynman@compat@parse#1.#2.#3\pgfeov{ |
| 90 |
\edef\tikzfeynman@compat@major{#1} |
| 91 |
\edef\tikzfeynman@compat@minor{#2} |
| 92 |
\edef\tikzfeynman@compat@patch{#3} |
| 93 |
\edef\tikzfeynman@compat{#1.#2.#3} |
| 94 |
} |
| 95 |
\let\tikzfeynman@compat=\tikzfeynman@empty |
| 96 |
\pgfkeyslet{/tikzfeynman/compat/.@cmd}{\tikzfeynman@compat@parse} |
| 97 |
\ProcessPgfPackageOptions{/tikzfeynman} |
| 98 |
|
| 99 |
\AtBeginDocument{ |
| 100 |
\ifx\tikzfeynman@version\tikzfeynman@compat\else |
| 101 |
\ifx\tikzfeynman@compat\tikzfeynman@empty |
| 102 |
\PackageWarning{tikz-feynman}{Consider loading TikZ-Feynman with \string\usepackage[compat=\tikzfeynman@version]{tikz-feynman} so that you can be warned if TikZ-Feynman changes.} |
| 103 |
\else |
| 104 |
\ifx\tikzfeynman@compat@major\tikzfeynman@version@major |
| 105 |
\ifx\tikzfeynman@compat@minor\tikzfeynman@version@minor |
| 106 |
\ifx\tikzfeynman@compat@patch\tikzfeynman@version@patch\else |
| 107 |
\PackageInfo{tikz-feynman}{The preamble requested version \tikzfeynman@compat, but the system version is \tikzfeynman@version. This should cause no issue.} |
| 108 |
\fi |
| 109 |
\else |
| 110 |
\PackageWarning{tikz-feynman}{The preamble requested version \tikzfeynman@compat, but the system version is \tikzfeynman@version. This may change some diagrams.} |
| 111 |
\fi |
| 112 |
\else |
| 113 |
\PackageError{tikz-feynman}{The preamble requested version \tikzfeynman@compat, but the system version is \tikzfeynman@version. They are most likely incompatible. Please download the appropriate version from jpellis.me/projects/tikz-feynman.} |
| 114 |
\fi |
| 115 |
\fi |
| 116 |
\fi |
| 117 |
} |
| 118 |
|
| 119 |
%% Override Lua code if necessary |
| 120 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 121 |
\def\tikzfeynman@apply@patch#1{ |
| 122 |
\directlua{require("tikzfeynman.patch.#1.lua")} |
| 123 |
} |
| 124 |
|
| 125 |
%% Version 3.0.0, 3.0.1 and 3.0.1a need to be patched. |
| 126 |
\ifluatex |
| 127 |
\def\tikzfeynman@temp{3.0.0} |
| 128 |
\ifx\pgfversion\tikzfeynman@temp |
| 129 |
\tikzfeynman@apply@patch{3.0.0} |
| 130 |
\else |
| 131 |
\def\tikzfeynman@temp{3.0.1} |
| 132 |
\ifx\pgfversion\tikzfeynman@temp |
| 133 |
\tikzfeynman@apply@patch{3.0.1} |
| 134 |
\else |
| 135 |
\def\tikzfeynman@temp{3.0.1a} |
| 136 |
\ifx\pgfversion\tikzfeynman@temp |
| 137 |
\tikzfeynman@apply@patch{3.0.1} |
| 138 |
\fi |
| 139 |
\fi |
| 140 |
\fi |
| 141 |
\fi |
| 142 |
|
| 143 |
%% Feynman Environment |
| 144 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 145 |
|
| 146 |
%% Provide `\begin{feynman} ... \end{feynman}` within TikZ pictures. |
| 147 |
\tikzaddtikzonlycommandshortcutlet\feynman\tikzfeynman@environment@feynman |
| 148 |
\tikzaddtikzonlycommandshortcutlet\endfeynman\endtikzfeynman@environment@feynman |
| 149 |
|
| 150 |
%% \begin{feynman}...\end{feynman} |
| 151 |
\def\tikzfeynman@environment@feynman{% |
| 152 |
\pgfutil@ifnextchar[{\tikzfeynman@environment@feynman@opt} |
| 153 |
{\tikzfeynman@environment@feynman@opt[]}} |
| 154 |
|
| 155 |
\def\tikzfeynman@environment@feynman@opt[#1]{% |
| 156 |
\begingroup |
| 157 |
%% Local overrides |
| 158 |
\let\tikz@@scan@fig=\tikzfeynman@scan@fig |
| 159 |
\let\tikzfeynman@orig@graph=\graph |
| 160 |
%% Local commands |
| 161 |
\let\vertex=\tikzfeynman@commands@vertex |
| 162 |
\let\diagram=\tikzfeynman@commands@diagram |
| 163 |
\let\graph=\tikzfeynman@commands@graph |
| 164 |
%% Opening hooks |
| 165 |
\scope |
| 166 |
\tikz@lib@ignore@sizetrue |
| 167 |
\tikzfeynman@tikz@search@tikzfeynman |
| 168 |
\pgfkeys{/tikzfeynman/every feynman@@,#1} |
| 169 |
\pgfkeysvalueof{/tikzfeynman/execute at begin feynman@@}% |
| 170 |
\pgfkeysvalueof{/tikzfeynman/execute at begin feynman}% |
| 171 |
} |
| 172 |
|
| 173 |
\def\endtikzfeynman@environment@feynman{% |
| 174 |
%% Closing hooks |
| 175 |
\pgfkeysvalueof{/tikzfeynman/execute at end feynman}% |
| 176 |
\pgfkeysvalueof{/tikzfeynman/execute at end feynman@@}% |
| 177 |
\endscope |
| 178 |
\endgroup |
| 179 |
} |
| 180 |
|
| 181 |
%% \feynmandiagram |
| 182 |
\def\feynmandiagram{% |
| 183 |
\pgfutil@ifnextchar[{\feynmandiagram@opt} |
| 184 |
{\feynmandiagram@opt[]}} |
| 185 |
\def\feynmandiagram@opt[#1]{% |
| 186 |
\pgfutil@ifnextchar[{\feynmandiagram@opt@opt[#1]} |
| 187 |
{\feynmandiagram@opt@opt[#1][#1]}} |
| 188 |
\def\feynmandiagram@opt@opt[#1][#2]{% |
| 189 |
\tikz [/tikzfeynman/.cd,#1] |
| 190 |
\graph [/tikzfeynman/.cd,/tikzfeynman/every diagram@@,/tikz/graphs/spring layout,#2]} |
| 191 |
|
| 192 |
%% Allow empty nodes |
| 193 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 194 |
\newif\iftikzfeynmanallowemptynode |
| 195 |
\newif\iftikzfeynmanvertex |
| 196 |
\def\tikzfeynman@scan@fig{% |
| 197 |
\pgfutil@ifnextchar a{\tikz@fig@scan@at} |
| 198 |
{\pgfutil@ifnextchar({\tikz@fig@scan@name} |
| 199 |
{\pgfutil@ifnextchar[{\tikz@fig@scan@options}% |
| 200 |
{\pgfutil@ifnextchar\bgroup{\tikz@fig@main}% |
| 201 |
{\iftikzfeynmanvertex% |
| 202 |
\tikzset{/tikzfeynman/every vertex@@}% |
| 203 |
\iftikzfeynmanallowemptynode% |
| 204 |
\else% |
| 205 |
\tikzset{/tikzfeynman/particle}% |
| 206 |
\fi% |
| 207 |
\fi% |
| 208 |
\tikz@fig@main{}}}}}}%}} |
| 209 |
|
| 210 |
%% Include /tikzfeynman in the search path |
| 211 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 212 |
\def\tikzfeynman@tikz@search@tikzfeynman{% |
| 213 |
\pgfkeys{/tikz/.unknown/.code=% |
| 214 |
\let\tikz@key\pgfkeyscurrentname% |
| 215 |
%% Is it a tikzfeynman key? |
| 216 |
\pgfkeys{/tikzfeynman/\tikz@key/.try={##1}}% |
| 217 |
\ifpgfkeyssuccess% |
| 218 |
\else% |
| 219 |
%% Is it a pgf key? |
| 220 |
\pgfkeys{/pgf/\tikz@key/.try={##1}}% |
| 221 |
\ifpgfkeyssuccess% |
| 222 |
\else% |
| 223 |
\expandafter\pgfutil@in@\expandafter!\expandafter{\tikz@key}% |
| 224 |
\ifpgfutil@in@% |
| 225 |
%% this is a color! |
| 226 |
\expandafter\tikz@addoption\expandafter{\expandafter\tikz@compat@color@set\expandafter{\tikz@key}}% |
| 227 |
\edef\tikz@textcolor{\tikz@key}% |
| 228 |
\else% |
| 229 |
\pgfutil@doifcolorelse{\tikz@key} |
| 230 |
{% |
| 231 |
\expandafter\tikz@addoption\expandafter{\expandafter\tikz@compat@color@set\expandafter{\tikz@key}}% |
| 232 |
\edef\tikz@textcolor{\tikz@key}% |
| 233 |
}% |
| 234 |
{% |
| 235 |
%% Ok, second chance: This might be an arrow specification: |
| 236 |
\expandafter\pgfutil@in@\expandafter-\expandafter{\tikz@key}% |
| 237 |
\ifpgfutil@in@% |
| 238 |
%% Ah, an arrow spec! |
| 239 |
\expandafter\tikz@processarrows\expandafter{\tikz@key}% |
| 240 |
\else% |
| 241 |
%% Ok, third chance: A shape! |
| 242 |
\expandafter\ifx\csname pgf@sh@s@\tikz@key\endcsname\relax% |
| 243 |
\pgfkeys{/errors/unknown key/.expand |
| 244 |
once=\expandafter{\expandafter/\expandafter t\expandafter |
| 245 |
i\expandafter k\expandafter z\expandafter/\tikz@key}{##1}}% |
| 246 |
\else% |
| 247 |
\edef\tikz@shape{\tikz@key}% |
| 248 |
\fi% |
| 249 |
\fi% |
| 250 |
}% |
| 251 |
\fi% |
| 252 |
\fi% |
| 253 |
\fi% |
| 254 |
} |
| 255 |
} |
| 256 |
|
| 257 |
|
| 258 |
%% Vertex |
| 259 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 260 |
%% Adapted from |\coordinate| code |
| 261 |
\def\tikzfeynman@commands@vertex{ |
| 262 |
\path \pgfextra{\tikzfeynmanallowemptynodetrue} |
| 263 |
\pgfextra{\tikzfeynmanvertextrue} |
| 264 |
node} |
| 265 |
|
| 266 |
%% Diagram |
| 267 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 268 |
\def\tikzfeynman@commands@diagram{\@ifstar |
| 269 |
\tikzfeynman@commands@diagram@star% |
| 270 |
\tikzfeynman@commands@diagram@nostar} |
| 271 |
|
| 272 |
\def\tikzfeynman@commands@diagram@nostar{% |
| 273 |
\pgfutil@ifnextchar[{\tikzfeynman@commands@diagram@nostar@opt} |
| 274 |
{\tikzfeynman@commands@diagram@nostar@opt[]}} |
| 275 |
\def\tikzfeynman@commands@diagram@nostar@opt[#1]{% |
| 276 |
\tikzfeynman@orig@graph [/tikzfeynman/every diagram@@,/tikz/graphs/spring layout,#1]} |
| 277 |
|
| 278 |
\def\tikzfeynman@commands@diagram@star{% |
| 279 |
\pgfutil@ifnextchar[{\tikzfeynman@commands@diagram@star@opt} |
| 280 |
{\tikzfeynman@commands@diagram@star@opt[]}} |
| 281 |
\def\tikzfeynman@commands@diagram@star@opt[#1]{% |
| 282 |
\tikzfeynman@orig@graph [/tikzfeynman/every diagram@@,#1]} |
| 283 |
|
| 284 |
%% Graph |
| 285 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 286 |
\def\tikzfeynman@commands@graph{% |
| 287 |
\pgfutil@ifnextchar[{\tikzfeynman@commands@graph@opt} |
| 288 |
{\tikzfeynman@commands@graph@opt[]}} |
| 289 |
\def\tikzfeynman@commands@graph@opt[#1]{% |
| 290 |
\PackageWarning{tikz-feynman}{It is not recommended to use \string\graph. Use \string\diagram\space or \string\diagram* instead.} |
| 291 |
\tikzfeynman@orig@graph [/tikzfeynman/every diagram@@,#1]} |
| 292 |
|
| 293 |
%% Optional argument in style key |
| 294 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 295 |
\def\tikzfeynman@key@opt#1[#2]#3\pgfeov{% |
| 296 |
\tikzfeynmanset{#1={[#2]#3}}} |
| 297 |
|
| 298 |
%% Insertion |
| 299 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 300 |
\def\tikzfeynman@insertion{% |
| 301 |
\pgfutil@ifnextchar[{\tikzfeynman@key@opt{insertion@@}} |
| 302 |
{\tikzfeynman@key@opt{insertion@@}[]}} |
| 303 |
\pgfkeyslet{/tikzfeynman/insertion/.@cmd}{\tikzfeynman@insertion} |
| 304 |
|
| 305 |
%% Momentum |
| 306 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 307 |
\def\tikzfeynman@momentum@std{% |
| 308 |
\pgfutil@ifnextchar[{\tikzfeynman@key@opt{momentum@@}} |
| 309 |
{\tikzfeynman@key@opt{momentum@@}[]}} |
| 310 |
\pgfkeyslet{/tikzfeynman/momentum/.@cmd}{\tikzfeynman@momentum@std} |
| 311 |
|
| 312 |
\def\tikzfeynman@momentum@stdp{% |
| 313 |
\pgfutil@ifnextchar[{\tikzfeynman@key@opt{momentum'@@}} |
| 314 |
{\tikzfeynman@key@opt{momentum'@@}[]}} |
| 315 |
\pgfkeyslet{/tikzfeynman/momentum'/.@cmd}{\tikzfeynman@momentum@stdp} |
| 316 |
|
| 317 |
\def\tikzfeynman@momentum@stdr{% |
| 318 |
\pgfutil@ifnextchar[{\tikzfeynman@key@opt{reversed momentum@@}} |
| 319 |
{\tikzfeynman@key@opt{reversed momentum@@}[]}} |
| 320 |
\pgfkeyslet{/tikzfeynman/reversed momentum/.@cmd}{\tikzfeynman@momentum@stdr} |
| 321 |
\pgfkeyslet{/tikzfeynman/rmomentum/.@cmd}{\tikzfeynman@momentum@stdr} |
| 322 |
|
| 323 |
\def\tikzfeynman@momentum@stdrp{% |
| 324 |
\pgfutil@ifnextchar[{\tikzfeynman@key@opt{reversed momentum'@@}} |
| 325 |
{\tikzfeynman@key@opt{reversed momentum'@@}[]}} |
| 326 |
\pgfkeyslet{/tikzfeynman/reversed momentum'/.@cmd}{\tikzfeynman@momentum@stdrp} |
| 327 |
\pgfkeyslet{/tikzfeynman/rmomentum'/.@cmd}{\tikzfeynman@momentum@stdrp} |
| 328 |
|
| 329 |
|
| 330 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 331 |
%% Styles |
| 332 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 333 |
|
| 334 |
\input tikzfeynman.keys.code.tex |
| 335 |
|
| 336 |
\endinput |