-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfeynmf.mf
1981 lines (1981 loc) · 56 KB
/
feynmf.mf
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
%%
%% This is file `feynmf.mf',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% feynmf.dtx (with options: `base')
%%
%% Copyright (C) 1989, 1990, 1992-1995 by [email protected]
%%
%% This file is NOT the source for feynmf, because almost all comments
%% have been stripped from it. It is NOT the preferred form of feynmf
%% for making modifications to it.
%%
%% Therefore you can NOT redistribute and/or modify THIS file. You can
%% however redistribute the complete source (feynmf.dtx and feynmf.ins)
%% and/or modify it under the terms of the GNU General Public License as
%% published by the Free Software Foundation; either version 2, or (at
%% your option) any later version.
%%
%% As a special exception, you can redistribute parts of this file for
%% the electronic distribution of scientific papers, provided that you
%% include a short note pointing to the complete source.
%%
%% Feynmf 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.
%%
%% You should have received a copy of the GNU General Public License
%% along with this program; if not, write to the Free Software
%% Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% \CheckSum{924}
%% \CharacterTable
%% {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%% Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%% Digits \0\1\2\3\4\5\6\7\8\9
%% Exclamation \! Double quote \" Hash (number) \#
%% Dollar \$ Percent \% Ampersand \&
%% Acute accent \' Left paren \( Right paren \)
%% Asterisk \* Plus \+ Comma \,
%% Minus \- Point \. Solidus \/
%% Colon \: Semicolon \; Less than \<
%% Equals \= Greater than \> Question mark \?
%% Commercial at \@ Left bracket \[ Backslash \\
%% Right bracket \] Circumflex \^ Underscore \_
%% Grave accent \` Left brace \{ Vertical bar \|
%% Right brace \} Tilde \~}
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
def subgraph (expr x, y, wd, ht) =
begingroup
save c, ne, nw, sw, se;
pair c, ne, nw, sw, se;
sw = (x,y);
se = sw + (wd,0);
nw = sw + (0,ht);
ne = sw + (wd,ht);
c = .5[sw,ne];
enddef;
def endsubgraph =
endgroup
enddef;
if known cmbase:
errhelp
"feynmf will only work with plain Metafont, as described in the book.";
errmessage "feynmf: CMBASE detected. Please use the PLAIN base.";
forever:
errmessage "No use in trying! You'd better eXit now ...";
errorstopmode;
endfor
fi
vardef parse_RCS (suffix RCS) (expr s) =
save n, c;
numeric n, RCS[];
string c;
RCS[0] := 0;
for n = 1 upto length (s):
c := substring (n-1,n) of s;
exitif ((RCS[0] > 0) and (c = " "));
if ((c = "0") or (c = "1") or (c = "2")
or (c = "3") or (c = "4") or (c = "5")
or (c = "6") or (c = "7") or (c = "8")
or (c = "9")):
if RCS[0] = 0:
RCS[0] := 1;
RCS[RCS[0]] := 0;
fi
RCS[RCS[0]] := 10 * RCS[RCS[0]] + scantokens (c);
elseif c = ".":
RCS[0] := RCS[0] + 1;
RCS[RCS[0]] := 0;
else:
fi
endfor
enddef;
vardef require_RCS_revision expr s =
save n, TeX_rev, mf_rev;
numeric n;
parse_RCS (TeX_rev, s);
parse_RCS (mf_rev, "$Revision: 1.30 $");
for n = 1 upto min (2, TeX_rev[0], mf_rev[0]):
if TeX_rev[n] > mf_rev[n]:
errhelp
"Your version of `feynmf.sty' is higher that of your `feynmf.mf'.";
errmessage "feynmf: Metafont macros out of date";
elseif TeX_rev[n] < mf_rev[n]:
errhelp
"Your version of `feynmf.mf' is higher that of your `feynmf.sty'.";
errmessage "feynmf: LaTeX style out of date";
fi
exitif (TeX_rev[n] <> mf_rev[n]);
endfor
enddef;
mode_setup;
boolean feynmfwizard;
feynmfwizard := false;
thin# := 1pt#; % dimension of the lines
thick# := 2thin#;
arrow_len# := 4mm#;
arrow_ang := 15;
curly_len# := 3mm#;
dash_len# := 3mm#; % 'photon' lines
dot_len# := 2mm#; % 'photon' lines
wiggly_len# := 4mm#; % 'photon' lines
wiggly_slope := 60;
zigzag_len# := 2mm#;
zigzag_width# := 2thick#;
decor_size# := 5mm#;
dot_size# := 2thick#;
define_blacker_pixels (thick, thin,
dash_len, dot_len, wiggly_len, curly_len,
zigzag_len, zigzag_width, arrow_len, decor_size, dot_size);
def shrink expr s =
begingroup
if shrinkables <> "":
save tmp_;
forsuffixes $ = scantokens shrinkables:
if known $.#:
tmp_ := $.#;
save $;
$.# := s * tmp_;
define_blacker_pixels ($);
else:
tmp_ := $;
save $;
$ := s * tmp_;
fi
endfor
fi
enddef;
def endshrink =
endgroup
enddef;
string shrinkables;
shrinkables := "";
vardef addto_shrinkables (text l) =
forsuffixes $ = l:
shrinkables := shrinkables & "," & str $;
endfor
enddef;
shrinkables := "thick,thin";
addto_shrinkables (dash_len, dot_len);
addto_shrinkables (wiggly_len, curly_len);
addto_shrinkables (zigzag_len, zigzag_width);
addto_shrinkables (arrow_len);
addto_shrinkables (decor_size, dot_size);
LaTeX_unitlength := mm;
vardef count (text list) =
forsuffixes $ = list: + 1 endfor
enddef;
vardef getopt (suffix opt) (expr s) =
save n, argp, escape, anchor, skip;
numeric opt.first, opt.last, n, anchor;
string opt[], opt[]arg;
boolean opt[]tainted, argp, escape, skip;
opt.first := 0;
opt.last := 0;
opt[opt.last] := "";
argp := false;
escape := false;
anchor := 0;
skip := true;
for n = 1 upto length (s):
if skip and (substring (n-1, n) of s = " "):
anchor := anchor + 1;
else:
skip := false;
if not escape and (substring (n-1, n) of s = ","):
if substring (n, n+1) of s = ",":
escape := true;
opt[opt.last]tainted := true;
else:
if argp:
opt[opt.last]arg := substring (anchor, n-1) of s;
else:
opt[opt.last] := substring (anchor, n-1) of s;
fi
anchor := n;
argp := false;
skip := true;
opt.last := opt.last + 1;
fi
elseif not argp and (substring (n-1, n) of s = "="):
opt[opt.last] := substring (anchor, n-1) of s;
anchor := n;
argp := true;
skip := true;
elseif argp or (substring (n-1, n) of s <> " "):
escape := false;
fi
fi
endfor
if argp:
opt[opt.last]arg := substring (anchor, length s) of s;
else:
opt[opt.last] := substring (anchor, length s) of s;
fi
for n = opt.first upto opt.last:
if known opt[n]tainted:
if opt[n]tainted:
opt[n]arg := untaint_string opt[n]arg;
fi
fi
endfor
enddef;
vardef untaint_string suffix s =
save n, anchor;
numeric n, anchor;
anchor := 0;
for n = 1 upto length (s) - 1:
if substring (n-1,n+1) of s = ",,":
substring (anchor, n-1) of s &
hide (anchor := n)
fi
endfor
substring (anchor, length s) of s
enddef;
vardef split_string (suffix comp) (expr s) =
save n, anchor;
numeric comp.first, comp.last, n, anchor;
string comp[];
comp.first := 0;
comp.last := 0;
comp[comp.last] := "";
anchor := 0;
for n = 1 upto length (s):
if substring (n-1,n) of s = ".":
comp[comp.last] := substring (anchor, n-1) of s;
comp.last := comp.last + 1;
anchor := n;
fi
endfor
comp[comp.last] := substring (anchor, length s) of s;
enddef;
vardef match_prefix (expr prefix, s) =
(prefix = substring (0, length prefix) of s)
enddef;
vardef match_option (expr s, option) =
save sc, optionc, n, i;
numeric sc.first, sc.last, optionc.first, optionc.last;
string sc[], optionc[];
numeric n, i;
split_string (sc, s);
split_string (optionc, option);
n := sc.last - sc.first;
if n <> (optionc.last - optionc.first):
false
else:
true
for i = 0 upto n:
and match_prefix (sc[sc.first+i],
optionc[optionc.first+i])
endfor
fi
enddef;
def save_picture text t =
save t; picture t; forsuffixes p=t: p:=nullpicture; endfor
enddef;
def begin_sketch =
begingroup save_picture currentpicture;
sketchlevel := sketchlevel+1;
enddef;
def end_sketch =
sketchlevel := sketchlevel-1;
sketchpad[sketchlevel] := currentpicture;
endgroup
enddef;
picture sketchpad[];
sketchlevel := 1;
vardef use_sketch text t =
addto currentpicture also (sketchpad[sketchlevel] t)
enddef;
vardef cdraw expr p =
draw p
enddef;
vardef cfill expr p =
fill p
enddef;
vardef cfilldraw expr p =
filldraw p
enddef;
vardef ccutdraw expr p =
interim autorounding := 0;
cutdraw p
enddef;
vardef cdrawdot expr p =
drawdot p
enddef;
vardef isdigit expr s =
save n;
(s = "0")
for n = 1 upto 9:
or (s = decimal n)
endfor
enddef;
vardef digits_index (expr s, start) =
save n, m, from, to;
for n = start upto (length s)-1:
if isdigit (substring (n,n+1) of s):
from := n;
for m = n upto length s:
if not isdigit (substring (m,m+1) of s):
to := m;
fi
exitif known to;
endfor
fi
exitif known from;
endfor
(from, if known to: to else: infinity fi)
enddef;
vardef digits_to_brackets suffix suf =
save s, idx;
string s;
pair idx;
s = str suf;
idx = (0,0);
forever:
idx := digits_index (s, xpart idx);
exitif unknown xpart idx;
s := substring (0,xpart idx) of s
& "[]" & substring (ypart idx,infinity) of s;
endfor
s
enddef;
tile_grain := 1in/300;
vardef def_tile (suffix t) (expr wd, ht) =
if not picture tlist.t:
picture tlist.scantokens (digits_to_brackets t);
fi
tlist.t := nullpicture;
tlist.t.dx := max (floor wd, 1);
tlist.t.dy := max (floor ht, 1);
enddef;
vardef use_tile (suffix t) (expr x, y, wd, ht) =
if (picture tlist.t):
for nx = 0 upto wd/tlist.t.dx:
for ny = 0 upto ht/tlist.t.dy:
addto currentpicture
also (tlist.t shifted
((x,y) + (nx*tlist.t.dx, ny*tlist.t.dy)) t_);
endfor
endfor
else:
errhelp "feynmf: your tiling has not been defined, "
& "check spelling and reprocess!";
errmessage "feynmf: tiling `" & str t & "' not known, "
& "replaced by `shaded'";
use_tile (shaded, x, y, wd, ht);
fi
enddef;
vardef shade_rectangle (expr dd, x, y, wd, ht) =
save d, u, dx, dy, currentpen;
pen currentpen;
pickup pencircle scaled thin;
d := max (floor (abs dd), 1);
dx := max (wd, ht);
dy := max (wd, ht);
for u = 0 step d/dx until 1:
if dd > 0:
cdraw (x-d,y+u*dy-d)--(x+(1-u)*dx+d,y+dy+d);
cdraw (x+u*dx-d,y-d)--(x+dx+d,y+(1-u)*dy+d);
else:
cdraw (x-d,y+u*dy+d)--(x+u*dx+d,y-d);
cdraw (x+(1-u)*dx-d,y+dy+d)--(x+dx+d,y+(1-u)*dy-d);
fi
endfor
enddef;
def addto_tile (suffix t) =
addto tlist.t
enddef;
vardef tile_from_string (suffix t) (expr str) =
tile_grain := max (floor tile_grain, 1);
save grain, mx, x, y, n, c, pic;
string c;
picture pic;
pic := nullpicture;
grain := tile_grain;
mx := 0;
x := 0;
y := 0;
for n := 1 upto length str:
c := substring (n-1,n) of str;
if c = "/":
mx := max (mx, x);
y := y+1;
x := 0;
elseif c = "*":
addto pic also (unitpixel shifted (x,-y) t_);
x := x+1;
elseif c = ".":
x := x+1;
fi
endfor
def_tile (t, grain*mx, grain*(y+1));
addto_tile (t) also (pic shifted (0,y) scaled grain t_);
pic := nullpicture;
enddef;
tile_from_string (gray10,
" ... /"&
" .*. /"&
" ... ");
tile_from_string (gray25,
" .. /"&
" *. ");
tile_from_string (gray50,
" .* /"&
" *. ");
tile_from_string (gray75,
" ** /"&
" .* ");
tile_from_string (gray90,
" *** /"&
" *.* /"&
" *** ");
def_tile (shaded, 4thin, 4thin);
pickup pencircle scaled thin;
begin_sketch
save dx, dy;
(dx,dy) = (tlist.shaded.dx,tlist.shaded.dy);
shade_rectangle (dx, 0, 0, dx, dy);
cullit;
fill unitsquare xscaled dx yscaled dy;
cull currentpicture keeping (2,infinity);
tlist.shaded := currentpicture;
end_sketch;
def_tile (hatched, 5thin, 5thin);
begin_sketch
save dx, dy;
(dx,dy) = (tlist.hatched.dx,tlist.hatched.dy);
shade_rectangle (dx, 0, 0, dx, dy);
shade_rectangle (-dx, 0, 0, dx, dy);
cullit;
fill unitsquare xscaled dx yscaled dy;
cull currentpicture keeping (2,infinity);
tlist.hatched := currentpicture;
end_sketch;
vardef make_halftone (suffix t) (expr g, wd, ht) =
tile_grain := max (floor tile_grain, 1);
if (halftone_cache_g <> g)
or (halftone_cache_grain <> tile_grain)
or (halftone_cache_wd <> wd)
or (halftone_cache_ht <> ht):
halftone_cache_g := g;
halftone_cache_grain := tile_grain;
halftone_cache_wd := wd;
halftone_cache_ht := ht;
grain := tile_grain;
def_tile (t, grain*wd, grain*ht);
if g <= 0:
addto_tile (t) contour unitsquare xscaled wd yscaled ht scaled grain t_;
elseif g < 1:
save period, offset, b, w;
period := max (1/g, 1/(1-g));
offset := wd - (period * ceiling (wd/period)) mod wd;
b := 0;
w := 0;
randomseed := halftone_randomseed;
for y = 0 upto ht-1:
for x = 0 upto wd-1:
if w > g*(b+w):
addto_tile (t) also (unitpixel
shifted (floor (x + y*offset + 2*uniformdeviate period)
mod wd, y)
scaled grain t_);
b := b+1;
else:
w := w+1;
fi;
endfor
endfor
cull tlist.t keeping (1,infinity);
fi
fi
enddef;
halftone_cache_g := -1;
halftone_cache_grain := -1;
halftone_cache_wd := -1;
halftone_cache_ht := -1;
halftone_randomseed := 137;
vardef tile (suffix t) (expr p) =
save u, x, y, max_x, min_x, max_y, min_y, xx, yy;
-max_x = -max_y = min_x = min_y = infinity;
for u = 0 step 0.1 until length p:
x := xpart (point u of p);
y := ypart (point u of p);
max_x := max(max_x, x);
max_y := max(max_y, y);
min_x := min(min_x, x);
min_y := min(min_y, y);
endfor
cullit withweight 2;
use_tile (t, min_x, min_y, max_x-min_x, max_y-min_y);
fill p;
cull currentpicture keeping (2,infinity)
enddef;
vardef drawtile (suffix t) (expr p) =
tile (t, p);
cdraw p
enddef;
vardef use_halftone (expr g, x, y, wd, ht) =
make_halftone (__tmp_tile__, g, 50, 50);
use_tile (__tmp_tile__, x, y, wd, ht)
enddef;
vardef halftone (expr g, p) =
make_halftone (__tmp_tile__, g, 50, 50);
tile (__tmp_tile__, p)
enddef;
vardef drawhalftone (expr g, p) =
halftone (g, p);
cdraw p
enddef;
vardef shade expr p =
tile (shaded, p)
enddef;
vardef hatch expr p =
tile (hatched, p)
enddef;
vardef emptydraw expr p =
cullit;
unfill p;
cullit;
cdraw p;
enddef;
vardef shadedraw expr p =
cullit;
unfill p;
cullit;
shade p;
cdraw p;
enddef;
vardef hatchdraw expr p =
cullit;
unfill p;
cullit;
hatch p;
cdraw p;
enddef;
vardef marrow (expr p, frac) =
save a, t, z;
pair z;
a = angle direction frac*length(p) of p;
z = point frac*length(p) of p;
(t1,whatever) = p intersectiontimes
(halfcircle scaled 2/3arrow_len rotated (a+90) shifted z);
(t2,whatever) = p intersectiontimes
(halfcircle scaled 4/3arrow_len rotated (a-90) shifted z);
arrow_head (p, t1, t2, arrow_ang)
enddef;
vardef tarrow (expr p, frac) =
save a, t, z;
pair z;
t1 = frac*length p;
a = angle direction t1 of p;
z = point t1 of p;
(t2,whatever) = p intersectiontimes
(halfcircle scaled 2arrow_len rotated (a-90) shifted z);
arrow_head (p, t1, t2, arrow_ang)
enddef;
vardef harrow (expr p, frac) =
save a, t, z;
pair z;
t2 = frac*length p;
a = angle direction t2 of p;
z = point t2 of p;
(t1,whatever) = p intersectiontimes
(halfcircle scaled 2arrow_len rotated (a+90) shifted z);
arrow_head (p, t1, t2, arrow_ang)
enddef;
vardef arrow_head (expr p, from, to, ang) =
save tip, ap, t;
pair tip;
path ap;
t1 := from;
t2 := to;
if t1 = -1: t1 := 0; fi
if t2 = -1: t2 := infinity; fi
tip = point t2 of p;
ap = subpath (t1,t2) of p shifted -tip;
(ap rotated ang
forced_join reverse ap rotated -ang
-- cycle) shifted tip
enddef;
vardef arrow expr p =
marrow (p, .5)
enddef;
tertiarydef p forced_join q =
subpath (0, length p - 1) of p
& point (length p - 1) of p
.. controls postcontrol (length p - 1) of p
and precontrol infinity of p
.. .5[point infinity of p, point 0 of q]
.. controls postcontrol 0 of q and precontrol 1 of q
.. point 1 of q
& subpath (1, infinity) of q
enddef;
vardef cut_decors (suffix from) (expr p) (suffix to) =
subpath (if known from.decor.shape:
xpart (p intersectiontimes
(from.decor.shape scaled from.decor.size
shifted from.loc))
else:
0
fi,
if known to.decor.shape:
length p
- xpart (reverse p intersectiontimes
(to.decor.shape scaled to.decor.size
shifted to.loc))
else:
infinity
fi) of p
enddef;
vardef make_blob (expr z_arg, diameter) =
save p,currentpen; path p; pen currentpen;
pickup pencircle scaled thick;
p = fullcircle scaled diameter shifted z_arg;
shadedraw p;
enddef;
vardef draw_blob (expr z_arg, diameter) =
if sketched_blob_diameter <> diameter: % drawn lately?
begin_sketch make_blob (origin, diameter); end_sketch; % redo hard work!
sketched_blob_diameter:= diameter; % record it
fi
use_sketch shifted z_arg; % the easy way ...
enddef;
def force_new_blob = sketched_blob_diameter := -1; enddef;
force_new_blob; % initialize it.
vardef pixlen (expr p, n) =
for k=1 upto length(p): + segment_pixlen (subpath (k-1,k) of p, n) endfor
enddef;
vardef segment_pixlen (expr p, n) =
for k=1 upto n: + abs (point k/n of p - point (k-1)/n of p) endfor
enddef;
vardef wiggly expr p_arg =
save wpp;
numeric wpp;
wpp = ceiling (pixlen (p_arg, 10) / wiggly_len) / length p_arg;
for k=0 upto wpp*length(p_arg) - 1:
point k/wpp of p_arg
{direction k/wpp of p_arg rotated wiggly_slope} ..
point (k+.5)/wpp of p_arg
{direction (k+.5)/wpp of p_arg rotated - wiggly_slope} ..
endfor
if cycle p_arg: cycle else: point infinity of p_arg fi
enddef;
vardef curly expr p =
save cpp;
numeric cpp;
cpp := ceiling (pixlen (p, 10) / curly_len) / length p;
if cycle p:
for k=0 upto cpp*length(p) - 1:
point (k+.33)/cpp of p
{direction (k+.33)/cpp of p rotated 90} ..
point (k-.33)/cpp of p
{direction (k-.33)/cpp of p rotated -90} ..
endfor
cycle
else:
point 0 of p
{direction 0 of p rotated -90} ..
for k=1 upto cpp*length(p) - 1:
point (k+.33)/cpp of p
{direction (k+.33)/cpp of p rotated 90} ..
point (k-.33)/cpp of p
{direction (k-.33)/cpp of p rotated -90} ..
endfor
point infinity of p
{direction infinity of p rotated 90}
fi
enddef;
vardef zigzag expr p =
save zpp;
numeric zpp;
zpp = ceiling (pixlen (p, 10) / zigzag_len) / length p;
if not cycle p:
point 0 of p --
fi
for k = 0 upto zpp*length(p) - 1:
point (k+1/3)/zpp of p shifted
(zigzag_width
* dir angle (direction (k+1/3)/zpp of p rotated 90)) --
point (k+2/3)/zpp of p shifted
(zigzag_width
* dir angle (direction (k+2/3)/zpp of p rotated -90)) --
endfor
if cycle p:
cycle
else:
point infinity of p
fi
enddef;
save vsty_hash;
def style_def suffix s =
vsty_hash.s := 1;
expandafter quote vardef scantokens ("draw_" & str s)
enddef;
vardef vsty_exists suffix s =
known vsty_hash.s
enddef;
vardef valid_style expr s =
expandafter vsty_exists scantokens (s)
enddef;
style_def phantom expr p =
\
enddef;
style_def phantom_arrow expr p =
cfill (arrow p);
enddef;
style_def plain expr p =
cdraw p;
enddef;
style_def plain_arrow expr p =
cdraw p;
cfill (arrow p);
enddef;
style_def dbl_plain expr p =
draw_double p;
enddef;
style_def dbl_plain_arrow expr p =
draw_double_arrow p;
enddef;
style_def wiggly expr p =
cdraw (wiggly p);
enddef;
style_def dbl_wiggly expr p =
draw_double (wiggly p);
enddef;
style_def curly expr p =
cdraw (curly p);
enddef;
style_def dbl_curly expr p =
draw_double (curly p);
enddef;
style_def zigzag expr p =
cdraw (zigzag p);
enddef;
style_def dbl_zigzag expr p =
draw_double (zigzag p);
enddef;
style_def dashes expr p =
save dpp;
numeric dpp;
dpp = ceiling (pixlen (p, 10) / dash_len) / length p;
for k=0 upto dpp*length(p) - 1:
cdraw point k/dpp of p ..
point (k+.5)/dpp of p;
endfor
enddef;
style_def dbl_dashes expr p =
save dpp;
numeric dpp;
dpp = ceiling (pixlen (p, 10) / dash_len) / length p;
for k=0 upto dpp*length(p) - 1:
draw_double point k/dpp of p ..
point (k+.5)/dpp of p;
endfor
enddef;
style_def dbl_dashes_arrow expr p =
draw_dbl_dashes p;
shrink (1.5);
cfill (arrow p);
endshrink;
enddef;
style_def dashes_arrow expr p =
draw_dashes p;
cfill (arrow p);
enddef;
style_def dots expr p =
save dpp;
numeric dpp;
dpp = ceiling (pixlen (p, 10) / dot_len) / length p;
for k=0 upto dpp*length(p):
cdrawdot point k/dpp of p;
endfor
enddef;
style_def dbl_dots expr p =
save dpp;
numeric dpp;
dpp = ceiling (pixlen (p, 10) / dot_len) / length p;
begingroup
save oldpen;
pen oldpen;
oldpen := currentpen;
pickup oldpen scaled 3; % draw a thick linn
for k=0 upto dpp*length(p):
cdrawdot point k/dpp of p;
endfor
pickup oldpen;
cullit;
for k=0 upto dpp*length(p):
undrawdot point k/dpp of p;
endfor
cullit; % and remove the stuffing
endgroup;
enddef;
style_def dbl_dots_arrow expr p =
draw_dbl_dots p;
shrink (1.5);
cfill (arrow p);
endshrink;
enddef;
style_def dots_arrow expr p =
draw_dots p;
cfill (arrow p);
enddef;
style_def double expr p =
save oldpen;
pen oldpen;
oldpen := currentpen;
pickup oldpen scaled 3;
ccutdraw p;
pickup oldpen;
cullit; undraw p; cullit;
enddef;
style_def double_arrow expr p =
draw_double p;
shrink (1.5);
cfill (arrow p);
endshrink;
enddef;
style_def vanilla expr p = draw_plain p enddef;
style_def fermion expr p = draw_plain_arrow p enddef;
style_def quark expr p = draw_plain_arrow p enddef;
style_def electron expr p = draw_plain_arrow p enddef;
style_def photon expr p = draw_wiggly p enddef;
style_def boson expr p = draw_wiggly p enddef;
style_def gluon expr p = draw_curly p enddef;
style_def heavy expr p = draw_dbl_plain_arrow p enddef;
style_def ghost expr p = draw_dots_arrow p enddef;
style_def scalar expr p = draw_dashes_arrow p enddef;
vardef fermion expr path_arg =
cfill (arrow (path_arg));
path_arg
enddef;
vardef photon expr path_arg =
wiggly path_arg
enddef;
vardef gluon expr path_arg =
curly path_arg
enddef;
tracingstats:=1;
boolean vtracing;
vtracing := false; % true
def vinit =
save vhash;
numeric vlist.first, vlist.last;
vlist.first := 1;
vlist.last := 0;
pair vlist[]loc;
numeric vlist[]decor.size, vlist[]decor.ang,
vlist[]arc.first, vlist[]arc.last,
vlist[]arc[], vlist[]arc[]lsr,
vlist[]arc[]tns, vlist[]arc[]lbl.dist,
vlist[]arc[]tag, vlist[]arc[]wd, vlist[]arc[]rub,
vlist[]constr.first, vlist[]constr.last,
vlist[]constr[], lambdax[][], lambday[][];
string vlist[]name, vlist[]lbl, vlist[]decor.sty,
vlist[]arc[]sty, vlist[]arc[]lbl, vlist[]arc[]lbl.side;
numeric vlist[]lbl.ang;
path vlist[]decor.shape;
numeric plist.first, plist.last, plist[]cnt, plist[]vtx[],
plist[]pull, plist[]lbl.ang, plist[]lbl.dist;
string plist[]lbl, plist[]sty, plist[]cona, plist[]conb;
plist.first := 1;
plist.last := 0;
numeric vlist[]poly.first, vlist[]poly.last,
vlist[]poly[], vlist[]poly[]idx;
pair lambdap[][];
enddef;
def vertices =
vlist.first upto vlist.last
enddef;
def varcs (text i) =
vlist[i]arc.first upto vlist[i]arc.last
enddef;
def vconstr (text i) =
vlist[i]constr.first upto vlist[i]constr.last
enddef;
def polygons =
plist.first upto plist.last
enddef;
def vpoly (text i) =
vlist[i]poly.first upto vlist[i]poly.last
enddef;
vardef venter suffix v =
if not vexists v:
vlist.last := vlist.last + 1;
vhash.v := vlist.last;
vlist[vhash.v]name := str v;
vlist[vhash.v]loc := (whatever,whatever);
vlist[vhash.v]arc.first := 1;
vlist[vhash.v]arc.last := 0;
vlist[vhash.v]constr.first := 1;
vlist[vhash.v]constr.last := 0;
vlist[vhash.v]lbl := "";
vlist[vhash.v]lbl.ang := whatever;
vlist[vhash.v]lbl.dist := 3thick;
vlist[vhash.v]poly.first := 1;
vlist[vhash.v]poly.last := 0;
fi
enddef;
vardef vexists suffix v =
if known vhash.v: true else: false fi
enddef;
vardef vlookup suffix v =
if vexists v: vhash.v else: 0 fi
enddef;
vardef vloc suffix v =
vlist[vlookup v]loc
enddef;
vardef vconnect (expr linesty) (text vl) =
save from, nfrom, nto, nopt, sty;
numeric from, nfrom, nto, nopt;
string sty;
getopt (opt, linesty);
sty := opt[opt.first];
if known opt[opt.first]arg:
message "feynmf: line styles don't take arguments. "
& "Argument `" & opt[opt.first]arg & "' ignored.";
fi
opt.first := opt.first + 1;
forsuffixes to = vl:
venter to;
nto := vlookup to;
if known nfrom:
vlist[nfrom]arc.last := vlist[nfrom]arc.last + 1;
vlist[nfrom]arc[vlist[nfrom]arc.last] := nto;
vlist[nfrom]arc[vlist[nfrom]arc.last]tns := 1;
if nfrom <> nto:
vlist[nto]arc.last := vlist[nto]arc.last + 1;
vlist[nto]arc[vlist[nto]arc.last] := nfrom;
vlist[nto]arc[vlist[nto]arc.last]tns := 1;
fi
vlist[nfrom]arc[vlist[nfrom]arc.last]lbl := "";
vlist[nfrom]arc[vlist[nfrom]arc.last]lbl.side := "";
vlist[nfrom]arc[vlist[nfrom]arc.last]lbl.dist := 3thick;
for nopt = opt.first upto opt.last:
if match_option (opt[nopt], "tension"):
get_argument (opt[nopt], scantokens (opt[nopt]arg),
vlist[nfrom]arc[vlist[nfrom]arc.last]tns);
get_argument (opt[nopt], scantokens (opt[nopt]arg),
vlist[nto]arc[vlist[nto]arc.last]tns);
elseif match_option (opt[nopt], "left"):
if known opt[nopt]arg:
vlist[nfrom]arc[vlist[nfrom]arc.last]lsr
:= - scantokens (opt[nopt]arg);
else:
vlist[nfrom]arc[vlist[nfrom]arc.last]lsr := -1;
fi
elseif match_option (opt[nopt], "straight"):
vlist[nfrom]arc[vlist[nfrom]arc.last]lsr := 0;
ignore_argument (opt[nopt], opt[nopt]arg);
elseif match_option (opt[nopt], "right"):
if known opt[nopt]arg:
vlist[nfrom]arc[vlist[nfrom]arc.last]lsr
:= scantokens (opt[nopt]arg);
else:
vlist[nfrom]arc[vlist[nfrom]arc.last]lsr := 1;
fi
elseif match_option (opt[nopt], "label"):
get_argument (opt[nopt], opt[nopt]arg,
vlist[nfrom]arc[vlist[nfrom]arc.last]lbl);
elseif match_option (opt[nopt], "label.side"):
get_argument (opt[nopt], opt[nopt]arg,
vlist[nfrom]arc[vlist[nfrom]arc.last]lbl.side);
elseif match_option (opt[nopt], "label.dist"):
get_argument (opt[nopt], scantokens (opt[nopt]arg),
vlist[nfrom]arc[vlist[nfrom]arc.last]lbl.dist);
elseif match_option (opt[nopt], "tag"):
if known opt[nopt]arg:
vlist[nfrom]arc[vlist[nfrom]arc.last]tag
:= scantokens (opt[nopt]arg);
else:
vlist[nfrom]arc[vlist[nfrom]arc.last]tag := 0;
fi
elseif match_option (opt[nopt], "width"):