summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/spectralsequences/sseqmain.code.tex
blob: e9d93abc8a4ee8a719156743762e90f94f90187a (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
%%
%% Package: spectralsequences v1.1.0
%% Author: Hood Chatham
%% Email: hood@mit.edu
%% Date: 2017-08-06
%% License: Latex Project Public License
%%
%% File: sseqmain.code.tex
%%
%%    Defines the main environments and commands
%%


%%%%%%%
%%%
%%%  Environment definitions
%%%
%%%%%%%
\def\sseq@usesavedpaths{%
    \sseq@savedpaths
    \sseq@clearchangestyles
    \sseq@tempsavedpaths
    \gdef\sseq@tempsavedpaths{}%
}

\sseq@addtostorelist\sseq@savedbackgroundpaths{}
\sseq@addtostorelist\sseq@restorestyles{}

\def\sseq@page{\protect\sseq@thepage}


\def\sseqdata{\@ifnextchar[{\sseqdata@}{\sseqdata@[]}}%}

\def\sseqdata@[#1]{%
    \edef\sseq@restorefont{\font@name}
    \selectfont\nullfont % Avoid space hazards!

    \def\par{}
%
    \ifx\pgfpictureid\@undefined\else %Uh-oh, we're inside tikz.
        \sseq@error@n{env-inside-tikz}{sseqdata}\@xp\sseq@breakdataenv
    \fi
    \ifsseq@inprogress % Uh-oh, we're already in a sseq environment. This is not good.
        \sseq@error@n{env-inside-sseq}{sseqdata}\@xp\sseq@breakdataenv
    \fi
    \sseq@inprogresstrue
    \def\sseq@sseqsetdirectory{/sseqpages}
    \sseq@keepchangestrue
    \sseq@storelist@setdefaults
    \let\sseq@xtickfn\@firstofone\let\sseq@ytickfn\@firstofone % These are default functions, which addtostorelist can't handle.
%
    \ifx\sseq@xmin@default\sseq@infinity
        \let\sseq@xminmax\sseq@xminmax@active
    \fi
    \ifx\sseq@ymin@default\sseq@infinity
        \let\sseq@yminmax\sseq@yminmax@active
    \fi
    \ifsseq@mathnodes
        \let\sseq@maybemathswitch=$\@gobble$
    \fi
%
    % copy commands into the user namespace.
    \sseq@installmacros
    \sseq@installmsghooks
    \sseq@install@xparse@Uarggrabber
    \def\xmin{\protect\sseq@xmin}\def\xmax{\protect\sseq@xmax}
    \def\ymin{\protect\sseq@ymin}\def\ymax{\protect\sseq@ymax}
%
    \sseq@modtikzcommands % Defer evaluation of tikz primitives
    \sseq@patchfor % patch \foreach to work with deferred macros
    \pgfkeys{/handlers/first char syntax/the character "/.initial=\sseq@handlequote} % install quotes parsing
%
%
    \pgfqkeys{/sseqpages/global/name only}{#1}
    \@ifundefined{sseq@thename}{\sseq@error{env-data-no-name}\sseq@breakdataenv}{}
    \sseq@obj@ifundef{exists}{
        \sseq@obj@gdef{exists}{}
        \pgfqkeys{/sseqpages/global}{{\sseq@thename} options/.code={}}
    }{
        \ifsseq@updateexisting\else
            \sseq@error@x{env-data-already-exist}{\sseq@thename}% this could be a warning
        \fi
        \sseq@restorestyles
        \sseq@getcmds

    }
    \sseq@setsavedpaths{standard}
%
    % the default option handler for /sseqpages/global adds to \sseq@currentoptionpath options
    \let\sseq@currentoptionpath\sseq@thename
    \pgfqkeys{/sseqpages/global}{#1}
    \ifx\sseq@targetx\pgfutil@empty\else
        \sseq@hasdegreetrue
    \fi
    \sseq@eval{
        \global\let\@xp\@nx\csname pgfk@/sseqpages/global/{\sseq@currentoptionpath} options/.@cmd\endcsname
            \@xp\@nx\csname pgfk@/sseqpages/global/{\sseq@currentoptionpath} options/.@cmd\endcsname
    }
    \sseq@savedpaths@xadd{\sseq@stylelist}
    \sseq@savedpaths@add{\begingroup} % prevent some of the two-pass user macros horrors
    \let\sseq@error@setup\sseq@error@setup@withinfo
}

% Just store all the settings
\def\endsseqdata{
    \let\sseq@error@setup\sseq@error@setup@noinfo
    \sseq@checkend{sseqdata}
    \sseq@savedpaths@add{\endgroup} % prevent some of the two-pass user macros horrors
    \xdef\sseq@restorestyles{\sseq@stylelist}
    \sseq@storecmds
    \ignorespacesafterend
    \sseq@breakpoint
}

\def\sseqpage{\@ifnextchar[{\sseqpage@}{\sseqpage@[]}} %]

\def\sseqpage@[#1]{%
    \edef\sseq@restorefont{\font@name}
    \selectfont\nullfont % Avoid space hazards!
    \def\par{}
%
    \ifx\pgfpictureid\@undefined\else %Uh-oh, we're inside tikz.
        \sseq@error@n{env-inside-tikz}{sseqpage}\@xp\sseq@breakpageenv
    \fi
    \ifsseq@inprogress % Uh-oh, we're already in a sseq environment. This is not good.
        \sseq@error@n{env-inside-sseq}{sseqpage}\@xp\sseq@breakpageenv
    \fi
    \sseq@inprogresstrue
    \sseq@ispageenvtrue
    \def\sseq@sseqsetdirectory{/sseqpages}
%
%    \ifsseq@mathnodes
%        \let\sseq@maybemathswitch=$\@gobble$
%    \fi
%
    % Copy commands into user namespace
    \sseq@installmacros
    \sseq@installmsghooks
    \sseq@install@xparse@Uarggrabber
    \def\xmin{\protect\sseq@xmin}\def\xmax{\protect\sseq@xmax}
    \def\ymin{\protect\sseq@ymin}\def\ymax{\protect\sseq@ymax}
    \sseq@modtikzcommands % Redefine tikz primitives to store themselves in the appropriate place
    \sseq@patchfor % Change foreach to record it's variable values in the appropriate places
    \pgfkeys{/handlers/first char syntax/the character "/.initial=\sseq@handlequote}% install quotes parsing
%
    \gdef\sseq@pagecleanup{}% For undoing local option settings
%
    \def\sseq@thepage{0}% page defaults to 0
    \sseq@thepagecount=\z@
    \pgfqkeys{/sseqpages/global/name only}{#1}% Get the name
    \sseq@tempiftrue
    \ifsseq@hasname
        \sseq@obj@ifundef{exists}{
            \sseq@error@x{env-page-not-exist}{\sseq@thename} % This could be a warning
            \sseq@obj@gdef{exists}{}
            \let\sseq@currentoptionpath\sseq@thename
            \pgfqkeys{/sseqpages/global}{{\sseq@thename} options/.code={}}
            \sseq@keepchangestrue
            \sseq@keepglobaloptionstrue
            \sseq@setsavedpaths{standard}
        }{
            \sseq@restorestyles
            \sseq@getcmds
            \ifsseq@keepchanges
                \sseq@setsavedpaths{standard}
            \else
                \sseq@setsavedpaths{temporary}
            \fi
            \sseq@tempiffalse
            \def\sseq@currentoptionpath{this page}
            \pgfqkeys{/sseqpages/global}{{this page} options/.code={},#1}
        }
    \else
        \edef\sseq@thename{temp@sseq@number@\the\sseq@anonsseqcount}
        \global\advance\sseq@anonsseqcount1
        \sseq@setsavedpaths{temporary}
    \fi
    \ifsseq@tempif % Either the spectral sequence has no name, or it has a name but no such existed.
        \sseq@storelist@setdefaults
        \sseq@savedpaths@xadd{\sseq@stylelist}
        \let\sseq@currentoptionpath\sseq@thename
        \pgfqkeys{/sseqpages/global}{{\sseq@thename} options/.code={},{this page} options/.code={},#1}
        \sseq@eval{
            \global\let\@xp\@nx\csname pgfk@/sseqpages/global/{\sseq@currentoptionpath} options/.@cmd\endcsname
                \@xp\@nx\csname pgfk@/sseqpages/global/{\sseq@currentoptionpath} options/.@cmd\endcsname
        }
    \fi
%
    \ifsseq@specifiedxrange
        \let\sseq@xminmax\@gobbletwo
    \else
        \let\sseq@xminmax\sseq@xminmax@active
    \fi
    \ifsseq@specifiedyrange
        \let\sseq@yminmax\@gobbletwo
    \else
        \let\sseq@yminmax\sseq@yminmax@active
    \fi
%
    \sseq@savedpaths@xadd{\sseq@stylelist}
    \sseq@savedpaths@add{\begingroup} % prevent some of the two-pass user macros horrors
    \ifx\sseq@targetx\pgfutil@empty\else
        \sseq@hasdegreetrue
    \fi
    \let\sseq@error@setup\sseq@error@setup@withinfo
}

% Here we do all of the work to actually print the page
\def\endsseqpage{
    \let\sseq@error@setup\sseq@error@setup@noinfo
    \sseq@checkend{sseqpage}
    \sseq@savedpaths@add{\endgroup} % prevent some of the two-pass user macros horrors
%
    \sseq@xscalecm=\sseq@xscale cm
    \sseq@yscalecm=\sseq@yscale cm
%
% check that range is okay
%
    \ifx\sseq@xmin\sseq@infinity\sseq@error{no-range}\def\sseq@xmin{0}\def\sseq@xmax{0}\@xp\sseq@break\fi % could be warning
    \ifx\sseq@ymin\sseq@infinity\sseq@error{no-range}\def\sseq@ymin{0}\def\sseq@ymax{0}\@xp\sseq@break\fi
%
    \ifnum\numexpr\sseq@xmax-\sseq@xmin\relax>\numexpr\maxdimen/\dimexpr1pt\relax-1\relax
        \sseq@error@xx{range-super-overflow}{x}
            {from \sseq@xmin\space to \sseq@xmax\space (xmax - xmin = \the\numexpr\sseq@xmax-\sseq@xmin)}
        \@xp\sseq@break
    \fi
    \ifnum\numexpr\sseq@ymax-\sseq@ymin\relax>\numexpr\maxdimen/\dimexpr1pt\relax-1\relax
        \sseq@error@xx{range-super-overflow}{y}
            {from \sseq@ymin\space to \sseq@ymax\space (ymax - ymin = \the\numexpr\sseq@ymax-\sseq@ymin)}
        \@xp\sseq@break
    \fi
%
    \sseq@tempdimen = \dimexpr \textwidth -\sseq@clip@padding@right - \sseq@xaxis@end@extend - \sseq@xaxis@start@extend - \sseq@yaxisgap \relax
    \sseq@tempcount = \numexpr \sseq@tempdimen /\sseq@xscalecm \relax
    \ifnum \numexpr\sseq@xmax-\sseq@xmin + 1 > \sseq@tempcount
      \pgfmathparse{\sseq@tempdimen/1cm/(\sseq@xmax-\sseq@xmin+1)}
      \sseq@error@xxxx{range-overflow}{x}
            {from \sseq@xmin\space to \sseq@xmax\space (xmax - xmin = \the\numexpr\sseq@xmax-\sseq@xmin)}
            {\the\sseq@tempcount}% max x range
            {\pgfmathresult}% max xscale
        \@xp\sseq@break
    \fi
%
    \sseq@tempdimen = \dimexpr \textheight - \sseq@clip@padding@top - \sseq@yaxis@end@extend - \sseq@yaxis@start@extend - \sseq@xaxisgap \relax
    \sseq@tempcount = \numexpr \sseq@tempdimen /\sseq@yscalecm \relax
    \ifnum \numexpr\sseq@ymax-\sseq@ymin +1 > \sseq@tempcount
        \pgfmathparse{\sseq@tempdimen/1cm/(\sseq@ymax-\sseq@ymin+1)}
        \sseq@error@xxxx{range-overflow}{y}
            {from \sseq@ymin\space to \sseq@ymax\space (ymax - ymin = \the\numexpr\sseq@ymax-\sseq@ymin)}
            {\the\sseq@tempcount}% max x range
            {\pgfmathresult}% max xscale
        \@xp\sseq@break
    \fi
%
    % Really this could be anything between -\sseq@xmin and -\sseq@xmax and it wouldn't matter. We'll split the difference.
    \sseq@xoffset=\numexpr\sseq@intdivceiling{\numexpr-\sseq@xmin-\sseq@xmax\relax}{\numexpr4*\sseq@xgridstep\relax}*(2*\sseq@xgridstep)\relax
    \sseq@yoffset=\numexpr\sseq@intdivceiling{\numexpr-\sseq@ymin-\sseq@ymax\relax}{\numexpr4*\sseq@ygridstep\relax}*(2*\sseq@ygridstep)\relax
%
%
    \tikzset{
        z=0pt,
        every path/.style={},
        every node/.style={}
    }
    \let\errmessage\sseq@errmessage@std
    \sseq@setlayoutparameters
    \begin{tikzpicture}[/sseqpages/global/{default} options,\ifsseq@hasname/sseqpages/global/{\sseq@thename} options\fi,/sseqpages/global/{this page} options]%
    \sseq@sseqstyle@globalpart
    %\pgftransformreset
    \sseq@globaldetonetransform
    \sseq@globalscaletransform
%
    \let\sseq@transform\sseq@error@illegaltransform % Disallow most coordinate transforms
    \let\sseq@shifttransform\sseq@checkshifttransform % Allow shifts as long as they are by integers and have no units.
%
    \sseq@setupclip
%
    \sseq@patchtikzcoords
%
    \pgfonlayer{background}%
    % Axes labels only occur once per page, so the cost of typesetting them with tikz doesn't matter ... THANK GOD
    \ifx\sseq@title\pgfutil@empty\else
        \ifsseq@drawtitle
            \sseq@eval{\@nx\path (0,-\sseq@yoffset) node[
                /sseqpages/global/every title,
                above=\sseq@topclippadding+5pt
                ] {\unexpanded\expandafter{\sseq@title}};
            }
        \fi
    \fi
    % Don't touch the shifts -- they are very persnickety.
    \ifx\sseq@xaxislabel\pgfutil@empty\else\ifsseq@drawxaxislabel
        \sseq@eval{\noexpand\node[
            align=center,
            /sseqpages/global/every x axis label,
            below,
            shift={\sseq@xlabelposition},
        ] {\unexpanded\expandafter{\sseq@xaxislabel}};}
    \fi\fi
    \ifx\sseq@yaxislabel\pgfutil@empty\else\ifsseq@drawyaxislabel
        \sseq@eval{\noexpand\node[
            align=center,
            /sseqpages/global/every y axis label,
            above,
            rotate=90,
            shift={\sseq@ylabelposition},
        ] {\unexpanded\expandafter{\sseq@yaxislabel}};}
    \fi\fi
%
    \sseq@grid
    \sseq@handlexaxis % Draw the axis with pgf primitives. These are defined in sseqdrawing.code.tex
    \sseq@handleyaxis
    \endpgfonlayer
%
    \ifsseq@mathnodes
        \tikzset{execute at begin node=$,execute at end node=$}%
    \fi
    %\let\sseq@error@setup\sseq@error@setup@withinfo
%
    \begingroup
    \sseq@savedbackgroundpaths
    \endgroup
%
    \sseq@useclip
%
    \ifsseq@drawdifferentials\else
        \let\sseq@differential@draw@ifpage\@gobble
    \fi
    \ifsseq@drawstructlines\else
        \let\sseq@structline@draw@ifpage\@gobble
    \fi
%
    \sseq@usesavedpaths
%
    \ifsseq@keepchanges
        \xdef\sseq@restorestyles{\sseq@stylelist}
    \fi
    \end{tikzpicture}%
    \ifsseq@keepchanges
        \sseq@storecmds   % store changes
    \else
        \sseq@pagecleanup % undo any changes specific to this page
    \fi
    \sseq@breakpoint
    \ignorespacesafterend
}

% Shorthand for sseqpage with empty body
\def\printpage[#1]{%
    \begin{sseqpage}[#1]
    \end{sseqpage}%
}

%%% Scope
\newcount\sseq@scope@savestackid
\def\sseq@scope@secondpasstoks{}
\def\sseq@scope{\@ifnextchar[{\sseq@scope@}{\sseq@scope@[]}}%]
\def\sseq@scope@[#1]{%
    \sseq@scope@savedpaths@add{\begin{scope}}%
    % This is a funky hack to fix a problem with shifts. On tmfass, if we don't handle shifts specially, we actually put so much stuff into
    % this \sseq@scope@secondpasstoks macro that we exceed TeX's upper bound for the maximum total macro memory. Or something like that -- I don't understand the error,
    % but it definitely only depends on how much stuff there is overall and on there being lots of scopes, not on any particular part of the diagram.
    % Anyways, to avoid this excessive storage demand, we don't put the shifts into the scope toks and apply them tons of times, we just do them once.
    \let\sseq@options@scopeshiftsecondpass\sseq@scope@savedpaths@add
    \sseq@processoptions{scope}{#1}% outputs into \sseq@savedoptioncode
    \edef\sseq@scope@secondpasstoks{\unexpanded\@xp{\sseq@scope@secondpasstoks}\unexpanded\@xp{\sseq@savedoptioncode}}
    \sseq@eval{\@nx\sseq@scope@savedpaths@add{\sseq@scope@toks{\unexpanded\@xp{\sseq@scope@secondpasstoks}}}}%
    %\advance\sseq@scope@savestackid\@ne
    %\sseq@savestack@name{scope@save\the\sseq@scope@savestackid}
}
\def\sseq@endscope{%
    \sseq@scope@savedpaths@add{\end{scope}}
    %\sseq@restorestack@name{scope@save\the\sseq@scope@savestackid
}




\ifsseq@draftmode % Okay, have to dummy out all the main commands.
    % Only add tikz background paths to the savedpaths. We need to draw background paths because they might change the bounding box!
    \sseq@setsavedpaths@draftmode
%
    % All we want to do here is record the range. Have to process options in order to figure out where it is.
    \sseq@DeclareDocumentCommand\class{or()}{%
        \begingroup
        \sseq@loadinputline
        \IfNoValueT{#2}{\sseq@break}%
        \sseq@xsetthiscall{\string\class\IfNoValueF{#1}{[\unexpanded{#1}]}\unexpanded{(#2)}}%
        \sseq@options@firstpassmode
        \the\sseq@sseqstyle
        \the\sseq@classstyle
        \sseq@options@normalmode
        \IfNoValueF{#1}{%
            \sseq@processoptions{class}{#1}% Outputs result into \sseq@savedoptioncode
        }%
        \sseq@cparsecoord{#2}{}%
        \sseq@xminmax{\xcoord}{\ycoord}%
        \sseq@yminmax{\xcoord}{\ycoord}%
        \sseq@pushstack@\coord % also need the class stack to calculate other \class commands.
        \sseq@cleanup@obj{partcoord.(\partialcoord).numnodes}%
        \ifnum\nodenum=\@ne
            \sseq@obj@gdef{partcoord.(\partialcoord).numnodes}{0}%
        \fi
        \sseq@obj@xdef{partcoord.(\partialcoord).numnodes}{\nodenum}%
        \edef\classname{class.\coord[0]}%
        \ifx\sseq@class@tag\pgfutil@empty\else
            \sseq@obj@ifdef{partcoord.(\partialcoord).tag.\sseq@class@tagprefix\sseq@class@tag}{%
                \sseq@error@xx{class-tag-already-defined}{\sseq@class@tagprefix\sseq@class@tag}{(\partialcoord)}% could be warning
            }{}%
            \sseq@cleanup@obj{partcoord.(\partialcoord).tag.\sseq@class@tagprefix\sseq@class@tag}%
            \sseq@obj@xdef{partcoord.(\partialcoord).tag.\sseq@class@tagprefix\sseq@class@tag}{\nodenum}%
        \fi
        \ifx\sseq@class@name\pgfutil@empty\else
            \sseq@cleanup@obj{class.\classname.name}
            \sseq@cleanup@obj{class.namedclass.\sseq@class@name}
            \sseq@namehandler
            \sseq@obj@xdef{class.\classname.name}{\sseq@class@name}
            \sseq@obj@xdef{class.namedclass.\sseq@class@name}{\coordnopar}
        \fi
        \sseq@breakpoint
        \endgroup
    }

    % Now the rest of these can be no-ops
    \sseq@DeclareDocumentCommand\classoptions{od()}{}
    \sseq@DeclareDocumentCommand\replaceclass{od()}{}
    \def\sseq@d@main#1#2#3#4#5{} % makes both \d and \doptions do nothing
    \sseq@DeclareDocumentCommand\structline{od()d()}{}
    \sseq@DeclareDocumentCommand\structlineoptions{od()d()}{}
    \sseq@DeclareDocumentCommand\circleclasses{or()r()}{}
    \endinput
\fi


\protected\def\sseq@xcoord{}\protected\def\sseq@ycoord{}

%%%%%
%%
%% The main commands
%%
%%%%%
%%% \class, \classoptions, \replaceclass
\sseq@DeclareDocumentCommand\class{or()}{%
    \begingroup
    \sseq@loadinputline
    \IfNoValueT{#2}{\sseq@break}
    \sseq@xsetthiscall{\string\class\IfNoValueF{#1}{[\unexpanded{#1}]}\unexpanded{(#2)}}%
    \sseq@options@firstpassmode
    \the\sseq@sseqstyle
    \the\sseq@classstyle
    \the\sseq@scope@toks
    \sseq@options@normalmode
    \IfNoValueF{#1}{%
        \sseq@processoptions{class}{#1}% Outputs result into \sseq@savedoptioncode
    }%
%
    \@ifundefined{sseq@class@page}{}{\sseq@error@xxx{cmdoptions-only}{page}      {\string\class}{\string\classoptions}}% could be warnings
    \@ifundefined{sseq@gen} {}{\sseq@error@xxx{cmdoptions-only}{generation}{\string\class}{\string\classoptions}}
%
    \sseq@cparsecoord{#2}{}%
    \ifnum\csname sseq@\sseq@classpattern @maxclasses\endcsname<\nodenum\relax
        \sseq@error@xxxx{classpattern-too-many-classes}{(\partialcoord)}{\nodenum}{\sseq@classpattern}{\@xp\the\csname sseq@\sseq@classpattern @maxclasses\endcsname}
        \sseq@breakfi
    \fi
%%%% No more breaks after this point
%
    \ifx\sseq@classinsert\empty
        % by default, just insert to the right of previous classes
        \edef\sseq@classinsert{\nodenum}
    \else
        \ifnum\sseq@classinsert<\z@
            % negative 1 is where we would normally insert things
            \edef\sseq@classinsert{\the\numexpr\nodenum+\sseq@classinsert+1}
        \fi
        \ifnum\sseq@classinsert<\@ne
            \def\sseq@classinsert{1}
        \fi
        \ifnum\sseq@classinsert>\nodenum\relax
            \edef\sseq@classinsert{\nodenum}
        \fi
        \ifnum\nodenum>\@ne
            \@xp\sseq@class@adjustclasses\@xp{\partialcoord} % Adjust all of the indices of the classes to the right of the one we're inserting
        \fi
    \fi
%
    \sseq@processlabels % This sets up the label nodes, now that we know the position of the class (I think that's what we needed?)
%
    \sseq@xminmax{\xcoord}{\ycoord}%
    \sseq@yminmax{\xcoord}{\ycoord}%
    \sseq@cleanup@obj{partcoord.(\partialcoord).numnodes}%
    \sseq@obj@xdef{partcoord.(\partialcoord).numnodes}{\nodenum}%
    \edef\classname{class.\coord[0]}%
    \ifx\sseq@class@tag\pgfutil@empty\else
        \sseq@obj@ifdef{partcoord.(\partialcoord).tag.\sseq@class@tagprefix\sseq@class@tag}{
            \sseq@error@xx{class-tag-already-defined}{\sseq@class@tagprefix\sseq@class@tag}{(\partialcoord)}% could be warning
        }{}
        \sseq@cleanup@obj{class.\coord.tag}
        \sseq@obj@xdef{class.\coord.tag}{\sseq@class@tagprefix\sseq@class@tag}
        \sseq@cleanup@obj{partcoord.(\partialcoord).tag.\sseq@class@tagprefix\sseq@class@tag}
        \sseq@obj@xdef{partcoord.(\partialcoord).tag.\sseq@class@tagprefix\sseq@class@tag}{\nodenum}%
    \fi
    \ifx\sseq@class@name\pgfutil@empty\else
        \sseq@cleanup@obj{class.\classname.name}
        \sseq@cleanup@obj{class.namedclass.\sseq@class@name}
        \sseq@namehandler
        \sseq@obj@xdef{class.\classname.name}{\sseq@class@name}
        \sseq@obj@xdef{class.namedclass.\sseq@class@name}{\coordnopar}
    \fi
    \ifcsname sseq@class@showname\endcsname
        \sseq@eval{\@nx\sseq@handleclassquotes{\sseq@obj{class.\classname.name}}{\sseq@class@showname}}
    \fi
    \sseq@pushstack@\coord
%
%
    \sseq@obj@gdef{class.\coord.num}{0}% For \replaceclass
    \sseq@obj@xdef{\classname.page}{\sseq@infinity}%
    \sseq@obj@xdef{class.\coord.n}{\sseq@classinsert}
    \ifx\sseq@familylist\pgfutil@empty\else
        \sseq@obj@xodef{\classname.familylist}{\sseq@familylist}
    \fi
    \ifx\sseq@savedoptioncode\pgfutil@empty\else
        \sseq@obj@xodef{\classname.options}{\sseq@savedoptioncode}%
    \fi
    \ifx\sseq@classnodetext\pgfutil@empty\else
        \sseq@obj@xodef{\classname.nodetext}{\sseq@classnodetext}
    \fi
    \ifx\sseq@classnodetextoptions\pgfutil@empty\else
        \sseq@obj@xodef{\classname.nodetext.options}{\sseq@classnodetextoptions}
    \fi
    \ifx\sseq@classlabelnodes\pgfutil@empty\else
        \sseq@obj@xodef{\classname.labelnodes}{\sseq@classlabelnodes}%
    \fi
    \ifsseq@needstikz
        \sseq@obj@xdef{\classname.needstikz}{\sseq@needstikztrue}%
    \fi
    \@ifundefined{sseq@tempoffset}{}{%
        \tikz@scan@one@point\sseq@setoffset\sseq@tempoffset
    }%
    \ifx\sseq@tooltip\pgfutil@empty\else
        \sseq@obj@protectedxdef{\classname.tooltip}{\sseq@tooltip}
    \fi
%
    \sseq@savedpaths@addclass{class.\coord}%
    \sseq@breakpoint
    \endgroup
}
\def\sseq@setoffset#1{\sseq@obj@gdef{\classname.offset}{\pgftransformshift{#1}}}

% This is for use with "insert" key. Add one to offset index of each class later than the one currently being inserted
% Takes the partial coordinate "x,y" in #1, and the position that the new class is being inserted into in \sseq@classinsert.
\def\sseq@class@adjustclasses#1{
    \sseq@tempcount=\z@
    \sseq@tempcountb=\sseq@obj{partcoord.(#1).numnodes}
    \loop
        \advance\sseq@tempcount\@ne
        \ifnum\sseq@obj{class.(#1,\the\sseq@tempcount).n}<\sseq@classinsert\relax\else
            \sseq@cleanup@obj{class.(#1,\the\sseq@tempcount).n}
            \sseq@eval{\@nx\sseq@obj@inc{class.(#1,\the\sseq@tempcount).n}} % unfortunately, \sseq@obj@inc uses \sseq@tempcount so we need this eval
        \fi
    \ifnum\sseq@tempcount<\sseq@tempcountb\repeat

}

\sseq@DeclareDocumentCommand\classoptions{od()}{%
    \begingroup
    \sseq@loadinputline
    \sseq@xsetthiscall{\string\classoptions\IfNoValueF{#1}{[\unexpanded{#1}]}\unexpanded{(#2)}}%
    \IfNoValueT{#1}{\sseq@error@x{cmdoptions-without-options}{\string\classoptions}\sseq@break}% could be warning
    \sseq@options@firstpassmode
    \the\sseq@sseqstyle
    \the\sseq@classstyle
    \the\sseq@scope@toks
    \sseq@options@normalmode
    \let\sseq@processlabels\sseq@processlabels@default % Don't double dip on labels from the scope or classstyle
    \sseq@processoptions{class}{#1}% Outputs result into \sseq@savedoptioncode
%
    \IfNoValueTF{#2}{
        \def\sseq@coord{\lastclass0}
    }{
        \def\sseq@coord{#2}
    }
    \sseq@parsecoord\coord{\sseq@coord}{\string\classoptions}%
%
    \sseq@processlabels
%
    \let\partialcoord\coord@partial
    \edef\sseq@classnum{\sseq@obj@ifdef{class.\coord.num}{\sseq@obj{class.\coord.num}}{0}}
    \@ifundefined{sseq@class@page}{%
        \@ifundefined{sseq@gen}{
            \@ifundefined{sseq@thepage}{
                \let\sseq@gen\sseq@classnum
            }{
                \sseq@obj@pagetogen{class.\coord}{\sseq@thepage} % stores in \sseq@gen
            }
            \let\sseq@genmax\sseq@gen
        }{
            \ifnum\sseq@gen<\z@
                \edef\sseq@gen{\the\numexpr\sseq@classnum+\sseq@gen+1}
            \fi
            \@ifundefined{sseq@genmax}{\let\sseq@genmax\sseq@gen}{
                \edef\sseq@genmax{\the\numexpr\sseq@classnum+\sseq@genmax+1}
            }
        }
    }{
        \@ifundefined{sseq@gen}{}{\sseq@error{classoptions-page-gen}}% This could be a warning
        \sseq@class@getgen{\sseq@class@page}
        \@ifundefined{sseq@class@pagemax}{
            % If no max is present, apply options to all pages starting at specified minimum
            \let\sseq@genmax\sseq@classnum%
            \let\sseq@class@pagemax\sseq@infinity % ensure if "page" is defined, "pagemax" is defined too
        }{
            \let\sseq@genmin\sseq@gen
            \sseq@class@getgen{\sseq@class@pagemax}
            \let\sseq@genmax\sseq@gen
            \let\sseq@gen\sseq@genmin
        }
        \edef\sseq@class@page{\the\numexpr\sseq@class@page-\@ne}
        \edef\sseq@class@pagemax{\the\numexpr\sseq@class@pagemax+\@ne}
    }
    \ifnum\sseq@gen=\m@ne
        \let\sseq@gen\sseq@classnum
    \fi
    \edef\classname{class.\coord[\sseq@gen]}
    \ifsseq@keepchanges\else
        \ifnum\sseq@thepagecount>\sseq@obj{\classname.page}\relax
            \sseq@error@xxx{classoptions-already-dead}{\sseq@gen}{\coordname}{\sseq@obj{\classname.page}}
            \sseq@breakfifi
        \fi
        \ifnum\sseq@gen>\z@
            \ifnum\sseq@thepagecount>\sseq@obj{class.\coord[\the\numexpr\sseq@gen-\@ne].page}\relax\else
                \sseq@error@xx{classoptions-not-yet-born}{\sseq@gen}{\coord}{\sseq@class@page}%
                \sseq@breakfififi
            \fi
        \fi
    \fi{}
    \ifx\sseq@class@tag\pgfutil@empty\else
        \sseq@obj@ifdef{partcoord.(\partialcoord).tag.\sseq@class@tagprefix\sseq@class@tag}{%
            \sseq@error@nn{class-tag-already-defined}{\sseq@class@tagprefix\sseq@class@tag}{\sseq@partialcoord}% could be warning
        }%
        \sseq@cleanup@obj{class.\coord.tag}%
        \sseq@obj@xdef{class.\coord.tag}{\sseq@class@tagprefix\sseq@class@tag}%
        \sseq@cleanup@obj{partcoord.(\partialcoord).tag.\sseq@class@tagprefix\sseq@class@tag}%
        \sseq@obj@xdef{partcoord.(\partialcoord).tag.\sseq@class@tagprefix\sseq@class@tag}{\sseq@index}%
    \fi
    \ifx\sseq@class@name\pgfutil@empty\else
        \sseq@obj@ifdef{class.\classname.name}{
            \sseq@error@nn{classoptions-class-already-named}{\coord}{\sseq@obj{class.\classname.name}}%could be warning
        }{}
        \sseq@cleanup@obj{class.\classname.name}
        \sseq@cleanup@obj{class.namedclass.\sseq@class@name}
        \sseq@namehandler
        \sseq@obj@xdef{class.\classname.name}{\sseq@class@name}
        \sseq@obj@xdef{class.namedclass.\sseq@class@name}{\coordnopar}
    \fi
    \ifcsname sseq@class@showname\endcsname
        \sseq@eval{\@nx\sseq@handleclassquotes{\sseq@obj{class.\classname.name}}{\sseq@class@showname}}
    \fi
    \sseq@tempcount=\sseq@gen\relax
    \advance\sseq@tempcount\m@ne
    \loop
        \advance\sseq@tempcount\@ne
        \edef\classname{class.\coord[\the\sseq@tempcount]}
        \sseq@cleanup@obj{\classname.options}
        \sseq@classoptions@setup@pagerange
        \sseq@classoptions@obj@addto@withpagerange{\classname.options}{\sseq@savedoptioncode}
    %
        \ifx\sseq@classnodetext\pgfutil@empty\else
            \sseq@cleanup@obj{\classname.nodetext}
            \sseq@classoptions@obj@addto@withpagerange{\classname.nodetext}{\sseq@classnodetext}
        \fi
        \ifx\sseq@classnodetextoptions\pgfutil@empty\else
            \sseq@cleanup@obj{\classname.nodetext.options}
            \sseq@classoptions@obj@addto@withpagerange{\classname.nodetext.options}{\sseq@classnodetextoptions}
        \fi
        \ifx\sseq@classlabelnodes\pgfutil@empty\else
            \sseq@cleanup@obj{\classname.labelnodes}
            \sseq@classoptions@obj@addto@withpagerange{\classname.labelnodes}{\sseq@classlabelnodes}
        \fi
        \ifx\sseq@familylist\pgfutil@empty\else
            \sseq@cleanup@obj{\classname.familylist}
            \sseq@classoptions@obj@addto@withpagerange{\classname.familylist}{\sseq@familylist}
        \fi
        \@ifundefined{sseq@tempoffset}{}{
            \sseq@cleanup@obj{\classname.offset}
            \tikz@scan@one@point\sseq@setoffset\sseq@tempoffset
        }
    \ifnum\sseq@tempcount<\sseq@genmax\repeat
    \sseq@breakpoint
    \endgroup
}
\def\sseq@classoptions@setup@pagerange{%
    \@ifundefined{sseq@class@page}{
        \def\sseq@classoptions@obj@addto@withpagerange@{\sseq@obj@gaddto{\sseq@tempobj}}
    }{
        \def\sseq@temp##1{##1}
        \ifnum\sseq@tempcount=\sseq@gen\relax
            \sseq@eval{\@nx\pretocmd\@nx\sseq@temp{\@nx\ifnum\sseq@thepagecount>\sseq@class@page\relax}{}{%
                \@nx\sseq@error@x{this-shouldnt-happen}{file main, function \string\sseq@classoptions@setup@pagerange}
            }}%
            \apptocmd\sseq@temp{\fi}{}{\sseq@error@x{this-shouldnt-happen}{file main, function \string\sseq@classoptions@setup@pagerange}}
        \fi
        \ifnum\sseq@tempcount=\sseq@genmax\relax
            \sseq@eval{\@nx\pretocmd\@nx\sseq@temp{\@nx\ifnum\sseq@thepagecount<\sseq@class@pagemax\relax}{}{\@nx\sseq@error@internal{}}}
            \apptocmd\sseq@temp{\fi}{}{\sseq@error@internal{this-shouldnt-happen}{file main, function \string\sseq@classoptions@setup@pagerange}}
        \fi
        \@xp\def\@xp\sseq@temp\@xp##\@xp1\@xp{\@xp{\sseq@temp{##1}}}
        \pretocmd\sseq@temp{\sseq@obj@gaddto{\sseq@tempobj}}{}{\sseq@error@internal{this-shouldnt-happen}{file main, function \string\sseq@classoptions@setup@pagerange}}
        \let\sseq@classoptions@obj@addto@withpagerange@\sseq@temp
    }
}
\def\sseq@classoptions@obj@addto@withpagerange#1#2{%
    \def\sseq@tempobj{#1}%
    \@xp\sseq@classoptions@obj@addto@withpagerange@\@xp{#2}%
}
\def\sseq@class@getgen#1{
    \bgroup
        \ifnum\sseq@classnum>\z@
            \sseq@eval{\unexpanded{\sseq@obj@pagetogen{class.\coord}}{#1}} % stores in \sseq@gen
        \else
            \def\sseq@gen{0}
        \fi
        \sseq@smuggle@macro\sseq@gen
    \egroup
}
\sseq@DeclareDocumentCommand\replaceclass{od()}{%
    \begingroup
    \sseq@loadinputline
    \sseq@xsetthiscall{\string\replaceclass\IfNoValueF{#1}{[\unexpanded{#1}]}\unexpanded{(#2)}}
    \sseq@options@firstpassmode
    \the\sseq@sseqstyle
    \the\sseq@classstyle
    \the\sseq@scope@toks
    \sseq@options@normalmode
    \IfNoValueF{#1}{%
        \sseq@processoptions{class}{#1}% Outputs result into \sseq@savedoptioncode
    }%
%
    \IfNoValueTF{#2}{
        \def\sseq@coord{\lastclass0}
    }{
        \def\sseq@coord{#2}
    }
    \sseq@parsecoord\coord{\sseq@coord}{\string\classoptions}%
    \sseq@processlabels
%
    \sseq@obj@ifundef{class.\coord.num}{\sseq@error@x{replaceclass-no-class}{\coordname}\sseq@break}{}
    \sseq@ifdead\coord{}{\sseq@error@x{replaceclass-not-dead-yet}{\coordname}\sseq@break}
    \ifsseq@keepchanges\else
        \ifnum\the\numexpr\sseq@obj{class.\coord[\sseq@obj{class.\coord.num}].page}<\sseq@thepagecount\else
            \edef\sseq@temp{\sseq@obj{class.\coord[\sseq@obj{class.\coord.num}].page}}
            \sseq@error@xxx{replaceclass-no-effect-on-this-page}{\coord}{\sseq@temp}{\the\numexpr\sseq@temp+\@ne}% warning
            \sseq@breakfifi
        \fi
    \fi
    \let\partialcoord\coord@partial
    \ifx\sseq@class@tag\pgfutil@empty\else
        \sseq@obj@ifdef{partcoord.(\partialcoord).tag.\sseq@class@tagprefix\sseq@class@tag}{%
            \sseq@error@nn{class-tag-already-defined}{\sseq@class@tagprefix\sseq@class@tag}{\sseq@partialcoord}% could be warning
        }{}%
        \sseq@cleanup@obj{partcoord.(\partialcoord).tag.\sseq@class@tagprefix\sseq@class@tag}%
        \sseq@obj@xdef{partcoord.(\partialcoord).tag.\sseq@class@tagprefix\sseq@class@tag}{\nodenum}%
    \fi
    \ifx\sseq@class@name\pgfutil@empty\else
        \sseq@cleanup@obj{class.\classname.name}
        \sseq@cleanup@obj{class.namedclass.\sseq@class@name}
        \sseq@namehandler
        \sseq@obj@xdef{class.\classname.name}{\sseq@class@name}
        \sseq@obj@xdef{class.namedclass.\sseq@class@name}{\coordnopar}
    \fi
    \ifcsname sseq@class@showname\endcsname
        \sseq@eval{\@nx\sseq@handleclassquotes{\sseq@obj{class.\classname.name}}{\sseq@class@showname}}
    \fi
    \sseq@cleanup@obj{class.\coord.num}
    \sseq@obj@inc{class.\coord.num}
    \let\partialcoord\coord@partial
    \ifx\sseq@class@tag\pgfutil@empty\else
        \sseq@obj@ifdef{partialcoord.(\partialcoord).tag.\sseq@class@tagprefix\sseq@class@tag}{%
            \sseq@error@nn{class-tag-already-defined}{\sseq@class@tagprefix\sseq@class@tag}{\sseq@partialcoord}% could be warning
        }{}%
        \sseq@obj@xdef{partialcoord.(\partialcoord).tag.\sseq@class@tagprefix\sseq@class@tag}{\nodenum}%
    \fi
    \edef\classname{class.\coord[\sseq@obj{class.\coord.num}]}
%
    \sseq@obj@xodef{\classname.familylist}{\sseq@familylist}
    \sseq@obj@xdef{\classname.page}{\sseq@infinity}
    \sseq@obj@xodef{\classname.options}{\sseq@savedoptioncode}
    \ifx\sseq@classnodetext\pgfutil@empty\else
        \sseq@obj@xodef{\classname.nodetext}{\sseq@classnodetext}
    \fi
    \ifx\sseq@classnodetextoptions\pgfutil@empty\else
        \sseq@obj@xodef{\classname.nodetext.options}{\sseq@classnodetextoptions}
    \fi
    \sseq@obj@xodef{\classname.labelnodes}{\sseq@classlabelnodes}
    \sseq@obj@gdef{\classname.dependencies}{}
    \ifsseq@needstikz
        \sseq@obj@xdef{\classname.needstikz}{\sseq@needstikztrue}
    \fi
    \@ifundefined{sseq@tempoffset}{}{\tikz@scan@one@point\sseq@setoffset\sseq@tempoffset}
%
    \sseq@breakpoint
    \endgroup
}
\def\sseq@class@draw@ifpage#1{
    \bgroup
    \sseq@obj@pagetogen{#1}{\sseq@thepage} % sets \sseq@gen
    \ifnum\sseq@gen>\m@ne % -1 means no class to print
        \ifnum\sseq@obj{#1[\sseq@gen].page}=\sseq@thepagecount
            \sseq@thispagetrue
        \fi
        \sseq@drawtrue
        \sseq@obj{#1[\sseq@gen].familylist}
        \ifsseq@draw
            \sseq@gsetthiscall{class #1}
            \sseq@class@drawnode{#1[\sseq@gen]}
        \fi
    \fi
    \egroup
}
% #1 -- class
% #2 -- page
% If there is a class #1 drawn on page #2, set \sseq@gen to be the generation of that class, otherwise set \sseq@gen to be -1.
\def\sseq@obj@pagetogen#1#2{
    \bgroup
        \def\sseq@gen{-1}
        \sseq@tempcount=\m@ne
        \sseq@tempcountb=\sseq@obj{#1.num}\relax
        \loop
            \advance\sseq@tempcount\@ne
            \ifnum\sseq@obj{#1[\the\sseq@tempcount].page}<#2\relax\else
                \edef\sseq@gen{\the\sseq@tempcount}
                \sseq@tempcount=\sseq@tempcountb\relax
            \fi
        \ifnum\sseq@tempcount<\sseq@tempcountb\repeat
        \sseq@smuggle@macro\sseq@gen
    \egroup
}
%%%
%%% \kill, \d and \doptions
%%%

% Because \kill doesn't take options, there's no need to use \sseq@DeclareDocumentCommand for the outer command.
% Rather than use \sseq@DeclareDocumentCommand with no arguments, we just do the normal stuff that \sseq@DeclareDocumentCommand would do,
% Then call \sseq@d@grabpage, the command that is responsible for handling the strange syntax of the page argument for \d.
\protected\def\sseq@kill{%
    \begingroup
    \sseq@setinputline % These two lines normally would happen inside of \sseq@DeclareDocumentCommand.
    \sseq@loadinputline
    \sseq@d@grabpage\sseq@kill@
}

% Now we need to parse a potential coordinate.
\sseq@DeclareDocumentCommandAs\sseq@kill@\kill {d()} {
    \sseq@xsetthiscall{\string\kill\unexpanded\@xp{\sseq@dpage}\IfNoValueF{#1}{(#1)}}%
    \sseq@parsecoord\coordinate{\IfNoValueTF{#1}{\lastclass}{#1}}{}%
    \sseq@ifintexpr{\sseq@dpage}{%
        \sseq@tempcount=\numexpr\sseq@dpage\relax % this is a convenient way to get rid of spaces because #3 has to be a number
    }{%
        \sseq@error@x{d-invalid-page}{\unexpanded\@xp{\sseq@dpage}}\sseq@break%
    }%
    \sseq@d@setpageminrec{class.\coordinate}{\the\sseq@tempcount}{coordinate}%  automatically handles \sseq@cleanup@obj
    \sseq@breakpoint
    \endgroup
}

% \sseq@d@grabpage is defined in sseqparsers.
\sseq@DeclareDocumentCommand\d{o}{%
    \begingroup
    \sseq@loadinputline
    \def\sseq@dtype{d}
    \def\sseq@d@theoptions{#1}
    \sseq@d@grabpage\sseq@d@
}

\sseq@DeclareDocumentCommand\doptions{o}{%
    \begingroup
    \sseq@loadinputline
    \def\sseq@dtype{doptions}
    \def\sseq@d@theoptions{#1}
    \sseq@d@grabpage\sseq@d@
}

\def\sseq@d@{
    \ifsseq@tempif
        \csname sseq@\sseq@dtype @grabcoord\@xp\endcsname
    \else
        \sseq@eval{\@nx\sseq@d@main{\sseq@dtype}{\unexpanded\@xp{\sseq@d@theoptions}}{\sseq@dpage}{\sseq@NoValue}{\sseq@NoValue}}
        \sseq@breakpoint
        \endgroup
    \fi
}

\sseq@DeclareDocumentCommandAs\sseq@d@grabcoord\d{d()d()}{
    \sseq@eval{\@nx\sseq@d@main{\sseq@dtype}{\unexpanded\@xp{\sseq@d@theoptions}}{\sseq@dpage}}{#1}{#2}
    \sseq@breakpoint
    \endgroup
}

\sseq@DeclareDocumentCommandAs\sseq@doptions@grabcoord\doptions{d()d()}{
    \sseq@eval{\@nx\sseq@d@main{\sseq@dtype}{\unexpanded\@xp{\sseq@d@theoptions}}{\sseq@dpage}}{#1}{#2}
    \sseq@breakpoint
    \endgroup
}


\def\sseq@d@main#1#2#3#4#5{%
    \sseq@options@firstpassmode
    \def\sseq@edgetype{differential}
    \the\sseq@sseqstyle
    \the\sseq@edgestyle
    \the\sseq@differentialstyle
    \the\sseq@scope@toks
    \sseq@options@normalmode
    \IfNoValueF{#2}{
        \sseq@processoptions{differential}{#2}% Outputs result into \sseq@savedoptioncode
    }
    \sseq@xsetthiscall{\@xp\string\csname#1\endcsname\IfNoValueF{#2}{\unexpanded{[#2]}}\unexpanded{#3}\IfNoValueF{#4}{\unexpanded{(#4)}}\IfNoValueF{#5}{\unexpanded{(#5)}}}%
    \sseq@ifintexpr{#3}{%
        \sseq@tempcount=\numexpr#3\relax % this is a convenient way to get rid of spaces because #3 has to be a number
    }{%
        \sseq@error@n{d-invalid-page}{#3}\sseq@break%
    }%
    \sseq@eval{\@nx\sseq@dparsecoord{\the\sseq@tempcount}{\IfNoValueTF{#4}{\lastclass0}{\unexpanded{#4}}}{\unexpanded{#5}}}
    \sseq@eval{\unexpanded{\csname sseq@d@#1\endcsname{#2}}{\the\sseq@tempcount}}%
    \sseq@breakpoint
}

% #1 -- options
% #2 -- page
% #3 -- source coordinate
\def\sseq@d@d#1#2{%%
    \sseq@d@setpageminrec{class.\source}{#2}{source}%  automatically handles \sseq@cleanup@obj
    \sseq@d@setpageminrec{class.\target}{#2}{target}
%
    \ifsseq@drawdifferential % TODO: probably should get rid of invisible now that we have \kill...
        \sseq@obj@xodef{d.#2\source\target.familylist}{\sseq@familylist}
        \sseq@obj@gdef{d.#2\source\target.page}{#2}
        \sseq@obj@xdef{d.#2\source\target.source}{\source}
        \sseq@obj@xdef{d.#2\source\target.target}{\target}
        \sseq@obj@xdef{d.#2\source\target.options}{\ifsseq@needstikz\@nx\sseq@needstikztrue\fi\unexpanded\@xp{\sseq@savedoptioncode}}
%
        \sseq@savedpaths@adddifferential{d.#2\source\target}%
    \else
        \sseq@obj@gdef{d.#2\source\target.invisible}{}
    \fi
}
\def\sseq@d@doptions#1#2{%
    \sseq@obj@ifundef{d.#2\source\target.options}{\sseq@error@n{cmdoptions-feature-doesn't-exist}{differential}\sseq@break}{}%
    \sseq@obj@ifdef{d.#2\source\target.invisible}{\sseq@error{doptions-invisible}\sseq@break}
    \ifsseq@keepchanges\else
        \@ifundefined{sseq@thepage}{}{
            \ifnum#2=\sseq@thepagecount\else\ifnum\sseq@thepagecount=\z@\else
                \sseq@error@n{doptions-no-effect-on-this-page}{#2}\sseq@breakfififi
            \fi\fi
        }%
    \fi
%
    \sseq@cleanup@obj{d.#2\source\target.familylist}
    \sseq@obj@xoaddto{d.#2\source\target.familylist}{\sseq@familylist}
    \sseq@cleanup@obj{d.#2\source\target.options}
    \sseq@obj@xoaddto{d.#2\source\target.options}{\sseq@savedoptioncode}
}

% Some helper macros:
% #1 -- class name for \sseq@obj
% #2 -- page
% #3 -- source or target for error handling purposes.
\def\sseq@d@setpageminrec#1#2#3{% not really recursive.
    \sseq@cleanup@obj{#1[\sseq@obj{#1.num}].page}
    \sseq@cleanup@obj{#1[\sseq@obj{#1.num}].deathinfo}
    \sseq@cleanup@obj{#1[\sseq@obj{#1.num}].deathline}
    \sseq@d@setpageclass{#1}{#2}{#3}
    \sseq@obj@map{#1[\sseq@obj{#1.num}].dependencies}{
        \sseq@d@setpagemin{##1}{#2} % automatically handles cleanup
    }
}

% #1 -- class name for \sseq@obj
% #2 -- page
% #3 -- source or target for error handling purposes.
\def\sseq@d@setpageclass#1#2#3{
    \edef\sseq@classgenname{#1[\sseq@obj{#1.num}]}
    % If the class is dead, then it's only not an error if it died on the current page
    \ifnum\sseq@obj{\sseq@classgenname.page}<\sseq@infinitycount
        % If the page it died on is greater than this one, hit-wrong-order error
        \ifnum\sseq@obj{\sseq@classgenname.page}>#2\relax
            \let\sseq@deadclass@genname\sseq@classgenname
            \sseq@preparestacktrace
            \sseq@error@xxxx{d-hit-wrong-order}{#3}{\csname #3name\endcsname}{#2}{\the\sseq@temptoks}
            \sseq@breakfifi
        \fi
        % If the page it died on is less than this one, class-already-hit error
        \ifnum\sseq@obj{\sseq@classgenname.page}<#2\relax
            \let\sseq@deadclass@genname\sseq@classgenname
            \sseq@preparestacktrace
            \sseq@error@xxxx{d-class-already-hit}{#3}{\csname #3name\endcsname}{#2}{\the\sseq@temptoks}
            \sseq@breakfifi
        \fi
    \fi
    % If the class has been replaced before, that's only okay if it was replaced on a previous page.
    \ifnum\sseq@obj{#1.num}>\z@
        \sseq@tempcount=\sseq@obj{#1.num}\relax
        \advance\sseq@tempcount\m@ne
        \ifnum\sseq@obj{#1[\the\sseq@tempcount].page}<#2\relax\else
            \ifnum#2=\sseq@obj{#1[\the\sseq@tempcount].page}
                 \sseq@error@xxxx{d-hit-same-page-replaceclass}{#3}{\csname #3name\endcsname}{#2}{\sseq@obj{#1[\the\sseq@tempcount].deathinfo}}
                 \sseq@breakfififi
            \else
                \edef\sseq@deadclass@genname{#1[\the\numexpr\sseq@obj{#1.num}-\@ne]}
                \sseq@preparestacktrace
                \sseq@error@xxxx{d-hit-wrong-order}{#3}{\csname #3name\endcsname}{#2}{\the\sseq@temptoks}
                \sseq@breakfififi
            \fi
        \fi
    \fi
    \sseq@obj@xdef{\sseq@classgenname.page}{#2}
    \sseq@obj@xdef{\sseq@classgenname.deathinfo}{#3 of differential \sseq@thiscall\space on page #2}
    \bgroup
    \def\foreach{\@nx\@nx\@nx\foreach}
    \protected\def\\{}
    \let\sseq@possibleperiod\empty
    \let\sseq@possibleperiodb\empty
    \sseq@obj@xdef{\sseq@classgenname.deathlocation}{%
        on input line \sseq@inputline\sseq@error@inforeachloop
    }
    \sseq@obj@xdef{\sseq@classgenname.deathline}{\sseq@inputline}
    \sseq@tempiffalse
    \edef\sseq@temp{\the\sseq@foreachcall}
    \ifx\sseq@temp\pgfutil@empty\else\sseq@tempiftrue\fi
    \ifx\sseq@restofstacktrace\pgfutil@empty\else\sseq@tempiftrue\fi
    \sseq@obj@xdef{\sseq@classgenname.deathstacktrace}{%
        \ifsseq@tempif
            \unexpanded{\\\\}Stack trace for differential \sseq@thiscall\ that killed #3:\unexpanded{\\}%
            \ifx\sseq@temp\sseq@empty\else\unexpanded{\ \ \ }\@nx\sseq@stack@unexpanded{\unexpanded\@xp{\the\sseq@foreachcall}}\fi
            \unexpanded\@xp{\sseq@restofstacktrace}%
        \fi
    }
    \egroup
}

\def\sseq@preparestacktrace{
    \def\foreach{\@nx\foreach}
    \edef\sseq@temp@i{\unexpanded\@xpthree{\sseq@obj{\sseq@deadclass@genname.deathline}}}
    \edef\sseq@temp@ii{\sseq@inputline}
    \ifx\sseq@temp@i\sseq@temp@ii
        \sseq@temptoks\@xpthree{\sseq@obj{\sseq@deadclass@genname.deathinfo} (in the same \foreach loop)}
    \else
        \protected\def\\{}
        \sseq@eval{\sseq@temptoks{\unexpanded\@xpthree{\sseq@obj{\sseq@deadclass@genname.deathinfo}}\space(\sseq@obj{\sseq@classgenname.deathlocation})}}
        \sseq@e@addto@macro\sseq@errorinfo{\unexpanded\@xpthree{\sseq@obj{\sseq@deadclass@genname.deathstacktrace}}}
    \fi
}

\def\sseq@d@setpagemin#1#2{
    \ifnum\sseq@obj{#1.page}>#2\relax
        \sseq@cleanup@obj{#1.page}
        \sseq@obj@xdef{#1.page}{#2}
    \fi
}
\def\sseq@differential@draw@ifpage#1{
    \sseq@drawtrue
    \sseq@obj{#1.familylist}
    \ifsseq@draw
        \ifnum\sseq@thepagecount=\z@
            \sseq@drawdifferential{#1}
        \else
            \ifnum\sseq@obj{#1.page}>\sseq@thepagemm\relax
                \ifnum\sseq@obj{#1.page}<\sseq@thepagemaxpp\relax
                    \sseq@drawdifferential{#1}
                \fi
            \fi
        \fi
    \fi
}
\def\sseq@drawdifferential#1{
    \bgroup
    \sseq@eval{
        \@nx\sseq@drawedge\sseq@obj{#1.source}\sseq@obj{#1.target}{differential}{%
            \@xptwo\@nx\sseq@obj{#1.options}
        }
    }
    \egroup
}
%%%
%%% \structline and \structlineoptions
%%%

\sseq@DeclareDocumentCommand\structline{od()}{%
    \begingroup
    \sseq@loadinputline
    \IfNoValueTF{#2}{
        \sseq@structline@main{structline}{#1}{#2}{#2}
    }{
        \def\next{\sseq@structline@@{structline}{#1}{#2}}%
        \@xptwo\next\sseq@trimleadingspaces
    }
}
\sseq@DeclareDocumentCommand\structlineoptions{od()}{%
    \begingroup
    \sseq@loadinputline
    \IfNoValueTF{#2}{
        \sseq@structline@main{structlineoptions}{#1}{#2}{#2}
    }{
        \def\next{\sseq@structlineoptions@@{structlineoptions}{#1}{#2}}%
        \@xptwo\next\sseq@trimleadingspaces
    }
}

\sseq@DeclareDocumentCommandAs\sseq@structline@@\structline{mmmd()}{%
    \sseq@structline@main{#1}{#2}{#3}{#4}
}

\sseq@DeclareDocumentCommandAs\sseq@structlineoptions@@\structlineoptions{mmmd()}{%
    \sseq@structline@main{#1}{#2}{#3}{#4}
}

\def\sseq@structline@main#1#2#3#4{
    \sseq@xsetthiscall{\string\structline\IfNoValueF{#2}{\unexpanded{[#2]}}\IfNoValueF{#3}{\unexpanded{(#3)}\IfNoValueF{#4}{\unexpanded{(#4)}}}}%
    \def\sseq@edgetype{structline}
    \sseq@options@firstpassmode
    \the\sseq@sseqstyle
    \the\sseq@edgestyle
    \the\sseq@structlinestyle
    \the\sseq@scope@toks
    \sseq@options@normalmode
    \IfNoValueF{#2}{%
        \sseq@processoptions{struct line}{#2}% Outputs result into \sseq@savedoptioncode
    }%
    \def\sourcename{#3}%
    \def\targetname{#4}%
    \IfNoValueTF{#3}{%
        \def\sourcename{\lastclass1}%
        \def\targetname{\lastclass}%
    }{%
        \IfNoValueT{#4}{%
            \def\targetname{\lastclass}%
        }%
    }%
    \sseq@parsecoord\source{\sourcename}{source of structure line}%
    \sseq@parsecoord\target{\targetname}{target of structure line}%
    \ifnum\xsource>\xtarget\relax
        \sseq@parsedcoords@swap\source\target
    \else
        \ifnum\xsource=\xtarget\relax
            \ifnum\ysource>\ytarget\relax
                \sseq@parsedcoords@swap\source\target
            \else
                \ifnum\ysource=\ytarget\relax
                    \ifnum\nsource>\ntarget\relax
                        \sseq@parsedcoords@swap\source\target
                    \else
                        \ifnum\nsource=\ntarget\relax
                            \sseq@error{structline-source-target-equal}%
                            \@xp\sseq@break\romannumeral-`0
                        \fi
                    \fi
                \fi
            \fi
        \fi
    \fi
    \@ifundefined{sseq@structline@page}{%this is repeated in circleclasses
        \def\sseq@pagemin{0}
        \ifnum\sseq@obj{class.\source.num}>\z@
            \edef\sseq@pagemin{\sseq@obj{class.\source[\the\numexpr\sseq@obj{class.\source.num}-1].page}}
        \fi
        \ifnum\sseq@obj{class.\target.num}>\z@
            \edef\sseq@test{\sseq@obj{class.\target[\the\numexpr\sseq@obj{class.\target.num}-1].page}}
            \ifnum\sseq@test>\sseq@pagemin\relax
                \let\sseq@pagemin\sseq@test
            \fi
        \fi
    }{\edef\sseq@pagemin{\the\numexpr\sseq@structline@page-\@ne}}
    \csname sseq@structline@#1\endcsname
    \sseq@breakpoint
    \endgroup
}
\def\sseq@structline@structline{
    \@ifundefined{sseq@structline@pagemax}{}{\sseq@error{structline-no-page-max}}% could be warning
    \ifnum\sseq@pagemin<\sseq@obj{class.\source[\sseq@obj{class.\source.num}].page}\relax\else
        \sseq@error{structline-stillborn}
        \sseq@breakfi
    \fi
    \ifnum\sseq@pagemin<\sseq@obj{class.\target[\sseq@obj{class.\target.num}].page}\relax\else % If the \structline is dead before it is born, throw an error
        \sseq@error{structline-stillborn}
        \sseq@breakfi
    \fi
    \sseq@obj@ifdef{structline.\source\target.num}{%
        \ifnum\sseq@obj{structline.\source\target[\sseq@obj{structline.\source\target.num}].page}=\sseq@infinitycount
            \sseq@error@xx{structline-already-exists}{\sourcename}{\targetname}
            \sseq@breakfi
        \fi
        \sseq@cleanup@obj{structline.\source\target.num}
        \sseq@obj@inc{structline.\source\target.num}
    }{
        \sseq@cleanup@obj{structline.\source\target.num}
        \sseq@obj@gdef{structline.\source\target.num}{0}
        \sseq@savedpaths@addstructline{structline.\source\target}
    }
    \edef\sseq@structlinename{structline.\source\target[\sseq@obj{structline.\source\target.num}]}
    % The following cleanup call is needed to prevent a glitch where if a \structline is made inside of a temporary sseqpage environment, then later attempts
    % to put a structline throw a "structline already exists" error
    \sseq@cleanup@obj{\sseq@structlinename.page}
    \sseq@obj@xdef{\sseq@structlinename.page}{\sseq@infinity}
    \sseq@obj@xdef{\sseq@structlinename.pagemin}{\sseq@pagemin}
    \sseq@obj@xdef{\sseq@structlinename.source}{\source}
    \sseq@obj@xdef{\sseq@structlinename.target}{\target}
    \sseq@class@adddependence{class.\source}{\sseq@structlinename}% If the source or target is already dead, this will set structlinename.page
    \sseq@class@adddependence{class.\target}{\sseq@structlinename}
    \sseq@obj@xodef{\sseq@structlinename.familylist}{\sseq@familylist}
    \sseq@cleanup@obj{\sseq@structlinename.options}
    \sseq@obj@xdef{\sseq@structlinename.options}{\ifsseq@needstikz\@nx\sseq@needstikztrue\fi\unexpanded\@xp{\sseq@savedoptioncode}}
}
\def\sseq@structline@structlineoptions{
    \sseq@obj@ifundef{structline.\source\target.num}{
        \sseq@error@n{cmdoptions-feature-doesn't-exist}{\structline}
        \sseq@break
    }{}
    \@ifundefined{sseq@structline@page}{
        \edef\sseq@gen{\sseq@obj{structline.\source\target.num}}
        \let\sseq@genmax\sseq@gen
    }{
        \sseq@structline@getgen{\sseq@structline@page}
        \@ifundefined{sseq@structline@pagemax}{%
            % If no max is present, apply options to all pages starting at specified minimum
            \edef\sseq@genmax{\sseq@obj{structline.\source\target.num}}%
            \let\sseq@structline@pagemax\sseq@infinity
        }{
            \let\sseq@genmin\sseq@gen
            \sseq@structline@getgen{\sseq@structline@pagemax}
            \let\sseq@genmax\sseq@gen
            \let\sseq@gen\sseq@genmin
        }
        \edef\sseq@structline@page{\the\numexpr\sseq@structline@page-1}
        \edef\sseq@structline@pagemax{\the\numexpr\sseq@structline@pagemax+1}
    }
    \sseq@tempcount=\sseq@gen\relax
    \advance\sseq@tempcount\m@ne
    \loop
        \advance\sseq@tempcount\@ne
        \edef\sseq@structlinename{structline.\source\target[\the\sseq@tempcount]}
        \sseq@cleanup@obj{\sseq@structlinename.options}
        \sseq@cleanup@obj{\sseq@structlinename.familylist}
        \ifsseq@needstikz
            \sseq@obj@gaddto{\sseq@structlinename.options}{\sseq@needstikztrue}
        \fi
        \ifnum\sseq@tempcount=\sseq@gen\relax
            \@ifundefined{sseq@structline@page}{}{
                \edef\sseq@savedoptioncode{\@nx\ifnum\sseq@thepagecount>\sseq@structline@page\relax\unexpanded\@xp{\sseq@savedoptioncode}\@nx\fi}
                \edef\sseq@familylist{\@nx\ifnum\sseq@thepagecount>\sseq@structline@page\relax\unexpanded\@xp{\sseq@familylist}\@nx\fi}
            }
        \fi
        \ifnum\sseq@tempcount=\sseq@genmax\relax
            \@ifundefined{sseq@structline@pagemax}{}{
                \edef\sseq@savedoptioncode{\@nx\ifnum\sseq@thepagecount<\sseq@structline@pagemax\relax\unexpanded\@xp{\sseq@savedoptioncode}\@nx\fi}
                \edef\sseq@familylist{\@nx\ifnum\sseq@thepagecount<\sseq@structline@pagemax\relax\unexpanded\@xp{\sseq@familylist}\@nx\fi}
            }
        \fi
        \sseq@obj@xoaddto{\sseq@structlinename.options}{\sseq@savedoptioncode}
        \sseq@obj@xoaddto{\sseq@structlinename.familylist}{\sseq@familylist}
    \ifnum\sseq@tempcount<\sseq@genmax\repeat
}
\def\sseq@structline@getgen#1{
    \bgroup
        \sseq@tempcount=\sseq@obj{structline.\source\target.num}\relax
        \ifnum\sseq@tempcount>\z@
            \ifnum#1<\z@\relax
                \@ifundefined{sseq@thepage}{
                    \ifnum\sseq@obj{structline.\source\target[\the\sseq@tempcount].page}<\sseq@infinitycount
                        \sseq@tempcount=\sseq@obj{structline.\source\target[\the\sseq@tempcount].page}\relax
                    \else
                        \advance\sseq@tempcount\m@ne
                        \sseq@tempcount=\sseq@obj{structline.\source\target[\the\sseq@tempcount].page}\relax
                        \advance\sseq@tempcount\@ne
                    \fi
                }{
                    \sseq@tempcount=\sseq@thepagecount
                }
                \advance\sseq@tempcount\@ne
                \advance\sseq@tempcount#1\relax
            \fi
            \sseq@eval{\unexpanded{\sseq@obj@pagetogen{structline.\source\target}}{\the\sseq@tempcount}} % stores in \sseq@gen
        \else
            \def\sseq@gen{0}
        \fi
        \sseq@smuggle@macro\sseq@gen
    \egroup
}
\def\sseq@class@adddependence#1#2{
    \edef\sseq@temp{\sseq@obj{#1.num}}
    \sseq@d@setpagemin{#2}{\sseq@obj{#1[\sseq@temp].page}}% automatically handles cleanup
    \sseq@cleanup@obj{#1[\sseq@temp].dependencies}
    \sseq@obj@xaddto{#1[\sseq@temp].dependencies}{\@nx\\{#2}}
}
\def\sseq@structline@draw@ifpage#1{
    \bgroup
    \ifnum\sseq@thepagecount=\z@
        \ifnum\sseq@obj{#1[0].pagemin}=\z@
            \sseq@drawtrue
            \sseq@obj{#1[0].familylist}
            \ifsseq@draw
                \sseq@structline@draw{#1[0]}
            \fi
        \fi
    \else
        \sseq@obj@pagetogen{#1}{\sseq@thepage} % sets \sseq@gen
        \ifnum\sseq@gen<\z@\else % negative sseq@gen means don't draw it
            \ifnum\sseq@obj{#1[\sseq@gen].page}=\sseq@thepagecount
                \sseq@thispagetrue
            \fi
            \ifnum\sseq@obj{#1[\sseq@gen].pagemin}<\sseq@thepagecount
                \sseq@drawtrue
                \sseq@obj{#1[\sseq@gen].familylist}
                \ifsseq@draw
                    \sseq@structline@draw{#1[\sseq@gen]}
                \fi
            \fi
        \fi
    \fi
    \egroup
}
\def\sseq@structline@draw#1{\sseq@eval{\@nx\sseq@drawedge\sseq@obj{#1.source}\sseq@obj{#1.target}{structline}{\@nx\sseq@obj{#1.options}}}}




\newcount\sseq@circleclassuid
\sseq@DeclareDocumentCommand\circleclasses{or()r()}{
    \begingroup
    \sseq@loadinputline
    \def\sseq@keysfortikzprim{}
    \IfNoValueF{#1}{
        \sseq@processoptions{fit}{#1}
    }
    \sseq@parsecoord\coorda{#2}{first \@nx\circleclass class}
    \sseq@parsecoord\coordb{#3}{second \@nx\circleclass class}
%
%
    \ifsseq@keepchanges
        \@ifundefined{sseq@fit@page}{% also in structline@main. TODO: refactor these chunks together?
            \def\sseq@pagemin{0}
            \ifnum\sseq@obj{class.\coorda.num}>\z@
                \edef\sseq@pagemin{\sseq@obj{class.\coorda[\the\numexpr\sseq@obj{class.\coorda.num}-\@ne].page}}
            \fi
            \ifnum\sseq@obj{class.\coordb.num}>\z@
                \edef\sseq@test{\sseq@obj{class.\coordb[\the\numexpr\sseq@obj{class.\coordb.num}-\@ne].page}}
                \ifnum\sseq@test>\sseq@pagemin\relax
                    \let\sseq@pagemin\sseq@test
                \fi
            \fi
        }{\edef\sseq@pagemin{\the\numexpr\sseq@fit@page-\@ne}}
        \@ifundefined{sseq@fit@pagemax}{\let\sseq@pagemax\sseq@infinity}{\let\sseq@pagemax\sseq@fit@pagemax}
    \else % Put it on the current page no matter what inside sseqpage
        \let\sseq@pagemax\sseq@infinity\def\sseq@pagemin{-1}
    \fi
%
%
    \global\advance\sseq@circleclassuid\@ne
    \edef\circleclassobjname{circleclass(\coordanopar)(\coordbnopar)\the\sseq@circleclassuid}
%
%
    \sseq@obj@xodef{\circleclassobjname.options}{\sseq@savedoptioncode}
    \sseq@obj@xodef{\circleclassobjname.familylist}{\sseq@familylist}
    \sseq@obj@xodef{\circleclassobjname.tikzprimoptions}{\sseq@keysfortikzprim}
    \sseq@obj@xdef{\circleclassobjname.fitnodes}{\@nx\tikz@lib@fit{(sseq{\coordanopar})(sseq{\coordbnopar})\sseq@fitalso}}
    %\edef\temp{\@nx\sseq@circleclass@draw{\coorda@internalname}{\coordb@internalname}{\unexpanded\@xp{\sseq@savedoptioncode}}}
    \sseq@savedpaths@xadd{\@nx\sseq@circleclass@draw@ifpage{\circleclassobjname}{\coordanopar}{\coordbnopar}}
    \sseq@obj@xdef{\circleclassobjname.page}{\sseq@pagemax}
    \sseq@obj@xdef{\circleclassobjname.pagemin}{\sseq@pagemin}
    \@ifundefined{sseq@fit@pagemax}{
        \ifsseq@keepchanges
            \sseq@class@adddependence{class.\coorda}{\circleclassobjname}% If the source or target is already dead, this will set structlinename.page
            \sseq@class@adddependence{class.\coordb}{\circleclassobjname}
        \fi
    }{}
    \sseq@breakpoint
    \endgroup
}

\ifsseq@patchfit\else
    \sseq@DeclareDocumentCommand\circleclasses{or()r()}{%
        \sseq@warning{circleclasses-not-provided}
    }
\fi

\def\sseq@circleclass@draw@ifpage#1#2#3{
    \sseq@drawtrue
    \sseq@obj{#1.familylist}
    \ifsseq@draw
        \ifnum\sseq@thepagecount<\numexpr\sseq@obj{#1.page}+\@ne
            \ifnum\sseq@obj{#1.page}=\sseq@thepagecount
                \sseq@thispagetrue
            \fi
            \ifnum\sseq@obj{#1.pagemin}<\sseq@thepagecount
                \sseq@circleclass@draw{#1}{#2}{#3}
            \fi
        \fi
    \fi
}

%%
%%  Labels
%%
%%    This code is called from the key value handler, but it has more to do with the code in this file so I am putting it here. Search in sseqkeys.code.tex for "Labels"
%%

\def\sseq@processlabels@default{%
    \global\let\sseq@classnodetext\pgfutil@empty
    \global\let\sseq@classnodetextoptions\pgfutil@empty
    \global\let\sseq@classlabelnodes\pgfutil@empty
}
\let\sseq@processlabels\sseq@processlabels@default

% I can't remember why we need to defer this. If at some point I figure this out, I should explain why here and in the definition of \class...
\def\sseq@handleclassquotes@inner#1#2{%
    \begingroup\pgfscope
    \def\sseq@classquotes@smugglehook{}
    \def\sseq@classquotes@smugglehook@inner{}
    \sseq@options@firstpassmode
    \sseq@thesseqstyle
    \sseq@thelabelstyle
    \sseq@theclasslabelstyle
    \the\sseq@scope@toks
    \sseq@options@normalmode
    \sseq@processoptions{class/label}{#2}%
    \sseq@classlabeltextfn{#1}% labeltextfn is a private handler, classlabeltextfn is exposed via "class label handler"
    \ifsseq@classlabel
        \sseq@options@firstpassmode
        \the\sseq@outerclasslabelstyle
        \sseq@x@addto@macro\sseq@classlabelnodes{%
            \@nx\sseq@drawlabel{%
                \sseq@maybemathswitch\unexpanded\@xp{\processedlabel}\sseq@maybemathswitch}%
                {% This is setup to prevent a bug where \classoptions and class label style don't work correctly together
                    \the\sseq@sseqstyle\@nx\the\sseq@sseqstyle@page
                    \the\sseq@labelstyle\@nx\the\sseq@labelstyle@page
                    \the\sseq@classlabelstyle\@nx\the\sseq@classlabelstyle@page
                    \sseq@theouterclasslabelstyle
                    \@nx\sseq@collections@labels@hook
                    \@nx\sseq@collections@classlabels@hook
                    \@nx\sseq@collections@outerclasslabels@hook
                    \unexpanded\@xp{\sseq@savedoptioncode}%
                }%
        }%
    \else
        \let\sseq@classquotes@smugglehook\sseq@classquotes@smugglehook@inner
        \sseq@options@firstpassmode
        \the\sseq@innerclasslabelstyle
        \sseq@options@normalmode
        \sseq@protectedeval{\@nx\pgfqkeys{/sseqpages/class/label}{#2}}%
        \sseq@protected@xdef\sseq@classnodetext{\sseq@maybemathswitch\processedlabel\sseq@maybemathswitch}%
        \xdef\sseq@classnodetextoptions{%
            %\unexpanded{\def\pgfkeysdefaultpath{/sseqpages/class/node texts/}}%
            \sseq@thelabelstyle\sseq@theclasslabelstyle\sseq@theinnerclasslabelstyle
            \@nx\sseq@collections@labels@hook
            \@nx\sseq@collections@classlabels@hook
            \@nx\sseq@collections@innerclasslabels@hook
            \unexpanded\@xp{\sseq@savedoptioncode}%
        }%
    \fi
    \@xp\endpgfscope\@xp\endgroup
    \sseq@classquotes@smugglehook
}

\def\sseq@handleedgequotes#1#2{% We use this via \let\tikz@quotes@as\sseq@handleedgequotes
    /utils/exec={% so it's called inside \pgfkeysalso{stuff}. Need to surround with /utils/exec={} to get out.
        \let\sseq@savedoptioncode@save\sseq@savedoptioncode
        \sseq@processoptions{label}{#2}
        \sseq@needstikztrue
        \let\sseq@temp\sseq@savedoptioncode
        \let\sseq@savedoptioncode\sseq@savedoptioncode@save
        \sseq@e@addto@options{
            \@nx\tikzset{
                every to/.append style={
                    edge node={
                        node [/sseqpages/label,
                             /utils/exec={
                                \let\@nx\sseq@tikz@transform@save\@nx\tikz@transform
                                \let\@nx\tikz@transform\relax
                                \@nx\sseq@thelabelstyle
                                \@nx\sseq@collections@labels@hook
                                \@nx\sseq@theedgelabelstyle
                                \@nx\sseq@collections@edgelabels@hook
                                \@xp\@nx\csname sseq@the\sseq@edgetype labelstyle\endcsname
                                \@xp\@nx\csname sseq@collections@\sseq@edgetype labels@hook\endcsname
                                \unexpanded\@xp{\sseq@temp}
                                \ifsseq@rotatelabels\iftikz@fullytransformed\else\@nx\tikz@fullytransformedtrue\@nx\tikz@addtransform{\@nx\pgftransformresetnontranslations\@nx\sseq@globalrotatetransform}\fi\fi
                                 \unexpanded\@xp{\sseq@edgeoptionhook} % this is just to make description work
                                 \let\@nx\tikz@transform\@nx\sseq@tikz@transform@save
                            }
                        ]{\sseq@labeltextfn{#1}}
                   }
                }
            }
        }
    }
}