-
Notifications
You must be signed in to change notification settings - Fork 2
/
sseqpages.sty
4144 lines (3876 loc) · 174 KB
/
sseqpages.sty
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
%%
%
% Sseqpages 0.9
% A package for drawing spectral sequences
% Written by Hood Chatham
%
%%
% TODO:
% manual
%
% names
%
% User interface to control arrow head for edges that go off page (option to turn ellipses off)
% Make shift={coord} work
% Fix shifts (what does this mean again? label shifts of some sort?)
%
% improve axes options? allow axis to be centered on coordinate or centered between coordinates
% Make sure user can't \sseqset{keep changes} inside environment
%
% Check \sseqset used inside environments
%
% Check "change classes" mechanism
% Figure out whether e.g., "change classes" could have a better name
%
% Check numexpr input is valid? (e.g., prevent something like **0 from throwing an "uncaught" error?) not very important
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{sseqpages}
\newif\ifsseq@versionwarn
\RequirePackage{tikz}
\RequirePackage{etoolbox}
\RequirePackage{xparse}
\usetikzlibrary{quotes}
\usetikzlibrary{positioning}
\usetikzlibrary{intersections}
\usetikzlibrary{backgrounds}
\usepgflibrary{arrows.meta}
%\usetikzlibrary{profiler}
\def\sseq@authorname#1{Hood Chatham}
\def\sseq@authoremail#1{[email protected]}
\DeclareOption{versionwarn}{\sseq@versionwarntrue}
\ProcessOptions\relax
\@ifpackagelater{tikz}{2015/07/08}{%
\@ifpackagelater{tikz}{2015/08/08}{%
\ifsseq@versionwarn
\expandafter\PackageWarning
\else
\expandafter\PackageError
\fi
{sseqpages}{You are using a version of Tikz later than the version sseqpages was developed for. Something might go wrong. Please say
'\string\usepackage[version warn]{sseqpages}' to suppress this error message and email me at \sseq@authoremail{} if you find any bugs}{}
}{%
% Current version of tikz
}
}{%
\ifsseq@versionwarn
\PackageWarning{sseqpages}{I'm not sure that the sseqpages package will work with Tikz versions earlier than 3.0.1a.}
\else
\PackageError{sseqpages}{I'm not sure that the sseqpages package will work with Tikz versions earlier than 3.0.1a. Please say
'\string\usepackage[version warn]{sseqpages}' to suppress this error message, and email me at \sseq@authoremail{} to let me know whether sseqpages works with your version
of Tikz. Or just update Tikz}{}
\fi
}
%%%%%% %%%%%%
%% %%
%% Declarations and preliminaries %%
%% %%
%%%%%% %%%%%%
\newif\ifsseq@hasname
\newif\ifsseq@updateexisting
\newif\ifsseq@ispageenv
\newif\ifsseq@keepchanges
\newif\ifsseq@globaldetone
\newif\ifsseq@needstikz
\newif\ifsseq@thispage
\newif\ifsseq@outofrange
\newif\ifsseq@classlabel
\newif\ifsseq@draworphanedges
\newif\ifsseq@drawedge
\newif\ifsseq@tikzprims@integershift
\sseq@drawedgetrue
\sseq@tikzprims@integershifttrue
\newif\ifsseq@tempif
\newtoks\sseq@temptoks
\newtoks\sseq@thislabelstyle
\newcount\sseq@anonsseqcount
\newcount\sseq@context@depth
\newcount\sseq@context@tempcount
\newcount\sseq@x
\newcount\sseq@y
\newcount\sseq@tempcount
\newcount\sseq@tempcountb
\newcount\sseq@tempx
\newcount\sseq@tempy
\newcount\sseq@tempxb
\newcount\sseq@tempyb
\sseq@context@depth\z@
\sseq@x\z@ \sseq@y\z@
\newdimen\sseq@gridstrokethickness
\sseq@gridstrokethickness=.1pt
% Ensure \@xp and \@nx have the correct values in case that amsmath isn't loaded
\let\@xp\expandafter
\let\@nx\noexpand
\def\@xptwo{\@xp\@xp\@xp}
\def\@xpthree{\@xp\@xp\@xp\@xp\@xp\@xp\@xp}
\def\sseq@nil{\sseq@thisshouldnthappen@nil unique expansion} % This expansion text should be unique so that \ifx\sseq@nil\othercommand is false.
\def\sseq@infinity{10000} % Larger than any coordinate anyone will ever use.
\def\sseq@macroname{\@xp\@gobble\string}
\def\sseq@gobble@to@nil#1\sseq@nil{}
% These are only used by defertikzcommand now
\def\sseq@callas#1{\def\sseq@callcmd{#1}}
\def\sseq@call#1{\bgroup\@xp\let\sseq@callcmd#1\@xptwo\egroup\sseq@callcmd}
\def\sseq@getfirstchar#1#2\sseq@nil{#1} % used in shift/checkshift transform
\def\sseq@smuggle@macro#1#2\egroup{\@xp\egroup\@xp\def\@xp#1\@xp{#1}}
% For expandable macros
\def\sseq@ifhop#1#2\fi{\fi#1}
\def\sseq@swapapply#1#2{#2#1}
\def\sseq@eval#1{\bgroup\edef\sseq@temp{#1}\@xp\egroup\sseq@temp}% I got this from sseq.sty
\def\sseq@protectedeval#1{\bgroup\protected@edef\sseq@temp{#1}\@xp\egroup\sseq@temp}
\def\sseq@eval@show#1{\bgroup\edef\sseq@temp{#1}\show\sseq@temp\@xp\egroup\sseq@temp}
\def\sseq@profilenew#1#2{\pgfprofilenew{#1}\pretocmd#2{\pgfprofilestart{#1}}{}{\error}\apptocmd#2{\pgfprofileend{#1}}{}{\error}}
\def\sseq@removeparens{\@xp\sseq@removeparens@}
\def\sseq@removeparens@(#1){#1}
% Stolen from trimspaces.sty
\bgroup
\catcode`\Q=3
\gdef\sseq@trimspaces#1{%
\romannumeral-`\q\sseq@trim@trim@\noexpand#1Q Q%
}
\long\gdef\sseq@trim@trim@#1 Q{\sseq@trim@trim@@#1Q}
\long\gdef\sseq@trim@trim@@#1Q#2{#1}
\egroup
\def\sseq@trimleadingspaces{\romannumeral-`q}
\def\sseq@ifempty#1{%
\@xp\ifx\@xp\sseq@nil\detokenize{#1}\sseq@nil
\@xp\@firstoftwo
\else
\@xp\@secondoftwo
\fi
}
\def\sseq@eatspacesthen#1{\bgroup\sseq@temptoks{#1}\@xp\@xp\@xp\egroup\@xp\the\@xp\sseq@temptoks\romannumeral-`\q}
\let\sseq@pgfmathparse@save\pgfmathparse
\def\sseq@pgfmathparse#1{\let\@@protect\protect\def\protect{}\sseq@pgfmathparse@save{#1}\restore@protect} % Prevent \protect from causing trouble for \pgfmathparse
%%% ifintexpr
% #1 -- expresion to test
% #2 -- true case
% #3 -- false case
% This tests true if \numexpr #1\relax throws no error and consumes all of #1 and false otherwise.
% Test if single token input is a digit
\def\sseq@digits{\\0\\1\\2\\3\\4\\5\\6\\7\\8\\9}
\def\sseq@ifdigit#1{\bgroup\sseq@tempiffalse\def\\##1{\ifx##1#1\sseq@tempiftrue\let\\\@gobble\fi}\sseq@digits\@xp\egroup\ifsseq@tempif\@xp\@firstoftwo\else\@xp\@secondoftwo\fi}
% Spaces matter to us, because \sseq@ifintexpr{1 1} is false but \sseqsifintexpr{11} is true
% so we make spaces into catcode other and use \scantokens
\def\sseq@ifintexpr#1{%
\bgroup
\catcode`\ =12\relax
\sseq@tempcount0\relax
\makeatletter
\scantokens{\sseq@ifintexpr@first{needsint}#1\sseq@nil}%
\@xp\egroup\next
}
\def\sseq@ifintexpr@first#1#2{\sseq@ifintexpr@{#2}}
% We need to use \futurelet so that we can detect open braces even when they only surround one token like {1}
% so we have to store the state in \sseq@ifintexpr@state
\def\sseq@ifintexpr@#1{\def\sseq@ifintexpr@state{#1}\futurelet\temptok\sseq@ifintexpr@@}
\ExplSyntaxOn
\def\sseq@ifintexpr@@{%
\ifx\temptok\bgroup%
\@xp\sseq@ifintexpr@false
\else
\ifx\temptok\sseq@nil
\csname sseq@ifintexpr@@\sseq@ifintexpr@state @done\@xptwo\endcsname
\else
\@xptwo\exp_last_unbraced:Nf\@xp\@xp\@xp\sseq@ifintexpr@@@
\fi
\fi
}
\ExplSyntaxOff
% We can't just use \futurelet because "\let\test(" makes \test unexpandable,
% so then "\csname hello\test\endcsname" is an error. This indexes into our state machine,
% cases: a digits, + or -, * or /, (, ), or something else (anything else always leads to false
\def\sseq@ifintexpr@@@#1{%
\ifx#1\sseq@nil
\def\next{\csname sseq@ifintexpr@@\sseq@ifintexpr@state @done\endcsname\sseq@nil}%
\else
\sseq@ifdigit{#1}%
{\sseq@ifintexpr@next{digit}}%
{%
\ifx#1+%
\sseq@ifintexpr@next{+-}
\else
\ifx#1-%
\sseq@ifintexpr@next{+-}
\else
\ifx#1*%
\sseq@ifintexpr@next{*/}
\else
\ifx#1/%
\sseq@ifintexpr@next{*/}
\else
\pgfutil@ifundefined{sseq@ifintexpr@@\sseq@ifintexpr@state @#1}%
{\let\next\sseq@ifintexpr@false}%
{\sseq@ifintexpr@next{#1}}%
\fi
\fi
\fi
\fi
}%
\fi
\next
}
\def\sseq@ifintexpr@true#1\sseq@nil{\ifnum\sseq@tempcount=0\relax \let\next\@firstoftwo\else\let\next\@secondoftwo\fi}
\def\sseq@ifintexpr@false#1\sseq@nil{\let\next\@secondoftwo}
\def\sseq@makeifint#1#2#3{\@xp\def\csname sseq@ifintexpr@@#1@#2\endcsname{#3}}
\def\sseq@ifintexpr@next#1{\@xp\let\@xp\next\csname sseq@ifintexpr@@\sseq@ifintexpr@state @#1\endcsname}
\sseq@makeifint{needsint}{done}{\sseq@ifintexpr@false}
\sseq@makeifint{needsint}{digit}{\sseq@ifintexpr@{int}}
\sseq@makeifint{needsint}{*/}{\sseq@ifintexpr@false}
\sseq@makeifint{needsint}{+-}{\sseq@ifintexpr@{needsint}}
\sseq@makeifint{needsint}{(}{\advance\sseq@tempcount1\relax\sseq@ifintexpr@{needsint}}
\sseq@makeifint{needsint}{)}{\sseq@ifintexpr@false}
\sseq@makeifint{needsint}{ }{\sseq@ifintexpr@{needsint}}
\sseq@makeifint{int}{done}{\sseq@ifintexpr@true}
\sseq@makeifint{int}{digit}{\sseq@ifintexpr@{int}}
\sseq@makeifint{int}{*/}{\sseq@ifintexpr@{needsint}}
\sseq@makeifint{int}{+-}{\sseq@ifintexpr@{needsint}}
\sseq@makeifint{int}{(}{\sseq@ifintexpr@false}
\sseq@makeifint{int}{)}{
\advance\sseq@tempcount-1\relax
\ifnum\sseq@tempcount<0\relax
\@xp\@xp\@xp\sseq@ifintexpr@false\@xp\@gobble
\else
\@xp\sseq@ifintexpr@
\fi{nointallowed}
}
\sseq@makeifint{int}{ }{\sseq@ifintexpr@{nointallowed}}
\sseq@makeifint{nointallowed}{done}{\sseq@ifintexpr@true}
\sseq@makeifint{nointallowed}{digit}{\sseq@ifintexpr@false}
\sseq@makeifint{nointallowed}{*/}{\sseq@ifintexpr@{needsint}}
\sseq@makeifint{nointallowed}{+-}{\sseq@ifintexpr@{needsint}}
\sseq@makeifint{nointallowed}{(}{\sseq@ifintexpr@false}
\sseq@makeifint{nointallowed}{)}{
\advance\sseq@tempcount-1\relax
\ifnum\sseq@tempcount<0\relax
\@xp\@xp\@xp\sseq@ifintexpr@false\@xp\@gobble
\else
\@xp\sseq@ifintexpr@
\fi{nointallowed}
}
\sseq@makeifint{nointallowed}{ }{\sseq@ifintexpr@{nointallowed}}
%% Error messages
\newtoks\sseq@thiscalltoks
\def\sseq@thiscall{\the\sseq@thiscalltoks}
\def\sseq@setthiscall{\let\sseq@error@annotation\sseq@error@annotation@call\sseq@thiscalltoks}
\def\sseq@esetthiscall#1{\let\sseq@error@annotation\sseq@error@annotation@call\sseq@eval{\sseq@thiscalltoks{#1}}}
\def\sseq@error@annotation{.^^J(\sseq@errorinfo)}
\def\sseq@error@annotation@call{.^^J(Error occurred during call "\sseq@thiscall"\space \sseq@errorinfo)}
\let\sseq@errmessage@std\errmessage
\def\sseq@errmessage#1{\sseq@builderrorinfo\sseq@errmessage@std{#1\sseq@error@annotation}}
\def\sseq@errorwithinfo#1{\let\errmessage\sseq@errmessage@std\sseq@builderrorinfo\pgfutil@packageerror{sseqpages}{#1\sseq@error@annotation}{}}
\def\sseq@errornoinfo#1{\let\errmessage\sseq@errmessage@std\sseq@builderrorinfo\pgfutil@packageerror{sseqpages}{#1}{}}
\DeclareRobustCommand\sseq@error{\sseq@error@}% This is robust just for \isalive...
\let\sseq@error@\sseq@errornoinfo
\def\sseq@errorinfo{}% Changed during \foreach
\def\sseq@inputlineno{\the\inputlineno}
\def\sseq@builderrorinfo{}% Changed during \foreach
\def\sseq@errorinfo@foreach{in the \@nx\foreach block that ends on line \the\inputlineno, with variable values:}
\def\sseq@error@internal#1{\sseq@error{Internal error: #1. Contact package author \sseq@authorname{} at \sseq@authoremail{}}{}}
\def\sseq@error@range{\sseq@error{Empty spectral sequence. For every spectral sequence you must either specify both the "x range" and "y range" or include at least one
\string\class}}
\def\sseq@error@standardparse#1{\sseq@error{You cannot use \string#1 inside a scope that has coordinate transformations other than integer shifts or the background key}}
\def\sseq@errorifpt#1#2{\sseq@errorifpt@#1.\sseq@nil{#2}}
\def\sseq@errorifpt@#1.#2\sseq@nil#3{\ifx\sseq@nil#2\sseq@nil\else\sseq@error{#3}\fi}
%%%%%% %%%%%%
%% %%
%% Commands to define other commands %%
%% %%
%%%%%% %%%%%%
\ExplSyntaxOn
%%% \sseq@NewDocumentCommand
%
% \sseq@NewDocumentCommand\somecommand is shorthand for \sseq@NewDocumentCommandAs\sseq@somecommand\somecommand
%
% so the result is that it defines \sseq@somecommand intended to be \let to \somecommand later.
\cs_new_protected:Npn\sseq@NewDocumentCommand#1{%
\exp_args:Nc \sseq@NewDocumentCommandAs { sseq@ \cs_to_str:N #1 }#1
}
%%% \sseq@NewDocumentCommandAS
%
% #1 - the command to define
% #2 - the command to use in argument parsing errors
% #3 - parameters (\NewDocumentCommand style)
% #4 - code
\cs_new_protected:Npn\sseq@NewDocumentCommandAs#1#2#3#4{
\group_begin:
\cs_set_eq:cN { tempsave_ \cs_to_str:N #2 } #2 % Store the original value of #2
\cs_set_eq:cc { tempsave_ \cs_to_str:N #2 \c_space_tl code } { \cs_to_str:N #2 \c_space_tl code } % Store the original value of #2
\DeclareDocumentCommand#2{#3}{\group_end: #4}
\cs_new:Npx #1{
\group_begin:
\exp_not:N \cs_set_eq:NN
\exp_not:c { \cs_to_str:N #2 \c_space_tl code }
\exp_not:c { \cs_to_str:N #1 \c_space_tl code }
\exp_not:c { \cs_to_str:N #1 \c_space_tl inner }
}
\cs_gset_eq:cN { \cs_to_str:N #1 \c_space_tl inner } #2
\cs_gset_eq:cc{ \cs_to_str:N #1 \c_space_tl code } { \cs_to_str:N #2 \c_space_tl code }
\cs_gset_eq:Nc #2 { tempsave_ \cs_to_str:N #2 }
\cs_gset_eq:cc { \cs_to_str:N #2 \c_space_tl code } { tempsave_ \cs_to_str:N #2 \c_space_tl code }
\group_end:
}
\ExplSyntaxOff
%%% Commands to help the user define "groups" of commands to be reused
\def\sseqnewgroup{\@ifnextchar*{\sseqnewgroup@}{\sseqnewgroup@{}}}
\def\sseqnewgroup@#1#2{\@ifnextchar[{\sseqnewgroup@@{#1}#2}{\sseqnewgroup@@{#1}#2[0]}}%]
\long\def\sseqnewgroup@@#1#2[#3]#4{%
\sseqnewcmd#1#2(\sseq@macrox,\sseq@macroy)[#3]{%
\bgroup
\def\sseq@newgroup@temp{}%
\sseq@tempiffalse
\sseq@ifempty{\options}{}{\sseq@tempiftrue}%
\sseq@tempcount=\numexpr\sseq@macrox\relax
\sseq@tempcountb=\numexpr\sseq@macroy\relax
\ifnum\sseq@tempcount=0\relax\else\sseq@tempiftrue\fi
\ifnum\sseq@tempcountb=0\relax\else\sseq@tempiftrue\fi
\ifsseq@tempif\sseq@eval{\@nx\begin{scope}[xshift=\the\sseq@tempcount,yshift=\the\sseq@tempcountb,\unexpanded{\options}]}\def\sseq@newgroup@temp{\end{scope}}\fi%
{}#4% This is set up to make sure no space problems occur with \patchcmd
\sseq@newgroup@temp
\egroup
}%
}
\def\sseqnewcmd{\@ifnextchar*{\@xp\sseqnewcmd@@\@gobble}{\sseqnewcmd@}}
\def\sseqnewcmd@#1{%
\@ifundefined{\sseq@macroname #1}{}{%
\sseq@error{%
A command named \string#1\space already exists. If you want to overwrite an existing command, say
'\string\sseqnewcmd*\string#1...' or '\string\sseqnewgroup*\string#1...' as appropriate%
}{}%
}%
\sseqnewcmd@@#1%
}
\def\sseqnewcmd@@#1{\@ifnextchar({\sseqnewcmd@@@#1}{\sseqnewcmd@@@#1(\x,\y)}}%)
\def\sseqnewcmd@@@#1(#2,#3){%
\@ifnextchar[{\sseqnewcmd@@@@#1(#2,#3)}{\sseqnewcmd@@@@#1(#2,#3)[0]}%]
}
\bgroup\lccode`\*=`\#\lccode`C=`C\lowercase{\egroup
\long\def\sseqnewcmd@@@@#1(#2,#3)[#4]#5{%
\ifnum#4>6 \sseq@error{Commands defined using '\string\sseqnewcmd' or '\string\sseqnewgroup' can take at most six arguments}\fi
\edef\helpera{\@xp\@nx\csname \sseq@macroname#1@\endcsname}% \helpera and \helperb contain the names of the two helper macros
\edef\helperb{\@xp\@nx\csname \sseq@macroname#1@@\endcsname}%
\xdef#1{\@nx\@ifnextchar[{\@xp\@nx\helpera}{\@xp\@nx\helpera[]}}% The outermost command and the first helper are easy
\@xp\xdef\helpera[##1](##2,##3){\@xp\@nx\helperb{##1}{##2}{##3}}%
\def\temp##1##2##3##4##5##6{#5}% Substitute placeholders for the arguments the user put in the body of the macro -- we'll replace these with actual pounds later.
\sseq@temptoks\@xp{\temp\ppfour\ppfive\ppsix\ppseven\ppeight\ppnine}%
\bgroup% Using \aftergroup's we can make a loop to determine how many arguments the innermost macro should take
\aftergroup\@xp\aftergroup\edef\aftergroup\helperb\aftergroup##\aftergroup1\aftergroup##\aftergroup2\aftergroup##\aftergroup3%
\ifnum#4>0\relax
\sseq@tempcount=0\relax
\sseq@tempcountb=3\relax
\loop
\advance\sseq@tempcount1\relax\advance\sseq@tempcountb1\relax
\aftergroup####\@xp\aftergroup\the\sseq@tempcountb
\ifnum\sseq@tempcount<#4\repeat
\fi
\aftergroup{%
\aftergroup\the\aftergroup\sseq@temptoks
\aftergroup}%
\egroup
%
\bgroup % Now we need to replace those fake \ppn placeholders with real pounds. Because of \lowercase, real pounds are *'s.
\@xp\sseq@patchrepeat\helperb{\options}{*1}%
\@xp\sseq@patchrepeat\helperb{#2}{*2}%
\@xp\sseq@patchrepeat\helperb{#3}{*3}%
\@xp\sseq@patchrepeat\helperb{\ppfour}{*4}%
\@xp\sseq@patchrepeat\helperb{\ppfive}{*5}%
\@xp\sseq@patchrepeat\helperb{\ppsix}{*6}%
\@xp\sseq@patchrepeat\helperb{\ppseven}{*7}%
\@xp\sseq@patchrepeat\helperb{\ppeight}{*8}%
\@xp\sseq@patchrepeat\helperb{\ppnine}{*9}%
\sseq@eval{\global\let\@xp\@nx\helperb\@xp\@nx\helperb}%
\egroup
}
}% end \lowercase
\def\sseq@patchrepeat#1#2#3{\patchcmd#1{#2}{#3}{\sseq@patchrepeat#1{#2}{#3}}{}}
%%%%%% %%%%%%
%% %%
%% Load and Store %%
%% %%
%%%%%% %%%%%%
% These are attributes that come with a given spectral sequence (by name)
% All of these values are loaded at the beginning of sseqpage (and of sseqdata if an existing sseq is being modified).
% They are then stored together at the end of sseqdata (and of sseqpage if "keep changes" option is present).
\def\sseq@storelist{}
\def\sseq@storelist@setdefaults{}
\def\sseq@addtostorelist#1#2{%
\sseq@g@addto@macro\sseq@storelist{\\#1}%
\sseq@x@addto@macro\sseq@storelist@setdefaults{\global\let\@nx#1\@xp\@nx\csname \sseq@macroname#1@default\endcsname}%
\@xp\gdef\csname\sseq@macroname#1@default\endcsname{#2}%
}
\def\sseq@addiftostorelist#1{\sseq@addiftostorelistopt{#1}{false}}
\def\sseq@addiftostorelist@truedefault#1{\sseq@addiftostorelistopt{#1}{true}}
\def\sseq@addiftostorelistopt#1#2{%
\@xp\newif\csname ifsseq@#1\endcsname
\sseq@g@addto@macro\sseq@storelist{\sseq@storelistif{#1}}%
\sseq@x@addto@macro\sseq@storelist@setdefaults{\@xp\@nx\csname sseq@#1@default\endcsname}%
\@xp\xdef\csname sseq@#1@default\endcsname{\global\@xp\@nx\csname sseq@#1#2\endcsname}%
}
% transfer data about the current spectral sequence between \<command> and \<command><sseqname>
\def\sseq@storelist@store#1{\edef\sseq@temp{\@nx\global\@nx\let\@xp\@nx\csname\sseq@macroname#1\sseq@thename\endcsname\@nx#1}\sseq@temp}
\def\sseq@storelist@get#1{\edef\sseq@temp{\global\let\@nx#1\@xp\@nx\csname\sseq@macroname#1\sseq@thename\endcsname}\sseq@temp}
\def\sseq@storelistif@store#1{%
\@xp\edef\csname sseq@storeif@#1\endcsname{\csname ifsseq@#1\endcsname \@xp\@nx\csname sseq@#1true\endcsname\else\@xp\@nx\csname sseq@#1false\endcsname\fi}%
\@xp\sseq@storelist@store\csname sseq@storeif@#1\endcsname
}
\def\sseq@storelistif@get#1{
\@xp\sseq@storelist@get\csname sseq@storeif@#1\endcsname
\csname sseq@storeif@#1\endcsname
}
\def\sseq@storecmds{\let\\\sseq@storelist@store\let\sseq@storelistif\sseq@storelistif@store\sseq@storelist}
\def\sseq@getcmds{\let\\\sseq@storelist@get\let\sseq@storelistif\sseq@storelistif@get\sseq@storelist}
%%%% New "poor man's OOP" Load/Store
% Directly stores things into commands that are annotated with the name of the spectral sequence.
% I use this primarily for commands that won't necessarily exist for every spectral sequence
% for instance because it has the description of a particular class or differential as part of its name
\def\sseq@obj@fullname#1{sseq.\sseq@thename.#1}
\def\sseq@obj#1{\csname sseq.\sseq@thename.#1\endcsname}
\def\sseq@obj@gdef#1{\@xptwo\gdef\sseq@obj{#1}}
\def\sseq@obj@xdef#1{\@xptwo\xdef\sseq@obj{#1}}
\def\sseq@obj@xodef#1{\@xp\gdef\csname \sseq@obj@fullname{#1}\@xp\endcsname\@xp}
\def\sseq@obj@let#1{\@xptwo\let\sseq@obj{#1}}
\def\sseq@obj@gletcsname#1#2{\global\@xp\let\csname\sseq@obj@fullname{#1}\@xp\endcsname\csname#2\endcsname}
\def\sseq@obj@gletobj#1#2{\global\@xp\let\csname\sseq@obj@fullname{#1}\@xp\endcsname\csname\sseq@obj@fullname{#1}\endcsname}
\def\sseq@obj@undef#1{\@xptwo\let\sseq@obj{#1}\relax}
\def\sseq@obj@show#1{\@xptwo\show\sseq@obj{#1}}
\def\sseq@obj@ifundef#1{\@ifundefined{\sseq@obj@fullname{#1}}}
\def\sseq@obj@ifdef#1#2#3{\@ifundefined{\sseq@obj@fullname{#1}}{#3}{#2}}
\def\sseq@obj@inc#1{\bgroup\sseq@tempcount\sseq@obj{#1}\relax\advance\sseq@tempcount1\relax\sseq@obj@xdef{#1}{\the\sseq@tempcount}\egroup}
\def\sseq@obj@gaddto{\@xptwo\sseq@g@addto@macro\sseq@obj} % TODO: either gaddto or g@addto
\def\sseq@obj@xaddto{\@xptwo\sseq@x@addto@macro\sseq@obj}
\def\sseq@obj@xoaddto#1{\@xp\sseq@g@addto@macro\csname \sseq@obj@fullname{#1}\@xp\endcsname\@xp}
\def\sseq@obj@map#1#2{\def\\##1{#2}\sseq@obj{#1}}
\def\sseq@obj@ifchanged#1#2#3{\sseq@obj@ifundef{#1.changed}{#3}{#2}}
\def\sseq@obj@changedtrue#1{\sseq@obj@gdef{#1.changed}{}}
\def\sseq@obj@changedfalse#1{\sseq@obj@undef{#1.changed}}
\def\sseq@cleanup@obj#1{
\ifsseq@keepchanges\else
\sseq@obj@ifchanged{#1}{}{
\sseq@obj@changedtrue{#1}
\sseq@x@addto@macro\sseq@pagecleanup{
\@nx\sseq@obj@gdef{#1}{\unexpanded\@xpthree{\sseq@obj{#1}}}
\@nx\sseq@obj@changedfalse{#1}
}
}
\fi
}
%%%% add to macro commands
\def\sseq@d@addto@macro#1#2{\@xp\def\@xp#1\@xp{#1#2}}
\def\sseq@e@addto@macro#1#2{\edef#1{\unexpanded\@xp{#1}#2}} % let #2 be expanded
\def\sseq@eo@addto@macro#1#2{\edef#1{\unexpanded\@xp{#1}\unexpanded\@xp{#2}}} % let #2 be expanded once
\def\sseq@g@addto@macro#1#2{\@xp\gdef\@xp#1\@xp{#1#2}}
\def\sseq@x@addto@macro#1#2{\xdef#1{\unexpanded\@xp{#1}#2}} % let #2 be expanded
\def\sseq@xprotected@addto@macro#1#2{\protected@xdef#1{\unexpanded\@xp{#1}#2}}
%%%% Saved paths, temporary saved paths, background saved paths
% \sseq@savedpaths@whatever is redefined to be \sseq@savedpaths@whatever@standard or \sseq@savedpaths@whatever@temporary depending on context
% This simplifies the code a lot because I don't have to check again where I should put things.
\sseq@addtostorelist\sseq@savedpaths{}
\def\sseq@tempsavedpaths{}
\def\sseq@savedpaths@addclass@standard#1{\sseq@x@addto@macro\sseq@savedpaths{\@nx\sseq@class@draw@ifpage{#1}}}
\def\sseq@savedpaths@adddifferential@standard#1{\sseq@x@addto@macro\sseq@savedpaths{\@nx\sseq@differential@draw@ifpage{#1}}}
\def\sseq@savedpaths@addstructline@standard#1{\sseq@x@addto@macro\sseq@savedpaths{\@nx\sseq@structline@draw@ifpage{#1}}}
\def\sseq@savedpaths@add@standard{\sseq@g@addto@macro\sseq@savedpaths}
\def\sseq@savedpaths@xadd@standard{\sseq@x@addto@macro\sseq@savedpaths}
\def\sseq@savedpaths@show@standard{\show\sseq@savedpaths}
\def\sseq@scope@savedpaths@add@standard#1{\sseq@savedpaths@add@standard{#1}\sseq@savedpaths@add@background{#1}}
\def\sseq@savedpaths@addclass@temporary#1{\sseq@x@addto@macro\sseq@tempsavedpaths{\@nx\sseq@class@draw@ifpage{#1}}}
\def\sseq@savedpaths@adddifferential@temporary#1{\sseq@x@addto@macro\sseq@tempsavedpaths{\@nx\sseq@differential@draw@ifpage{#1}}}
\def\sseq@savedpaths@addstructline@temporary#1{\sseq@x@addto@macro\sseq@tempsavedpaths{\@nx\sseq@structline@draw@ifpage{#1}}}
\def\sseq@savedpaths@add@temporary{\sseq@g@addto@macro\sseq@tempsavedpaths}
\def\sseq@savedpaths@xadd@temporary{\sseq@x@addto@macro\sseq@tempsavedpaths}
\def\sseq@savedpaths@show@temporary{\show\sseq@tempsavedpaths}
\def\sseq@scope@savedpaths@add@temporary#1{\sseq@savedpaths@add@temporary{#1}\sseq@savedpaths@add@background{#1}}
\def\sseq@savedpaths@addclass@background#1{\sseq@error@internal{\@nx\sseq@savedpaths@addclass occurred in background mode}}
\def\sseq@savedpaths@adddifferential@background#1{\sseq@error@internal{\@nx\sseq@savedpaths@adddifferential occurred in background mode}}
\def\sseq@savedpaths@addstructline@background#1{\sseq@error@internal{\@nx\sseq@savedpaths@addstructline occurred in background mode}}
\def\sseq@savedpaths@add@background{\sseq@g@addto@macro\sseq@savedbackgroundpaths}
\def\sseq@savedpaths@xadd@background{\sseq@x@addto@macro\sseq@savedbackgroundpaths}
\def\sseq@savedpaths@show@background{\show\sseq@savedbackgroundpaths}
\def\sseq@setsavedpaths#1{%
\@xp\let\@xp\sseq@savedpaths@addclass \csname sseq@savedpaths@addclass@#1\endcsname
\@xp\let\@xp\sseq@savedpaths@adddifferential\csname sseq@savedpaths@adddifferential@#1\endcsname
\@xp\let\@xp\sseq@savedpaths@addstructline \csname sseq@savedpaths@addstructline@#1\endcsname
\@xp\let\@xp\sseq@savedpaths@add \csname sseq@savedpaths@add@#1\endcsname
\@xp\let\@xp\sseq@savedpaths@xadd \csname sseq@savedpaths@xadd@#1\endcsname
\pgfutil@ifundefined{sseq@scope@savedpaths@add@#1}{}{%
\@xp\let\@xp\sseq@savedpaths@show \csname sseq@savedpaths@show@#1\endcsname
\@xp\let\@xp\sseq@scope@savedpaths@add \csname sseq@scope@savedpaths@add@#1\endcsname
}%
}
\def\sseq@usesavedpaths{%
\sseq@savedpaths
\sseq@clearchangestyles
\sseq@tempsavedpaths
\gdef\sseq@tempsavedpaths{}%
}
%%% Install user commands
% copy commands into user namespace by removing sseq@ prefixes
% given a list of commands, \let\thiscommand\sseq@thiscommand on each one
\def\sseq@usermacrolist{\class\replaceclass\d\structline\classoptions\doptions\structlineoptions\isdead\isalive\pgfmathparse}
\def\sseq@installusermacros{\@xp\sseq@installusermacros@\sseq@usermacrolist\sseq@nil}
\def\sseq@installusermacros@#1{%
\ifx#1\sseq@nil\else % if so, that was the last command in the list
\@xp\let\@xp#1\csname sseq@\sseq@macroname#1\endcsname
\@xp\sseq@installusermacros@
\fi %
}
%%%%%% %%%%%%
%% %%
%% Patch \foreach error messages %%
%% %%
%%%%%% %%%%%%
% Put together an error message that says which stage in the for loop caused the error
\def\sseq@builderrorinfo@foreach{%
\let\sseq@errorinfo\sseq@errorinfo@foreach % The starting message, which says we're in a for each loop and these are the variables involved
% Now print each of the current saved values
\let\\\sseq@errorinfo@foreach@slsl % Iterator to print out "variable = value"
\sseq@context@tempcount0\relax
\loop % Work through each layer of context / foreach loop
\advance\sseq@context@tempcount1\relax
\csname sseq@for@savedtoks\the\sseq@context@tempcount\endcsname
\ifnum\sseq@context@tempcount<\sseq@context@depth\repeat %
}
\def\sseq@errorinfo@foreach@slsl#1#2{% No semicolon before the first variable
\sseq@g@addto@macro\sseq@errorinfo{ \@nx#1= #2}\let\\\sseq@errorinfo@foreach@slsl@ii
}
\def\sseq@errorinfo@foreach@slsl@ii#1#2{%
\sseq@g@addto@macro\sseq@errorinfo{; \@nx#1= #2}%
}
\def\sseq@pgffor@atbeginforeach{%
\begingroup %
\let\sseq@builderrorinfo\sseq@builderrorinfo@foreach % Install foreach error annotations
\let\errmessage\sseq@errmessage
\let\sseq@error@\sseq@errorwithinfo
\advance\sseq@context@depth1\relax
\sseq@for@clearsavedtoks % empty the saved variables at this level
}
\def\sseq@for@clearsavedtoks{\@xp\gdef\csname sseq@for@savedtoks\the\sseq@context@depth\endcsname{}}
\def\sseq@for@savemacro#1#2{\@xp\sseq@g@addto@macro\csname sseq@for@savedtoks\the\sseq@context@depth\endcsname{\\#1{#2}}}
\def\sseq@for@esavemacro#1#2{\@xp\sseq@x@addto@macro\csname sseq@for@savedtoks\the\sseq@context@depth\endcsname{\@nx\\\@nx#1{#2}}}
\def\sseq@for@savemacros{\@ifnextchar\def{\sseq@for@savemacros@}{}}
\def\sseq@for@savemacros@#1#2#3{\sseq@for@savemacro#2{#3}\@ifnextchar\def{\sseq@for@savemacros@}{}}
\def\sseq@for@savedpaths@add#1{%
\sseq@savedpaths@add@background{#1}%
\ifsseq@keepchanges
\sseq@savedpaths@add@standard{#1}%
\else
\sseq@savedpaths@add@temporary{#1}%
\fi
}
%% Patch \foreach (Modifies tikz code)
% Perform a deep copy
\def\sseq@pgffor@@vars@opt[#1]{\pgfkeys{/sseqpages/foreach/.cd,#1}\pgffor@vars}
\let\sseq@pgffor@doloop\pgffor@doloop
\let\sseq@pgffor@invokebody\pgffor@invokebody
\let\sseq@pgffor@assign@@@parse\pgffor@assign@@@parse
\let\sseq@pgffor@count@@parse\pgffor@count@@parse
\let\sseq@pgffor@remember@@@parse\pgffor@remember@@@parse
\let\sseq@pgffor@remember@@@parse@old\pgffor@remember@@@parse@old
\let\sseq@pgffor@multiassignfinal\pgffor@multiassignfinal
\let\sseq@pgffor@default@endgroup\pgffor@default@endgroup
\let\sseq@pgffor@atendforeach\pgffor@atendforeach
\def\sseq@patchfor{%
\let\pgffor@@vars@opt\sseq@pgffor@@vars@opt
\let\pgffor@atbeginforeach\sseq@pgffor@atbeginforeach
\let\pgffor@invokebody\sseq@pgffor@invokebody
\let\pgffor@doloop\sseq@pgffor@doloop
\let\pgffor@assign@@@parse\sseq@pgffor@assign@@@parse
\let\pgffor@count@@parse\sseq@pgffor@count@@parse
\let\pgffor@remember@@@parse\sseq@pgffor@remember@@@parse
\let\pgffor@remember@@@parse@old\sseq@pgffor@remember@@@parse@old
\let\pgffor@multiassignfinal\sseq@pgffor@multiassignfinal
\let\pgffor@default@endgroup\sseq@pgffor@default@endgroup
\let\pgffor@atendforeach\sseq@pgffor@atendforeach
}
%% Now modify all of the commands to tell sseqpages about the variable values
\def\sseq@for@nopatch{\sseq@error@internal{failed to patch \string\foreach}}
\patchcmd\sseq@pgffor@invokebody % store setting after
{\expandafter\expandafter\expandafter\def\expandafter\pgffor@var\expandafter{\pgffor@value}}
{\expandafter\expandafter\expandafter\def\expandafter\pgffor@var\expandafter{\pgffor@value}%
\@xp\sseq@for@esavemacro\pgffor@var{\pgffor@var}}
{}{\sseq@for@nopatch}
\patchcmd\sseq@pgffor@invokebody
{\expandafter\expandafter\expandafter\pgffor@reset@hooks\expandafter\pgffor@beginhook\expandafter\pgffor@body\pgffor@endhook}
{\expandafter\expandafter\expandafter\pgffor@reset@hooks\expandafter\pgffor@beginhook\expandafter\pgffor@body\pgffor@endhook}
{}{\sseq@for@nopatch}
\patchcmd\sseq@pgffor@doloop % store setting before
{\ifx\pgffor@assign@before@code}
{\@xp\sseq@for@esavemacro\pgffor@var{\pgffor@var}%
\ifx\pgffor@assign@before@code}
{}{\sseq@for@nopatch}
\patchcmd\sseq@pgffor@invokebody % reset stored definitions before
{\ifx\pgffor@assign@after@code}
{\sseq@for@clearsavedtoks%
\ifx\pgffor@assign@after@code}
{}{\sseq@for@nopatch}
\patchcmd\sseq@pgffor@doloop % reset stored definitions before
{\ifx\pgffor@assign@after@code}
{\sseq@for@clearsavedtoks%
\ifx\pgffor@assign@after@code}
{}{\sseq@for@nopatch}
\patchcmd\sseq@pgffor@remember@@@parse@old
{\pgfutil@append@tomacro{\pgffor@assign@once@code}{\def#2{#4}}}
{\pgfutil@append@tomacro{\pgffor@assign@once@code}{\def#2{#4}\sseq@for@savemacro#2{#4}}}
{}{\sseq@for@nopatch}
\patchcmd\sseq@pgffor@assign@@@parse
{\pgfutil@append@tomacro{\pgffor@assign@once@code}{\pgfmathparse{#2}\let#1=\pgfmathresult}}
{\pgfutil@append@tomacro{\pgffor@assign@once@code}{\pgfmathparse{#2}\let#1=\pgfmathresult\sseq@for@esavemacro#1{\pgfmathresult}}}
{}{\sseq@for@nopatch}
\patchcmd\sseq@pgffor@assign@@@parse
{\pgfutil@append@tomacro{\pgffor@assign@once@code}{\def#1{#2}}}
{\pgfutil@append@tomacro{\pgffor@assign@once@code}{\def#1{#2}\sseq@for@savemacro#1{#2}}}
{}{\sseq@for@nopatch}
\patchcmd\sseq@pgffor@assign@@@parse
{\pgfutil@append@tomacro{\pgffor@assign@before@code}{\pgfmathparse{#2}\let#1=\pgfmathresult}}
{\pgfutil@append@tomacro{\pgffor@assign@before@code}{\pgfmathparse{#2}\let#1=\pgfmathresult\sseq@for@esavemacro#1{\pgfmathresult}}}
{}{\sseq@for@nopatch}
\patchcmd\sseq@pgffor@assign@@@parse
{\pgfutil@append@tomacro{\pgffor@assign@before@code}{\def#1{#2}}}
{\pgfutil@append@tomacro{\pgffor@assign@before@code}{\def#1{#2}\sseq@for@savemacro#1{#2}}}
{}{\sseq@for@nopatch}
\patchcmd\sseq@pgffor@count@@parse
{\pgfutil@append@tomacro\pgffor@assign@before@code{\pgfmathparse{int(#1+1)}\let#1=\pgfmathresult}}
{\pgfutil@append@tomacro\pgffor@assign@before@code{\pgfmathparse{int(#1+1)}\let#1=\pgfmathresult\sseq@for@esavemacro#1{\pgfmathresult}}}
{}{\sseq@for@nopatch}
\patchcmd\sseq@pgffor@remember@@@parse
{\pgfutil@append@tomacro{\pgffor@assign@after@code}{\expandafter\def\expandafter#1\expandafter{\the#2}}}
{\pgfutil@append@tomacro{\pgffor@assign@after@code}{\expandafter\def\expandafter#1\expandafter{\the#2}\sseq@for@esavemacro#1{\the#2}}}
{}{\sseq@for@nopatch}
\patchcmd\sseq@pgffor@remember@@@parse
{\pgfutil@append@tomacro{\pgffor@assign@after@code}{\expandafter\def\expandafter#1\expandafter{#2}}}
{\pgfutil@append@tomacro{\pgffor@assign@after@code}{\expandafter\def\expandafter#1\expandafter{#2}\@xp\sseq@for@savemacro\@xp#1\@xp{#2}}}
{}{\sseq@for@nopatch}
\patchcmd\sseq@pgffor@remember@@@parse@old
{\pgfutil@append@tomacro{\pgffor@assign@after@code}{\edef#2{#1}}}
{\pgfutil@append@tomacro{\pgffor@assign@after@code}{\edef#2{#1}\sseq@for@esavemacro#2{#1}}}
{}{\sseq@for@nopatch}
\patchcmd\sseq@pgffor@multiassignfinal
{\expandafter\expandafter\expandafter\def\expandafter\pgffor@currentvar\expandafter{\pgffor@temp}}
{\expandafter\expandafter\expandafter\def\expandafter\pgffor@currentvar\expandafter{\pgffor@temp}%
\@xp\sseq@for@esavemacro\pgffor@currentvar{\pgffor@temp}}
{}{\sseq@for@nopatch}
\patchcmd\sseq@pgffor@default@endgroup
{\else\pgffor@remember@once@expanded}
{\else\pgffor@remember@once@expanded %
\@xp\sseq@for@savemacros\pgffor@remember@once@expanded}
{}{\sseq@for@nopatch}
\patchcmd\sseq@pgffor@atendforeach
{\else\pgffor@remember@expanded}
{\else\pgffor@remember@expanded %
\@xp\sseq@for@savemacros\pgffor@remember@expanded}
{}{\sseq@for@nopatch}
\pretocmd\sseq@pgffor@atendforeach{\sseq@for@clearsavedtoks}{}{\sseq@for@nopatch}
%%%%%% %%%%%%
%% %%
%% Some Internal Utilities %%
%% %%
%%%%%% %%%%%%
\def\sseq@iffullcoord(#1){\@xp\sseq@iffullcoord@#1,\sseq@nil}
\def\sseq@iffullcoord@#1,#2,#3\sseq@nil{\ifx\sseq@nil#3\sseq@nil\@xp\@secondoftwo\else\@xp\@firstoftwo\fi}
% Only works for full coordinates. Used for error checking in \replaceclass and \d.
\def\sseq@ifundefcoord{\@xp\sseq@ifundefcoord@}
\def\sseq@ifundefcoord@(#1){%
\sseq@obj@ifundef{class.(#1).num}%
}
\def\sseq@ifdead#1{\ifnum\sseq@obj{class.#1[\sseq@obj{class.#1.num}].page}<\sseq@infinity\relax \@xp\@firstoftwo\else\@xp\@secondoftwo\fi}
\def\sseq@getdeathpage#1{\sseq@obj{class.#1[\sseq@obj{class.#1.num}].page}}
%%%%%%%%
%%
%% Coordinate Parsers
%%
%%%%%%%%
% These do all of the work of taking a coordinate of the form (x,y), (x,y,n), or (x,y,tag) and turning them
% into the internal representation needed for the rest of the package.
% This comes in two parts:
% \sseq@parsecoord@maincoord -- separates a coordinate into {x,y}{n or tag}, numerically evaluates x and y, and adds in the values of \sseq@x and \sseq@y
% \sseq@parsecoord@index -- decides which class {n or tag} represents
%
% There are three interface commands:
% \sseq@parsecoord -- for most things
% \sseq@cparsecoord -- for \class (but not for \replaceclass or \classoptions). Doesn't use \sseq@parsecoord@index at all.
% \sseq@dparsecoord -- for \d and \doptions
% \sseq@parsecoordex -- for \isalive: the body of a page constraint needs to be \edef'd so we need a completely expandable version
%
% In order to handle errors that come up in \sseq@parsecoordex, there is also the command \sseq@parsecoordex@reporterror that needs to be called on the macro where
% the result of \sseq@parsecoordex is stored. It's also important that the error can't be wrapped in braces (possible TODO: fix that with \scantokens).
%% Expandable parsing macro for dealing with the coordinate
% #1 -- callback which takes two arguments:
% ##1 -- "x,y" evaluated and updated to reflect value of \sseq@x and \sseq@y
% ##2 -- whatever came after the semicolon, if anything
% #2 -- a coordinate of the form {x,y} or {x,y;stuff}
% #3 -- for error messages
\def\sseq@parsecoord@maincoord#1#2{%
\pgfutil@in@,{#1}
\ifpgfutil@in@
\def\sseq@errortype{#2}
\sseq@parsecoord@maincoord@#1,\sseq@nil{#2}
\else
\sseq@error{Invalid coordinate\sseq@ifempty{#2}{}{ provided to #2}}
\fi
}
\def\sseq@parsecoord@maincoord@#1,#2,#3\sseq@nil#4{%
\sseq@ifintexpr{#1}{}{\sseq@error{Invalid x coordinate\sseq@ifempty{#4}{}{ provided to #4}}}%
\sseq@ifintexpr{#2}{}{\sseq@error{Invalid y coordinate\sseq@ifempty{#4}{}{ provided to #4}}}%
\edef\sseq@xcoord{\the\numexpr\sseq@x+(#1)\relax}%
\edef\sseq@ycoord{\the\numexpr\sseq@y+(#2)\relax}%
\edef\sseq@xycoord{\sseq@xcoord,\sseq@ycoord}%
\sseq@ifempty{#3}{\let\sseq@restcoord\pgfutil@empty}{%
\edef\sseq@restcoord{\sseq@parsecoord@eatcomma#3\sseq@nil}%
}%
}%
\def\sseq@parsecoord@eatcomma#1,\sseq@nil{#1}
%% \sseq@parsecoord@index -- Find out which class an index indicates
% if the index is positive, just return it (don't check whether it is within bounds!!)
% if the index is negative, return (number of nodes at (x,y)) - index + 1
% if index is empty, return 1 (should it be -1?)
%
% We don't check whether positive indices are within bounds because \structline wants to use this command,
% but it allows struct lines that automatically attach to endpoints that don't yet exist.
% Calling commands that do want it to be in bounds (\d and \isalive) are responsible for checking themselves.
%
% #1 -- output variable
% #2 -- x,y
% #3 -- index or tag
% #4 -- description for error messages
\def\sseq@parsecoord@index#1#2#3#4{
\sseq@eval{\unexpanded{\sseq@parsecoord@indexex{\def#1}}{#2}{#3}{#4}}
\sseq@parsecoord@reporterror{#1}
}
% #1 -- callback which takes one argument -- the final coordinate in parentheses.
% #2 -- x,y
% #3 -- n
% #4 -- description for error messages
\def\sseq@parsecoord@index{%
\ifx\sseq@rawindex\pgfutil@empty
\def\sseq@index{1}
\else
\sseq@obj@ifdef{partcoord.(\sseq@xycoord).tag.\sseq@class@tagprefix\sseq@rawindex}{% If the raw index is a tag
\edef\sseq@index{\sseq@obj{partcoord.(\sseq@xycoord).tag.\sseq@class@tagprefix\sseq@rawindex}}
}{%
\sseq@ifintexpr{\sseq@rawindex}{%
\ifnum\sseq@rawindex<0\relax% Negative case -- why this command exists
\sseq@obj@ifundef{partcoord.(\sseq@xycoord).numnodes}{%
\sseq@error{negative index \sseq@index\space provided \sseq@ifempty{\sseq@errortype}{}{for \sseq@errortype\space}but no classes yet exist in (\sseq@xycoord).
Negative indices count from the most recent class in the given position; in particular, there must be at least one existing class}}{}%
\edef\sseq@index{\the\numexpr\sseq@obj{partcoord.(\sseq@xycoord).numnodes} + \sseq@rawindex + 1\relax}%
\ifnum\sseq@index<1\relax
\sseq@error{index \sseq@rawindex\space provided for the \sseq@errortype\space is out of bounds -- only \sseq@obj{partcoord.(\sseq@xycoord).numnodes} classes exist at position (\sseq@xycoord)}%
\fi
\else
\edef\sseq@index{\the\numexpr\sseq@rawindex}
\fi
}{
\sseq@error{Tag '\sseq@rawindex' provided \ifx\sseq@errortype\pgfutil@empty\else for \sseq@errortype\space\fi is not a valid integer expression but no such tag exists in position (\sseq@xycoord)}%
}
}
\fi
}
% #1 -- callback
% #2 -- coordinate
% #3 -- the error message
\def\sseq@parsecoord#1{\sseq@parsecoord@maincoord{\sseq@parsecoordex@callback{#1}}}
\def\sseq@parsecoordex@callback#1#2#3#4{%
\sseq@parsecoord@callback@iferror{#2}{%
#1{#2}%
}{%
\sseq@parsecoord@indexex{#1}{#2}{#3}{#4}%
}%
}
% #1 -- callback
% #2 -- coordinate
% #3 -- the error message
\def\sseq@parsecoord#1#2#3{%
\sseq@parsecoord@maincoord{#2}{#3}%
\let\sseq@rawindex\sseq@restcoord
\sseq@parsecoord@index
\@xp\let\csname \sseq@macroname#1@partial\endcsname\sseq@xycoord
\edef#1{(\sseq@xycoord,\sseq@index)}%
\@xp\def\csname \sseq@macroname#1name\endcsname{(#2)}%
}
% #1 -- coordinate
\def\sseq@cparsecoord#1{%
\sseq@parsecoord@maincoord{#1}{}%
\ifx\sseq@restcoord\pgfutil@empty\else\sseq@error{Too many coordinates}\fi%
\let\partialcoord\sseq@xycoord
\let\xcoord\sseq@xcoord
\let\ycoord\sseq@ycoord
}
% #1 -- page
% #2 -- coordinate
\def\sseq@dparsecoord#1#2{%
\sseq@parsecoord@maincoord{#2}{}%
\edef\sseq@rawsindex{\@xp\sseq@dparsecoord@getxindex\@xp{\sseq@restcoord}}%
\edef\sseq@rawtindex{\@xp\sseq@dparsecoord@getyindex\@xp{\sseq@restcoord}}
%
\let\sseq@rawindex\sseq@rawsindex
\sseq@parsecoord@index
\let\sourcecoord\sseq@xycoord
\edef\source{(\sseq@xycoord,\sseq@index)}%
\edef\sourcename{(\sseq@xycoord\ifx\sseq@rawindex\pgfutil@empty\else,\sseq@rawindex\fi)}
%
\sseq@eval{\edef\@nx\sseq@xycoord{\@nx\sseq@differential@gettarget{#1}{\sseq@xycoord}}}
\let\sseq@rawindex\sseq@rawtindex
\sseq@parsecoord@index
\let\targetcoord\sseq@xycoord
\edef\target{(\sseq@xycoord,\sseq@index)}%
\edef\targetname{(\sseq@xycoord\ifx\sseq@rawindex\pgfutil@empty\else,\sseq@rawindex\fi)}
%
\sseq@ifundefcoord\source{%
\sseq@error{%
Source \sourcename\space of differential '\sseq@thiscall' can't support
a differential because a class in that position never existed% TODO: make separate out of bounds index error message
}{}%
}{}%
%
\sseq@ifundefcoord\target{%
\sseq@error{%
Target \targetname\space of differential '\sseq@thiscall' can't accept
a differential because a class in that position never existed%
}{}%
}{}%
%
\ifnum\sseq@obj{partcoord.(\sourcecoord).numnodes}=1\relax\else
\ifx\xindex\pgfutil@empty
\sseq@error{%
There are multiple nodes at source coordinate (\sourcecoord) so instead of '\sseq@thiscall' you should say
'\sseq@thiscall@command\unexpanded\@xp{\sseq@thiscall@options}\sseq@thiscall@page(#2,n\ifx\yindex\pgfutil@empty\else,\yindex\fi)' where n specifies which of the
\sseq@obj{partcoord.(\sourcecoord).numnodes} nodes at (\sourcecoord) should be the source%
}%
\fi
\fi
\ifnum\sseq@obj{partcoord.(\targetcoord).numnodes}=1\relax\else
\ifx\yindex\pgfutil@empty
\sseq@error{%
There are multiple nodes at target coordinate (\targetcoord) so instead of '\sseq@thiscall' you should say
'\sseq@thiscall@command\unexpanded\@xp{\sseq@thiscall@options}\sseq@thiscall@page(#2,\xindex,n)' where n specifies which of the
\sseq@obj{partcoord.(\targetcoord).numnodes} nodes at (\targetcoord) should be the target%
}%
\fi
\fi
}
\def\sseq@differential@gettarget#1#2{\sseq@differential@gettarget@{#1}#2\sseq@nil}
\def\sseq@differential@gettarget@#1#2,#3\sseq@nil{\the\numexpr#2+\sseq@targetx{#1}\relax,\the\numexpr#3+\sseq@targety{#1}\relax}
% Takes a comma separated list that can be empty, have one element, or two elements, returns first element (or empty if list is empty).
\def\sseq@dparsecoord@getxindex#1{\sseq@dparsecoord@getxindex@#1,\sseq@nil}
\def\sseq@dparsecoord@getxindex@#1,#2\sseq@nil{#1}
% Takes a comma separated list that can be empty, have one element, or two elements, returns second element (or empty if less than two elements).
\def\sseq@dparsecoord@getyindex#1{\sseq@dparsecoord@getyindex@#1,\sseq@nil}
\def\sseq@dparsecoord@getyindex@#1,#2\sseq@nil{%
\sseq@ifempty{#2}{}{%
\sseq@dparsecoord@getyindex@removecomma#2\sseq@nil%
}%
}
\def\sseq@dparsecoord@getyindex@removecomma#1,\sseq@nil{#1}
%
% errors
%
% When the error hasn't been inside an \edef
\def\sseq@parsecoord@reporterror#1{
\@xp\sseq@parsecoord@reporterror@#1\@gobble\sseq@nil
}
\def\sseq@parsecoord@reporterror@#1{%
\ifx\sseq@error#1%
\@xp\sseq@error
\else
\@xp\sseq@gobble@to@nil
\fi
}
% When the error has been inside an \edef
\edef\sseq@parsecoordex@reporterror#1{
\@nx\@xp\@nx\sseq@parsecoordex@reporterror@#1\@xp\@nx\csname sseq@error \endcsname{}\@nx\sseq@nil
}
\@xp\def\@xp\sseq@parsecoordex@reporterror@\@xp#\@xp1\csname sseq@error \endcsname#2#3\sseq@nil{\ifx\sseq@nil#3\sseq@nil\else\sseq@error{#2}\fi}
\def\sseq@parsecoord@callback@iferror#1{\sseq@parsecoord@callback@iferror@#1.\sseq@nil}
\def\sseq@parsecoord@callback@iferror@#1#2\sseq@nil{%
\ifx\sseq@error#1%
\@xp\@firstoftwo
\else