summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/tikz-feynman/tikzlibraryfeynman.code.tex
blob: 380f71250969932ffcb5fd784c4a8908f1569d36 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% TikZ-Feynman
% Feynman Diagrams with TikZ
% Copyright (C) 2015  Joshua Ellis
%
%
% This work may be distributed and/or modified under the conditions of the LaTeX
% Project Public License, either version 1.3 of this license or (at your option)
% any later version.
%
% This work has the LPPL maintenance status `maintained'.
%
% The Current Maintainer of this work is Joshua Ellis.
%
% This program is distributed in the hope that it will be useful, but WITHOUT
% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
% FOR A PARTICULAR PURPOSE.  See the LaTeX Project Public License for more
% details.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Pre-requisites
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usetikzlibrary{
  arrows.meta,
  calc,
  decorations,
  decorations.markings,
  decorations.pathmorphing,
  decorations.pathreplacing,
  graphs,
  patterns,
  positioning,
  shapes.geometric,
}
\ifluatex
  \usetikzlibrary{
    graphdrawing
  }
  \usegdlibrary{
    circular,
    force,
    layered,
    trees
  }
\fi

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Function definitions
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% Miscellaneous functions
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\tikzfeynman@empty{}

%% Key Manager
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Setup the tikz-feynman key family
\pgfkeys{/tikzfeynman/.is family}

%% |\tikzfeynmanset| allows keys that belong with tikz-feynman to be easily set.
\def\tikzfeynmanset{\pgfqkeys{/tikzfeynman}}

%% Luatex Waring
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Check if we are using luatex
\newif\iftikzfeynman@warn@luatex%
\tikzfeynmanset{
  warn luatex/.is if=tikzfeynman@warn@luatex,
  warn luatex=true,
}

\AtBeginDocument{
  \ifluatex\else
    \iftikzfeynman@warn@luatex
      \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}
    \fi
  \fi
}

%% Version check
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Check which version is expected and which is installed
\def\tikzfeynman@compat@parse#1.#2.#3\pgfeov{
  \edef\tikzfeynman@compat@major{#1}
  \edef\tikzfeynman@compat@minor{#2}
  \edef\tikzfeynman@compat@patch{#3}
  \edef\tikzfeynman@compat{#1.#2.#3}
}
\let\tikzfeynman@compat=\tikzfeynman@empty
\pgfkeyslet{/tikzfeynman/compat/.@cmd}{\tikzfeynman@compat@parse}

\AtBeginDocument{
  \ifx\tikzfeynman@version\tikzfeynman@compat\else
    \ifx\tikzfeynman@compat\tikzfeynman@empty
      \PackageWarning{tikz-feynman}{Consider adding \string\tikzfeynmanset{compat=\tikzfeynman@version} to your preamble so that you can be warned if TikZ-Feynman changes.}
    \else
      \ifx\tikzfeynman@compat@major\tikzfeynman@version@major
        \ifx\tikzfeynman@compat@minor\tikzfeynman@version@minor
          \ifx\tikzfeynman@compat@patch\tikzfeynman@version@patch\else
            \PackageInfo{tikz-feynman}{The preamble requested version \tikzfeynman@compat, but the system version is \tikzfeynman@version.  This should cause no issue.}
          \fi
        \else
          \PackageWarning{tikz-feynman}{The preamble requested version \tikzfeynman@compat, but the system version is \tikzfeynman@version.  This may change some diagrams.}
        \fi
      \else
        \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 at github.com/JP-Ellis/tikz-feynman.}
      \fi
    \fi
  \fi
}

%% Override Lua code if necessary
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\tikzfeynman@apply@patch{
  \directlua{require("tikzfeynman.patch.lua")}
}

%% Version 3.0.0, 3.0.1 and 3.0.1a need to be patched.
\ifluatex
  \def\tikzfeynman@temp{3.0.0}
  \ifx\pgfversion\tikzfeynman@temp
    \tikzfeynman@apply@patch
  \else
    \def\tikzfeynman@temp{3.0.1}
    \ifx\pgfversion\tikzfeynman@temp
      \tikzfeynman@apply@patch
    \else
      \def\tikzfeynman@temp{3.0.1a}
      \ifx\pgfversion\tikzfeynman@temp
        \tikzfeynman@apply@patch
      \fi
    \fi
  \fi
\fi

%% Feynman Environment
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% Provide `\begin{feynman} ... \end{feynman}` within TikZ pictures.
\tikzaddtikzonlycommandshortcutlet\feynman\tikzfeynman@environment@feynman
\tikzaddtikzonlycommandshortcutlet\endfeynman\endtikzfeynman@environment@feynman

%% \begin{feynman}...\end{feynman}
\def\tikzfeynman@environment@feynman{%
  \pgfutil@ifnextchar[{\tikzfeynman@environment@feynman@opt}
  {\tikzfeynman@environment@feynman@opt[]}}

\def\tikzfeynman@environment@feynman@opt[#1]{%
  \begingroup
  %% Local overrides
  \let\tikz@@scan@fig=\tikzfeynman@scan@fig
  \let\tikzfeynman@orig@graph=\graph
  %% Local commands
  \let\vertex=\tikzfeynman@commands@vertex
  \let\diagram=\tikzfeynman@commands@diagram
  \let\graph=\tikzfeynman@commands@graph
  %% Opening hooks
  \scope
  \tikz@lib@ignore@sizetrue
  \tikzfeynman@tikz@search@tikzfeynman
  \pgfkeys{
    /tikzfeynman/every feynman@@,
    /tikzfeynman/every feynman,
    #1}
  \pgfkeysvalueof{/tikzfeynman/execute at begin feynman@@}%
  \pgfkeysvalueof{/tikzfeynman/execute at begin feynman}%
}

\def\endtikzfeynman@environment@feynman{%
  %% Closing hooks
  \pgfkeysvalueof{/tikzfeynman/execute at end feynman}%
  \pgfkeysvalueof{/tikzfeynman/execute at end feynman@@}%
  \endscope
  \endgroup
}

%% \feynmandiagram
\def\feynmandiagram{%
  \pgfutil@ifnextchar[{\feynmandiagram@opt}
  {\feynmandiagram@opt[]}}
\def\feynmandiagram@opt[#1]{%
  \pgfutil@ifnextchar[{\feynmandiagram@opt@opt[#1]}
  {\feynmandiagram@opt@opt[#1][#1]}}
\def\feynmandiagram@opt@opt[#1][#2]{%
  \tikz [/tikzfeynman/.cd, .search also={/tikz}, #1]
  \graph [/tikzfeynman/every diagram@@, /tikzfeynman/every diagram, /tikz/graphs/spring layout, #2]}

%% Allow empty nodes
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newif\iftikzfeynmanallowemptynode
\newif\iftikzfeynmanvertex
\def\tikzfeynman@scan@fig{%
  \pgfutil@ifnextchar a{\tikz@fig@scan@at}
  {\pgfutil@ifnextchar({\tikz@fig@scan@name}
    {\pgfutil@ifnextchar[{\tikz@fig@scan@options}%
      {\pgfutil@ifnextchar\bgroup{\tikz@fig@main}%
      {\iftikzfeynmanvertex%
         \tikzset{
           /tikzfeynman/every vertex@@,
           /tikzfeynman/every vertex}%
         \iftikzfeynmanallowemptynode%
         \else%
           \tikzset{/tikzfeynman/particle}%
         \fi%
       \fi%
       \tikz@fig@main{}}}}}}%}}

%% Include /tikzfeynman in the search path
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\tikzfeynman@tikz@search@tikzfeynman{%
  \pgfkeys{/tikz/.unknown/.code=%
    \let\tikz@key\pgfkeyscurrentname%
    %% Is it a tikzfeynman key?
    \pgfkeys{/tikzfeynman/\tikz@key/.try={##1}}%
    \ifpgfkeyssuccess%
    \else%
      %% Is it a pgf key?
      \pgfkeys{/pgf/\tikz@key/.try={##1}}%
      \ifpgfkeyssuccess%
      \else%
        \expandafter\pgfutil@in@\expandafter!\expandafter{\tikz@key}%
        \ifpgfutil@in@%
          %% this is a color!
          \expandafter\tikz@addoption\expandafter{\expandafter\tikz@compat@color@set\expandafter{\tikz@key}}%
          \edef\tikz@textcolor{\tikz@key}%
        \else%
          \pgfutil@doifcolorelse{\tikz@key}
          {%
            \expandafter\tikz@addoption\expandafter{\expandafter\tikz@compat@color@set\expandafter{\tikz@key}}%
            \edef\tikz@textcolor{\tikz@key}%
          }%
          {%
            %% Ok, second chance: This might be an arrow specification:
            \expandafter\pgfutil@in@\expandafter-\expandafter{\tikz@key}%
            \ifpgfutil@in@%
              %% Ah, an arrow spec!
              \expandafter\tikz@processarrows\expandafter{\tikz@key}%
            \else%
              %% Ok, third chance: A shape!
              \expandafter\ifx\csname pgf@sh@s@\tikz@key\endcsname\relax%
                \pgfkeys{/errors/unknown key/.expand
                once=\expandafter{\expandafter/\expandafter t\expandafter
                i\expandafter k\expandafter z\expandafter/\tikz@key}{##1}}%
              \else%
                \edef\tikz@shape{\tikz@key}%
              \fi%
            \fi%
          }%
        \fi%
      \fi%
    \fi%
  }
}


%% Vertex
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Adapted from |\coordinate| code
\def\tikzfeynman@commands@vertex{
  \path \pgfextra{\tikzfeynmanallowemptynodetrue}
        \pgfextra{\tikzfeynmanvertextrue}
        node}

%% Diagram
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\tikzfeynman@commands@diagram{\@ifstar
  \tikzfeynman@commands@diagram@star%
  \tikzfeynman@commands@diagram@nostar}

\def\tikzfeynman@commands@diagram@nostar{%
  \pgfutil@ifnextchar[{\tikzfeynman@commands@diagram@nostar@opt}
  {\tikzfeynman@commands@diagram@nostar@opt[]}}
\def\tikzfeynman@commands@diagram@nostar@opt[#1]{%
  \tikzfeynman@orig@graph [/tikzfeynman/every diagram@@, /tikzfeynman/every diagram, /tikz/graphs/spring layout, #1]}

\def\tikzfeynman@commands@diagram@star{%
  \pgfutil@ifnextchar[{\tikzfeynman@commands@diagram@star@opt}
  {\tikzfeynman@commands@diagram@star@opt[]}}
\def\tikzfeynman@commands@diagram@star@opt[#1]{%
  \tikzfeynman@orig@graph [/tikzfeynman/every diagram@@, /tikzfeynman/every diagram, #1]}

%% Graph
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\tikzfeynman@commands@graph{%
  \pgfutil@ifnextchar[{\tikzfeynman@commands@graph@opt}
  {\tikzfeynman@commands@graph@opt[]}}
\def\tikzfeynman@commands@graph@opt[#1]{%
  \PackageWarning{tikz-feynman}{It is not recommended to use \string\graph.  Use \string\diagram\space or \string\diagram* instead.}
  \tikzfeynman@orig@graph [/tikzfeynman/every diagram@@, /tikzfeynman/every diagram, #1]}

%% Optional argument in style key
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\tikzfeynman@key@opt#1[#2]#3\pgfeov{%
  \tikzfeynmanset{#1={[#2]#3}}}

%% Insertion
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\tikzfeynman@insertion{%
  \pgfutil@ifnextchar[{\tikzfeynman@key@opt{insertion@@}}
  {\tikzfeynman@key@opt{insertion@@}[]}}
\pgfkeyslet{/tikzfeynman/insertion/.@cmd}{\tikzfeynman@insertion}

%% Momentum
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\tikzfeynman@momentum@std{%
  \pgfutil@ifnextchar[{\tikzfeynman@key@opt{momentum@@}}
  {\tikzfeynman@key@opt{momentum@@}[]}}
\pgfkeyslet{/tikzfeynman/momentum/.@cmd}{\tikzfeynman@momentum@std}

\def\tikzfeynman@momentum@stdp{%
  \pgfutil@ifnextchar[{\tikzfeynman@key@opt{momentum'@@}}
  {\tikzfeynman@key@opt{momentum'@@}[]}}
\pgfkeyslet{/tikzfeynman/momentum'/.@cmd}{\tikzfeynman@momentum@stdp}

\def\tikzfeynman@momentum@stdr{%
  \pgfutil@ifnextchar[{\tikzfeynman@key@opt{reversed momentum@@}}
  {\tikzfeynman@key@opt{reversed momentum@@}[]}}
\pgfkeyslet{/tikzfeynman/reversed momentum/.@cmd}{\tikzfeynman@momentum@stdr}
\pgfkeyslet{/tikzfeynman/rmomentum/.@cmd}{\tikzfeynman@momentum@stdr}

\def\tikzfeynman@momentum@stdrp{%
  \pgfutil@ifnextchar[{\tikzfeynman@key@opt{reversed momentum'@@}}
  {\tikzfeynman@key@opt{reversed momentum'@@}[]}}
\pgfkeyslet{/tikzfeynman/reversed momentum'/.@cmd}{\tikzfeynman@momentum@stdrp}
\pgfkeyslet{/tikzfeynman/rmomentum'/.@cmd}{\tikzfeynman@momentum@stdrp}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Styles
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\input tikzfeynman.keys.code.tex

\endinput