summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/spectralsequences/spectralsequences.sty
blob: 10268984bda5ea87074af5224f02755cc9272f5b (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
%%
%% Package: spectralsequences v1.2.2
%% Author: Hood Chatham
%% Email: hood@mit.edu
%% Date: 2019-02-18
%% License: Latex Project Public License
%%
%% A package for drawing spectral sequences
%%


% TODO:
%  Try catch blocks
%  Make an argument type for the \d page argument.
%  deal with xmin, xmax, etc (was there actually a problem we were trying to fix?)
%
%  Redo sseqerrortest and set up regression test script as part of build (damn I didn't realize we'd lost anything imporant with that find -d disaster)
%  Maybe we should add some other regression tests too
%
%  Lower priority:
%   error messages that should be warnings by default?
%


\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{spectralsequences}[2019/02/18 v1.2.2]

\RequirePackage{tikz}
\RequirePackage{etoolbox}
\RequirePackage{xparse}
\RequirePackage{verbatim}

\usetikzlibrary{quotes}
\usetikzlibrary{fit}
\usetikzlibrary{positioning}
\usetikzlibrary{intersections}
\usetikzlibrary{backgrounds}
\usepgflibrary{arrows.meta}
\usetikzlibrary{shapes}
%\usetikzlibrary{patterns}
%\usetikzlibrary{profiler}

\newif\ifsseq@draftmode
\newif\ifsseq@tooltip
\DeclareOption{draft}{\sseq@draftmodetrue}
\DeclareOption{tooltips}{\sseq@tooltiptrue}
\ProcessOptions\relax

\ifsseq@tooltip
    \RequirePackage{pdfcomment}
\else
    \let\ulp@afterend\relax % So that removing the tooltip option doesn't cause the aux file to have an error.
\fi

\def\sseq@authorname{Hood Chatham}
\def\sseq@authoremail{hood@mit.edu}


% Commands we are going to expose just inside of environments
\def\sseq@macrolist{%
    \xcoord\ycoord\page %\xmin\xmax\ymin\ymax % these just get protected
    % Defined in sseqmessages:
    \quiet\endquiet
    % These are defined in sseqmain:
    \class\classoptions\replaceclass\replacesource\replacetarget
    \d\doptions\kill\structline\structlineoptions\circleclasses
    \lastlabel
    % The following are defined in sseqparsers:
    \pgfmathparse\isalive\lastx\lasty\lastclass\savestack\restorestack\pushstack\nameclass\tagclass
    \parsecoordinate\parsedifferential\getdtarget\gettag
    \IfOutOfBoundsTF\IfOutOfBoundsT\IfOutOfBoundsF\IfInBoundsTF\IfInBoundsT\IfInBoundsF
    \IfExistsTF\IfExistsT\IfExistsF\IfAliveTF\IfAliveT\IfAliveF
    \IfValidDifferentialTF\IfValidDifferentialT\IfValidDifferentialF
    \DrawIfValidDifferentialTF\DrawIfValidDifferentialT\DrawIfValidDifferentialF\DrawIfValidDifferential
    % sseqforeach
    \Do\DoUntilOutOfBounds\DoUntilOutOfBoundsThenNMore
}


% All the tikz commands. We replace these in our environment too. Replacements  defined in sseqparsers.
\def\sseq@tikzcommands{%
    \clip\coordinate\draw\fill\filldraw
    \graph\matrix\node\path\pattern
    \shade\shadedraw\useasboundingbox
}


%%%%%%                                            %%%%%%
%%                                                    %%
%%            Declarations and preliminaries          %%
%%                                                    %%
%%%%%%                                            %%%%%%
\newif\ifsseq@inprogress

\newif\ifsseq@hasname
\newif\ifsseq@updateexisting
\newif\ifsseq@ispageenv
\newif\ifsseq@keepchanges
\newif\ifsseq@keepglobaloptions
\newif\ifsseq@globaldetone

\newif\ifsseq@needstikz
\newif\ifsseq@thispage
\newif\ifsseq@outofrange
\newif\ifsseq@classlabel
\newif\ifsseq@draworphanedges
\newif\ifsseq@draw
\newif\ifsseq@drawedge
\newif\ifsseq@tikzprims@integershift
\newif\ifsseq@anchor
\sseq@drawedgetrue
\sseq@tikzprims@integershifttrue

\newif\ifsseq@patchforeach
\newif\ifsseq@patchfit
\newif\ifsseq@patchxparseU

\newif\ifsseq@tempif
\newif\ifsseq@gtempif
\newif\ifsseq@error

\newtoks\sseq@temptoks
\newtoks\sseq@scope@toks

\newcount\sseq@thepagecount
\newcount\sseq@anonsseqcount
\newcount\sseq@x
\newcount\sseq@y
\newcount\sseq@tempcount
\newcount\sseq@tempcountb
\newcount\sseq@tempx
\newcount\sseq@tempy
\newcount\sseq@tempxb
\newcount\sseq@tempyb
\newcount\sseq@xoffset % We add these to everything to avoid overflow errors as much as possible
\newcount\sseq@yoffset

\newcount\sseq@stackdepth

\newdimen\sseq@tempdimen
\newdimen\sseq@tempxdimen
\newdimen\sseq@tempydimen
\newdimen\sseq@xscalecm
\newdimen\sseq@yscalecm
\newdimen\sseq@clip@xcenter
\newdimen\sseq@clip@ycenter
\newdimen\sseq@tooltip@height
\newdimen\sseq@tooltip@width
\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.
\newcount\sseq@infinitycount
\sseq@infinitycount=\sseq@infinity\relax
\def\sseq@macroname{\@xp\@gobble\string}
\def\sseq@gobble@to@nil#1\sseq@nil{}
\def\sseq@macrogobble#1->{}

% 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}}


\def\sseq@protected@edef{\let\sseq@store@slsl\\\def\\{\protect\\}\let\@@protect \protect \let \protect \@unexpandable@protect \afterassignment \sseq@restore@protect \edef}
\def\sseq@protected@xdef{\let\sseq@store@slsl\\\def\\{\protect\\}\let\@@protect \protect \let \protect \@unexpandable@protect \afterassignment \sseq@restore@protect \xdef}
\def\sseq@restore@protect{\let\protect\@@protect\let\\\sseq@store@slsl}

\def\sseq@eval#1{\bgroup\edef\sseq@temp{#1}\@xp\egroup\sseq@temp}% I got this from sseq.sty
\def\sseq@protectedeval#1{\bgroup\sseq@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}}

%%%% 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{\sseq@protected@xdef#1{\unexpanded\@xp{#1}#2}}

\def\sseq@d@addto@toks#1#2{#1\@xp{\the#1#2}}
\def\sseq@e@addto@toks#1#2{\sseq@eval{#1{\the#1#2}}}

\def\sseq@d@addto@temptoks{\sseq@d@addto@toks\sseq@temptoks}
\def\sseq@e@addto@temptoks{\sseq@e@addto@toks\sseq@temptoks}


% Used in sseqkeys to delete spaces from style commands.
% Set the catcode of space to ignore, and then reparse the characters in #2.
\def\sseq@setmacronospaces#1#2{%
    \bgroup\catcode`\ =9\relax
        \makeatletter
        \scantokens{\expandafter\egroup\expandafter\def\expandafter#1\expandafter{\csname #2\endcsname}}%
}

\def\sseq@setnospaces#1#2{%
    \bgroup\catcode`\ =9\relax
        \makeatletter
        \scantokens{\expandafter\egroup\expandafter\def\expandafter#1\expandafter{\@firstofone{#2}}}%
}


\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@ifnil#1{
    \ifx\sseq@nil#1
        \@xp\@firstoftwo
    \else
        \@xp\@secondoftwo
    \fi
}

\let\sseq@breakpoint\relax
\let\sseq@breakpointfinally\@gobble
\def\sseq@break#1\sseq@breakpoint{}
\def\sseq@break@finally#1\sseq@breakpoint#2{#2}

\def\sseq@breakfi{\fi\sseq@break}
\def\sseq@breakfifi{\fi\fi\sseq@break}
\def\sseq@breakfififi{\fi\fi\fi\sseq@break}
\long\def\sseq@breakdataenv#1\end#2{
    \def\sseq@tempa{sseqdata}\def\sseq@tempb{#2}\ifx\sseqtempa\sseqtempb
        \@xp\sseq@breakdataenv@
    \else
        \@xp\sseq@breakdataenv
    \fi
}
\def\sseq@breakdataenv@{\let\endsseqdata\sseq@breakendsseqdata\end{sseqdata}}

\long\def\sseq@breakpageenv#1\end#2{
    \def\sseq@tempa{sseqpage}\def\sseq@tempb{#2}\ifx\sseqtempa\sseqtempb
        \@xp\sseq@breakpageenv@
    \else
        \@xp\sseq@breakpageenv
    \fi
}
\def\sseq@breakpageenv@{\let\endsseqpage\sseq@breakendsseqpage\end{sseqpage}}
\def\sseq@breakendsseqdata{}
\def\sseq@breakendsseqpage{}

\def\sseq@seteverythingtonoops{%
    \let\sseqdata\comment
    \let\sseqpage\comment
    \let\sseqkeys\@gobble
    \let\sseqnewgroup\@gobblethree
}



\input sseqmessages.code.tex        % Exposes directly: \sseqerrortowarning
\input sseqcheckdefinitions.code.tex

\ifsseq@tempif\else % Set to false in checkdefinitions if it failed to patch the key-value system.
    \sseq@seteverythingtonoops
    \sseq@pgfkeyspatchfailed
\fi

\input sseqloadstore.code.tex       % Responsible for installing environment-only macros
\input sseqmacromakers.code.tex     % Exposes directly: \DeclareSseqCommand, \NewSseqCommand, \DeclareSseqGroup, \NewSseqGroup

\input sseqparsers.code.tex         % Responsible for making tikz modifications, exposes directly \sseqnormalizemonomial, \sseqparseint



\ifsseq@patchforeach
    \input sseqforeach.code.tex
\else
    \def\sseq@patchfor{}
\fi

\input sseqkeys.code.tex            % Exposes directly: \sseqset, \sseqnewfamily
\input sseqmain.code.tex            % Defines all the main commands. Exposes directly: the environments, \xmin, \xmax, etc, \SseqCopyPage
\input sseqdrawing.code.tex

% Give standard definitions for savedpaths wrappers
\def\sseq@beginscope@object{\begin{scope}}
\def\sseq@endscope@object{\end{scope}}
\let\sseq@scope@object\@firstofone
\let\sseq@style@object\@firstofone
\let\sseq@class@object\sseq@class@draw@ifpage
\let\sseq@differential@object\sseq@differential@draw@ifpage
\let\sseq@structline@object\sseq@structline@draw@ifpage
\let\sseq@circleclass@object\sseq@circleclass@draw@ifpage
\let\sseq@tikzpath@object\@firstofone


%%% Some default key settings
\sseqset{
    edge labels={auto=right},
    classes={draw,circle,inner sep=0pt,minimum size=0.35em},
    circle classes={newellipse, ellipse ratio=1.2,draw, inner sep=2pt},
    edges=draw,
    math nodes,
    differentials=->,
    pins=help lines
}

\ifsseq@tooltip
    \let\sseqtooltip\sseq@tooltip@wrapper
\fi

% Extra commands to expose:
\let\sseqifempty\sseq@ifempty
\let\SseqParseInt\sseqparseint
\let\SseqNewFamily\sseqnewfamily

\def\sseqpower#1#2{\@xp\sseqtypesetpower@\@xp{\the\numexpr#2}{#1}{1}}
\def\sseqpowerempty#1#2{\@xp\sseqtypesetpower@\@xp{\the\numexpr#2}{#1}{}}
\def\sseqtypesetpower@#1#2#3{\ifnum#1=\z@#3\else\ifnum#1=\@ne#2\else#2^{#1}\fi\fi}