Debian Codegraph @

texmf-dist/tex/latex/spectralsequences/sseqparsers.code.tex

raw
1 %%
2 %% Package: spectralsequences v1.3.3 2023-01-28
3 %% Author: Hood Chatham
4 %% Email: [email protected]
5 %% Date: 2023-01-28
6 %% License: Latex Project Public License
7 %%
8 %% File: sseqparsers.code.tex
9 %%
10 %% Defines the parsers and input sanitizers. Also handles tikz primitive parsing and \isalive.
11 %% ExplSyntaxOn for this whole file!
12
13 \ExplSyntaxOn
14 \let\sseq@NoValue\c__xparse_no_value_tl
15 % They changed \c__xparse_no_value_tl to \c_novalue_tl at some point. If the first definition doesn't work, try again.
16 \@ifundefined{sseq@NoValue}{\let\sseq@NoValue\c_novalue_tl}{}
17
18 \protected\def\sseqparseint#1#2{
19 \sseq@ifintexpr{#2+0}{ % +0 here to prevent \lastx from freaking out if it's at the end of #2.
20 \edef#1{\the\numexpr#2\relax}
21 }{
22 \sseq@error{invalid-int-expr}
23 }
24 }
25
26 % WARNING: doesn't work =(
27 \def\sseq@ifint#1{
28 \ifcat$\romannumeral0#1$
29 \prg_return_true:
30 \else
31 \ifcat$\romannumeral-0#1$
32 \prg_return_true:
33 \else
34 \prg_return_false:
35 \fi
36 \fi
37 }
38
39 % Prevent \protect from causing trouble for \pgfmathparse
40 \let\sseq@pgfmathparse@orig\pgfmathparse
41 \protected\def\sseq@pgfmathparse#1{%
42 \bgroup
43 \let\@@protect\protect
44 \def\protect{}%
45 \let\pgfmath@protected@edef\edef
46 \sseq@pgfmathparse@orig{#1}%
47 \restore@protect
48 \sseq@smuggle@macro\pgfmathresult
49 \egroup
50 }
51
52
53 %%% ifpgfmathexpr
54 % #1 -- expression to test
55 % #2 -- true case
56 % #3 -- false case
57 % This tests true if \pgfmathparse{#1} throws an error or not. Luckily, \pgfmathparse pipes its errors through \pgfmath@error so this is easy.
58 \def\sseq@ifpgfmathexpr#1{
59 \begingroup
60 \let\protect\pgfutil@empty
61 \global\sseq@gtempiftrue
62 \def\pgfmath@error##1##2{\global\sseq@gtempiffalse\sseq@closegroups\sseq@break}
63 \def\sseq@groupflag{}
64 \pgfmathparse{#1}
65 \global\let\ifpgfmathunitsdeclared\ifpgfmathunitsdeclared
66 \ifpgfmathunitsdeclared
67 \xdef\sseq@mathresult{\pgfmathresult pt}
68 \else
69 \xdef\sseq@mathresult{\pgfmathresult}
70 \fi
71 \endgroup
72 \sseq@breakpoint
73 \ifsseq@gtempif
74 \@xp\@firstoftwo
75 \else
76 \@xp\@secondoftwo
77 \fi
78 }
79
80 \def\sseq@closegroups{\ifx\sseq@groupflag\empty\endgroup\@xp\sseq@closegroups\fi}
81
82
83 % Test if single token input is a digit
84 \def\sseq@ifdigit#1{
85 \ifodd0
86 \ifx#1 0 1 \else
87 \ifx#1 1 1 \else
88 \ifx#1 2 1 \else
89 \ifx#1 3 1 \else
90 \ifx#1 4 1 \else
91 \ifx#1 5 1 \else
92 \ifx#1 6 1 \else
93 \ifx#1 7 1 \else
94 \ifx#1 8 1 \else
95 \ifx#1 9 1 \else
96 \fi \fi \fi \fi \fi
97 \fi \fi \fi \fi \fi
98 \relax
99 \@xp\@firstoftwo
100 \else
101 \@xp\@secondoftwo
102 \fi
103 }
104
105 %%% ifintexpr
106 % #1 -- expresion to test
107 % #2 -- true case
108 % #3 -- false case
109 % This tests true if \numexpr #1\relax throws no error and consumes all of #1 and false otherwise.
110
111 % Spaces matter to us, because \sseq@ifintexpr{1 1} is false but \sseqsifintexpr{11} is true
112 % so we make spaces into catcode other and use \scantokens
113 \def\sseq@fexpsafenil{\@nx\sseq@fexpsafenil}
114
115 \def\sseq@ifintexpr#1{%
116 \bgroup
117 \sseq@tempcount\z@
118 \sseq@ifintexpr@{needsint}#1\sseq@fexpsafenil%
119 \@xp\egroup\next
120 }
121
122 % We need to use \futurelet so that we can detect open braces even when they only surround one token like {1}
123 % also we use it to detect spaces. Store the state in \sseq@ifintexpr@state first.
124 \def\sseq@ifintexpr@#1{\def\sseq@ifintexpr@state{#1}\futurelet\testtok\sseq@ifintexpr@@}
125 \def\sseq@ifintexpr@@{%
126 \ifx\testtok\bgroup%
127 \let\next\sseq@ifintexpr@false
128 \else
129 \ifx\testtok\sseq@fexpsafenil
130 \@xp\let\@xp\next\csname sseq@ifintexpr@@\sseq@ifintexpr@state @done\endcsname
131 \else
132 % We need to check here for a space because \string<space> produces NO OUTPUT regardless of the catcode of the space.
133 % This messes up \sseq@ifintexpr@@@ because it doesn't expect \string#1 to produce no characters.
134 \@xp\ifx\space\testtok
135 \def\next{\sseq@ifintexpr@next{\space}\@xp\next\romannumeral-`0}
136 \else
137 \let\next\sseq@ifintexpr@@@
138 \fi
139 \fi
140 \fi
141 \next
142 }
143
144 \def\sseq@ifintexpr@@@#1{
145 \ifcat$\@xp\@gobble\string#1$%
146 \@xp\sseq@ifintexpr@@@@\@xp#1
147 \else
148 % This is a macro, so fexpand it
149 % Then use f expansion.
150 \@xp\sseq@ifintexpr@@@fexpcs\@xp#1
151 \fi
152 }
153
154 \def\sseq@ifintexpr@@@fexpcs{\exp_last_unbraced:Nf\sseq@ifintexpr@@@fexpcs@}
155 \def\sseq@ifintexpr@@@fexpcs@{\futurelet\testtok\sseq@ifintexpr@@@fexpcs@@}
156 \def\sseq@ifintexpr@@@fexpcs@@{
157 \ifx\testtok\bgroup
158 \@xp\sseq@ifintexpr@false % We already tested for groups above, so we need to check if this expanded to a group
159 \else
160 \@xp\sseq@ifintexpr@@@@ % If it's still a control sequence, then this will fail in the \pgfutil@ifundefined step
161 \fi
162 }
163
164
165
166 % We can't just use \futurelet because "\let\testtok(" makes \testtok unexpandable
167 % (I guess that makes sense, but why is it that I need \@xp\ifx\otherspace above if I've also \let\otherspace to a character? Mysterious...),
168 % so then "\csname hello\testtok\endcsname" is an error. This indexes into our state machine,
169 % cases: a digits, + or -, * or /, (, ), or something else (anything else always leads to false
170 \def\sseq@ifintexpr@@@@#1{%
171 \ifx#1\sseq@fexpsafenil
172 \def\next{\csname sseq@ifintexpr@@\sseq@ifintexpr@state @done\endcsname\sseq@fexpsafenil}%
173 \else
174 \sseq@ifdigit{#1}%
175 {\sseq@ifintexpr@next{digit}}%
176 {%
177 \ifx#1+%
178 \sseq@ifintexpr@next{+-}
179 \else
180 \ifx#1-%
181 \sseq@ifintexpr@next{+-}
182 \else
183 \ifx#1*%
184 \sseq@ifintexpr@next{*/}
185 \else
186 \ifx#1/%
187 \sseq@ifintexpr@next{*/}
188 \else
189 % This extra \string here is so that if a control sequence fexpanded and still gave a control sequence,
190 % we don't get a missing \endcsname error here, it just returns false
191 \pgfutil@ifundefined{sseq@ifintexpr@@\sseq@ifintexpr@state @\string#1}%
192 {\let\next\sseq@ifintexpr@false}%
193 {\sseq@ifintexpr@next{#1}}%
194 \fi
195 \fi
196 \fi
197 \fi
198 }%
199 \fi
200 \next
201 }
202
203 \def\sseq@ifintexpr@true#1\sseq@fexpsafenil{\ifnum\sseq@tempcount=\z@ \let\next\@firstoftwo\else\let\next\@secondoftwo\fi}
204 \def\sseq@ifintexpr@false#1\sseq@fexpsafenil{\let\next\@secondoftwo}
205
206 \def\sseq@makeifint#1#2#3{\@xp\def\csname sseq@ifintexpr@@#1@#2\endcsname{#3}}
207 \def\sseq@ifintexpr@next#1{\@xp\let\@xp\next\csname sseq@ifintexpr@@\sseq@ifintexpr@state @#1\endcsname}
208
209 \sseq@makeifint{needsint}{done}{\sseq@ifintexpr@false}
210 \sseq@makeifint{needsint}{digit}{\sseq@ifintexpr@{int}}
211 \sseq@makeifint{needsint}{*/}{\sseq@ifintexpr@false}
212 \sseq@makeifint{needsint}{+-}{\sseq@ifintexpr@{needsint}}
213 \sseq@makeifint{needsint}{(}{\advance\sseq@tempcount\@ne\sseq@ifintexpr@{needsint}}
214 \sseq@makeifint{needsint}{)}{\sseq@ifintexpr@false}
215 \sseq@makeifint{needsint}{\space}{\sseq@ifintexpr@{needsint}}
216
217 \sseq@makeifint{int}{done}{\sseq@ifintexpr@true}
218 \sseq@makeifint{int}{digit}{\sseq@ifintexpr@{int}}
219 \sseq@makeifint{int}{*/}{\sseq@ifintexpr@{needsint}}
220 \sseq@makeifint{int}{+-}{\sseq@ifintexpr@{needsint}}
221 \sseq@makeifint{int}{(}{\sseq@ifintexpr@false}
222 \sseq@makeifint{int}{)}{
223 \advance\sseq@tempcount\m@ne
224 \ifnum\sseq@tempcount<\z@\relax
225 \@xp\@xp\@xp\sseq@ifintexpr@false\@xp\@gobble
226 \else
227 \@xp\sseq@ifintexpr@
228 \fi{nointallowed}
229 }
230 \sseq@makeifint{int}{\space}{\sseq@ifintexpr@{nointallowed}}
231
232 \sseq@makeifint{nointallowed}{done}{\sseq@ifintexpr@true}
233 \sseq@makeifint{nointallowed}{digit}{\sseq@ifintexpr@false}
234 \sseq@makeifint{nointallowed}{*/}{\sseq@ifintexpr@{needsint}}
235 \sseq@makeifint{nointallowed}{+-}{\sseq@ifintexpr@{needsint}}
236 \sseq@makeifint{nointallowed}{(}{\sseq@ifintexpr@false}
237 \sseq@makeifint{nointallowed}{)}{
238 \advance\sseq@tempcount\m@ne
239 \ifnum\sseq@tempcount<\z@
240 \@xp\@xp\@xp\sseq@ifintexpr@false\@xp\@gobble
241 \else
242 \@xp\sseq@ifintexpr@
243 \fi{nointallowed}
244 }
245 \sseq@makeifint{nointallowed}{\space}{\sseq@ifintexpr@{nointallowed}}
246
247 %%
248 %% This parser defines the syntax for the page argument of \d.
249 %%
250 %% #1 -- callback. Will pass control to this function when done.
251 %% stores output in \sseq@dpage
252 %% It also sets the flag \sseq@tempif to be
253 %% true if there is an open parenthesis after the page
254 %% false if there is no open parentheis -- so no optional argument for \d.
255 \def\sseq@d@grabpage#1{
256 \let\sseq@grabdpage@return#1
257 \futurelet\testtok\sseq@grabdpage@
258 }
259 \def\sseq@grabdpage@{
260 \sseq@tempiftrue
261 \ifx\testtok\bgroup
262 \let\next\sseq@grabdpage@group
263 \else
264 \def\sseq@dpage{}
265 \let\next\sseq@grabdpage@norm
266 \fi
267 \next
268 }
269
270 \def\sseq@grabdpage@group#1{\def\sseq@dpage{#1}\sseq@grabdpage@return}
271
272 % I guess this is "norm" because it's the most basic case.
273 % Why did I make this so complicated?
274 \def\sseq@grabdpage@norm{
275 \futurelet\testtok\sseq@grabdpage@norm@
276 }
277
278 % If the next token is a open group or a new paragraph, we're done collecting and there's no parenthetical argument.
279 % If the next token is an open paren, we're done collecting and there is a parenthetical argument.
280 % Spaces get added to the token list (I guess that's important because it changes arithmetic sometimes? there must have been an issue at some point)
281 % Every other token gets handled by \sseq@grabdpage@token
282 \def\sseq@grabdpage@norm@{
283 \let\next\sseq@grabdpage@token
284 \ifx\testtok\bgroup % Open group ==> done collecting page, no optional argument
285 \sseq@tempiffalse
286 \let\next\sseq@grabdpage@return
287 \else
288 \ifx\testtok\par % new paragraph ==> done collecting page, no optional argument
289 \sseq@tempiffalse
290 \let\next\sseq@grabdpage@return
291 \else
292 \ifx\testtok( % paren ==> done collecting page, optional argument
293 \let\next\sseq@grabdpage@return
294 \else
295 \@xp\ifx\space\testtok
296 \let\next\sseq@grabdpage@space
297 \fi
298 \fi
299 \fi
300 \fi
301 \next
302 }
303
304 \def\sseq@grabdpage@space{\sseq@d@addto@macro\sseq@dpage{~}\@xp\sseq@grabdpage@norm\romannumeral-`0}
305
306 % All other tokens
307 \def\sseq@grabdpage@token#1{
308 \ifcat$\@xp\@gobble\string#1$% % If #1 is a non-macro token, just add it to \sseq@dpage
309 \sseq@d@addto@macro\sseq@dpage{#1}
310 \@xp\sseq@grabdpage@norm
311 \else % Now it's a macor
312 \ifx#1\end % \end ==> done
313 \sseq@tempiffalse
314 \@xp\sseq@grabdpage@return\@xp#1\romannumeral-`0
315 \else
316 \ifx#1\begin % \begin ==> done
317 \sseq@tempiffalse
318 \@xp\sseq@grabdpage@return\@xp#1\romannumeral-`0
319 \else % Otherwise, let's try to expand it.
320 \@xp\sseq@grabdpage@token@fexpcs\@xp#1\romannumeral-`0
321 \fi
322 \fi
323 \fi
324 }
325
326 \def\sseq@grabdpage@token@fexpcs{\exp_last_unbraced:Nf\sseq@grabdpage@token@fexpcs@}
327 \def\sseq@grabdpage@token@fexpcs@{\futurelet\testtok\sseq@grabdpage@token@fexpcs@@}
328 \def\sseq@grabdpage@token@fexpcs@@{
329 \ifx\testtok\bgroup
330 \sseq@tempiffalse
331 \@xp\sseq@grabdpage@return
332 \else
333 \@xp\sseq@grabdpage@token@fexpcs@@@
334 \fi
335 }
336 \def\sseq@grabdpage@token@fexpcs@@@#1{
337 \ifcat$\@xp\@gobble\string#1$% Did it fexpand into a non control sequence token?
338 \sseq@d@addto@macro\sseq@dpage{#1} % If so add it
339 \@xp\sseq@grabdpage@norm
340 \else
341 \sseq@tempiffalse
342 \@xp\sseq@grabdpage@return\@xp#1% Else remember to put the token back if we're not going to use it!!
343 \fi
344 }
345
346
347 %%
348 %%
349 %% New Class Pattern
350 %%
351 %%
352
353 \newcount\sseq@cp@row
354 \newcount\sseq@cp@n
355
356 \def\SseqNewClassPattern#1#2{
357 \ifcsname sseq@#1xoffset1/1\endcsname\sseq@error@n{classpattern-already-defined}{#1}\fi % could be a warning
358 \begingroup
359 \def\sseq@name{#1}
360 \def\sseq@temp{}
361 \def\sseq@state{nocoord}
362 \sseq@cp@row=\@ne
363 \sseq@cp@n=\z@
364 \let\next\sseq@newclasspattern@
365 \sseq@newclasspattern@#2\sseq@nil
366 }
367 \let\sseqnewclasspattern\SseqNewClassPattern
368
369 \def\sseq@newclasspattern@{
370 \@ifnextchar\bgroup{\sseq@error@n{classpattern-unexpected-token}{\{}}{\sseq@newclasspattern@processstate}
371 }
372
373 \def\sseq@newclasspattern@processstate{
374 \csname sseq@newclasspattern@processstate@\sseq@state\endcsname
375 }
376
377 \def\sseq@newclasspattern@processstate@xcoord#1{
378 \ifx#1,
379 \sseq@ifpgfmathexpr{\sseq@temp}{
380 \let\sseq@tempx\sseq@mathresult
381 \def\sseq@temp{}
382 \def\sseq@state{ycoord}
383 }{
384 \sseq@error@x{classpattern-invalid-math-expression}{\sseq@temp}
385 \let\next\sseq@newclasspattern@abort
386 }
387 \else
388 \ifx#1\sseq@nil
389 \sseq@error{classpattern-missing-tokens}
390 \let\next\endgroup
391 \else
392 \sseq@d@addto@macro\sseq@temp{#1}
393 \fi
394 \fi
395 \next
396 }
397
398 \def\sseq@newclasspattern@processstate@ycoord#1{
399 \ifx#1)
400 \sseq@ifpgfmathexpr{\sseq@temp}{% Need iffloatexpr =(
401 \let\sseq@tempy\sseq@mathresult
402 \def\sseq@temp{}
403 \def\sseq@state{nocoord}
404 \advance\sseq@cp@n1\relax
405 \ifnum\sseq@cp@n>\sseq@cp@row\relax
406 \sseq@error@xx{classpattern-extra-coord-ignored}{(\sseq@tempx,\sseq@tempy)}{\the\sseq@cp@row}
407 \else
408 \sseq@e@addto@macro\sseq@newclasspattern@dodefs{
409 \def\@xp\@nx\csname sseq@\sseq@name xoffset\the\sseq@cp@n/\the\sseq@cp@row\endcsname{\sseq@tempx}
410 \def\@xp\@nx\csname sseq@\sseq@name yoffset\the\sseq@cp@n/\the\sseq@cp@row\endcsname{\sseq@tempy}
411 }
412 \fi
413 }{
414 \sseq@error@x{classpattern-invalid-math-expression}{\sseq@temp}
415 \let\next\sseq@newclasspattern@abort
416 }
417 \else
418 \ifx#1\sseq@nil
419 \sseq@error{classpattern-missing-tokens}
420 \let\next\endgroup
421 \else
422 \sseq@d@addto@macro\sseq@temp{#1}
423 \fi
424 \fi
425 \next
426 }
427
428 \def\sseq@newclasspattern@processstate@nocoord#1{
429 \ifx#1(
430 \def\sseq@state{xcoord}
431 \else
432 \ifx#1;
433 \ifnum\sseq@cp@n<\sseq@cp@row\relax
434 \sseq@error@x{classpattern-too-few-coords}{\the\sseq@cp@row}
435 \let\next\sseq@newclasspattern@abort
436 \else
437 \advance\sseq@cp@row\@ne
438 \sseq@cp@n=\z@
439 \fi
440 \else
441 \ifx#1\sseq@nil
442 \let\next\sseq@newclasspattern@finish
443 \else
444 \sseq@error@n{classpattern-unexpected-token}{#1}
445 \let\next\sseq@newclasspattern@abort
446 \fi
447 \fi
448 \fi
449 \next
450 }
451
452 \def\sseq@newclasspattern@finish{
453 \ifnum\sseq@cp@n=\z@\relax
454 \advance\sseq@cp@row\m@ne
455 \else
456 \ifnum\sseq@cp@n=\sseq@cp@row\relax\else
457 \sseq@error@x{classpattern-too-few-coords}{\the\sseq@cp@row}
458 \let\sseq@newclasspattern@dodefs\empty
459 \fi
460 \fi
461 % This will make a definition even if the class pattern was rejected because of the too-few-coords error
462 % It doesn't matter though, because we don't use this to check for existence
463 \sseq@e@addto@macro\sseq@newclasspattern@dodefs{%
464 \chardef\@xp\@nx\csname sseq@\sseq@name @maxclasses\endcsname=\the\sseq@cp@row\relax
465 }%
466 \@xp\endgroup
467 \sseq@newclasspattern@dodefs
468
469
470 }
471 \def\sseq@newclasspattern@dodefs{}
472 \def\sseq@newclasspattern@abort#1\sseq@nil{\endgroup}
473
474
475
476
477 %%%%%% %%%%%%
478 %% %%
479 %% Coordinate Parsers %%
480 %% %%
481 %%%%%% %%%%%%
482
483
484 \def\sseq@ifdead#1{\ifnum\sseq@obj{class.#1[\sseq@obj{class.#1.num}].page}<\sseq@infinitycount\@xp\@firstoftwo\else\@xp\@secondoftwo\fi}
485
486
487 % 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
488 % into the internal representation needed for the rest of the package.
489 % This comes in two parts:
490 % \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
491 % \sseq@parsecoord@index -- decides which class {n or tag} represents
492 %
493 % There are several interface commands:
494 % \sseq@parsecoord -- for most things
495 % \sseq@cparsecoord -- for \class (but not for \replaceclass or \classoptions). Doesn't use \sseq@parsecoord@index at all.
496 % \sseq@dparsecoord -- for \d and \doptions
497 % \sseq@parsecoordex -- for \isalive: the body of a page constraint needs to be \edef'd so we need a completely expandable version.
498 % The expandable version doesn't have any error checking -- to get the error checking, we pass the coordinates once through the unexpandable version
499 % inside of an hbox.
500 % \sseq@parsecoord@allownonexisting -- doesn't raise an error if the class doesn't exist.
501
502 \def\sseq@errortype{}
503 \def\sseq@printerrortype#1{\@xp\sseq@ifempty\@xp{\sseq@errortype}{}{#1 \sseq@errortype}}
504 \def\sseq@printforerrortype{\sseq@printerrortype{~for~}}
505
506 %% Pulls off x,y and evaluates them, puts n or empty into a separate variable.
507 % #1 -- a coordinate of the form {x,y} or {x,y,stuff}
508 \let\sseq@relax\relax
509 % The \sseq@relax is just to make \lastclass work. It has to pull an argument off the token stream to expandably check whether
510 % it is an integer. However, without this \sseq@relax, \lastclass could appear as the last token of the edef, which is no good.
511 \def\sseq@parsecoord@maincoord#1{\exp_last_unbraced:Nx\sseq@parsecoord@maincoord@{#1\sseq@relax}}
512 \def\sseq@parsecoord@maincoord@#1\sseq@relax{%
513 \pgfutil@in@ \sseq@protecterror { #1 }
514 \ifpgfutil@in@
515 \bgroup
516 \sseq@restorefont % This prevents "Missing character" stuff from being written to the log.
517 \let\sseq@protecterror\relax
518 \setbox0=\hbox{#1} % Trigger the error message
519 \egroup
520 \@xp\sseq@break
521 \else
522 \pgfutil@in@,{#1}
523 \ifpgfutil@in@
524 \sseq@parsecoord@maincoord@@#1,\sseq@nil
525 \else
526 \pgfutil@in@{lastclass}{#1}
527 \ifpgfutil@in@
528 \def\handledname{#1}
529 \else
530 \sseq@protectedeval{\@nx\sseq@classname@handler{\sseq@classnameprefix#1\sseq@classnamepostfix}}
531 \let\handledname\result
532 \fi
533 \sseq@obj@ifdef{class.namedclass.\detokenize\@xp{\handledname}}{
534 \let\sourcename\handledname
535 \@xpthree\sseq@parsecoord@maincoord@named\sseq@obj{class.namedclass.\detokenize\@xp{\sourcename}}\sseq@nil
536 }{
537 \sseq@error{invalid-coordinate}\sseq@breakfifi
538 }
539 \fi
540 \fi
541 }
542
543 \def\sseq@parsecoord@maincoord@@#1,#2,#3\sseq@nil{%
544 \sseq@ifintexpr{#1}{%
545 \sseq@ifintexpr{#2}{}{\sseq@error@n{invalid-coordinate}{y~}\sseq@breakfifi} % breakfifi to get out of ifs from maincoord@
546 \edef\sseq@xcoord{\the\numexpr\sseq@x+(#1)\relax}%
547 \edef\sseq@ycoord{\the\numexpr\sseq@y+(#2)\relax}%
548 \edef\sseq@xycoord{\sseq@xcoord,\sseq@ycoord}%
549 \sseq@ifempty{#3}{\let\sseq@restcoord\pgfutil@empty}{%
550 \edef\sseq@restcoord{\sseq@removecomma#3\sseq@nil}%
551 }%
552 }{%
553 \pgfutil@in@{lastclass}{#1}%
554 \ifpgfutil@in@
555 \def\handledname{#1}%
556 \else
557 \sseq@protectedeval{\@nx\sseq@classname@handler{\sseq@classnameprefix#1\sseq@classnamepostfix}}%
558 \let\handledname\result
559 \fi
560 \sseq@obj@ifdef{class.namedclass.\detokenize\@xp{\handledname}}{%
561 \def\sourcename{#1}
562 \@xpthree\sseq@parsecoord@maincoord@named\sseq@obj{class.namedclass.\detokenize{#1}}\sseq@nil
563 \edef\sseq@restcoord{\sseq@removecomma#2,#3\sseq@nil}%
564 }{%
565 \sseq@error@n{invalid-coordinate}{x~}\sseq@breakfifi % breakfifi to get out of ifs from maincoord@
566 }%
567 }%
568 }%
569
570 \def\sseq@parsecoord@maincoord@named#1,#2,#3\sseq@nil{
571 \def\sseq@xcoord{#1}%
572 \def\sseq@ycoord{#2}%
573 \edef\sseq@xycoord{\sseq@xcoord,\sseq@ycoord}
574 \def\sseq@restcoord{}
575 \pgfkeys@spdef\sseq@rawindex{#3}
576 \def\sseq@index{#3}
577 \let\rawindex\sseq@rawindex
578 \let\index\sseq@index
579 }
580
581 \def\sseq@removecomma#1,\sseq@nil{#1}
582
583
584 % "Input" to this command is stored in the following commands:
585 % \sseq@xycoord -- x,y
586 % \sseq@rawindex -- n
587 % \sseq@errortype -- description for error messages
588 \def\sseq@errortype@tikzprim{tikz ~ primitive}% This is sort of a silly hack, but this first error check shouldn't happen in a tikz primitive.
589 \def\sseq@parsecoord@index{%
590 \sseq@obj@ifundef{partcoord.(\sseq@xycoord).numnodes}{
591 \ifsseq@parsecoord@allownonexisting
592 \ifx\sseq@rawindex\pgfutil@empty
593 \def\sseq@index{} % Communicates to \sseq@tikzprimitives@coords@maybeclass that this is not a class
594 \else
595 \sseq@error@x{no-classes}{(\sseq@xycoord)} \sseq@fbreak
596 \fi
597 \else
598 \sseq@error@x{no-classes}{(\sseq@xycoord)} \sseq@fbreak
599 \fi
600 }{
601 \ifx\sseq@rawindex\pgfutil@empty
602 \def\sseq@index{1}
603 \else
604 \sseq@obj@ifdef{partcoord.(\sseq@xycoord).tag.\sseq@class@tagprefix\sseq@rawindex}{% If the raw index is a tag
605 \edef\sseq@index{\sseq@obj{partcoord.(\sseq@xycoord).tag.\sseq@class@tagprefix\sseq@rawindex}}
606 }{%
607 \sseq@ifintexpr{\sseq@rawindex}{%
608 \edef\sseq@rawindexeval{\the\numexpr\sseq@rawindex}
609 \ifnum\sseq@rawindexeval<\z@%
610 \edef\sseq@index{\the\numexpr\sseq@obj{partcoord.(\sseq@xycoord).numnodes} + \sseq@rawindex + \@ne\relax}%
611 \ifnum\sseq@index<\@ne
612 \sseq@error@xxx{index-too-large}{\sseq@rawindex}{\sseq@obj{partcoord.(\sseq@xycoord).numnodes}}{(\sseq@xycoord)}%
613 \edef\sseq@index{1}
614 \sseq@fbreak
615 \fi
616 \else
617 \edef\sseq@index{\the\numexpr\sseq@rawindex}
618 \ifnum\sseq@rawindexeval>\sseq@obj{partcoord.(\sseq@xycoord).numnodes}\relax
619 \sseq@error@xxx{index-too-large}{\sseq@rawindex}{\sseq@obj{partcoord.(\sseq@xycoord).numnodes}}{(\sseq@xycoord)}%
620 \edef\sseq@rawindex{\sseq@obj{partcoord.(\sseq@xycoord).numnodes}}
621 \sseq@fbreak
622 \fi
623 \fi
624 }{
625 \sseq@error@xx{undefined-tag}{\sseq@rawindex}{(\sseq@xycoord)}%
626 \def\sseq@index{1}%
627 }
628 }
629 \fi
630 }
631 }
632
633 % #1 -- name to define
634 % #2 -- coordinate
635 % #3 -- the error message
636 \def\sseq@eatparens(#1){#1}
637 \def\sseq@parsecoord#1#2#3{%
638 \def\sseq@index{}%
639 \def\sseq@errortype{#3}%
640 \sseq@parsecoord@maincoord{#2}%
641 \exp_args:NNf\def\sseq@rawindex{\exp_args:No\sseq@trimspaces{\sseq@restcoord}}
642 \ifx\sseq@index\pgfutil@empty
643 \@xp\sseq@parsecoord@index
644 \fi
645 \sseq@parsecoord@setupvariables{#1}{#2}
646 }
647
648 \newif\ifsseq@parsecoord@allownonexisting
649 \def\sseq@parsecoord@allownonexisting#1#2#3{%
650 \sseq@parsecoord@allownonexistingtrue
651 \sseq@parsecoord{#1}{#2}{#3}
652 \sseq@parsecoord@allownonexistingfalse
653 }
654
655
656 \def\sseq@parsecoord@setupvariables#1#2{
657 % TODO: clean this up a bit? it's pretty ad-hoc.
658 % Whenever you update this, make sure to update sseq@paredcoords@swap below too.
659 \@xp\let\csname x\sseq@macroname#1\endcsname\sseq@xcoord
660 \@xp\let\csname y\sseq@macroname#1\endcsname\sseq@ycoord
661 \@xp\let\csname n\sseq@macroname#1\endcsname\sseq@index
662 \@xp\let\csname \sseq@macroname#1@partial\endcsname\sseq@xycoord
663 \edef#1{(\sseq@xycoord,\sseq@index)}%
664 \@xp\edef\csname\sseq@macroname#1nopar\endcsname{\sseq@xycoord,\sseq@index}
665 \@xp\edef\csname\sseq@macroname#1name\endcsname{(#2)}%
666 \@xp\edef\csname\sseq@macroname#1nameunbraced\endcsname{\@xptwo\sseq@eatparens\csname\sseq@macroname#1name\endcsname}% edef?
667 \@xp\edef\csname\sseq@macroname#1@internalname\endcsname{sseq{\sseq@xycoord,\sseq@index}}%
668 }
669
670
671 % This quiets parsecoord for the rest of the current scope.
672 % The reason we did it this way is because parsecoord makes too many local definitions...
673 \def\sseq@quiet@parsecoord{
674 \msg_redirect_name:nnn {spectralsequences}{invalid-coordinate}{none}
675 \msg_redirect_name:nnn {spectralsequences}{no-classes}{none}
676 \msg_redirect_name:nnn {spectralsequences}{index-too-large}{none}
677 \msg_redirect_name:nnn {spectralsequences}{undefined-tag}{none}
678 }
679
680
681 % These are used for \replacesource and \replacetarget, though they might be useful for other things too.
682 \def\sseq@parsedcoord@save#1#2{
683 \cs_gset_eq:cc { sseq@parsedcoord@save@x#1 } { x\sseq@macroname#2 }
684 \cs_gset_eq:cc { sseq@parsedcoord@save@y#1 } { y\sseq@macroname#2 }
685 \cs_gset_eq:cc { sseq@parsedcoord@save@n#1 } { n\sseq@macroname#2 }
686 \cs_gset_eq:cc { \sseq@macroname#1@partial } { \sseq@macroname#2@partial }
687 \cs_gset_eq:cN { sseq@parsedcoord@save@#1 } #2
688 \cs_gset_eq:cc { sseq@parsedcoord@save@#1nopar } { \sseq@macroname#2nopar }
689 \cs_gset_eq:cc { sseq@parsedcoord@save@#1name } { \sseq@macroname#2name }
690 \cs_gset_eq:cc { sseq@parsedcoord@save@#1nameunbraced } { \sseq@macroname#2nameunbraced }
691 \cs_gset_eq:cc { sseq@parsedcoord@save@#1@internalname } { \sseq@macroname#2@internalname }
692 }
693
694 \def\sseq@parsedcoord@restore#1#2{
695 \cs_set_eq:cc { x\sseq@macroname#1 } { sseq@parsedcoord@save@x#2 }
696 \cs_set_eq:cc { y\sseq@macroname#1 } { sseq@parsedcoord@save@y#2 }
697 \cs_set_eq:cc { n\sseq@macroname#1 } { sseq@parsedcoord@save@n#2 }
698 \cs_set_eq:cc { \sseq@macroname#1@partial } { #2@partial }
699 \cs_set_eq:Nc #1 { sseq@parsedcoord@save@#2 }
700 \cs_set_eq:cc { \sseq@macroname#1nopar } { sseq@parsedcoord@save@#2nopar }
701 \cs_set_eq:cc { \sseq@macroname#1name } { sseq@parsedcoord@save@#2name }
702 \cs_set_eq:cc { \sseq@macroname#1nameunbraced } { sseq@parsedcoord@save@#2nameunbraced }
703 \cs_set_eq:cc { \sseq@macroname#1@internalname } { sseq@parsedcoord@save@#2@internalname }
704 }
705
706 % #1 & #2 -- the two base commands that were handed to \sseq@parsecoord to swap.
707 % This is only used in \structline to normalize the name of structure lines, so that sseqpages knows what you are talking about
708 % if you say \structline(coorda)(coordb) and then later \structline(coordb)(coorda)
709 \def\sseq@parsedcoords@swap#1#2{
710 \sseq@parsedcoord@save{swaptempa}{#1}
711 \sseq@parsedcoord@save{swaptempb}{#2}
712 \sseq@parsedcoord@restore{#1}{swaptempb}
713 \sseq@parsedcoord@restore{#2}{swaptempa}
714 }
715
716 % EXPOSE: a wrapper around \sseq@parsecoord. Use full name of coordinate to avoid name class with sseq@parsecoord.
717 \sseq@DeclareDocumentCommand \parsecoordinate { m r() }{%
718 \sseq@parsecoord{#1}{#2}{call of \string\parsecoord}%
719 }
720
721 % #1 -- coordinate
722 \def\sseq@cparsecoord#1{%
723 \def\sseq@index{}
724 \sseq@parsecoord@maincoord{#1}%
725 \ifx\sseq@index\pgfutil@empty\else\sseq@error{named-coordinate-class}\fi% probably not possible to get this error
726 \ifx\sseq@restcoord\pgfutil@empty\else\sseq@error{class-extra-coords}\fi%
727 \let\partialcoord\sseq@xycoord
728 \let\xcoord\sseq@xcoord
729 \let\ycoord\sseq@ycoord
730 \edef\nodenum{\sseq@obj@ifundef{partcoord.(\partialcoord).numnodes}{1}{\the\numexpr\sseq@obj{partcoord.(\partialcoord).numnodes}+1}}%
731 \edef\coordnopar{\xcoord,\ycoord,\nodenum}
732 \edef\coord{(\coordnopar)}%
733 }
734
735
736 % #1 -- page
737 % #2 -- coordinate
738 % #3 -- target coordinate or "No Value"
739 \def\sseq@dparsecoord#1#2#3{%
740 \def\sseq@index{}%
741 \def\sseq@errortype{differential}%
742 \sseq@parsecoord@maincoord{#2}%
743 \ifx\sseq@index\pgfutil@empty
744 \edef\sseq@rawsindex{\@xp\sseq@dparsecoord@getxindex\@xp{\sseq@restcoord}}%
745 \@xp\pgfkeys@spdef\@xp\sseq@rawsindex\@xp{\sseq@rawsindex}
746 \edef\sseq@rawtindex{\@xp\sseq@dparsecoord@getyindex\@xp{\sseq@restcoord}}%
747 \@xp\pgfkeys@spdef\@xp\sseq@rawtindex\@xp{\sseq@rawtindex}
748 %
749 \let\sseq@rawindex\sseq@rawsindex
750 \def\sseq@errortype{source ~ of ~ differential}
751 \@xp\sseq@parsecoord@index % the \@xp is needed so that \sseq@break inside of parsecoordindex works properly.
752 \else
753 \edef\sseq@rawtindex{\@xp\sseq@dparsecoord@getxindex\@xp{\sseq@restcoord}}%
754 \@xp\pgfkeys@spdef\@xp\sseq@rawtindex\@xp{\sseq@rawtindex}
755 \edef\sseq@shouldbeempty{\@xp\sseq@dparsecoord@getyindex\@xp{\sseq@restcoord}}
756 \ifx\sseq@shouldbeempty\pgfutil@empty\else
757 \sseq@error{d-named-coord-two-indexes}
758 \fi
759 \fi
760 \sseq@parsecoord@setupvariables{\source}{(\sseq@xycoord\ifx\sseq@rawindex\pgfutil@empty\else,\sseq@rawindex\fi)}
761 \let\sourcecoord\source@partial
762 \IfNoValueTF{#3}{
763 \ifsseq@hasdegree\else\sseq@error{d-no-degree}\@xp\sseq@break\fi
764 \sseq@eval{\edef\@nx\sseq@xycoord{\@nx\sseq@differential@gettarget{#1}{\sseq@xycoord}}}
765 \let\sseq@rawindex\sseq@rawtindex
766 \def\sseq@errortype{target ~ of ~ differential}
767 \sseq@parsecoord@index
768 \let\targetcoord\sseq@xycoord
769 \sseq@parsecoord@setupvariables{\target}{(\sseq@xycoord\ifx\sseq@rawindex\pgfutil@empty\else,\sseq@rawindex\fi)}
770 }{
771 \ifx\sseq@rawtindex\pgfutil@empty\else
772 \sseq@error{d-target-index-target-coord}
773 \fi
774 \sseq@parsecoord\target{#3}{differential}
775 \let\targetcoord\target@partial
776 \ifsseq@hasdegree
777 \ifsseq@strictdegree
778 \sseq@eval{\edef\@nx\sseq@checktarget{\@nx\sseq@differential@gettarget{#1}{\sourcecoord}}}
779 \ifx\sseq@checktarget\targetcoord\else
780 \sseq@error@xxx{d-wrong-degree}{(\sseq@checktarget)}{\targetname}{(\targetcoord)}
781 \fi
782 \fi
783 \fi
784 }
785 \sseq@parsedcoord@save{lastsource}{\source}
786 \sseq@parsedcoord@save{lasttarget}{\target}
787 }
788
789 \def\sseq@differential@gettarget#1#2{\sseq@differential@gettarget@{#1}#2\sseq@nil}
790 \def\sseq@differential@gettarget@#1#2,#3\sseq@nil{\the\numexpr#2+\sseq@targetx{#1}\relax,\the\numexpr#3+\sseq@targety{#1}\relax}
791
792 \def\sseq@getfirsttwoelts#1,#2,#3\sseq@nil{#1,#2}
793 \protected\def\sseq@getdtarget#1#2#3{\sseq@eval{\edef\@nx#1{\@nx\sseq@differential@gettarget{#2}{\sseq@getfirsttwoelts#3,,\sseq@nil}}}}
794
795 % Takes a comma separated list that can be empty, have one element, or two elements, returns first element (or empty if list is empty).
796 \def\sseq@dparsecoord@getxindex#1{\sseq@dparsecoord@getxindex@#1,\sseq@nil}
797 \def\sseq@dparsecoord@getxindex@#1,#2\sseq@nil{#1}
798 % 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).
799 \def\sseq@dparsecoord@getyindex#1{\sseq@dparsecoord@getyindex@#1,\sseq@nil}
800 \def\sseq@dparsecoord@getyindex@#1,#2\sseq@nil{%
801 \sseq@ifempty{#2}{}{%
802 \sseq@removecomma#2\sseq@nil%
803 }%
804 }
805
806 % EXPOSE: a wrapper around \sseq@parsecoord.
807 \sseq@DeclareDocumentCommand\parsecoordinate { m r() }{%
808 \sseq@parsecoord{#1}{#2}{call of \string\parsecoord}%
809 }
810
811
812 % EXPOSE: a wrapper around \sseq@dparsecoord.
813 \protected\def\sseq@parsedifferential{%
814 \sseq@d@grabpage\sseq@parsedifferential@
815 }
816
817 \DeclareDocumentCommand \sseq@parsedifferential@ { d() d() } {%
818 \sseq@eval{\@nx\sseq@dparsecoord{\sseq@dpage}{\IfNoValueTF{#1}{\lastclass0}{\unexpanded{#1}}}{\unexpanded{#2}}}%
819 }
820
821 % Expandable coordinate parsing for \isalive.
822 % Doesn't do any error checking -- the error checking is done by passing it through \sseq@parsecoord in a non-\edef context.
823 % #1 -- a callback. Must be a single command b/c it's an N in \exp_args
824 % #2 -- the coordinate
825 \cs_set:Npn \exp_last_unbraced:NNNf #1#2#3#4
826 {
827 \exp_after:wN #1
828 \exp_after:wN #2
829 \exp_after:wN #3
830 \exp:w \exp_end_continue_f:w #4
831 }
832
833 \def\sseq@parsecoordex{\exp_last_unbraced:NNNf\sseq@parsecoordex@}
834 \def\sseq@parsecoordex@#1(#2){\sseq@parsecoordex@@#1#2,\@nil}
835
836 % Older versions of etex don't provide \expanded so need more expensive version of \exp_args:NNof.
837 \ifx\expanded\undefined
838 \cs_set:Npn\exp_args:NNof { \::N \::o \::f \::: }
839 \else
840 \cs_set:Npn\exp_args:NNof #1#2#3#4 {
841 \expanded {
842 \exp_not:N #1
843 \exp_not:N #2
844 { \unexpanded \expandafter { #3 } }
845 { \unexpanded \expandafter { \exp:w \exp_end_continue_f:w #4} }
846 }
847 }
848 \fi
849
850 \def\sseq@parsecoordex@@#1#2,#3,#4\@nil{
851 \ifx&#4&
852 \exp_args:NNo\sseq@parsecoord@indexex#1{\the\numexpr#2\@xp,\the\numexpr#3}{1}
853 \else
854 \exp_args:NNof\sseq@parsecoord@indexex#1{\the\numexpr#2\@xp,\the\numexpr#3\@xp\relax}{\exp_args:Nf\sseq@trimspaces{\sseq@removecomma#4\sseq@nil}}
855 \fi
856 }
857
858
859 % This is \sseq@parsecoord@index pared down as much as possible -- all error checking is removed because that will happen in a
860 % \setbox0=\hbox{stuff} sequestered calculation that uses \sseq@parsecoord@index instead.
861 % #1 -- callback which takes one argument -- the final coordinate in parentheses.
862 % #2 -- x,y
863 % #3 -- n
864 \def\sseq@parsecoord@indexex#1#2#3{%
865 \sseq@obj@ifdef{partcoord.(#2).tag.\sseq@class@tagprefix#3}{% If the raw index is a tag
866 \exp_args:NNo\sseq@parsecoord@indexex@#1{\the\numexpr\sseq@obj{partcoord.(#2).tag.\sseq@class@tagprefix#3}}{#2}%
867 }{%
868 \ifnum\numexpr#3<0\space
869 \exp_args:NNo\sseq@parsecoord@indexex@#1{\the\numexpr\sseq@obj{partcoord.(#2).numnodes} + #3 + 1}{#2}%
870 \else
871 \exp_args:NNo\sseq@parsecoord@indexex@#1{\the\numexpr#3}{#2}%
872 \fi
873 }%
874 }
875 \def\sseq@parsecoord@indexex@#1#2#3{
876 #1(#3,#2)
877 }
878
879
880
881
882 %%%
883 %%% The Stack
884 %%%
885
886 % This maybe should be moved into sseqmain.code.tex...
887 \sseq@addtostorelist\sseq@stacktop{}
888 \def\sseq@stackitem#1#2{\csname sseq.\[email protected].#1.#2\endcsname} % gobble #2 which we added in for the error message
889 \def\sseq@getstackentry#1#2{
890 \ifnum#1<\sseq@stackdepth
891 \exp_args:No\sseq@getstackentry@{\sseq@stacktop}{#1}{#2}
892 \else
893 \sseq@protecterror{\sseq@error@xx{index-out-of-bounds}{#1}{\the\sseq@stackdepth}}
894 \fi
895 }
896
897 \def\sseq@getstackentry@#1#2{
898 \ifnum#2=\z@\@xp\@firstoftwo\else\@xp\@secondoftwo\fi
899 { \sseq@stackitem{#1} }
900 { \exp_args:Nco\sseq@getstackentry@ { sseq.\[email protected].#1.next } { \the\numexpr#2-1 } }
901 }
902
903
904 \protected\def\sseq@pushstack(#1){
905 \bgroup
906 \sseq@parsecoord@allownonexisting\temp{#1}{}
907 \sseq@pushstack@\temp
908 \sseq@breakpoint
909 \egroup
910 }
911
912 % Note that \class directly calls pushstack@ to avoid reparsing the coordinate
913 \def\sseq@pushstack@{\@xp\sseq@pushstack@@}
914
915 \def\sseq@pushstack@@(#1,#2,#3){
916 %\def\temp{#1,#2,#3}\show\temp
917 \global\advance\sseq@stackdepth\@ne
918 \@xp\gdef\csname sseq.\[email protected].\the\[email protected]\endcsname{#1}
919 \@xp\gdef\csname sseq.\[email protected].\the\[email protected]\endcsname{#2}
920 \@xp\xdef\csname sseq.\[email protected].\the\[email protected]\endcsname{lastclass.\the\sseq@stackdepth}
921 \sseq@obj@gdef{class.namedclass.lastclass.\the\sseq@stackdepth}{#1,#2,#3}
922 \global\@xp\let\csname sseq.\[email protected].\the\[email protected]\endcsname\sseq@stacktop
923 \xdef\sseq@stacktop{\the\sseq@stackdepth}
924 }
925
926
927 \newcount\sseq@userstacksavecount
928 \protected\def\sseq@savestack{
929 \global\advance\sseq@userstacksavecount\@ne
930 \sseq@savestack@name{usersave@\the\sseq@userstacksavecount}
931 }
932 \protected\def\sseq@restorestack{
933 \sseq@restorestack@name{usersave@\the\sseq@userstacksavecount}
934 \global\advance\sseq@userstacksavecount\m@ne
935 }
936
937 \def\sseq@savestack@name#1{\sseq@obj@xdef{stack.save#1}{\sseq@stacktop}}
938
939 \def\sseq@restorestack@name#1{\xdef\sseq@stacktop{\sseq@obj{stack.save#1}}}
940
941 \def\sseq@lastx#1{
942 % \romannumeral is testing here whether #1 is a nonnegative integer
943 % if #1 consists of a single nonnegative integer then -0#1 will be turned into some nonpositive integer
944 % and romannumeral produces no output when handed a nonpositive integer, so the result will be empty.
945 % If #1 has any nonnumerical tokens or is negative, there will be left over stuff.
946 %
947 % We also have to subtract off \sseq@x so that this behaves correctly inside of a scope (the \lastx value should be unshifted)
948 \@xp\sseq@ifempty\@xp{\romannumeral-0#1}{
949 \the\numexpr\sseq@getstackentry{#1}{lastx}-\sseq@x\relax
950 }{
951 \the\numexpr\sseq@getstackentry{0}{lastx}-\sseq@x\relax#1 % #1 isn't a number so put it back
952 }
953 }
954 \def\sseq@lasty#1{
955 \@xp\sseq@ifempty\@xp{\romannumeral-0#1}{
956 \the\numexpr\sseq@getstackentry{#1}{lasty}-\sseq@y\relax
957 }{
958 \the\numexpr\sseq@getstackentry{0}{lasty}-\sseq@y\relax#1 % #1 isn't a number so put it back
959 }
960 }
961
962 \def\sseq@lastclass#1{
963 \@xp\sseq@ifempty\@xp{\romannumeral-0#1}{
964 \sseq@getstackentry{#1}{lastclass}
965 }{
966 \sseq@getstackentry{0}{lastclass}#1 % #1 isn't a number so put it back
967 }
968 }
969
970
971 \sseq@DeclareDocumentCommand\nameclass {mr()} {
972 \bgroup
973 \sseq@setthiscall{\sseq@nameclass#1(#2)}
974 \let\sseq@possibleoninputlinepar\empty
975 \sseq@parsecoord\coord{#2}{}
976 \sseq@cleanup@obj{class.namedclass.#1}
977 \sseq@obj@xdef{class.namedclass.#1}{\coordnopar}
978 \sseq@breakpoint
979 \egroup
980 }
981
982 \sseq@DeclareDocumentCommand\tagclass{mr()}{
983 \bgroup
984 \sseq@setthiscall{\tagclass#1(#2)}
985 \let\sseq@possibleoninputlinepar\empty
986 \def\sseq@class@tag{#1}
987 \sseq@parsecoord\coord{#2}{}%
988 \sseq@obj@ifdef{partcoord.(\sseq@xycoord).tag.\sseq@class@tagprefix\sseq@class@tag}{%
989 \sseq@error@nn{class-tag-already-defined}{\sseq@class@tagprefix\sseq@class@tag}{(\sseq@xycoord)}% could be warning
990 }%
991 \sseq@cleanup@obj{class.\coord.tag}%
992 \sseq@obj@xdef{class.\coord.tag}{\sseq@class@tagprefix\sseq@class@tag}%
993 \sseq@cleanup@obj{partcoord.(\sseq@xycoord).tag.\sseq@class@tagprefix\sseq@class@tag}%
994 \sseq@obj@xdef{partcoord.(\sseq@xycoord).tag.\sseq@class@tagprefix\sseq@class@tag}{\sseq@index}%
995 \sseq@breakpoint
996 \egroup
997 }
998
999 \sseq@DeclareDocumentCommand\gettag{mr()}{
1000 \bgroup
1001 \sseq@setthiscall{\gettag#1(#2)}
1002 \let\sseq@possibleoninputlinepar\empty
1003 \sseq@parsecoord\coord{#2}{}
1004 \sseq@obj@ifdef{class.\coord.tag}{
1005 \xdef#1{\sseq@obj{class.\coord.tag}}
1006 }{
1007 \sseq@error@n{class-no-tag}{(#2)}
1008 }
1009 \sseq@breakpoint
1010 \egroup
1011 }
1012
1013 \prg_new_conditional:Npnn \sseq_if_empty:n #1 {T,F,TF} {
1014 \sseq@ifempty{\prg_return_true:}{\prg_return_false:}
1015 }
1016
1017 \let\SseqIfEmptyTF\sseq_if_empty:nTF
1018 \let\SseqIfEmptyT\sseq_if_empty:nT
1019 \let\SseqIfEmptyF\sseq_if_empty:nF
1020
1021 % Test if a class exists.
1022 \prg_new_conditional:Npnn \sseq_if_exists:n #1 { T , F , TF } {
1023 \bgroup
1024 \sseq@tempiftrue
1025 \sseq@quiet@parsecoord
1026 \sseq@parsecoord\coord{#1}{}
1027 \@gobbletwo\sseq@breakpoint\sseq@tempiffalse % this executes \sseq@tempiffalse if we broke, otherwise it gets gobbled
1028 \ifsseq@tempif
1029 \egroup
1030 \prg_return_true:
1031 \else
1032 \egroup
1033 \prg_return_false:
1034 \fi
1035 }
1036
1037 % Test if a class is out of bounds. Return false if the class doesn't exist.
1038 \prg_new_conditional:Npnn \sseq_if_out_of_bounds:n #1 { T , F , TF } {
1039 \bgroup
1040 \sseq@tempiftrue
1041 \sseq@quiet@parsecoord
1042 \sseq@parsecoord\coord{#1}{}
1043 \@gobbletwo\sseq@breakpoint\sseq@tempiffalse % this executes \sseq@tempiffalse if we broke, otherwise it gets gobbled
1044 \ifsseq@tempif
1045 \sseq_if_out_of_bounds_inner:nnTF { \xcoord } { \ycoord }{\egroup\prg_return_true:}{\egroup\prg_return_false:}
1046 \else
1047 \egroup
1048 \prg_return_false:
1049 \fi
1050 }
1051
1052 % For internal use b/c it's faster not to call \sseq@parsecoord
1053 % Make sure to add \sseq@x and \sseq@y to the coordinate before passing along
1054 % to if_out_of_bounds_inner to correctly account for translations.
1055 \prg_new_conditional:Npnn \sseq_if_out_of_bounds_noparse:nn #1#2 {TF} {
1056 \sseq_if_out_of_bounds_inner:nnTF { #1 + \sseq@x } { #2 + \sseq@y }
1057 { \prg_return_true: }
1058 { \prg_return_false: }
1059 }
1060
1061
1062 \prg_new_conditional:Npnn \sseq_if_out_of_bounds_inner:nn #1#2 {TF} {
1063 \bool_lazy_all:nTF {
1064 { \int_compare_p:nNn { #1 } < { \sseq@xmaxpp } }
1065 { \int_compare_p:nNn { #1 } > { \sseq@xminmm } }
1066 { \int_compare_p:nNn { #2 } < { \sseq@ymaxpp } }
1067 { \int_compare_p:nNn { #2 } > { \sseq@yminmm } }
1068 }
1069 { \prg_return_false: }
1070 { \prg_return_true: }
1071 }
1072
1073 \prg_new_conditional:Npnn \sseq_if_alive:nn #1 #2 { T, F, TF } {
1074 \bgroup
1075 \sseq@tempiftrue
1076 \sseq@quiet@parsecoord
1077 \sseq@parsecoord\coord{#2}{}
1078 \@gobbletwo\sseq@breakpoint\sseq@tempiffalse
1079 \ifsseq@tempif
1080 \sseq@obj@pagetogen{class.\coord}{#1}
1081 \ifnum\sseq@gen>-1\relax
1082 \egroup
1083 \prg_return_true:
1084 \else
1085 \egroup
1086 \prg_return_false:
1087 \fi
1088 \else
1089 \egroup
1090 \prg_return_false:
1091 \fi
1092 }
1093
1094
1095 \protected\def\sseq@DrawIfValidDifferential{\sseq@DrawIfValidDifferential@{}{}}
1096 \protected\def\sseq@DrawIfValidDifferentialT{\sseq@DrawIfValidDifferential@{T}{}}
1097 \protected\def\sseq@DrawIfValidDifferentialF{\sseq@DrawIfValidDifferential@{}{F}}
1098 \protected\def\sseq@DrawIfValidDifferentialTF{\sseq@DrawIfValidDifferential@{T}{F}}
1099
1100 \DeclareDocumentCommand\sseq@DrawIfValidDifferential@{mmO{}}{%
1101 \begingroup
1102 \sseq@loadinputline
1103 \def\sseq@dtype{d}
1104 \def\sseq@trueclause{#1}
1105 \def\sseq@falseclause{#2}
1106 \def\sseq@doptions{#3}
1107 \sseq@d@grabpage\sseq@DrawIfValidDifferential@@
1108 }
1109
1110
1111 % #4 -- first coord
1112 % #5 -- possible second coord
1113 \DeclareDocumentCommand \sseq@DrawIfValidDifferential@@ { d() d() } {%
1114 \ifx\sseq@trueclause\pgfutil@empty
1115 \@xp\@firstoftwo
1116 \else
1117 \@xp\@secondoftwo
1118 \fi{\sseq@DrawIfValidDifferential@@@{#1}{#2}{}}
1119 {\sseq@DrawIfValidDifferential@@@{#1}{#2}}
1120 }
1121
1122 % #1 -- first coord
1123 % #2 -- possible second coord
1124 % #3 -- rest of true clause
1125 \def \sseq@DrawIfValidDifferential@@@#1#2#3{
1126 \sseq@eval{\endgroup%\@nx\tracingall
1127 \exp_not:c{sseq_if_valid_differential:nnT\sseq@falseclause}{\sseq@dpage}{\IfNoValueTF{#1}{\lastclass0}{\unexpanded{#1}}}{\unexpanded{#2}}{%
1128 \@nx\d[\exp_not:o{\sseq@doptions}]\sseq@dpage\IfNoValueF{#1}{(\unexpanded{#1})}\IfNoValueF{#2}{(\unexpanded{#2})}%
1129 \unexpanded{#3}%
1130 }%
1131 }%
1132 }
1133
1134 \protected\def\sseq@IfValidDifferentialTF{\sseq@IfValidDifferential{TF}}
1135 \protected\def\sseq@IfValidDifferentialT{\sseq@IfValidDifferential{T}}
1136 \protected\def\sseq@IfValidDifferentialF{\sseq@IfValidDifferential{F}}
1137
1138 \protected\def\sseq@IfValidDifferential#1{%
1139 \bgroup
1140 \def\sseq@truefalseclauses{#1}
1141 \sseq@d@grabpage{\sseq@IfValidDifferential@}
1142 }
1143
1144 \DeclareDocumentCommand \sseq@IfValidDifferential@ { d() d() } {%
1145 \sseq@eval{\egroup\exp_not:c{sseq_if_valid_differential:nn\sseq@truefalseclauses}{\sseq@dpage}{\IfNoValueTF{#1}{\lastclass0}{\unexpanded{#1}}}{\unexpanded{#2}}}%
1146 }
1147
1148 \prg_new_conditional:Npnn \sseq_if_valid_differential:nn #1 #2 #3 { T, F, TF } {
1149 \bgroup
1150 \sseq@tempiftrue
1151 \sseq@ifintexpr{#1}{%
1152 \edef\sseq@pagenum{\the\numexpr#1\relax}
1153 }{%
1154 \sseq@break% return false
1155 }%
1156 \sseq@quiet@parsecoord
1157 \msg_redirect_name:nnn {spectralsequences} {d-wrong-degree} {none}
1158 \msg_redirect_name:nnn {spectralsequences} {d-target-index-target-coord} {none}
1159 \msg_redirect_name:nnn {spectralsequences} {d-named-coord-two-indexes} {none}
1160 \msg_redirect_name:nnn {spectralsequences} {d-hit-wrong-order} {none}
1161 \msg_redirect_name:nnn {spectralsequences} {d-class-already-hit} {none}
1162 \msg_redirect_name:nnn {spectralsequences} {d-hit-same-page-replaceclass}{none}
1163 \sseq@dparsecoord{\sseq@pagenum}{#2}{#3}
1164 \let\sseq@obj@xdef\@gobbletwo
1165 \sseq@d@setpageclass{class.\source}{\sseq@pagenum}{source}
1166 \sseq@d@setpageclass{class.\target}{\sseq@pagenum}{target}
1167 \@gobbletwo\sseq@breakpoint\sseq@tempiffalse
1168 \ifsseq@tempif
1169 \egroup
1170 \prg_return_true:
1171 \else
1172 \egroup
1173 \prg_return_false:
1174 \fi
1175 }
1176
1177
1178
1179 \sseq@DeclareDocumentCommand \IfExistsTF { r() } { \sseq_if_exists:nTF { #1 } }
1180 \sseq@DeclareDocumentCommand \IfExistsT { r() } { \sseq_if_exists:nT { #1 } }
1181 \sseq@DeclareDocumentCommand \IfExistsF { r() } { \sseq_if_exists:nF { #1 } }
1182
1183 \sseq@DeclareDocumentCommand \IfOutOfBoundsTF { r() } { \sseq_if_out_of_bounds:nTF { #1 } }
1184 \sseq@DeclareDocumentCommand \IfOutOfBoundsT { r() } { \sseq_if_out_of_bounds:nT { #1 } }
1185 \sseq@DeclareDocumentCommand \IfOutOfBoundsF { r() } { \sseq_if_out_of_bounds:nF { #1 } }
1186 \sseq@DeclareDocumentCommand \IfInBoundsTF { r() mm } { \sseq_if_out_of_bounds:nTF { #1 } { #3 } { #2 } }
1187 \sseq@DeclareDocumentCommand \IfInBoundsT { r() } { \sseq_if_out_of_bounds:nF { #1 } }
1188 \sseq@DeclareDocumentCommand \IfInBoundsF { r() } { \sseq_if_out_of_bounds:nT { #1 } }
1189
1190 \sseq@DeclareDocumentCommand \IfAliveTF { mr() }{ \sseq_if_alive:nnTF{#1}{#2}}
1191 \sseq@DeclareDocumentCommand \IfAliveT { mr() } { \sseq_if_alive:nnT{#1}{#2}}
1192 \sseq@DeclareDocumentCommand \IfAliveF { mr() } { \sseq_if_alive:nnF{#1}{#2}}
1193
1194
1195 %%%%%%
1196 %%%
1197 %%% Tikz Primitives
1198 %%%
1199 %%%%%%
1200
1201 % Replace a tikz command with a command that saves the command on savedpaths
1202
1203 \def\sseq@modtikzcommands{%
1204 \let\scope\sseq@scope
1205 \let\endscope\sseq@endscope
1206 \@xp\sseq@modtikzcommands@\sseq@tikzcommands\sseq@nil
1207 }
1208 \def\sseq@modtikzcommands@#1{%
1209 \ifx#1\sseq@nil\else
1210 \protected\edef#1{\@xp\@nx\csname\sseq@macroname#1\space\endcsname\@nx#1}%
1211 \@xp\let\csname\sseq@macroname#1\space\endcsname\sseq@defer@tikzcommand % This is just for error reporting so that it will say "Paragraph ended before \draw was complete"
1212 \@xp\sseq@modtikzcommands@
1213 \fi
1214 }
1215
1216 \def\sseq@defer@tikzcommand#1{%
1217 \begingroup
1218 \let\sseq@isaliveprotect\sseq@isaliveprotect@protect
1219 \sseq@setinputline
1220 \sseq@loadinputline
1221 \sseq@callas{#1}%
1222 \gdef\sseq@thepathsofar{#1[/utils/exec={\sseq@thesseqstyle\sseq@thetikzprimitivestyle\the\sseq@scope@toks\sseq@savedoptioncode}]}%
1223 \xdef\sseq@whattheusersaid{\string#1}
1224 \sseq@defer@tikzcommand@
1225 }
1226
1227 \def\sseq@defer@tikzcommand@{%
1228 \futurelet\testtok\sseq@defer@tikzcommand@@
1229 }
1230
1231 % This serves as a marker to break out of parser.
1232 % TODO: support \pgfextra? Should we pass \pgfextra along to be handled by tikz parser?
1233 \def\sseq@defer@tikzcommand@escape{sseq@defer@tikzcommand@escape}
1234 \def\sseq@defer@tikzcommand@@{%
1235 \ifx\testtok;
1236 \let\next\sseq@defer@tikzcommand@finish
1237 \else
1238 \ifx\testtok[%
1239 \let\next\sseq@defer@tikzcommand@option
1240 \else
1241 \ifx\testtok(%
1242 \let\next\sseq@defer@tikzcommand@coord
1243 \else
1244 \@xp\ifx\space\testtok
1245 \let\next\sseq@defer@tikzcommand@space
1246 \else
1247 % TODO: also support "foreach" keyword without the backslash.
1248 \ifx\testtok\foreach
1249 \let\next\sseq@defer@tikzcommand@foreach
1250 \else
1251 \ifx\testtok\sseq@defer@tikzcommand@escape % escape is like \pgfextra, breaks out of the parsing.
1252 \let\next\@gobble
1253 \else
1254 \ifx\testtok\bgroup
1255 \let\next\sseq@defer@tikzcommand@group
1256 \else
1257 \let\next\sseq@defer@tikzcommand@other
1258 \fi
1259 \fi
1260 \fi
1261 \fi
1262 \fi
1263 \fi
1264 \fi
1265 \sseq@call{\next}%
1266 }
1267
1268
1269 \def\sseq@defer@tikzcommand@foreach{
1270 \def\pgffor@beginhook{\expandafter\sseq@defer@tikzcommand@\pgfutil@firstofone}
1271 \def\pgffor@endhook{\sseq@defer@tikzcommand@escape}
1272 \def\pgffor@afterhook{\sseq@defer@tikzcommand@}
1273 }
1274
1275 \def\sseq@defer@tikzcommand@option[#1]{%
1276 \sseq@processoptions{tikz ~ primitives}{#1}%
1277 \ifx\sseq@savedoptioncode\pgfutil@empty\else
1278 \sseq@x@addto@macro\sseq@thepathsofar{[/utils/exec={\unexpanded\@xp{\@xp\sseq@options@bothpassmode\sseq@savedoptioncode}}]}%
1279 \fi
1280 \sseq@g@addto@macro\sseq@whattheusersaid{[#1]}
1281 \sseq@defer@tikzcommand@
1282 }
1283
1284 \def\sseq@defer@tikzcommand@coord(#1){
1285 \sseq@tikzprimitives@coord(#1)
1286 \sseq@g@addto@macro\sseq@whattheusersaid{(#1)}
1287 \sseq@defer@tikzcommand@
1288 }
1289
1290 % When do groups occur in tikz commands? should we try to parse the inside?
1291 \def\sseq@defer@tikzcommand@group#1{
1292 \sseq@g@addto@macro\sseq@whattheusersaid{{#1}}
1293 \sseq@xprotected@addto@macro\sseq@thepathsofar{{#1}}%
1294 \sseq@defer@tikzcommand@
1295 }
1296
1297 \long\def\sseq@defer@tikzcommand@other#1{
1298 \ifcat$\@xp\@gobble\string#1$ % test for control word. Won't catch active characters.
1299 \@xp\use_i:nnn
1300 \else
1301 \@xp\ifx\csname sseq@illegalintikz@\string#1\endcsname\relax
1302 \exp_last_unbraced:Nf \use_ii:nnn
1303 \else
1304 \exp_last_unbraced:Nf \use_iii:nnn
1305 \fi
1306 \fi{ % case i: it's not a control word. Just add it to the saved path
1307 \sseq@g@addto@macro\sseq@whattheusersaid{#1}
1308 \sseq@g@addto@macro\sseq@thepathsofar{#1}%
1309 \sseq@defer@tikzcommand@
1310 }{ % case ii: it's some different control word. Let's try full expanding it.
1311 % note that here we cannot figure out what the user actually said, so we just have to report the f-expanded version.
1312 \def\tempa{#1} % save the current value
1313 \exp_last_unbraced:Nf \sseq@defer@tikzcommand@other@cs#1
1314 }{ % case iii: it's an illegal control word (e.g., \class, \d, \begin, \end, ...) throw an error.
1315 \sseq@error@xx{incomplete-tikz}{\unexpanded\@xp{\sseq@whattheusersaid}}{
1316 \ifx\par#1 the ~ start ~ of ~ a ~ new ~ paragraph
1317 \else \string#1\fi
1318 }
1319 \sseq@defer@tikzcommand@finish@ % finish@ doesn't try to grab a semicolon, which is good because there isn't one.
1320 #1 % Reinsert the token that is causing us to stop
1321 }
1322 }
1323
1324 \def\sseq@defer@tikzcommand@other@cs#1{ % so we f expanded the control sequence, now we test if that did anything
1325 \def\tempb{#1} % get the first f expanded token
1326 \ifx\tempa\tempb
1327 \@xp\@firstoftwo
1328 \else
1329 \@xp\@secondoftwo
1330 \fi{% it didn't get expanded any more, so just add it to the stored stuff
1331 \sseq@g@addto@macro\sseq@whattheusersaid{#1}
1332 \sseq@g@addto@macro\sseq@thepathsofar{#1}
1333 \sseq@defer@tikzcommand@
1334 }{% it got expanded. Run it through the main loop again.
1335 \sseq@defer@tikzcommand@#1
1336 }
1337 }
1338
1339 % Illegal control words:
1340 \long\def\sseq@setillegalcontrolwords#1{\sseq@setillegalcontrolwords@#1\sseq@nil}
1341 \long\def\sseq@setillegalcontrolwords@#1{
1342 \ifx#1\sseq@nil\else
1343 \@xp\def\csname sseq@illegalintikz@\string#1\endcsname{}
1344 \@xp\sseq@setillegalcontrolwords@
1345 \fi
1346 }
1347
1348 % We missing anything here?
1349 \sseq@setillegalcontrolwords{
1350 \class\classoptions\replaceclass\d\doptions\structline\structlineoptions\circleclasses
1351 \savestack\restorestack\pushstack\nameclass\foreach\begin\end\par
1352 \clip\coordinate\draw\fill\filldraw
1353 \graph\matrix\node\path\pattern
1354 \shade\shadedraw\useasboundingbox
1355 }
1356
1357
1358 \@xp\def\@xp\sseq@defer@tikzcommand@space\space{%
1359 \sseq@g@addto@macro\sseq@thepathsofar{~}%
1360 \sseq@g@addto@macro\sseq@whattheusersaid{~}
1361 \sseq@defer@tikzcommand@
1362 }
1363
1364 \def\sseq@defer@tikzcommand@finish;{
1365 \sseq@g@addto@macro\sseq@whattheusersaid{;}
1366 \sseq@defer@tikzcommand@finish@
1367 }
1368
1369 % If the expression was incomplete, we'll jump here to avoid adding the semicolon to the error printout
1370 \def\sseq@defer@tikzcommand@finish@{
1371 \sseq@g@addto@macro\sseq@thepathsofar{;}
1372 %\show\sseq@thepathsofar
1373 \global\sseq@thiscalltoks\@xp{\sseq@whattheusersaid}
1374 \ifx\sseq@pageconstraint\sseq@pageconstraint@true
1375 %\show\sseq@thepathsofar
1376 \sseq@savedpaths@xaddtikzpath{\unexpanded\@xp{\sseq@thepathsofar}}%
1377 \else
1378 \sseq@savedpaths@xaddtikzpath{%
1379 \@nx\sseq@tikzcommand@conditionaldraw{\unexpanded\@xp{\sseq@thepathsofar}}{\unexpanded\@xp{\sseq@pageconstraint}}
1380 }%
1381 \fi
1382 \endgroup
1383 }
1384
1385
1386 \def\sseq@tikzcommand@conditionaldraw#1#2{%
1387 \sseq@pgfmathparse@rescan{#2}%
1388 \ifnum\pgfmathresult>\z@ #1 \fi
1389 }
1390
1391 \def\sseq@pgfmathparse@rescan#1{\makeatletter\catcode`\&=12\relax\scantokens{\pgfmathparse{#1}}}
1392
1393 %%% Coordinate parser, copied with huge simplifications from \tikz@@scan@@no@calculator, tikz.code.tex line 4994.
1394 %%% We don't need to handle any of the weird cases, we just need to know about them so we can give up and let tikz do the work later.
1395 % TODO: do same coordinate fixing for coordinates in calculations (yeah right! not even clear this is a good idea...)
1396 \def\sseq@tikzprimitives@coord(#1){
1397 \begingroup
1398 \let\next\sseq@tikzprimitives@coords@maybenamedclass
1399 \ifsseq@tikzprims@integershift
1400 \pgfutil@in@${#1}
1401 \ifpgfutil@in@
1402 \let\next\sseq@tikzprimitives@coords@handlemath
1403 \else
1404 \pgfutil@in@ :{#1}
1405 \ifpgfutil@in@\else
1406 \pgfutil@in@{intersection }{#1}
1407 \ifpgfutil@in@\else
1408 \pgfutil@in@|{#1}%
1409 \ifpgfutil@in@\else
1410 \pgfutil@in@,{#1}
1411 \ifpgfutil@in@
1412 \let\next\sseq@tikzprimitives@coords@maybeclass
1413 \fi
1414 \fi
1415 \fi
1416 \fi
1417 \fi
1418 \fi
1419 \next{#1}
1420 \endgroup
1421 }
1422 \def\sseq@tikzprimitives@coords@maybeclass#1{
1423 \let\next\sseq@tikzprimitives@coords@notaclass % most branches do this.
1424 % First check whether there are any of the protect "to be determined later" variables like \xmax, etc. If there are, it's not a class
1425 \sseq@protected@edef\sseq@temp@i{#1}
1426 \edef\sseq@temp@ii{#1}
1427 \ifx\sseq@temp@i\sseq@temp@ii
1428 \@xp\sseq@tikzprimitive@getcoord@anchor#1.\sseq@nil % puts coord into \sseq@tempcoord, anchor if any into \sseq@tempanchor
1429 \exp_args:NNo\pgfutil@in@.{\sseq@tempanchornopt} % If there's an extra . in the "anchor", it's not an anchor, and this is not a class
1430 \ifpgfutil@in@\else
1431 \exp_args:NNo \pgfutil@in@,{\sseq@tempcoord} % If the . we used to delineate the "anchor" was in the x-coordinate, it's not an anchor and this is not a class
1432 \ifpgfutil@in@
1433 \exp_args:NNo \pgfutil@in@,{\sseq@tempanchornopt} % If there is a comma in the "anchor" it's not an anchor and this is not a class
1434 \ifpgfutil@in@\else
1435 \ifx\sseq@tempanchor\pgfutil@empty
1436 \sseq@tempiftrue
1437 \else % If there's an "anchor" we need to test whether the expression is a valid decimal coordinate. If it is, we're going to treat it as not a class
1438 % outputs into sseq@tempif, sets sseq@tempiffalse if it IS valid math, b/c then we're not a anchor
1439 \sseq@anchortrue % If this ends up getting handled as a tikz coordinate, we'll have to add an "anchor ignored" error
1440 \sseq@tikzprimitives@testlastcoord@validmathexpression#1,\sseq@nil
1441 \fi
1442 \ifsseq@tempif
1443 \@xp\sseq@tikzprimitives@ifintcoords\@xp{\sseq@tempcoord}{ % check we're all integer coordinates
1444 \sseq@parsecoord@allownonexisting\coord{\sseq@tempcoord}{tikz ~ primitive}%
1445 \ifx\sseq@index\pgfutil@empty\else
1446 \sseq@x@addto@macro\sseq@thepathsofar{(sseq{\sseq@removeparens\coord}\sseq@tempanchor)}% Okay, we're all set, it's a class
1447 \let\next\@gobble % don't run \sseq@tikzprimitives@notaclass
1448 \fi
1449 }{}%
1450 \fi
1451 \fi
1452 \fi
1453 \fi
1454 \fi
1455 \next{#1}
1456 }
1457
1458 % Sets tempiffalse if if the second coordinate IS a valid math expression -- then t
1459 \def\sseq@tikzprimitives@testlastcoord@validmathexpression#1,#2,#3\sseq@nil{
1460 \sseq@ifpgfmathexpr{#2}{
1461 \sseq@tempiffalse
1462 }{
1463 \sseq@tempiftrue
1464 }
1465 }
1466
1467 \def\sseq@tikzprimitives@coords@maybenamedclass#1{%
1468 \sseq@tikzprimitive@getcoord@anchor#1.\sseq@nil % puts coord into \sseq@tempcoord, anchor if any into \sseq@tempanchor
1469 \protected@edef\sseq@tempcoord{\sseq@tempcoord}%
1470 % need this detokenize here to prevent it from throwing errors when there's a command inside...
1471 \sseq@obj@ifdef{class.namedclass.\detokenize\@xp{\sseq@tempcoord}}{
1472 \sseq@x@addto@macro\sseq@thepathsofar{(sseq{\sseq@obj{class.namedclass.\detokenize\@xp{\sseq@tempcoord}}\sseq@tempanchor})}%
1473 }{%
1474 \sseq@tikzprimitives@coords@notaclass{#1}%
1475 }%
1476 }
1477
1478 \let\sseq@tikzprimitives@coords@maybeclass@save\sseq@tikzprimitives@coords@maybeclass
1479
1480
1481 \def\sseq@tikzprimitives@coords@notaclass#1{
1482 \def\next{\sseq@tikzprimitives@coords@notaclass@leavetotikz{#1}}
1483 \pgfutil@in@${#1}
1484 \ifpgfutil@in@\else
1485 \pgfutil@in@ :{#1}
1486 \ifpgfutil@in@\else
1487 \pgfutil@in@{intersection }{#1}
1488 \ifpgfutil@in@\else
1489 \pgfutil@in@|{#1}%
1490 \ifpgfutil@in@\else
1491 \pgfutil@in@,{#1}
1492 \ifpgfutil@in@
1493 \def\next{\sseq@tikzprimitives@coords@notaclass@handle{#1}}
1494 \fi
1495 \fi
1496 \fi
1497 \fi
1498 \fi
1499 \next
1500 }
1501
1502 \def\sseq@tikzprimitives@coords@notaclass@leavetotikz#1{
1503 \sseq@g@addto@macro\sseq@thepathsofar{(#1)}
1504 }
1505
1506 \def\sseq@tikzprimitives@coords@notaclass@handle#1{
1507 \ifsseq@anchor
1508 % Still seems impossible to trigger this?
1509 \sseq@error@xxx{anchor-ignored}{(#1)}{(\unexpanded\@xp{\sseq@tempcoord})}{\sseq@tempanchor}
1510 \@xp\sseq@tikzprimitives@coords@notaclass@handle@\sseq@tempcoord,\sseq@nil
1511 \else
1512 \sseq@tikzprimitives@coords@notaclass@handle@#1,\sseq@nil
1513 \fi
1514 }
1515
1516 \def\sseq@tikzprimitives@coords@notaclass@handle@#1,#2,#3\sseq@nil{
1517 \sseq@ifempty{#3}{
1518 \let\sseq@index\pgfutil@empty
1519 }{
1520 \edef\sseq@index{,\unexpanded\@xp{\sseq@removecomma#3\sseq@nil}}
1521 \edef\sseq@indexnocomma{\unexpanded\@xp{\sseq@removecomma#3\sseq@nil}}
1522 }
1523 \sseq@ifpgfmathexpr{#1}{%
1524 % Decide whether we can keep the result, which is stored in \sseq@mathresult
1525 \protected@edef\sseq@tempa{#1}
1526 \edef\sseq@tempb{#1}
1527 \ifx\sseq@tempa\sseq@tempb
1528 \let\sseq@tempx\sseq@mathresult
1529 \else
1530 \def\sseq@tempx{#1}
1531 \fi
1532 }{
1533 \sseq@error@xx{invalid-tikz-coord}{(#1,#2\sseq@index)}{x}
1534 \def\sseq@defer@tikzcommand@finish;{\endgroup}
1535 }
1536 \sseq@ifpgfmathexpr{#2}{
1537 % Decide whether we can keep the result, which is stored in \sseq@mathresult
1538 \protected@edef\sseq@tempa{#2}
1539 \edef\sseq@tempb{#2}
1540 \ifx\sseq@tempa\sseq@tempb
1541 \let\sseq@tempy\sseq@mathresult
1542 \else
1543 \def\sseq@tempy{#2}
1544 \fi
1545 }{
1546 \sseq@error@xx{invalid-tikz-coord}{(#1,#2\sseq@index)}{y}
1547 \def\sseq@defer@tikzcommand@finish;{\endgroup}
1548 }
1549 \def\sseq@tempa{#1}
1550 \ifx\sseq@index\pgfutil@empty\else
1551 \sseq@error@xxx{index-ignored}{(\unexpanded{#1,#2}\unexpanded\@xp{\sseq@index})}{\unexpanded{(#1,#2)}}{\unexpanded\@xp{\sseq@indexnocomma}}
1552 \fi
1553 \sseq@xprotected@addto@macro\sseq@thepathsofar{(\sseq@tempx,\sseq@tempy)}
1554 }
1555
1556 \def\sseq@tikzprimitives@ifintcoords#1{\sseq@tikzprimitives@ifintcoords@#1,\sseq@nil}
1557 \def\sseq@tikzprimitives@ifintcoords@#1,#2,#3\sseq@nil{%
1558 \sseq@ifintexpr{#1}{%
1559 \sseq@ifintexpr{#2}{%
1560 \@firstoftwo
1561 }{\@secondoftwo}%
1562 }{\@secondoftwo}%
1563 }
1564 \def\sseq@tikzprimitives@coords@handlemath#1{\sseq@tikzprimitives@coords@handlemath@(#1)}
1565 \def\sseq@tikzprimitives@coords@handlemath@#1$#2$){\sseq@g@addto@macro\sseq@thepathsofar{#1$#2$)}}
1566 \def\sseq@tikzprimitive@getcoord@anchor#1.#2\sseq@nil{
1567 \def\sseq@tempcoord{#1}
1568 \ifx\sseq@nil#2\sseq@nil
1569 \def\sseq@tempanchor{}
1570 \def\sseq@tempanchornopt{}
1571 \else
1572 \edef\sseq@tempanchor{.\sseq@tikzprimitive@getcoord@anchor@eatdot#2}
1573 \edef\sseq@tempanchornopt{\sseq@tikzprimitive@getcoord@anchor@eatdot#2}
1574 \fi
1575 }
1576 \def\sseq@tikzprimitive@getcoord@anchor@eatdot#1.{#1}
1577 \def\sseq@uptopt#1.#2\sseq@nil{#1}
1578 %%% Page constraint and \isalive
1579 % #1 -- the new page constraint
1580 % #2 -- a binary logical operator (&& or ||).
1581 \def\sseq@updatepageconstraint#1#2{
1582 \def\sseq@isaliveprotect{}
1583 \let\sseq@isalive@\sseq@isalive@active
1584 \bgroup
1585 % Was pretty hard to get \isalive to report errors correctly. And to work in general >_<
1586 \let\sseq@isalive@parens\sseq@isalive@parens@check
1587 \sseq@d@addto@macro\sseq@error@hook{\let\protect\relax}%
1588 \let\protect\@unexpandable@protect
1589 \edef\sseq@error@annotation{\unexpanded{.^^J(In page constraint "#1")}\unexpanded\@xp{\sseq@error@annotation}}
1590 \selectfont\sseq@restorefont
1591 \setbox0=\hbox{#1}
1592 \egroup
1593 \sseq@protected@edef\sseq@pageconstraint{(\unexpanded\@xp{\sseq@pageconstraint})#2(#1)}
1594 }
1595
1596
1597 \def\sseq@updatepageconstraintrange{%
1598 \sseq@protected@edef\sseq@pageconstraint{%
1599 (\unexpanded\@xp{\sseq@pageconstraint})&&(\temp<=\page \ifx\tempmax\empty\else&&\page<=\tempmax\fi)%
1600 }%
1601 }
1602
1603 % This protect variant allows us to delay evaluation of \isalive, just so that we can
1604 % capture something close to the original argument to (does this matter anymore?)
1605 \let\sseq@isaliveprotect\relax
1606 \def\sseq@isaliveprotect@protect{\@nx\sseq@isaliveprotect\@nx}
1607 \def\sseq@isalive{\sseq@isaliveprotect\sseq@isalive@}
1608 \def\sseq@isalive@{\sseq@isalive@error}
1609 \def\sseq@isalive@error{\sseq@error{is-alive-illegal-here}}
1610 \def\sseq@isalive@active#1{%
1611 \@xp\ifx\@xp$\@gobble#1$%
1612 \@xp\sseq@isalive@parens\@xp#1%
1613 \else
1614 \sseq@isalive@list#1\sseq@nil
1615 \fi
1616 }
1617 \def\sseq@isalive@list(#1)#2{%
1618 \sseq@isalive@parens(#1)%
1619 \ifx\sseq@nil#2\else
1620 &&\@xp\sseq@isalive@list\@xp#2%
1621 \fi
1622 }
1623
1624 \def\sseq@isalive@parens@check(#1){
1625 \sseq@parsecoord\coord{#1}{\string\isalive}
1626 }
1627 \def\sseq@isalive@parens(#1){\sseq@parsecoordex\sseq@isalive@parens@(#1)}
1628 \def\sseq@isalive@parens@(#1,#2,#3){\@nx\sseq@isalive@final{#1}{#2}{#3}{\sseq@obj{class.(#1,#2,#3).num}}}
1629 \def\sseq@isalive@final#1#2#3#4{%
1630 \ifnum\sseq@obj{class.(#1,#2,#3)[#4].page}<\sseq@thepagecount
1631 0%
1632 \else
1633 \ifnum#4=\z@
1634 1%
1635 \else
1636 \ifnum\sseq@obj{class.(#1,#2,#3)[\the\numexpr #4-1\relax].page}=\sseq@thepagecount
1637 0%
1638 \else
1639 1%
1640 \fi
1641 \fi
1642 \fi
1643 }
1644
1645
1646
1647
1648
1649 %%%
1650 %%% This is a macro for typesetting monomials.
1651 %%%
1652
1653 % We need to check for math subscript characters
1654 \char_set_catcode_math_subscript:N \_
1655
1656 \def\sseq@support@std{}
1657 \protected\def\SseqNormalizeMonomialSetVariables#1{%
1658 \bgroup
1659 \gdef\sseq@support@std{}%
1660 \def\sseqnormalizemonomial@add{%
1661 \def\temp{1}%
1662 \ifx\sseq@var\temp\else
1663 \edef\sseq@var{\unexpanded\@xp{\sseq@var}\unexpanded\@xp{\sseq@subscript}}%
1664 \@ifundefined{\sseqnormalizemonomial@varcs}{%
1665 \@xp\xdef\csname\sseqnormalizemonomial@varcs\endcsname{0}%
1666 \sseq@x@addto@macro\sseq@support@std{\@nx\\{\unexpanded\@xp{\sseq@var}}{\sseqnormalizemonomial@varcs}}%
1667 }{}%
1668 \fi
1669 \sseqnormalizemonomial@testend
1670 }%
1671 \SseqNormalizeMonomial{#1}%
1672 \egroup
1673 }
1674
1675
1676 \protected\def\SseqNormalizeMonomial#1{%
1677 \bgroup
1678 \def\sseq@ourinput{#1}%
1679 \let\sseq@support\sseq@support@std
1680 \sseq@ifempty{#1}{\egroup\def\result{1}}{%
1681 \sseqnormalizemonomial@#1\sseq@nil
1682 }%
1683 }
1684 \def\sseqnormalizemonomial@#1{%
1685 \pgfkeys@spdef\sseq@var{#1}%
1686 \def\sseq@power{1}%
1687 \def\sseq@subscript{}%
1688 \futurelet\testtok\sseqnormalizemonomial@@
1689 }
1690
1691 \def\sseqnormalizemonomial@@{%
1692 \ifx\testtok^%
1693 \let\next\sseqnormalizemonomial@sup
1694 \else
1695 \ifx\testtok_%
1696 \let\next\sseqnormalizemonomial@sub
1697 \else
1698 \let\next\sseqnormalizemonomial@add
1699 \fi
1700 \fi
1701 \next
1702 }
1703
1704 \def\sseqnormalizemonomial@sup^#1{%
1705 \sseq@ifintexpr{#1}{%
1706 \edef\sseq@power{\the\numexpr#1\relax}%
1707 }{%
1708 \sseq@error@xxx{NormalizeMonomial-invalid-exponent}{\unexpanded{#1}}{\unexpanded\@xp{\sseq@var}}{\unexpanded\@xp{\sseq@ourinput}}
1709 \let\result\sseq@ourinput
1710 \sseq@gobble@to@nil
1711 }
1712 \futurelet\testtok\sseqnormalizemonomial@@
1713 }
1714
1715 \def\sseqnormalizemonomial@sub_#1{%
1716 \def\sseq@subscript{_{#1}}%
1717 \futurelet\testtok\sseqnormalizemonomial@@
1718 }
1719
1720 \def\sseqnormalizemonomial@add{%
1721 \def\temp{1}%
1722 \ifx\sseq@var\temp\else
1723 \edef\sseq@var{\unexpanded\@xp{\sseq@var}\unexpanded\@xp{\sseq@subscript}}%
1724 \@ifundefined{\sseqnormalizemonomial@varcs}{%
1725 \@xp\edef\csname\sseqnormalizemonomial@varcs\endcsname{\sseq@power}%
1726 \sseq@e@addto@macro\sseq@support{\@nx\\{\unexpanded\@xp{\sseq@var}}{\sseqnormalizemonomial@varcs}}%
1727 }{%
1728 \@xp\edef\csname\sseqnormalizemonomial@varcs\endcsname{\the\numexpr\csname\sseqnormalizemonomial@varcs\endcsname + \sseq@power}%
1729 }%
1730 \fi
1731 \sseqnormalizemonomial@testend
1732 }
1733
1734
1735 \def\sseqnormalizemonomial@testend{%
1736 \ifx\testtok\sseq@nil
1737 \sseqnormalizemonomial@done
1738 \sseq@smuggle@macro\result
1739 \egroup
1740 \let\next\@gobble
1741 \else
1742 \@xp\ifx\space\testtok
1743 \def\next{\@xp\futurelet\@xp\testtok\@xp\sseqnormalizemonomial@testend\romannumeral-`0}%
1744 \else
1745 \let\next\sseqnormalizemonomial@
1746 \fi
1747 \fi
1748 \next
1749 }
1750
1751 \def\sseqnormalizemonomial@varcs{sseqnormalizemonomial@var@\detokenize\@xp{\sseq@var}}
1752
1753 \def\sseqnormalizemonomial@done{%
1754 \def\result{}%
1755 \def\\##1##2{%
1756 \sseq@tempcount=\csname ##2\endcsname\relax
1757 \ifnum\sseq@tempcount=\z@
1758 \else
1759 \ifnum\sseq@tempcount=\@ne
1760 \sseq@d@addto@macro\result{##1}%
1761 \else
1762 \sseq@e@addto@macro\result{\unexpanded{##1}^{\the\sseq@tempcount}}%
1763 \fi
1764 \fi
1765 }%
1766 \sseq@support
1767 \ifx\result\pgfutil@empty % use 1 for empty monomial
1768 \def\result{1}%
1769 \fi
1770 }
1771
1772 % Restore catcode of underscore to letter
1773 \catcode`\_ = 11\relax
1774
1775
1776 \def\SseqAHSSNameHandler#1{
1777 \pgfutil@in@[{#1}
1778 \ifpgfutil@in@
1779 \@xp\@firstofone
1780 \else
1781 \sseq@error{AHSSNameHandler-missing-cell}{#1}
1782 \def\result{#1}
1783 \@xp\@gobble
1784 \fi{
1785 \SseqAHSSNameHandler@#1\sseq@nil
1786 }
1787 }
1788
1789
1790 \def\SseqAHSSNameHandler@#1[#2\sseq@nil{
1791 \pgfutil@in@]{#2}
1792 \ifpgfutil@in@
1793 \@xp\@firstofone
1794 \else
1795 \sseq@error{AHSSNameHandler-missing-cell}{#1[#2}
1796 \def\result{#1[#2}
1797 \@xp\@gobble
1798 \fi{
1799 \SseqAHSSNameHandler@@{#1}#2\sseq@nil
1800 }
1801 }
1802
1803 \def\SseqAHSSNameHandler@@#1#2]#3\sseq@nil{
1804 \SseqNormalizeMonomial{#1#3}
1805 \sseq@ifintexpr{#2}{
1806 \edef\result{\unexpanded\@xp{\result}[\the\numexpr#2+\sseq@y]}
1807 }{
1808 \sseq@error{AHSSNameHandler-invalid-integer}{#2}{#1[#2]#3}
1809 \edef\result{\unexpanded\@xp{\result[#2]}}
1810 }
1811 }
1812
1813
1814
1815
1816 \ExplSyntaxOff