summaryrefslogtreecommitdiff
path: root/graphics/pgf/contrib/tikz-feynhand/tikzlibraryfeynhand.code.tex
blob: 02f3495735e6c8b351673f93aa8b970055931d74 (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

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% TikZ-FeynHand, Version 1.1.0 of 2019/08/19
% Feynhand Diagrams with TikZ (LaTex manual version)
% Copyright (C) 2019 Max Dohse
% Copyright (C) 2016 Joshua Ellis
%
% This LaTeX file and the whole package are free: 
% you can redistribute it and/or modify it under the
% terms of the GNU General Public License as published by the Free Software Foundation, 
% either version 3 of the License, or (at your option) any later version.
%
% This file is a modification of the file tikzlibraryfeynman.code.tex
% of the package tikz-feynman (version 1.1.0 of 2016/02/05)
% which is available online at https://ctan.org/pkg/tikz-feynman
% for a list of changes, see the file CHANGES.TXT
%
% available at https://ctan.org/pkg/tikz-feynhand
% The Current Maintainer of this work is Max Dohse.
%
% 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. 
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Pre-requisites
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usetikzlibrary{
  arrows.meta,
  calc,
  decorations,
  decorations.markings,
  decorations.pathmorphing,
  decorations.pathreplacing,
  external,
  patterns,
  positioning,
  shapes.geometric,
}

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

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

%% Key Manager
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Setup the tikz-feynhand key family
\pgfkeys{
  /tikzfeynhand/.is family,
  /tikzfeynhand/.search also={/tikz},
}

%% |\tikzfeynhandset| allows keys that belong with tikz-feynhand to be easily set.
\def\tikzfeynhandset{\pgfqkeys{/tikzfeynhand}}

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

\AtBeginDocument{
  \ifx\tikzfeynhand@version\tikzfeynhand@compat\else
    \ifx\tikzfeynhand@compat\tikzfeynhand@empty
      \PackageWarning{tikz-feynhand}{Consider loading TikZ-Feynhand with \string\usepackage[compat=\tikzfeynhand@version]{tikz-feynhand} so that you can be warned if TikZ-Feynhand changes.}
    \else
      \ifx\tikzfeynhand@compat@major\tikzfeynhand@version@major
        \ifx\tikzfeynhand@compat@minor\tikzfeynhand@version@minor
          \ifx\tikzfeynhand@compat@patch\tikzfeynhand@version@patch\else
            \PackageInfo{tikz-feynhand}{The preamble requested version \tikzfeynhand@compat, but the system version is \tikzfeynhand@version.  This should cause no issue.}
          \fi
        \else
          \PackageWarning{tikz-feynhand}{The preamble requested version \tikzfeynhand@compat, but the system version is \tikzfeynhand@version.  This may change some diagrams.}
        \fi
      \else
        \PackageError{tikz-feynhand}{The preamble requested version \tikzfeynhand@compat, but the system version is \tikzfeynhand@version.  They are most likely incompatible.  Please download the appropriate version from jpellis.me/projects/tikz-feynhand.}
      \fi
    \fi
  \fi
}

%% Feynhand Environment
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% Provide `\begin{feynhand} ... \end{feynhand}` within TikZ pictures.
\tikzaddtikzonlycommandshortcutlet\feynhand\tikzfeynhand@environment@feynhand
\tikzaddtikzonlycommandshortcutlet\endfeynhand\endtikzfeynhand@environment@feynhand

%% \begin{feynhand}...\end{feynhand}
\def\tikzfeynhand@environment@feynhand{%
  \pgfutil@ifnextchar[{\tikzfeynhand@environment@feynhand@opt}
  {\tikzfeynhand@environment@feynhand@opt[]}}

\def\tikzfeynhand@environment@feynhand@opt[#1]{%
  \begingroup
  %% Local overrides
  \let\tikz@@scan@fig=\tikzfeynhand@scan@fig
  %% Local commands
  \let\vertex=\tikzfeynhand@commands@vertex
  \let\propagator=\tikzfeynhand@commands@propagator
  \let\propag=\propagator
  %% Opening hooks
  \scope
  \tikzfeynhand@tikz@search@tikzfeynhand
  \pgfkeys{/tikzfeynhand/every feynhand@@,#1}
  \pgfkeysvalueof{/tikzfeynhand/execute at begin feynhand@@}%
  \pgfkeysvalueof{/tikzfeynhand/execute at begin feynhand}%
  }

\def\endtikzfeynhand@environment@feynhand{%	
  %% Closing hooks
  \pgfkeysvalueof{/tikzfeynhand/execute at end feynhand}%
  \pgfkeysvalueof{/tikzfeynhand/execute at end feynhand@@}%
  \endscope
  \endgroup
  }

%%% Allow empty nodes
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newif\iftikzfeynhandallowemptynode
\newif\iftikzfeynhandvertex
\def\tikzfeynhand@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}%
          {\iftikzfeynhandvertex%
             \tikzset{/tikzfeynhand/every vertex@@}%
             \iftikzfeynhandallowemptynode%
               \else%
               \tikzset{/tikzfeynhand/particle}%
               \fi%
            \fi%
            \tikz@fig@main{}
          }
        }
      }
    }
}

%% Include /tikzfeynhand in the search path
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\tikzfeynhand@tikz@search@tikzfeynhand{%
  \pgfkeys{/tikz/.unknown/.code=%
    \let\tikz@key\pgfkeyscurrentname%
    %% Is it a tikzfeynhand key?
    \pgfkeys{/tikzfeynhand/\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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% SEE ALSO \vertex above!
%% Adapted from |\coordinate| code
\def\tikzfeynhand@commands@vertex{%
  \path \pgfextra{\tikzfeynhandallowemptynodetrue}
        \pgfextra{\tikzfeynhandvertextrue}
        node}

%% Propagators
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand{\tikzfeynhand@commands@propagator}[1][]{\draw [#1]}

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

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

%% Slash
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\tikzfeynhand@slash{%
  \pgfutil@ifnextchar[{\tikzfeynhand@key@opt{slash@@}}
  {\tikzfeynhand@key@opt{slash@@}[]}}
\pgfkeyslet{/tikzfeynhand/slash/.@cmd}{\tikzfeynhand@slash}

%% Backslash
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\tikzfeynhand@backslash{%
  \pgfutil@ifnextchar[{\tikzfeynhand@key@opt{backslash@@}}
  {\tikzfeynhand@key@opt{backslash@@}[]}}
\pgfkeyslet{/tikzfeynhand/backslash/.@cmd}{\tikzfeynhand@backslash}

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

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

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

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

% short versions of momentum styles
\pgfkeyslet{/tikzfeynhand/rmomentum/.@cmd}{\tikzfeynhand@momentum@stdr}
\pgfkeyslet{/tikzfeynhand/rmomentum'/.@cmd}{\tikzfeynhand@momentum@stdrp}

\pgfkeyslet{/tikzfeynhand/mom/.@cmd}{\tikzfeynhand@momentum@std}
\pgfkeyslet{/tikzfeynhand/mom'/.@cmd}{\tikzfeynhand@momentum@stdp}

\pgfkeyslet{/tikzfeynhand/revmom/.@cmd}{\tikzfeynhand@momentum@stdr}
\pgfkeyslet{/tikzfeynhand/revmom'/.@cmd}{\tikzfeynhand@momentum@stdrp}

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

\input tikzfeynhand.keys.code.tex

\endinput