summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/latex/tikz-feynman/tikz-feynman.tex
blob: c4c96d61aaaa27227216d4e139091366e9b127aa (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
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% TikZ-Feynman
% Feynman Diagrams with TikZ
% Copyright (C) 2015  Joshua Ellis
%
%
% This LaTeX file is 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 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 GNU General Public License for more details.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% HEADER
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def\pgfautoxrefs{1}
\documentclass[a4paper,final]{ltxdoc}

\usepackage{etex}

%% Formatting
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\usepackage[vmargin=4cm, hmargin=3cm]{geometry}  % Customize text width, page height, margins, etc.
% \usepackage{multicol}  % {multicols}{n} environment
% \usepackage{pdflscape} % {landscape} environment

%\usepackage{setspace} % Line spacing
%\singlespacing        % 1-spacing (default)
%\onehalfspacing       % 1,5-spacing
%\doublespacing        % 2-spacing

\usepackage{fontspec}  % Allows other fonts to be specified
\setmainfont{EB Garamond}[
  Contextuals={Alternate},
  Numbers=OldStyle,
]
\setmonofont{Inconsolata-g}[
  Scale=MatchLowercase,
]
\newfontface\swshape{EB Garamond 12 Italic}[Style=Swash]

\usepackage{microtype}   % Fine small typographical details
\usepackage{titlesec}    % Change section heading font
\titleformat*{\section}{\huge\scshape}
\titleformat*{\subsection}{\Large\scshape}
\titleformat*{\subsubsection}{\large\scshape}
\titleformat*{\paragraph}{\scshape}

\usepackage[perpage]{footmisc}
\usepackage{enumitem}    % Easily customize lists
\setlist[description]{font=\normalfont\scshape}

%% Change the Table of Contents fonts
\usepackage{tocloft}
\renewcommand{\cftsecfont}{\normalfont\scshape}
\setlength\cftbeforesecskip{0pt}
\setcounter{tocdepth}{2}

%% Language
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\usepackage[UKenglish]{babel} % Set up the language
\usepackage{csquotes}
\usepackage{siunitx}          % Provides \SI{1}{\metre}, also \ang{90}.
\usepackage{textcomp}

%% Graphics & Figure
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\usepackage{graphicx}   % Allow graphics to be included
\usepackage{xcolor}     % Define and use colours
% \usepackage{subcaption} % Subfigures inside a figure

% Keep all pictures in the './img/' sub-directory.
\graphicspath{{./img/}}

\usepackage{tikz}       % Powerful drawing language
\usepackage{tikz-feynman}
\makeatletter
\tikzfeynmanset{compat=\tikzfeynman@version@major.\tikzfeynman@version@minor.\tikzfeynman@version@patch}
\makeatother

%% TikZ pictures and plots can significantly increase the time it takes to
%% produce the output.  The `external` TikZ library library defers the creation
%% of these figures to a sub-process which creates a separate PDF file which is
%% then simply imported into the main document.  To call the sub-process, you
%% have to execute the appropriate makefile.  If you are using LatexMk, you can
%% use the `.latexmkrc` to automatically do this for you.
%%
%% The following setup works on Linux, and should work on OS X too.
% \usetikzlibrary{external}
% \tikzexternalize[shell escape=-shell-escape, prefix=pgf-img/]
% \immediate\write18{mkdir -p pgf-img}
% \tikzset{
%     external/mode=list and make,
%     external/system call={
%         lualatex \tikzexternalcheckshellescape -halt-on-error -interaction=batchmode -jobname="\image" "\texsource" || rm "\image.pdf"},
% }

%% Math Packages
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\usepackage{amsmath}   % The core math package
\usepackage{amssymb}   % Defines additional math fonts
\usepackage{mathtools} % Various extra maths functions
% \usepackage{cancel}    % Show cancellations with \cancel{}
% \usepackage{autonum}   % Only number referenced equations (must be loaded after cleverref)
\usepackage{dsfont}

\usepackage[cmintegrals,varg]{newtxmath} % Nice math with Garamond

%% Define \withnumber which forces the line to have number
\newcommand{\withnumber}{\refstepcounter{equation}\tag{\theequation}}

%% Allows page breaks in math (1 = avoid if possible, 4 = whenever)
%% Page breaks can be avoided at particular places by using \\*
\allowdisplaybreaks[2]

\DeclarePairedDelimiter{\angles}{\langle}{\rangle}

%% Tables
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\usepackage{array}     % New column types, including >{}x<{}
\usepackage{booktabs}  % Provides nicer horizontal lines
\usepackage{multirow}  % Allows cells to span multiple rows
%\usepackage{longtable} % Allows for tables to span multiple pages

%% Define the maths version of clr columns.
\newcolumntype{C}{>{\(}c<{\)}}
\newcolumntype{L}{>{\(}l<{\)}}
\newcolumntype{R}{>{\(}r<{\)}}

%% Other Packages
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\usepackage{listings}    % Code listings
\usepackage{minted}      % Use Pygments
\usepackage{fp}          % Floating point arithmetics
\usepackage{makeidx}     % Index creation
\usepackage{xr}          % Cross-referencing
\usepackage[orig,UKenglish]{isodate}     % Handle dates

\usepackage{hyperref}    % Automatically inserts hyperlinks.
\usepackage{cleveref}    % Use `\cref{}` to reference anything

\usepackage{autonum}

%% Bibliography
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% hyperref should be loaded first
\usepackage[
    backend=biber,
    style=phys,
    autocite=inline,
    biblabel=brackets,
    eprint=true,
    doi=true,
    isbn=true,
]{biblatex}

\addbibresource{references.bib}

%% Other modifications
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Modify the skip after each paragraph
\setlength{\parskip}{1ex plus 0.5ex minus 0.2ex}
\setlength{\parindent}{0pt}

\providecommand{\LuaTeX}{Lua\TeX}
\providecommand{\tikzfeynmanname}{\tikzname-Feynman}
\providecommand{\pgfmanual}{\href{http://mirrors.ctan.org/graphics/pgf/base/doc/pgfmanual.pdf}{\tikzname{} manual}}

\IfFileExists{pgfmanual-en-macros}{
  \let\attribute\relax
  \input{pgfmanual-en-macros}
}{
  \PackageError{tikz-feynman-manual}{
This document requires the file pgfmanual-en-macros.tex (distributed
with pgf) to compile.  Please place a copy of that file in the current
directory}{}}

\makeindex

\pgfkeys{
  /pdflinks/search key prefixes in={/tikzfeynman/}
  /pdflinks/internal link prefix=tikzfeynman,
  %
  /pdflinks/warnings=false,
  % for debugging:
  /pdflinks/show labels=false,
}

\makeatletter
%% Make table of content heading smaller
\renewcommand\tableofcontents{%
    \section*{\normalfont\large\scshape\contentsname}%
    \vspace{-1.5\baselineskip}%
    \@starttoc{toc}%
}
\makeatother

%% Define some slightly nicer colors
\definecolor{link-color}{RGB}{96 0 0}
\definecolor{cite-color}{RGB}{0 96 0}
\definecolor{file-color}{RGB}{0 0 96}
\definecolor{url-color}{RGB}{0 0 96}
\definecolor{link-border-color}{RGB}{255 159 159}
\definecolor{cite-border-color}{RGB}{159 255 159}
\definecolor{file-border-color}{RGB}{159 159 255}
\definecolor{url-border-color}{RGB}{159 159 255}

\hypersetup{
  pdfborder=0 0 0,
}

%% Change the abstract style
\renewenvironment{abstract}{
  \begin{center}
    \begin{minipage}{0.9\textwidth}
      \begin{center}
        \Large
        Abstract
      \end{center}\vspace*{-1em}
      \rule{\textwidth}{1pt}
}{
      \par\noindent
      \rule{\textwidth}{1pt}
    \end{minipage}
  \end{center}
}

%% Put the abstract only on the arXiv version
\newif\ifarxiv
\arxivfalse

%% Acknowledgements go in two different places depending on whether it is the
%% arXiv version or not.  Have the common code here.
\def\acknowledgements{
  \subsection*{Acknowledgements}
  \label{subsec:acknowledgements}

  The original proof-of-concept for using \tikzname{} to draw Feynman diagrams
  was done by the user `\href{http://tex.stackexchange.com/users/2552}{Jake}' on
  the \TeX{} StackExchange.  His original answer can be viewed at:
  \url{http://tex.stackexchange.com/a/87395/26980}.

  I must also thank all the people who have used the development versions of
  \tikzfeynmanname{} and offered suggestions to improve it and found bugs for me
  to fix.
}

%% Center codeexample
\makeatletter
\let\codeexample@orig=\codeexample
\let\endcodeexample@orig=\endcodeexample
\def\codeexample{
  \begin{center}
    \codeexample@orig
}
\def\endcodeexample{
    \endcodeexample@orig
  \end{center}
}

%% Document Information
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\makeatletter
\newcommand{\@keywords}{}
\newcommand{\keywords}[1]{\renewcommand{\@keywords}{#1}}
\newcommand{\@institution}{}
\newcommand{\institution}[1]{\renewcommand{\@institution}{#1}}

\AtBeginDocument{
  \hypersetup{
    pdftitle={\@title},
    pdfauthor={\@author},
    pdfkeywords={\@keywords},
  }
}
\makeatother

\title{\tikzfeynmanname}
\author{Joshua \textsc{Ellis}}
\institution{
  ARC Centre of Excellence for Particle Physics at the Terascale \\
  School of Physics, The University of Melbourne \textsc{vic} 3010, Australia
}
\keywords{Feynman diagram, TeX, LaTeX, TikZ, pgf, TikZ-Feynman}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% DOCUMENT
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\pagenumbering{roman}

\begin{titlepage}
  \makeatletter
  \begin{center}
    \vspace*{1em}
    \tikz\node[scale=1.5]{%
      \color{gray}\Huge\ttfamily \char`\{\textcolor{red!75!black}{\@title}\char`\}};


    \vspace{0.5em}
    {\huge Feynman diagrams with \tikzname}

    \vspace{0.7em}
    {Version \texttt{\tikzfeynman@version} \qquad \origdate\printdateTeX{\tikzfeynman@date}}

    \vspace{1.3em}
    {by \@author} \\[1em]
    {\@institution}
  \end{center}
  \makeatother

  \vfill

\begin{codeexample}[graphic=white]
\feynmandiagram [large, vertical=e to f] {
  a -- [fermion] b -- [photon, momentum=\(k\)] c -- [fermion] d,
  b -- [fermion, momentum'=\(p_{1}\)] e -- [fermion, momentum'=\(p_{2}\)] c,
  e -- [gluon]  f,
  h -- [fermion] f -- [fermion] i;
};
\end{codeexample}

  \vfill

  \begin{multicols}{2}
    \tableofcontents
  \end{multicols}
\end{titlepage}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% CONTENT
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\clearpage
\pagenumbering{arabic}

\ifarxiv
\begin{abstract}
  \tikzfeynmanname{} is a \LaTeX{} package allowing Feynman diagrams to be
  easily generated within \LaTeX{} with minimal user instructions and without
  the need of external programs.  It builds upon the \tikzname{} package and
  leverages the graph placement algorithms from \tikzname{} in order to automate
  the placement of many vertices.  \tikzfeynmanname{} still allows fine-tuned
  placement of vertices so that even complex diagrams can be generated with
  ease.
\end{abstract}
\fi

\section{Introduction}
\label{sec:introduction}

\tikzfeynmanname{} provides a new way to draw Feynman diagrams in \LaTeX{} that
does not rely on external programs and uses a clear extensible syntax.

\ifarxiv\else
If you use \tikzfeynmanname{} in an academic setting, please cite:
\begin{quote}
  \fullcite{tikz-feynman}
\end{quote}
\fi

Feynman diagrams provide a description of interactions of subatomic particles in
a form that is clearer and more succinct than the corresponding mathematical
description.  They were introduced by \citeauthor{PhysRev.76.769} and first
appear in his paper \citetitle{PhysRev.76.769} \cite{PhysRev.76.769}.  Since
then, \LaTeX{} has become widely used to type-set scientific papers and
currently, two leading methods of drawing Feynman diagrams in \LaTeX{} are
\href{https://www.ctan.org/pkg/feynmf}{|feynMF|/|feynMP|} \cite{feynmf} and
\href{https://www.ctan.org/pkg/axodraw}{|AxoDraw|} \cite{axodraw}, with the
latter also featuring a \textsc{gui} front-end called
\href{http://jaxodraw.sourceforge.net}{|JaxoDraw|} \cite{jaxodrawV1,jaxodrawV2}.

Both |feynMF|/|feynMP| and |AxoDraw| have quite complicated syntax.  As an
example, the code to generate an \(\ell\ell \to \ell\ell\) scattering Feynman
diagram in each package is:
\begin{center}
  \begin{tabular}{p{0.3\linewidth} p{0.27\linewidth} p{0.34\linewidth}}
    |AxoDraw| & |feynMF|/|feynMP| & \tikzfeynmanname{} \\[-2em]
\begin{codeexample}[execute code=false]
\begin{picture}
\ArrowLine(190,270)(160,300)
\ArrowLine(160,240)(190,270)
\ArrowLine(270,300)(240,270)
\ArrowLine(240,270)(270,240)
\Photon(190,270)(240,270){4}{4.5}
\Vertex(190,270){1.5}
\Vertex(240,270){1.5}
\end{picture}
\end{codeexample}
              &
\begin{codeexample}[execute code=false]
\begin{fmfchar*}(40,30)
\fmfpen{thick}
\fmfleft{i1,i2}
\fmfright{o1,o2}
\fmf{fermion}{i1,v1,o1}
\fmf{fermion}{i2,v2,o2}
\fmf{photon,label=$q$}{v1,v2}
\fmfdot{v1,v2}
\end{fmfchar*}
\end{codeexample}
                                  &
\begin{codeexample}[execute code=false]
\feynmandiagram [horizontal=a to b] {
  i1 -- [fermion] a -- [fermion] i2,
  a -- [photon] b,
  f1 -- [fermion] b -- [fermion] f2,
};
\end{codeexample} \\[-2em]
  \end{tabular}
\end{center}
The learning curves for both |AxoDraw| and |feynMF|/|feynMP| are quite steep,
and although this is partly resolved by using |JaxoDraw|, this requires an
external program.  In addition, the creation of Feynman diagrams in
|feynMF|/|feynMP| requires further processing outside of \LaTeX{}.

\tikzfeynmanname{} on the other hand uses a clear syntax and delegates the
positioning of vertices to algorithms originally developed by
\citeauthor{hu2005} \cite{hu2005}, and \citeauthor{eades1991} \cite{eades1991},
both of which were implemented into \tikzname{} by \citeauthor{pohlmann2011}
\cite{pohlmann2011}.  Since \tikzfeynmanname{} is built on \tikzname{}, users
can harness the power and extensibilty of \tikzname{} \cite{tikz} making it easy
to extend to accommodate individual needs.  In order to produce more complicated
diagrams, relative or absolute positioning of vertices can also be used in
\tikzfeynmanname{} so that any diagram can be generated with relative ease.

\tikzfeynmanname{} is made available through the
\href{https://ctan.org/pkg/tikz-feynman}{Comprehensive \TeX{} Archive Network
  (\textsc{ctan})}\footnote{\url{https://ctan.org/pkg/tikz-feynman}} and can
also be downloaded from the
\href{http://www.jpellis.me/projects/tikz-feynman}{project
  page}\footnote{\url{http://www.jpellis.me/projects/tikz-feynman}}.  The
project is open source and contributions are welcome.  The management of bugs
and feature requests is done at
\href{https://github.com/JP-Ellis/tikz-feynman}{Github}\footnote{\url{https://github.com/JP-Ellis/tikz-feynman}}.

\tikzfeynmanname{}'s versioning will approximately follow
\href{http://semverg.org}{semantic versioning}.  This means that changes in the
third number (|1.0.0| to |1.0.1|) will consist of bug fixes and very minor
changes but they should not change the output otherwise\footnote{That is, with
  the exception of the bug that they are fixing.}.  Changes in the second number
(|1.0.0| to |1.1.0|) will consist of new features but everything should be
backwards compatible.  Finally, changes in the first number (|1.0.0| to |2.0.0|)
indicates a major change in the package and code written for |1.0.0| is not
guaranteed to work on |2.0.0|.  The intended version of this package to use
should be indicated when the package is loaded with
|\usepackage[compat=x.y.z]{tikz-feynman}| so the user may be informed of any
discrepancyx.  If needed, earlier versions may be downloaded from the
\href{http://www.jpellis.me/projects/tikz-feynman}{project
  page}\footnote{\url{http://www.jpellis.me/projects/tikz-feynman}}.

\subsection*{Licence}
\label{subsec:licence}

This \emph{documentation} may be redistributed and/or modified under the terms
of the \textsc{gnu} General Public License as published by the Free Software
Foundation, either version 3 of the License, or (at your option) any later
version.

The \emph{code of this package} 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 package is distributed in the hope that it will be useful, but
\textsc{without any warranty}; without even the implied warranty of
\textsc{merchantability} or \textsc{fitness for a particular purpose}.

\ifarxiv\else
\acknowledgements
\fi


\clearpage
\section{Tutorial}
\label{sec:tutorial}

\subsection{Loading the Package}
\label{sibsec:loading_the_package}

After installing the package, the \tikzfeynmanname{} package can be loaded with
|\usepackage{tikz-feynman}| in the preamble.  It is recommend that you also
specify the version of \tikzfeynmanname{} to use with the optional package
argument |compat|: |\usepackage[compat=1.1.0]{tikz-feynman}|.  This ensures that
any new versions of \tikzfeynmanname{} do not produce any undesirable changes
without warning.

\subsection{A First Diagram}
\label{subsec:a_first_diagram}

Feynman diagrams can be declared with the |\feynmandiagram| command.  It is
analogous to the |\tikz| command from \tikzname~and requires a final semi-colon
(|;|) to finish the environment.  For example, a simple \(s\)-channel diagram
is:

\begin{codeexample}[]
\feynmandiagram [horizontal=a to b] {
  i1 -- [fermion] a -- [fermion] i2,
  a -- [photon] b,
  f1 -- [fermion] b -- [fermion] f2,
};
\end{codeexample}

Let's go through this example line by line:
\begin{description}
\item[Line 1] |\feynmandiagram| introduces the Feynman diagram and allows for
  optional arguments to be given in the brackets \texttt{[\meta{options}]}.  In
  this instance, |horizontal=a to b| orients the algorithm outputs such that the
  line through vertices |a| and |b| is horizontal.
\item[Line 2] The left fermion line is drawn by declaring three vertices (|i1|,
  |a| and |i2|) and connecting them with edges |--|.  Just like the
  |\feynmandiagram| command above, each edge also take optional arguments
  specified in brackets \texttt{[\meta{options}]}.  In this instance, we want
  these edges to have arrows to indicate that they are fermion lines, so we add
  the |fermion| style to them.

  As you will see later on, optional arguments can also be given to the vertices
  in exactly the same way.
\item[Line 3] This edge connects vertices |a| and |b| with an edge styled as a
  photon.  Since there is already a vertex labelled |a|, the algorithm will
  connect it to a new vertex labeled |b|.
\item[Line 4] This line is analogous to line 2 and introduces two new vertices,
  |f1| and |f2|.  It re-uses the previously labelled |b| vertex.
\item[Line 5] Finish the declaration of the Feynman diagram.  The final
  semi-colon (|;|) is important.
\end{description}

The name given to each vertex in the graph does not matter.  So in this example,
|i1|, |i2| denote the initial particles; |f1|, |f2| denotes the final particles;
and |a|, |b| are the end points of the propagator.  The only important aspect is
that what we called |a| in line 2 is also |a| in line 3 so that the underlying
algorithm treats them as the same vertex.

The order in which vertices are declared does not matter as the default
algorithm re-arranges everything\footnote{It is possible for the algorithm to
  get a litte confused in some circumstances, but these cases should be rather
  rare.  For some algorithms (such as the |layered~layout|), the order in which
  vertices are introduces \emph{does} matter.  This is documented in
  \cref{subsubsec:diagram_keys}.}.  For example, one might prefer to draw the
fermion lines all at once, as with the following example (note also that the way
we named vertices is completely different):

\begin{codeexample}[]
\feynmandiagram [horizontal=f2 to f3] {
  f1 -- [fermion] f2 -- [fermion] f3 -- [fermion] f4,
  f2 -- [photon] p1,
  f3 -- [photon] p2,
};
\end{codeexample}

As a final remark, the calculation of where vertices should be placed is usually
done through an algorithm written in Lua.  As a result, \LuaTeX{} is required in
order to make use of these algorithms.  If \LuaTeX{} is not used,
\tikzfeynmanname{} will default to a more rudimentary algorithm and will warn
the user instead.

\subsection{Adding Styles}
\label{subsec:adding_styles}

So far, the examples have only used the |photon| and |fermion| styles.  The
\tikzfeynmanname{} package comes with quite a few extra styles for edges and
vertices which are all documented over in \cref{sec:documentation}.  As an
example, it is possible to add momentum arrows with |momentum=|\meta{text}, and
in the case of end vertices, the particle can be labelled with
|particle=|\meta{text}.  As an example, we take the generic \(s\)-channel
diagram from \cref{subsec:a_first_diagram} and make it a \(e^{+}e^{-} \to
\mu^{+}\mu^{-}\) diagram:
\begin{codeexample}[]
\feynmandiagram [horizontal=a to b] {
  i1 [particle=\(e^{-}\)] -- [fermion] a -- [fermion] i2 [particle=\(e^{+}\)],
  a -- [photon, edge label=\(\gamma\), momentum'=\(k\)] b,
  f1 [particle=\(\mu^{+}\)] -- [fermion] b -- [fermion] f2 [particle=\(\mu^{-}\)],
};
\end{codeexample}
In addition to the style keys documented below, style keys from \tikzname{} can
be used as well:
\begin{codeexample}[]
\feynmandiagram [horizontal=a to b] {
  i1 [particle=\(e^{-}\)] -- [fermion, very thick] a -- [fermion, opacity=0.2] i2 [particle=\(e^{+}\)],
  a -- [red, photon, edge label=\(\gamma\), momentum'={[arrow style=red]\(k\)}] b,
  f1 [particle=\(\mu^{+}\)] -- [fermion, opacity=0.2] b -- [fermion, very thick] f2 [particle=\(\mu^{-}\)],
};
\end{codeexample}
For a list of all the various styles that \tikzname{} provides, have a look at
the \pgfmanual; it is extremely thorough and provides many usage examples.

\tikzfeynmanname{} also supports combining styles together which can be useful
in certain new models such as supersymmetry:
\begin{codeexample}[]
\feynmandiagram [horizontal=a to b] {
  i1 [particle=\(\tilde W\)] -- [plain, boson] a -- [anti fermion] i2 [particle=\(q\)],
  a -- [charged scalar, edge label=\(\tilde q\)] b,
  f1 [particle=\(\tilde g\)] -- [plain, gluon] b -- [fermion] [particle=\(q\)],
};
\end{codeexample}

\subsection{When the Algorithm Isn't Enough}
\label{subsec:when_the_algorithm_isnt_enough}

By default, the |\feynmandiagram| and |\diagram| commands use the
|spring layout| algorithm to place all the edges\footnote{For more details on
  this layout and any other graph layouts available, see
  \cref{subsubsec:diagram_keys}}. The |spring layout| algorithm attempts to
`spread out' the diagram as much as possible which---for most simpler
diagrams---gives a satisfactory result; however in some cases, this does not
produce the best diagram and this section will look at alternatives.  There are
three main alternatives:
\begin{description}
\item[Add invisible edges] While still using the default algorithm, it is
  possible to force certain vertices to be closer together by adding extra edges
  and making them invisible through |draw=none|.  The algorithm will treat these
  extra edges in the same way, but they are simply not drawn at the end;

\item[Use a different algorithm] In some circumstances, other algorithms may be
  better suited.  Some of the other graph layout algorithms are listed in
  \cref{subsubsec:diagram_keys}, and an exhaustive list of all algorithms and
  their parameters is given in the \pgfmanual;

\item[Manual placement] As a last resort, very complicated or unusual diagrams
  will require each vertex to be manually placed.
\end{description}

\subsubsection{Invisible Edges}
\label{subsubsec:invisible_edges}

The underlying algorithm treats all edges in exactly the same way when
calculating where to place all the vertices, and the actual drawing of the
diagram (after the placements have been calculated) is done separately.
Consequently, it is possible to add edges to the algorithm, but prevent them
from being drawn by adding |draw=none| to the edge style.

This is particularly useful if you want to ensure that the initial or final
states remain closer together than they would have otherwise as illustrated in
the following example (note that |opacity=0.2| is used instead of |draw=none| to
illustrate where exactly the edge is located).

\begin{codeexample}[]
% No invisible to keep the two photons together
\feynmandiagram [small, horizontal=a to t1] {
  a [particle=\(\pi^{0}\)] -- [scalar] t1 -- t2 -- t3 -- t1,
  t2 -- [photon] p1 [particle=\(\gamma\)],
  t3 -- [photon] p2 [particle=\(\gamma\)],
};
\end{codeexample}
\begin{codeexample}[]
% Invisible edge ensures photons are parallel
\feynmandiagram [small, horizontal=a to t1] {
  a [particle=\(\pi^{0}\)] -- [scalar] t1 -- t2 -- t3 -- t1,
  t2 -- [photon] p1 [particle=\(\gamma\)],
  t3 -- [photon] p2 [particle=\(\gamma\)],
  p1 -- [opacity=0.2] p2,
};
\end{codeexample}

\subsubsection{Alternative Algorithms}
\label{subsubsec:alternative_algorithms}

The graph drawing library from \tikzname{} has several different algorithms to
position the vertices\footnote{See \cref{subsubsec:diagram_keys} for some
  alternative algorithms.}  By default, |\diagram| and |\feynmandiagram| use the
|spring layout| algorithm to place the vertices.  The |spring layout| attempts
to spread everything out as much as possible which, in most cases, gives a nice
diagram; however, there are certain cases where this does not work.  A good
example where the |spring layout| doesn't work are decays where we have the
decaying particle on the left and all the daughter particles on the right.
\begin{codeexample}[]
% Using the default spring layout
\feynmandiagram [horizontal=a to b] {
  a [particle=\(\mu^{-}\)] -- [fermion] b -- [fermion] f1 [particle=\(\nu_{\mu}\)],
  b -- [boson, edge label=\(W^{-}\)] c,
  f2 [particle=\(\overline \nu_{e}\)] -- [fermion] c -- [fermion] f3 [particle=\(e^{-}\)],
};
\end{codeexample}
\begin{codeexample}[]
% Using the layered layout
\feynmandiagram [layered layout, horizontal=a to b] {
  a [particle=\(\mu^{-}\)] -- [fermion] b -- [fermion] f1 [particle=\(\nu_{\mu}\)],
  b -- [boson, edge label'=\(W^{-}\)] c,
  c -- [anti fermion] f2 [particle=\(\overline \nu_{e}\)],
  c -- [fermion] f3 [particle=\(e^{-}\)],
};
\end{codeexample}
You may notice that in addition to adding the |layered layout| style to
|\feynmandiagram|, we also changed the order in which we specify the vertices.
This is because the |layered layout| algorithm does pay attention to the order
in which vertices are declared (unlike the default |spring layout|); as a
result, |c--f2, c--f3| has a different meaning to |f2--c--f3|.  In the former
case, |f2| and |f3| are both on the layer below |c| as desired; whilst the
latter case places |f2| on the layer above |c| (that, the same layer as where
the \(W^{-}\) originates).

\subsubsection{Manual Placement}
\label{subsubsec:manual_placement}

In more complicated diagrams, it is quite likely that none of the algorithms
work, no matter how many invisible edges are added.  In such cases, the vertices
have to be placed manually.  \tikzfeynmanname{} allows for vertices to be
manually placed by using the |\vertex| command.

The |\vertex| command is available only within the |feynman| environment (which
itself is only available inside a |tikzpicture|).  The |feynman| environment
loads all the relevant styles from \tikzfeynmanname{} and declares additional
\tikzfeynmanname-specific commands such as |\vertex| and |\diagram|.  This is
inspired from PGFPlots and its use of the |axis| environment.

The |\vertex| command is very much analogous to the |\node| command from
\tikzname{}, with the notable exception that the vertex contents are optional;
that is, you need not have |{|\meta{text}|}| at the end.  In the case where |{}|
is specified, the vertex automatically is given the |particle| style, and
otherwise it is a usual (zero-sized) vertex.

To specify where the vertices go, it is possible to give explicit coordinates
though it is probably easiest to use the |positioning| library from \tikzname{}
which allows vertices to be placed relative to existing vertices\footnote{The
  \pgfmanual{} has some extensive documentation explaining how to use the
  |positioning| library.}.  By using relative placements, it is possible to
easily tweak one part of the graph and everything will adjust accordingly---the
alternative being to manually adjust the coordinates of every affected vertex.

Finally, once all the vertices have been specified, the |\diagram*| command is
used to specify all the edges.  This works in much the same way as |\diagram|
(and also |\feynmandiagram|), except that it uses an very basic algorithm
to place new nodes and allows existing (named) nodes to be included.  In order
to refer to an existing node, the node must be given in parentheses.

This whole process of specifying the nodes and then drawing the edges between
them is shown below for the muon decay:

\begin{codeexample}[]
\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}
\end{codeexample}

\clearpage
\section{Documentation}
\label{sec:documentation}

\subsection{Commands \emph{\&} Environments}
\label{subsec:commands}

\begin{command}{\tikzfeynmanset\marg{options}}
  This command will process \meta{options} using |\pgfkeys| with the default
  path set to |/tikzfeynman|.  Typically, \meta{options} will be a
  comma-separated list of the form \meta{key}|=|\meta{value}, though the full
  power of the mechanism behind |\pgfkeys| can be used (see the \pgfmanual{} for
  a complete description).

  Typically, this is used in the preamble of the document to add or change
  certain keys for the whole document.
\end{command}

\begin{command}{\feynmandiagram\opt{\oarg{TikZ options}\oarg{diagram options}}\marg{diagram instructions}}
  This commands creates a |{tikzpicture}| and |{feynman}| environment, and
  places a |\diagram| inside with the provided \meta{diagram instruction}.
  Please refer to the documentation for |\diagram| for the \meta{diagram
    instruction} syntax.

  The optional arguments specified in \meta{tikz options} are passed on to the
  |{tikzpicture}|, and the \meta{diagram options} are passed on to |\diagram|.
  If only one optional argument is given, then the optional arguments are given
  to both.  A single optional argument will usually suffice as most keys are
  recognized by both commands; however, in the event that a key is not
  recognized, both options are provided.
\end{command}

\begin{environment}{{feynman}\opt{\oarg{options}}}
  The |{feynman}| environment is where all the drawing of Feynman diagrams takes
  place.  It makes all the \tikzfeynmanname{} styles available and defines
  commands such as |\vertex| and |\diagram| which are otherwise unavailable
  outside of this environment.  The |{feynman}| environment is only accessible
  within the |{tikzpicture}| environment.

  Options which are passed in \meta{options} apply for the whole environment in
  the same way that the |{scope}| environment work in \tikzname.

  \begin{command}{\vertex\opt{\oarg{options}} (\meta{name}) \opt{at (\meta{coordinate})} \opt{\marg{contents}};}
    Defines a new vertex with the provided \meta{name}.  If \meta{contents} is
    not provided, the resulting vertex will have zero size.  On the other hand,
    if \meta{contents} is provided, the |particle=|\meta{contents} style is
    applied.  Additional styles can be applied to the vertex through
    \meta{options}.

    The final semicolon (|;|) is vital for this command since without it, the
    \LaTeX{} engine will not know when the |\vertex| command ends.
    Additionally, this command \emph{cannot} be chained like one can do with the
    inbuilt \tikzname{} commands.

    This command is only available with the |{feynman}| environment.
  \end{command}

  \begin{command}{\diagram\opt{\oarg{options}}\marg{diagram instructions}}
    Begins a new diagram using the |spring layout|.  Keys passed through
    \meta{options} can include general \tikzname{} keys, graph-specific keys and
    any applicable \tikzfeynmanname{} keys too.  Other algorithms (such as |tree
    layout|) can be passed through \meta{options} and that will override the
    |spring layout|.

    The syntax for the \meta{diagram instructions} is thoroughly described in
    the \pgfmanual, but in the context of this package, it will usually suffice
    to know the following:
    \begin{itemize}
    \item Vertices within the graph are specified with no delimiters (i.e.~no
      parenthesis, no brackets) and only require spaces around either side.  In
      order to refer to a vertex defined outside of the |\diagram| command, its
      name must be given in parenthesis: |(|\meta{name}|)|.  Note that in order
      to refer to external vertices, one must use |\diagram*| as most algorithms
      (including the default |spring layout|) are incompatible with vertices
      defined outside of the algorithm.

      When a vertex name is used multiple times, the underlying algorithm will
      consider them to be the same vertex and introduces additional edges.

      Options can be given to the vertex in brackets after the name: \meta{name}
      |[|\meta{options}|]|.  For vertices defined outside of the |\diagram|
      command, these options should be specified when the vertex is first
      declared.

    \item The edges between each pair of vertices is specified with |--|, and
      these can be chained together: \verb|a -- b -- c|.  In order to pass a
      style to the edge, it is specified in brackets after the dashed:
      |-- | \oarg{options}.  For example, to make on edge red, one would use
      |-- [red]|.

    \item A comma (|,|)---or equivalently a semicolon (|;|)---specifies the end
      of a sequence of edges and vertices and allows for another sequence to be
      started.  So \verb|a -- b, c -- d| will create two disconnected edges.

    \item Subgroups (aking to scopes in \tikzname) are specified with braces:
      |{|\oarg{options}\meta{diagram instructions}|}|.  This can be quite
      useful when a lot of edges or nodes share a common style.  For example,
      one could use |{[edges={fermion}]|\verb| a -- b -- c, x -- y -- z}| and
      every edge will have the |fermion| style applied automatically.

      Another useful feature of subgroups is that an edge to a group will create
      an edge to each vertex in that subgroup as shown below.  The example also
      shows how they can be nested which in some cases (such as with a
      |layered layout|) can be extremely useful.

\begin{codeexample}[]
\feynmandiagram [nodes=circle, horizontal=a1 to b3] {
  a1 -- {b1, b2, b3 -- {c1, c2 -- d1}}
};
\end{codeexample}
    \end{itemize}
  \end{command}

  \begin{command}{\diagram*\opt{\oarg{options}}\marg{diagram instructions}}
    Same as |\diagram|, but instead of using the |spring layout| algorithm to
    place the vertices, this uses the most basic algorithm.  This basic
    algorithm in most cases will not produce a satisfactory diagram, but is
    intended to be used with vertices are declared and positioned outside of the
    |\diagram*| command.  Essentially, |\diagram*| should be used only to
    connect existing vertices.
  \end{command}
\end{environment}



\subsection{Keys \emph{\&} Styles}
\label{subsec:Keys}

The various styles and options that allow the Feynman diagrams to be customized
are defined in what \tikzname{} calls \emph{keys}.  The documentation includes
all keys which are defined within \tikzfeynmanname{} which all begin with the
prefix |/tikzfeynman|.  In addition, a few of the keys from \tikzname{} itself
which are particularly useful to \tikzfeynmanname{} are documented and these are
prefixed with |/tikz| or |/graph drawing|.  Please refer to the \pgfmanual{} for
a more in thorough documentation of the \tikzname{} keys.


\tikzfeynmanname{} provides many |every |\meta{key} which allow every instance
of \meta{key} to be modified.  For example, to make every diagram red except for
small diagrams which should be blue, then one would add to the preamble:
\begin{codeexample}[execute code=false]
\tikzfeynmanset{
  every diagram={red},
  every small={blue},
}
\end{codeexample}
If you are completely unhappy with a particular inbuilt style, you can define
your own style with with \meta{key}|/.style={...}| as shown in the
following example:
\begin{codeexample}[execute code=false]
\tikzfeynmanset{
  myblob/.style={
    shape=circle,
    draw=blue,
    fill=red,
  }
}
\end{codeexample}

All the keys defined here are made available inside the |{feynman}| environment
and inside |\feynmandiagram|; but if you wish to access them outside of this
(say, in a regular |{tikzpicture}| environment), you will need to specify the
full path with the leading |/tikzfeynman|.

\subsubsection{Feynman Keys}
\label{subsubsec:feynman_keys}

\begin{keylist}{%
    /tikzfeynman/execute at begin feynman=\marg{\TeX{} code},
    /tikzfeynman/execute at end feynman=\marg{\TeX{} code}}
  Allows for custom code to be executed at the start or end of each |{feynman}|
  environment.
\end{keylist}

\begin{key}{/tikzfeynman/every feynman=\meta{styles}}
  Set of styles which are applied to every |{feynman}| environments (and
  consequently, every apply inside all |\feynmandiagram| too).  The style also
  applies to regular \tikzname{} commands used inside the |{feynman}|
  environment.

\begin{codeexample}[]
\tikzfeynmanset{every feynman={red}}
\begin{tikzpicture}
  \node at (0, 0.5) {This is not red};
  \begin{feynman}
    \node at (0, -0.5) {This is red};
  \end{feynman}
\end{tikzpicture}
\end{codeexample}
\end{key}

\begin{stylekey}{/tikzfeynman/inline=\meta{node}}
  A style used to display a Feynman diagram inline (typically in an equation),
  and aligning such that its vertical placement is at the node specified.  The
  node specification must enclosed in parentheses.  For nodes which contain text
  (such as when the |particle| style is applied), it is possible to use the
  baseline of the text inside the node to line up with the baseline of the
  equation by using |(|\meta{node}|.base)| as demonstrated in the following
  example.  Note that this key applies additional styles to make the diagram fit
  in an equation more nicely; if you do not wish to have these additional
  styles, use the |baseline| key.

  \begin{equation}
    \feynmandiagram [inline=(d.base), horizontal=d to b] {
      a -- [fermion] b -- [fermion] c,
      b -- [boson] d [particle=\(\gamma\)],
    };
    = i g_{e} \gamma^{\mu}
  \end{equation}

\begin{codeexample}[execute code=false]
\begin{equation}
  \feynmandiagram [inline=(d.base), horizontal=d to b] {
    a -- [fermion] b -- [fermion] c,
    b -- [boson] d [particle=\(\gamma\)],
  };
  = i g_{e} \gamma^{\mu}
\end{equation}
\end{codeexample}
\end{stylekey}

\begin{key}{/tikz/baseline=\meta{node}}
  Changes the vertical alignment of the Feynman diagram such that it diagram's
  baseline is at the node specified.  This works in the same was as
  |inline=|\meta{node}, but it does not apply any additional styles (notice how
  the following example is larger than the one above).
  \begin{equation}
    \feynmandiagram [baseline=(d.base), horizontal=d to b] {
      a -- [fermion] b -- [fermion] c,
      b -- [boson] d [particle=\(\gamma\)],
    };
    = i g_{e} \gamma^{\mu}
  \end{equation}

\begin{codeexample}[execute code=false]
\begin{equation}
  \feynmandiagram [baseline=(d.base), horizontal=d to b] {
    a -- [fermion] b -- [fermion] c,
    b -- [boson] d [particle=\(\gamma\)],
  };
  = i g_{e} \gamma^{\mu}
\end{equation}
\end{codeexample}
\end{key}

\begin{keylist}{%
    /graph drawing/horizontal=\meta{node} to \meta{node},
    /graph drawing/horizontal'=\meta{node} to \meta{node},
    /graph drawing/vertical=\meta{node} to \meta{node},
    /graph drawing/vertical'=\meta{node} to \meta{node}}
  The underlying algorithm will arrange all the nodes relative to each other,
  but beyond that it has no idea how the overall graph should be oriented.
  By using one of the above keys, the final output of the algorithm is oriented
  and/or mirrored such that the two nodes specified are on the same horizontal
  (or vertical) line.  The two nodes need not actually be connected by an edge
  for this to work.

  The two \meta{node} specifications should \emph{not} be enclosed in
  parentheses, unlike the |inline| and |baseline| keys.

  The |horizontal'| and |vertical'| keys work in the same was as |horizontal|
  and |vertical|, but with a flip.

\begin{codeexample}[]
\feynmandiagram [inline=(b), horizontal=a to b, red] {
  a -- b -- {c [particle=\(c\)], d [particle=\(d\)]}
};
\feynmandiagram [inline=(b), horizontal'=a to b, blue] {
  a -- b -- {c [particle=\(c\)], d [particle=\(d\)]}
};
\feynmandiagram [inline=(b), vertical=a to b, green!40!black] {
  a -- b -- {c [particle=\(c\)], d [particle=\(d\)]}
};
\feynmandiagram [inline=(b), vertical=b to a, black] {
  a -- b -- {c [particle=\(c\)], d [particle=\(d\)]}
};
\end{codeexample}
\end{keylist}

\subsubsection{Diagram Keys}
\label{subsubsec:diagram_keys}

\begin{key}{/tikzfeynman/every diagram=\meta{styles}}
  Set of styles which are applied to every diagram; that is, to everything
  inside the |\feynmandiagram|, |\diagram| and |\diagram*| commands but not the
  general |{feynman}| environment (see \cref{subsubsec:feynman_keys} for that).

\begin{codeexample}[]
\tikzfeynmanset{every diagram={red}}
\feynmandiagram [small, horizontal=d to b] {
  a -- [fermion] b -- [fermion] c,
  b -- [boson] d,
};
\end{codeexample}
\end{key}

\begin{keylist}{%
    /tikzfeynman/small,
    /tikzfeynman/medium,
    /tikzfeynman/large}
  Changes the default separation between the vertices and changes the size of
  arrows, blobs, and other shapes to fit different context.  The |small| size is
  best used with when the diagram is quite simple and doesn't have too many
  annotations (such as momentum arrows and particle labels).  The |medium| size
  is the default and is usually large enough that even diagrams with many labels
  and momentum arrows do not become too cluttered.  Finally the |large| key is
  best for large illustrations as used on the title page of this document.

\begin{codeexample}[]
\feynmandiagram [baseline=(b), small, horizontal=d to b, red] {
  a -- [fermion] b -- [fermion] c,
  b -- [boson] d,
};
\feynmandiagram [baseline=(b), medium, horizontal=d to b, green!40!black] {
  a -- [fermion] b -- [fermion] c,
  b -- [boson] d,
};
\feynmandiagram [baseline=(b), large, horizontal=d to b, blue] {
  a -- [fermion] b -- [fermion] c,
  b -- [boson] d,
};
\end{codeexample}
\end{keylist}

There are several algorithms which are available to place the vertices which are
all provided within the |graph drawing| library from \tikzname.  Below are
listed a few of these layouts which are more relevant for drawing Feynman
diagrams.  For a more complete description of how these algorithm work, please
refer to the \pgfmanual{}.  Please note that most graph drawing algorithms are
implemented in Lua and thus require \LuaTeX{} in order to work.  If \LuaTeX{} is
not used, \tikzfeynmanname{} will default to a more rudimentary algorithm and
will warn the user instead.

\begin{key}{/graph drawing/spring layout=\opt{\meta{string}}}
  Uses Hu's spring layout \cite{hu2005} as implemented by Pohlmann
  \cite{pohlmann2011}.  This models each edge as springs and attempts to spread
  everything out as much as possible.  This is the default layout.

\begin{codeexample}[]
\feynmandiagram [nodes=circle, small, horizontal=c to d] {
  {a, b} -- c -- d -- {e, f},
};
\end{codeexample}
\end{key}

\begin{key}{/graph drawing/spring electrical layout=\opt{\meta{string}}}
  Uses Hu's spring electrical layout \cite{hu2005} as implemented by Pohlmann
  \cite{pohlmann2011}.  This models each edge as springs and gives each vertex a
  charge.  This algorithm allows for the charge of a particular vertex to be
  adjusted using the |electric charge| key (the default is |1|).

\begin{codeexample}[]
\feynmandiagram [nodes=circle,
    small, horizontal=c to d,
    spring electrical layout
  ] {
  {a, b [electric charge=2]} -- c -- d -- {e, f [electric charge=0.1]},
};
\end{codeexample}
\end{key}

\begin{key}{/graph drawing/layered layout=\opt{\meta{string}}}
  Uses the Sugiyama layout algorithm \cite{eades1991} as implemented by Pohlmann
  \cite{pohlmann2011} in order to place the node.

  When an edge is specified, the first vertex is always located on the layer
  above the second vertex.  This creates a hierarchy of vertices which is
  particularly useful for decays.

  Two vertices can be forced to be on the same layer with the
  |/graph drawing/same layer| key.

\begin{codeexample}[]
\feynmandiagram [nodes=circle, small, horizontal=a to b, layered layout] {
  a -- b -- {c, d -- {e, f}},
};
\end{codeexample}
\begin{codeexample}[]
\feynmandiagram [nodes=circle, small, horizontal=a to b, layered layout] {
  a -- b -- {c -- {c1, c2}, d -- {d1, d2}},
  {[same layer] c1, d},
};
\end{codeexample}
\end{key}

\begin{key}{/graph drawing/tree layout=\opt{\meta{string}}}
  Uses the Reingold--Tilform algorithm in order to place the node.  This works
  in a similar way to the layered layout, but has quite a lot of additional
  options to handle missing children in the tree.  Please refer to the
  \pgfmanual{} for a thorough description of these additional features.

  When an edge is specified, the first vertex is always located on the layer
  above the second vertex.  This creates a hierarchy of vertices which is
  particularly useful for decays.

\begin{codeexample}[]
\feynmandiagram [nodes=circle, small, horizontal=a to b, tree layout] {
  a -- b -- {c, d -- {e, f}},
};
\end{codeexample}
\begin{codeexample}[]
\feynmandiagram [nodes=circle, small, horizontal=a to b, tree layout] {
  a -- b -- {c -- {c1, c2}, d -- {d1, d2}},
};
\end{codeexample}
\end{key}

\begin{keylist}{%
  /tikz/graphs/edges=\meta{options},
  /tikz/graphs/nodes=\meta{options}}
  Just like it is possible to change the shape of every vertex or edge in the
  whole document, it is also possible to change the shape of every vertex or
  edge in a single diagram by modifying these keys and adding the desired
  styles.
\end{keylist}

\subsubsection{Vertex Keys}
\label{subsubsec:vertex_keys}

\begin{key}{/tikzfeynman/vertex}
  The default, base style applied to every vertex initially.  Other styles
  are subsequently added.  This sets the vertex |shape| to be a |coordinate|,
  that is, a null shape with no size or width.
\end{key}

\begin{key}{/tikzfeynman/every \meta{vertex shape}=\meta{styles}}
  The style of specific vertices can be modified by changing the appropriate
  |every |\meta{vertex shape} key.  For example, in order to change the style of
  every |dot|-styled vertex, you can modify the |every dot| key, or to modify
  every vertex globally, the |every vertex| key can be modified.

\begin{codeexample}[]
\tikzfeynmanset{
  every vertex={red, dot},
  every particle={blue},
  every blob={draw=green!40!black, pattern color=green!40!black},
}
\feynmandiagram [horizontal=a to b] {
  a [particle={\(\gamma, Z\)}] -- [boson] b [blob],
  c -- [fermion] b -- [fermion] d,
};
\end{codeexample}
\end{key}

\begin{key}{/tikzfeynman/dot}
  Modifies the vertex so that it has a small filled circle.

\begin{codeexample}[]
\feynmandiagram [small] {
  a -- b [dot] -- {c, d}
};
\end{codeexample}
\end{key}

\begin{key}{/tikzfeynman/square dot}
  Modifies the vertex so that it has a small filled square.

\begin{codeexample}[]
\feynmandiagram [small] {
  a -- b [square dot] -- {c, d}
};
\end{codeexample}
\end{key}

\begin{key}{/tikzfeynman/empty dot}
  Modifies the vertex so that it has a small empty circle.

\begin{codeexample}[]
\feynmandiagram [small] {
  a -- b [empty dot] -- {c, d}
};
\end{codeexample}
\end{key}

\begin{key}{/tikzfeynman/crossed dot}
  Modifies the vertex so that it has a small circle with a cross inside.

\begin{codeexample}[]
\feynmandiagram [small] {
  a -- b [crossed dot] -- {c, d}
};
\end{codeexample}
\end{key}

\begin{key}{/tikzfeynman/blob}
  Modifies the vertex so that it is a large blob, usually used to denote an
  effective operator.

\begin{codeexample}[]
\feynmandiagram [small] {
  a -- b [blob] -- {c, d}
};
\end{codeexample}
\end{key}

\begin{key}{/tikzfeynman/particle=\meta{name}}
  Modifies the vertex so that it shows \meta{name}.  This is intended to label
  initial and final particles, but it should not be used on internal vertices as
  it will result in the lines at the vertex having a gap.  For propagators (the
  |edge label| key is much more appropriate).

  Note that if \meta{name} contains characters such as brackets (|[]|) or
  commas (|,|), the whole \meta{name} has to be enclosed in braces (|{}|);
  otherwise, the parser will interpret the comma as the end of the \meta{name}
  and the start of the next key, or the closing bracket as the end of all
  optional arguments.

\begin{codeexample}[]
\feynmandiagram [small, horizontal=a to b] {
  a [particle={\(\gamma, Z\)}] -- [boson] b -- {c, d},
};
\end{codeexample}
\end{key}


\subsubsection{Edge Keys}
\label{subsubsec:edge_keys}

Just like with the various vertex keys, each edge type has a corresponding
|every |\meta{edge type}; however, due to the existence of very similar keys
such as |scalar|, |charged scalar| and |anti charged scalar|, more specific keys
inherit styles from less specific ones.  For example, styles in |every scalar|
will apply to |charged scalar| and |anti charged scalar|.

The edge styles do not override each other and instead stack.  This means that
an edge styled with both |boson| and |fermion| will consist of a straight line
with a wavy line on top and an error.  If not styles are provided, then a simple
solid line is drawn.

\begin{key}{/tikzfeynman/every edge=\meta{styles}}
  A style to apply to every edge initially.
\end{key}

\begin{stylekey}{/tikzfeynman/every \meta{edge style}=\meta{styles}}
  The style of specific edges can be modified by changing the appropriate
  |every |\meta{edge style} key.  For example, in order to make a global change
  to every |boson|, you can modify the |every boson| key.

\begin{codeexample}[]
\tikzfeynmanset{
  every edge={green},
  every boson={red},
  every photon={blue},
}
\feynmandiagram [small] {
  a [particle=\(a\)] -- [boson] o -- [photon] b [particle=\(b\)],
  f1 [particle=\(c\)] -- [fermion] o -- [scalar] f2 [particle=\(d\)],
};
\end{codeexample}
\end{stylekey}

\begin{key}{/tikzfeynman/plain}
  Draws a simple solid line.  This style is identical to the default style
  applied if no other style is used, but is provided so that it can be combined
  with other styles.

\begin{codeexample}[]
\feynmandiagram [horizontal=a to b] {a -- [plain] b};
\feynmandiagram [horizontal=a to b] {a -- [plain, gluon] b};
\end{codeexample}
\end{key}

\begin{key}{/tikzfeynman/boson}
  Draws a sinusoidal line to denote a boson.

\begin{codeexample}[]
\feynmandiagram [horizontal=a to b] {a -- [boson] b};
\end{codeexample}
\end{key}

\begin{key}{/tikzfeynman/charged boson}
  Draws a sinusoidal line with an arrow to denote a charged boson.

\begin{codeexample}[]
\feynmandiagram [horizontal=a to b] {a -- [charged boson] b};
\end{codeexample}
\end{key}

\begin{key}{/tikzfeynman/anti charged boson}
  Draws a sinusoidal line with an arrow pointing the other way to to denote a
  anti charged boson.

\begin{codeexample}[]
\feynmandiagram [horizontal=a to b] {a -- [anti charged boson] b};
\end{codeexample}
\end{key}

\begin{key}{/tikzfeynman/photon}
  Draws a sinusoidal line to denote a photon.

\begin{codeexample}[]
\feynmandiagram [horizontal=a to b] {a -- [photon] b};
\end{codeexample}
\end{key}

\begin{key}{/tikzfeynman/scalar}
  Draws a dashed line to denote a scalar.

\begin{codeexample}[]
\feynmandiagram [horizontal=a to b] {a -- [scalar] b};
\end{codeexample}
\end{key}

\begin{key}{/tikzfeynman/charged scalar}
  Draws a dashed line with an arrow to denote a charged scalar.

\begin{codeexample}[]
\feynmandiagram [horizontal=a to b] {a -- [charged scalar] b};
\end{codeexample}
\end{key}

\begin{key}{/tikzfeynman/anti charged scalar}
  Draws a dashed line with an arrow pointing the other way to denote a charged
  scalar antiparticle.

\begin{codeexample}[]
\feynmandiagram [horizontal=a to b] {a -- [anti charged scalar] b};
\end{codeexample}
\end{key}

\begin{key}{/tikzfeynman/ghost}
  Draws a dotted line to denote a ghost.

\begin{codeexample}[]
\feynmandiagram [horizontal=a to b] {a -- [ghost] b};
\end{codeexample}
\end{key}


\begin{key}{/tikzfeynman/fermion}
  Draws a solid line with an arrow to denote a fermion.

\begin{codeexample}[]
\feynmandiagram [horizontal=a to b] {a -- [fermion] b};
\end{codeexample}
\end{key}

\begin{key}{/tikzfeynman/anti fermion}
  Draws a solid line with an arrow pointing the other way to denote an antifermion.

\begin{codeexample}[]
\feynmandiagram [horizontal=a to b] {a -- [anti fermion] b};
\end{codeexample}
\end{key}

\begin{key}{/tikzfeynman/majorana}
  Draws a solid line with two arrows pointing to the center to denote an
  Majorana particle.

\begin{codeexample}[]
\feynmandiagram [horizontal=a to b] {a -- [majorana] b};
\end{codeexample}
\end{key}

\begin{key}{/tikzfeynman/anti majorana}
  Draws a solid line with two arrows pointing to the ends to denote a Majorana
  particle.

\begin{codeexample}[]
\feynmandiagram [horizontal=a to b] {a -- [anti majorana] b};
\end{codeexample}
\end{key}

\begin{key}{/tikzfeynman/gluon}
  Draws a coiled line to denote a gluon.

\begin{codeexample}[]
\feynmandiagram [horizontal=a to b] {a -- [gluon] b};
\end{codeexample}
\end{key}

\begin{keylist}{%
  /tikz/edge label=\meta{text},
  /tikz/edge label'=\meta{text}}
  Places a label halfway along the edge with the given text.  The primed key
  switches which side of the edge the label is placed.
\end{keylist}

\begin{key}{/tikzfeynman/insertion=\opt{\oarg{options}}\meta{distance}}
  Places an insertion (for mass or momentum insertion) along an edge.  The
  distance specifies how far along the edge the insertion should be placed such
  that |0| and |1| respectively correspond to the start and the end of the edge.

  Multiple insertions can be placed along a single edge by repeating the style
  key.

  Through the \meta{options} argument, the insertion size and style can be
  changed.

\begin{codeexample}[]
\feynmandiagram [horizontal=a to b] {a -- [insertion=0.33, insertion=0.67] b};
\end{codeexample}

  \begin{key}{/tikzfeynman/insertion/size=\meta{distance} (initially 3pt)}
    Specifies how big the insertion should be.  The length of each edge starting
    from the center will be \(\sqrt{2} \times \meta{distance}\).

\begin{codeexample}[]
\feynmandiagram [horizontal=a to b] {a -- [insertion={[size=10pt]0.4}] b};
\end{codeexample}
  \end{key}

  \begin{key}{/tikzfeynman/insertion/style=\meta{distance} (initially \normalfont empty)}
    Specifies additional styles to applying to the lines of the insertion.

\begin{codeexample}[]
\feynmandiagram [horizontal=a to b] {a -- [insertion={[style=red]0.4}] b};
\end{codeexample}
  \end{key}
\end{key}

\subsubsection{Momentum Keys}
\label{subsubsec:momentum_keys}

\begin{keylist}{%
    /tikzfeynman/momentum=\opt{\oarg{options}}\meta{text},
    /tikzfeynman/momentum'=\opt{\oarg{options}}\meta{text},
    /tikzfeynman/reversed momentum=\opt{\oarg{options}}\meta{text},
    /tikzfeynman/reversed momentum'=\opt{\oarg{options}}\meta{text},
    /tikzfeynman/rmomentum=\opt{\oarg{options}}\meta{text},
    /tikzfeynman/rmomentum'=\opt{\oarg{options}}\meta{text}}
  Places a momentum arrow on the specified edge with label given by \meta{text}.
  The primed (|'|) version place the momentum arrow on the other side of the
  edge; that is, if the momentum arrow was on the right, it will be placed on
  the left of the edge.  The |reversed momentum| and |reversed momentum'| keys
  are analogous to |momentum| and |momentum'| except that the momentum arrow
  points in the opposite direction.  Finally, the |rmomentum| and |rmomentum'|
  are aliases of |reversed momentum| and |reversed momentum'|.

  Note that due to the way the arrow is drawn, it doesn't inherit styles of the
  edge.  As a result, they have to be re-specified through \meta{options}.

\begin{codeexample}[]
\feynmandiagram [layered layout, horizontal=a to b] {
  a -- [red, fermion, edge label'=\(ab\), momentum={[arrow style=red]\(p_{ab}\)}] b
    -- [blue, photon, edge label'=\(bc\)] c
    -- [green!40!black, scalar, momentum=\(p_{cd}\)] d,
};
\end{codeexample}

\begin{codeexample}[]
\feynmandiagram [layered layout, horizontal=b to c] {
  a -- [photon, momentum=\(p\)] b
    -- [fermion, half left, looseness=1.5, momentum=\(k\)] c
    -- [fermion, half left, looseness=1.5, momentum=\(k-p\)] b,
  c -- [photon, momentum=\(p\)] d,
};
\end{codeexample}

The \meta{options} allows for the following options to customize the appearance
of the momentum arrows.  These can be either set globally with the usual
|\tikzfeynmanset|, or can be set on a individual basis through the
\meta{options} argument of the |momentum| key.  In the latter case, only the
\meta{key} in |/tikzfeynman/momentum/|\meta{key} is required.

\begin{key}{/tikzfeynman/momentum/label distance=\meta{distance} (initially 0pt)}
  Set the separation between the text and the arrow.  Note that the text is
  still surrounded by an |inner sep=0.3333em| by default so the default
  distance of |0pt| will not result in the momentum label touching the arrow.
\end{key}

\begin{key}{/tikzfeynman/momentum/arrow distance=\meta{distance} (initially 3mm)}
  Set the separation between the edge and the arrow.
\end{key}

\begin{key}{/tikzfeynman/momentum/arrow shorten=\meta{distance} (initially 0.15)}
  Specify the fraction of the total edge length by which the momentum arrow is
  shortened at each end.
\end{key}

\begin{key}{/tikzfeynman/momentum/label style=\meta{style} (initially \normalfont empty)}
  Define styles to apply to the momentum label node.
\end{key}

\begin{key}{/tikzfeynman/momentum/arrow style=\meta{style} (initially \normalfont empty)}
  Define style to apply to the momentum arrow.
\end{key}
\end{keylist}

\subsubsection{Modifier Keys}
\label{subsubsec:modifier_keys}

Modifier keys serve only to slightly modify a small feature of the edge.

\begin{keylist}{%
    /tikzfeynman/half left,
    /tikzfeynman/half right,
    /tikzfeynman/quarter left,
    /tikzfeynman/quarter right}
  Modifies the edge so that it bends left or right in such a way that it
  completes half a circle, or a quarter of a circle.

\begin{codeexample}[]
\feynmandiagram [horizontal=a to b] {
  a -- [red, fermion, half left] b -- [blue, fermion, half left] a,
};
\end{codeexample}

\begin{codeexample}[]
\feynmandiagram [horizontal=a to c] {
  a -- [red!0!blue, fermion, quarter left] b
    -- [red!33!blue, fermion, quarter left] c
    -- [red!66!blue, fermion, quarter left] d
    -- [red!100!blue, fermion, quarter left] a,
};
\end{codeexample}
\end{keylist}

\begin{keylist}{%
  /tikz/out=\meta{angle},
  /tikz/in=\meta{angle}}
  Specifies the angle at which the edge leaves the first vertex in an edge and
  the angle at which it enters the second vertex in an edge.
\end{keylist}

\begin{key}{/tikz/relative=\opt{\meta{true or false}} (default true)}
  If |relative| is set to |false|, the angle is relative to the paper whilst when
  |relative| is set to |true|, the angle is relative to the straight line
  joining the two vertices.
\end{key}

\begin{key}{/tikz/looseness=\meta{number} (initially 1)}
  As the name suggests, this specifies how `loose' or `tight' a curve is
  connecting two vertices.
\end{key}

\clearpage
\section{Examples}
\label{sec:examples}

Below are a few diagrams which demonstrate how the package can be used in some
more practical examples..

\begin{description}
\item[Vertex Rule] \hspace*{0pt} \newline
\begin{codeexample}[]
\feynmandiagram [horizontal=a to b] {
  a [particle=\(Z\)] -- [photon, momentum=\(p_{1}\)] b,
  f1 [particle=\(\overline f\)]
     -- [fermion, rmomentum'=\(p_{3}\)] b
     -- [fermion, momentum=\(p_{2}\)] f2 [particle=\(f\)],
};
\end{codeexample}

\item[Tree Level Diagrams] \hspace*{0pt} \newline
\begin{codeexample}[]
\feynmandiagram [horizontal=a to b] {
  i1 [particle=\(e^{-}\)] -- [fermion] a -- [fermion] i2 [particle=\(e^{+}\)],
  a -- [photon, edge label=\(\gamma\)] b,
  f1 [particle=\(\mu^{-}\)] -- [fermion] b -- [fermion] f2 [particle=\(\mu^{+}\)],
};
\end{codeexample}

\begin{codeexample}[]
\feynmandiagram [vertical'=a to b] {
  i1 [particle=\(e^{-}\)]
     -- [fermion] a
     -- [fermion] f1 [particle=\(e^{-}\)],
  a -- [photon, edge label=\(\gamma\)] b,
  i2 [particle=\(e^{+}\)]
     -- [anti fermion] b
     -- [anti fermion] f2 [particle=\(e^{+}\)],
};
\end{codeexample}

\begin{codeexample}[]
\begin{tikzpicture}
  \begin{feynman}
    \diagram [vertical'=a to b] {
      i1 [particle=\(e^{-}\)]
         -- [fermion] a
         -- [draw=none] f1 [particle=\(e^{+}\)],
      a -- [photon, edge label'=\(p\)] b,
      i2 [particle=\(e^{+}\)]
         -- [anti fermion] b
         -- [draw=none] f2 [particle=\(e^{-}\)],
    };
    \diagram* {
      (a) -- [fermion] (f2),
      (b) -- [anti fermion] (f1),
    };
  \end{feynman}
\end{tikzpicture}
\end{codeexample}

\item[Loops] \hspace*{0pt} \newline
\begin{codeexample}[]
\feynmandiagram [layered layout, horizontal=b to c] {
  a -- [photon, momentum=\(p\)] b
    -- [fermion, half left, momentum=\(k\)] c
    -- [fermion, half left, momentum=\(k-p\)] b,
  c -- [photon, momentum=\(p\)] d,
};
\end{codeexample}

\begin{codeexample}[]
\feynmandiagram [layered layout, horizontal=a to b] [edges=gluon] {
  {i1, i2} -- a -- [half left] b -- [half left] a,
  b -- {f1, f2},
};
\end{codeexample}

\newpage
\item[Box Diagrams] \hspace*{0pt} \newline
\begin{codeexample}[]
\feynmandiagram [layered layout, horizontal=a to b] {
  % Draw the top and bottom lines
  i1 [particle=\(d\)]
     -- [fermion] a
     -- [photon, edge label=\(W^{-}\)] b
     -- [fermion] f1 [particle=\(\mu^{-}\)],
  i2 [particle=\(\overline s\)]
     -- [anti fermion] c
     -- [photon, edge label'=\(W^{+}\)] d
     -- [anti fermion] f2 [particle=\(\mu^{+}\)],
  % Draw the two internal fermion lines
  { [same layer] a -- [fermion,      edge label'=\(q\)] c },
  { [same layer] b -- [anti fermion, edge label=\(\nu_{\mu}\)] d},
};
\end{codeexample}

\newpage
\item[Meson decay and mixing] \hspace*{0pt} \newline
\begin{codeexample}[]
\begin{tikzpicture}
  \begin{feynman}
    \vertex (a1) {\(\overline b\)};
    \vertex[right=1.5cm of a1] (a2);
    \vertex[right=1cm of a2] (a3);
    \vertex[right=1.5cm of a3] (a4) {\(\overline u\)};

    \vertex[below=2em of a1] (b1) {\(d\)};
    \vertex[below=2em of a4] (b2) {\(d\)};

    %% See section 13.5 of PGF/TikZ manual
    \vertex at ($(a2)!0.5!(a3)!0.5cm!90:(a3)$) (d);
    %% Equivalent way to obtain (d):
    % \vertex at ($(b2)!0.5!(b3) + (0, -0.5cm)$) (d);
    \vertex[above=of a4] (c1) {\(u\)};
    \vertex[above=2em of c1] (c3) {\(\overline d\)};
    \vertex at ($(c1)!0.5!(c3) - (1cm, 0)$) (c2);

    \diagram* {
      (a4) -- [fermion] (a3) -- [fermion] (a2) -- [fermion] (a1),
      (b1) -- [fermion] (b2),
      (c3) -- [fermion, out=180, in=45] (c2) -- [fermion, out=-45, in=180] (c1),
      (a2) -- [boson, quarter left] (d) -- [boson, quarter left] (a3),
      (d) -- [boson, bend left, edge label=\(W^{+}\)] (c2),
    };

    \draw [decoration={brace}, decorate] (b1.south west) -- (a1.north west)
          node [pos=0.5, left] {\(B^{0}\)};
    \draw [decoration={brace}, decorate] (c3.north east) -- (c1.south east)
          node [pos=0.5, right] {\(\pi^{+}\)};
    \draw [decoration={brace}, decorate] (a4.north east) -- (b2.south east)
          node [pos=0.5, right] {\(\pi^{-}\)};
  \end{feynman}
\end{tikzpicture}
\end{codeexample}

\newpage
\begin{codeexample}[]
\begin{tikzpicture}
  \begin{feynman}
    \vertex (a1) {\(\overline b\)};
    \vertex[right=1cm of a1] (a2);
    \vertex[right=1cm of a2] (a3);
    \vertex[right=1cm of a3] (a4) {\(b\)};
    \vertex[right=1cm of a4] (a5);
    \vertex[right=2cm of a5] (a6) {\(u\)};

    \vertex[below=2em of a1] (b1) {\(d\)};
    \vertex[right=1cm of b1] (b2);
    \vertex[right=1cm of b2] (b3);
    \vertex[right=1cm of b3] (b4) {\(\overline d\)};
    \vertex[below=2em of a6] (b5) {\(\overline d\)};

    \vertex[above=of a6] (c1) {\(\overline u\)};
    \vertex[above=2em of c1] (c3) {\(d\)};
    \vertex at ($(c1)!0.5!(c3) - (1cm, 0)$) (c2);

    \diagram* {
      {[edges=fermion]
        (b1) -- (b2) -- (a2) -- (a1),
        (b5) -- (b4) -- (b3) -- (a3) -- (a4) -- (a5) -- (a6),
      },
      (a2) -- [boson, edge label=\(W\)] (a3),
      (b2) -- [boson, edge label'=\(W\)] (b3),

      (c1) -- [fermion, out=180, in=-45] (c2) -- [fermion, out=45, in=180] (c3),
      (a5) -- [boson, bend left, edge label=\(W^{-}\)] (c2),
    };

    \draw [decoration={brace}, decorate] (b1.south west) -- (a1.north west)
          node [pos=0.5, left] {\(B^{0}\)};
    \draw [decoration={brace}, decorate] (c3.north east) -- (c1.south east)
          node [pos=0.5, right] {\(\pi^{-}\)};
    \draw [decoration={brace}, decorate] (a6.north east) -- (b5.south east)
          node [pos=0.5, right] {\(\pi^{+}\)};
  \end{feynman}
\end{tikzpicture}
\end{codeexample}

\newpage
\begin{codeexample}[]
\begin{tikzpicture}
  \begin{feynman}
    \vertex (a1) {\(\overline b\)};
    \vertex[right=2cm of a1] (a2);
    \vertex[right=0.5cm of a2] (a3);
    \vertex[right=0.5cm of a3] (a4);
    \vertex[right=2cm of a4] (a5) {\(\overline s\)};

    \vertex[below=2cm of a1] (b1) {\(d\)};
    \vertex[below=2cm of a5] (b2) {\(d\)};

    \vertex[below=1.5em of a5] (c1) {\(s\)};
    \vertex[above=1.5em of b2] (c3) {\(\overline s\)};
    \vertex at ($(c1)!0.5!(c3) - (1cm, 0)$) (c2);

    \diagram* {
      {[edges=fermion]
        (a5) -- (a4) -- (a3) -- (a2) -- (a1),
      },
      (b1) -- [fermion] (b2),
      (c3) -- [fermion, out=180, in=-60] (c2) -- [fermion, out=60, in=180] (c1),
      (a3) -- [gluon, bend right] (c2),
      (a4) -- [boson, out=90, in=90, looseness=2.0, edge label'=\(W^{+}\)] (a2)
    };

    \draw [decoration={brace}, decorate] (b1.south west) -- (a1.north west)
          node [pos=0.5, left] {\(B^{0}\)};
    \draw [decoration={brace}, decorate] (a5.north east) -- (c1.south east)
          node [pos=0.5, right] {\(\phi\)};
    \draw [decoration={brace}, decorate] (c3.north east) -- (b2.south east)
          node [pos=0.5, right] {\(K^{0}\)};
  \end{feynman}
\end{tikzpicture}
\end{codeexample}

\end{description}

%% Index
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\clearpage
\printindex

%% Bibliography (and acknowledgements)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\clearpage
\pagestyle{plain}

\ifarxiv
\acknowledgements
\fi

\printbibliography

\end{document}

%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% End: