Debian Codegraph @

texmf-dist/source/latex/strands/strands.dtx

raw
1 % \iffalse meta-comment
2 %
3 % Copyright (C) 2021 by Diego Arcis <[email protected]>
4 % --------------------------------------------------------------------
5 % This work may be distributed and/or modified under the conditions of
6 % the LaTeX Project Public License, either version 1.3 of this license
7 % or (at your option) any later version.
8 %
9 % The latest version of this license is in:
10 % http://www.latex-project.org/lppl.txt
11 %
12 % and version 1.3 or later is part of all distributions of LaTeX, that
13 % is, version 2005/12/01 or later.
14 %
15 % The Current Maintainer of this work is Diego Arcis.
16 %
17 % This work consists of the files strands.dtx and strands.ins and they
18 % derive the filebase strands.sty.
19 % --------------------------------------------------------------------
20 %
21 % \fi
22 %
23 % \iffalse
24 %<package>\NeedsTeXFormat{LaTeX2e}[2005/12/01]
25 %<package>\ProvidesPackage{strands}[2021/07/11 v1.1 Strands]
26 %
27 %<*driver>
28 \documentclass{ltxdoc}
29 \usepackage{strands}
30 \EnableCrossrefs
31 \CodelineIndex
32 \RecordChanges
33 \begin{document}
34 \DocInput{strands.dtx}
35 \end{document}
36 %</driver>
37 % \fi
38 %
39 % \CheckSum{1713}
40 %
41 % \CharacterTable
42 % {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
43 % Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
44 % Digits \0\1\2\3\4\5\6\7\8\9
45 % Exclamation \! Double quote \" Hash (number) \#
46 % Dollar \$ Percent \% Ampersand \&
47 % Acute accent \' Left paren \( Right paren \)
48 % Asterisk \* Plus \+ Comma \,
49 % Minus \- Point \. Solidus \/
50 % Colon \: Semicolon \; Less than \<
51 % Equals \= Greater than \> Question mark \?
52 % Commercial at \@ Left bracket \[ Backslash \\
53 % Right bracket \] Circumflex \^ Underscore \_
54 % Grave accent \` Left brace \{ Vertical bar \|
55 % Right brace \} Tilde \~}
56 %
57 %
58 % \changes{v1.1}{2021/07/11}{Initial version}
59 %
60 % \GetFileInfo{strands.sty}
61 %
62 % \DoNotIndex{\#,\$,\%,\&,\@,\\,\{,\},\^,\_,\~,\}
63 % \DoNotIndex{\@ne}
64 % \DoNotIndex{\advance,\begingroup,\catcode,\closein}
65 % \DoNotIndex{\closeout,\day,\def,\edef,\else,\empty,\endgroup}
66 %
67 % \title{The \textsf{strands} package
68 % \thanks{This document corresponds to \textsf{strands}~\fileversion, dated~\filedate.}
69 % }
70 % \author{Diego Arcis \\ \texttt{[email protected]}}
71 %
72 % \maketitle
73 %
74 % \StopEventually{\PrintIndex}
75
76 % packages:
77 \RequirePackage{forarray}
78 \RequirePackage{ifthen}
79 \RequirePackage{tikz}
80 \RequirePackage{xfp}
81 \RequirePackage{xstring}
82 \RequirePackage{xkeyval}
83
84 \usetikzlibrary{snakes}
85
86 \newcommand{\getelem}[3]{ % \getelem{list}{index}{\name}
87 \StrBetween[#2,\fpeval{#2+1}]{,#1,}{,}{,}[#3]
88 }
89
90 % global variables:
91 \makeatletter
92 \define@cmdkey[str]{strands}{backcolor}{}
93 \define@cmdkey[str]{strands}{bend}{}
94 \define@cmdkey[str]{strands}{bendbraid}{}
95 \define@cmdkey[str]{strands}{bendtangle}{}
96 \define@cmdkey[str]{strands}{bulletsize}{}
97 \define@cmdkey[str]{strands}{braidcross}{}
98 \define@cmdkey[str]{strands}{braidsingcross}{}
99 \define@cmdkey[str]{strands}{braidvirtcross}{}
100 \define@cmdkey[str]{strands}{coverunion}{}
101 \define@cmdkey[str]{strands}{direction}{}
102 \define@cmdkey[str]{strands}{externalize}{}
103 \define@cmdkey[str]{strands}{font}{}
104 \define@cmdkey[str]{strands}{gencharposbraid}{}
105 \define@cmdkey[str]{strands}{gencharnegbraid}{}
106 \define@cmdkey[str]{strands}{gencharvirtual}{}
107 \define@cmdkey[str]{strands}{gencharsingular}{}
108 \define@cmdkey[str]{strands}{genchartangle}{}
109 \define@cmdkey[str]{strands}{genchartie}{}
110 \define@cmdkey[str]{strands}{genchartiedtangle}{}
111 \define@cmdkey[str]{strands}{genchartrivial}{}
112 \define@cmdkey[str]{strands}{height}{}
113 \define@cmdkey[str]{strands}{labelver}{}
114 \define@cmdkey[str]{strands}{labelhor}{}
115 \define@cmdkey[str]{strands}{norma}{}
116 \define@cmdkey[str]{strands}{normb}{}
117 \define@cmdkey[str]{strands}{normcolor}{}
118 \define@cmdkey[str]{strands}{normsymbol}{}
119 \define@cmdkey[str]{strands}{nstr}{}
120 \define@cmdkey[str]{strands}{num}{}
121 \define@cmdkey[str]{strands}{rotate}{}
122 \define@cmdkey[str]{strands}{scale}{}
123 \define@cmdkey[str]{strands}{strwidth}{}
124 \define@cmdkey[str]{strands}{tiebend}{}
125 \define@cmdkey[str]{strands}{tiebull}{}
126 \define@cmdkey[str]{strands}{tiebullsize}{}
127 \define@cmdkey[str]{strands}{tiecolor}{}
128 \define@cmdkey[str]{strands}{tieheight}{}
129 \define@cmdkey[str]{strands}{tiesnake}{}
130 \define@cmdkey[str]{strands}{tiesnakeamp}{}
131 \define@cmdkey[str]{strands}{tiesnakends}{}
132 \define@cmdkey[str]{strands}{tiesnakelen}{}
133 \define@cmdkey[str]{strands}{tiestyle}{}
134 \define@cmdkey[str]{strands}{tiewidth}{}
135 \define@cmdkey[str]{strands}{timeswidth}{}
136 \define@cmdkey[str]{strands}{tkzpic}{}
137 \define@cmdkey[str]{strands}{width}{}
138
139 % default options:
140 \presetkeys[str]{strands}{
141 backcolor=white, % color of the paper.
142 bend=45, % bend of partitions.
143 bendbraid=30, % bend for braid crossings.
144 bendtangle=45, % bend for tangles.
145 braidcross=3, % size of the braid crossing.
146 braidsingcross=1.6, % size of the singular braid crossing.
147 braidvirtcross=8, % size of the virtual braid crossing.
148 bulletsize=0.04,
149 coverunion=0.001, % extra length to cover the union of strands.
150 direction=1,
151 externalize=0, % use 1 to transform images to PDF.
152 font=0.7, % size of the fonts for labels.
153 gencharposbraid=p,
154 gencharnegbraid=n,
155 gencharvirtual=v,
156 gencharsingular=s,
157 genchartangle=t,
158 genchartie=e,
159 genchartiedtangle=f,
160 genchartrivial=i,
161 height=1, % to set the height of strands.
162 labelver=0.2,
163 labelhor=0.03,
164 norma=0, % to normalize the height above.
165 normb=0, % to normalize the height below.
166 normcolor=transparent,
167 normsymbol=-,
168 nstr=0, % number of strands.
169 num=0, % number of dots for arc partitions.
170 rotate=0, % to rotate all pictures.
171 scale=1, % to scale all pictures.
172 strwidth=0.7, % to set the width of the strands.
173 tiebend=0, % to set bend of ties.
174 tiebull=0, % bullets for ties.
175 tiebullsize=0.04,
176 tiecolor=red, % to set color of the ties.
177 tieheight=0.5, % height of ties respect to the global height.
178 tiesnake=false,
179 tiesnakeamp=1,
180 tiesnakends=0,
181 tiesnakelen=3,
182 tiestyle=dashed, % to set the type of the tie lines.
183 tiewidth=0.5, % to set the width of tie lines.
184 timeswidth=3,
185 tkzpic=1,
186 width=0.6, % to set the width between strands.
187 }{}
188
189 \setkeys[str]{strands}{}
190
191 % declare custom options:
192 \DeclareOptionX{backcolor}{\renewcommand{\cmdstr@strands@backcolor}{#1}}
193 \DeclareOptionX{bend}{\renewcommand{\cmdstr@strands@bend}{#1}}
194 \DeclareOptionX{bendbraid}{\renewcommand{\cmdstr@strands@bendbraid}{#1}}
195 \DeclareOptionX{bendtangle}{\renewcommand{\cmdstr@strands@bendtangle}{#1}}
196 \DeclareOptionX{braidcross}{\renewcommand{\cmdstr@strands@braidcross}{#1}}
197 \DeclareOptionX{braidsingcross}{\renewcommand{\cmdstr@strands@braidsingcross}{#1}}
198 \DeclareOptionX{braidvirtcross}{\renewcommand{\cmdstr@strands@braidvirtcross}{#1}}
199 \DeclareOptionX{bulletsize}{\renewcommand{\cmdstr@strands@bulletsize}{#1}}
200 \DeclareOptionX{coverunion}{\renewcommand{\cmdstr@strands@coverunion}{#1}}
201 \DeclareOptionX{direction}{\renewcommand{\cmdstr@strands@direction}{#1}}
202 \DeclareOptionX{externalize}{\renewcommand{\cmdstr@strands@externalize}{#1}}
203 \DeclareOptionX{font}{\renewcommand{\cmdstr@strands@font}{#1}}
204 \DeclareOptionX{gencharposbraid}{\renewcommand{\cmdstr@strands@gencharposbraid}{#1}}
205 \DeclareOptionX{gencharnegbraid}{\renewcommand{\cmdstr@strands@gencharnegbraid}{#1}}
206 \DeclareOptionX{gencharvirtual}{\renewcommand{\cmdstr@strands@gencharvirtual}{#1}}
207 \DeclareOptionX{gencharsingular}{\renewcommand{\cmdstr@strands@gencharsingular}{#1}}
208 \DeclareOptionX{genchartangle}{\renewcommand{\cmdstr@strands@genchartangle}{#1}}
209 \DeclareOptionX{genchartie}{\renewcommand{\cmdstr@strands@genchartie}{#1}}
210 \DeclareOptionX{genchartiedtangle}{\renewcommand{\cmdstr@strands@genchartiedtangle}{#1}}
211 \DeclareOptionX{height}{\renewcommand{\cmdstr@strands@height}{#1}}
212 \DeclareOptionX{labelver}{\renewcommand{\cmdstr@strands@labelver}{#1}}
213 \DeclareOptionX{labelhor}{\renewcommand{\cmdstr@strands@labelhor}{#1}}
214 \DeclareOptionX{norma}{\renewcommand{\cmdstr@strands@norma}{#1}}
215 \DeclareOptionX{normb}{\renewcommand{\cmdstr@strands@normb}{#1}}
216 \DeclareOptionX{normcolor}{\renewcommand{\cmdstr@strands@normcolor}{#1}}
217 \DeclareOptionX{nstr}{\renewcommand{\cmdstr@strands@nstr}{#1}}
218 \DeclareOptionX{num}{\renewcommand{\cmdstr@strands@num}{#1}}
219 \DeclareOptionX{rotate}{\renewcommand{\cmdstr@strands@rotate}{#1}}
220 \DeclareOptionX{scale}{\renewcommand{\cmdstr@strands@scale}{#1}}
221 \DeclareOptionX{strwidth}{\renewcommand{\cmdstr@strands@strwidth}{#1}}
222 \DeclareOptionX{tiebend}{\renewcommand{\cmdstr@strands@tiebend}{#1}}
223 \DeclareOptionX{tiebull}{\renewcommand{\cmdstr@strands@tiebull}{#1}}
224 \DeclareOptionX{tiebullsize}{\renewcommand{\cmdstr@strands@tiebullsize}{#1}}
225 \DeclareOptionX{tiecolor}{\renewcommand{\cmdstr@strands@tiecolor}{#1}}
226 \DeclareOptionX{tiesnake}{\renewcommand{\cmdstr@strands@tiesnake}{#1}}
227 \DeclareOptionX{tiestyle}{\renewcommand{\cmdstr@strands@tiestyle}{#1}}
228 \DeclareOptionX{tiewidth}{\renewcommand{\cmdstr@strands@tiewidth}{#1}}
229 \DeclareOptionX{timeswidth}{\renewcommand{\cmdstr@strands@timeswidth}{#1}}
230 \DeclareOptionX{tkzpic}{\renewcommand{\cmdstr@strands@tkzpic}{#1}}
231 \DeclareOptionX{width}{\renewcommand{\cmdstr@strands@width}{#1}}
232 \DeclareOptionX*{\PackageWarning{strands}{`\CurrentOption' ignored}} % ignore unknown options.
233 \ProcessOptionsX\relax
234
235 \ifnum\cmdstr@strands@externalize=1
236 \usetikzlibrary{external}
237 \tikzexternalize[optimize=false,prefix=strpack]
238 \fi
239
240 % \decoratestrands - macro to add bullets and labels to picture.
241
242 \makeatletter
243 \define@cmdkey[str]{decor}{bulla}{}
244 \define@cmdkey[str]{decor}{bullb}{}
245 \define@cmdkey[str]{decor}{bulletends}{}
246 \define@cmdkey[str]{decor}{floor}{}
247 \define@cmdkey[str]{decor}{font}{}
248 \define@cmdkey[str]{decor}{height}{}
249 \define@cmdkey[str]{decor}{labelver}{}
250 \define@cmdkey[str]{decor}{labelhor}{}
251 \define@cmdkey[str]{decor}{nstr}{}
252 \define@cmdkey[str]{decor}{type}{}
253 \define@cmdkey[str]{decor}{width}{}
254
255 \presetkeys[str]{decor}{
256 bulla=1,
257 bullb=1,
258 bulletends=\cmdstr@strands@bulletsize,
259 floor=0,
260 font=\cmdstr@strands@font,
261 height=\cmdstr@strands@height,
262 labelver=\cmdstr@strands@labelver,
263 labelhor=\cmdstr@strands@labelhor,
264 nstr=\cmdstr@strands@nstr,
265 type=3,
266 width=\cmdstr@strands@width
267 }{}
268
269 \newcommand{\decoratestrands}[1][]{
270 \setkeys[str]{decor}{#1} % set variables.
271 \foreach\ind in{0,...,\fpeval{\cmdstr@decor@nstr-1}}{
272 \ifnum \cmdstr@decor@bulla=1 % bullets above.
273 \filldraw(\fpeval{\ind*\cmdstr@decor@width},
274 \fpeval{(\cmdstr@decor@floor+1)*\cmdstr@decor@height})circle(\cmdstr@decor@bulletends);
275 \fi
276 \ifnum \cmdstr@decor@bullb=1 % bullets below.
277 \filldraw(\fpeval{\ind*\cmdstr@decor@width},
278 \fpeval{\cmdstr@decor@floor*\cmdstr@decor@height})circle(\cmdstr@decor@bulletends);
279 \fi
280 % classic labels.
281 \ifnum \cmdstr@decor@type<5;
282 \ifnum \cmdstr@decor@type>0 % labels above from 1 to n.
283 \node[scale=\cmdstr@decor@font]at
284 (\fpeval{\ind*\cmdstr@decor@width},
285 \fpeval{(\cmdstr@decor@floor+1)*\cmdstr@decor@height+\cmdstr@decor@labelver})
286 {$\fpeval{\ind+1}$};
287 \fi
288 \node[scale=\cmdstr@decor@font]at
289 (\fpeval{\ind*\cmdstr@decor@width},
290 \fpeval{\cmdstr@decor@floor*\cmdstr@decor@height-\cmdstr@decor@labelver})
291 {$\ifnum\fpeval{(\cmdstr@decor@type+1)*(\cmdstr@decor@type-2)}=0{
292 \fpeval{\ind+1}
293 }\else{\ifnum\fpeval{abs(\cmdstr@decor@type)}=3{
294 \fpeval{\ind+\cmdstr@decor@nstr+1}
295 }\else{\ifnum\fpeval{abs(\cmdstr@decor@type)}=4{
296 \fpeval{\ind+1}'
297 }\fi}\fi}\fi$};
298 \fi
299 % signed labels (n must be even).
300 \ifnum \cmdstr@decor@type=5
301 \ifnum\ind<\fpeval{\cmdstr@decor@nstr/2} % labels from -2n to 2n.
302 \node[scale=\cmdstr@decor@font]at
303 (\fpeval{(\ind+\cmdstr@decor@nstr/2)*\cmdstr@decor@width},
304 \fpeval{(\cmdstr@decor@floor+1)*\cmdstr@decor@height+\cmdstr@decor@labelver})
305 {$\fpeval{\ind+1}$};
306 \node[scale=\cmdstr@decor@font]at
307 (\fpeval{\ind*\cmdstr@decor@width-\cmdstr@decor@labelhor},
308 \fpeval{(\cmdstr@decor@floor+1)*\cmdstr@decor@height+\cmdstr@decor@labelver})
309 {-$\fpeval{\cmdstr@decor@nstr/2-\ind}$};
310 \node[scale=\cmdstr@decor@font]at
311 (\fpeval{(\ind+\cmdstr@decor@nstr/2)*\cmdstr@decor@width},
312 \fpeval{\cmdstr@decor@floor*\cmdstr@decor@height-\cmdstr@decor@labelver})
313 {$\fpeval{\ind+\cmdstr@decor@nstr/2+1}$};
314 \node[scale=\cmdstr@decor@font]at
315 (\fpeval{\ind*\cmdstr@decor@width-\cmdstr@decor@labelhor},
316 \fpeval{\cmdstr@decor@floor*\cmdstr@decor@height-\cmdstr@decor@labelver})
317 {-$\fpeval{\cmdstr@decor@nstr-\ind}$};
318 \fi
319 \fi
320 }
321 }
322
323 % \vpartition - macro to draw set partitions in the partition monoid.
324
325 % Example: the set partition {1,2}{3,-4}{4,-3} of [2*4] is drawn as follows:
326
327 % \vpartition[<options>]{{1,2},{3,-4},{4,-3}}
328
329 % 1 2 3 4
330 % | | | |
331 % ----- - -
332 % -
333 % - -
334 % | |
335 % 5 6 7 8
336
337 \makeatletter
338 \define@cmdkey[str]{vvpart}{bend}{}
339 \define@cmdkey[str]{vvpart}{bulla}{}
340 \define@cmdkey[str]{vvpart}{bullb}{}
341 \define@cmdkey[str]{vvpart}{bulletends}{}
342 \define@cmdkey[str]{vvpart}{floor}{}
343 \define@cmdkey[str]{vvpart}{font}{}
344 \define@cmdkey[str]{vvpart}{height}{}
345 \define@cmdkey[str]{vvpart}{labelver}{}
346 \define@cmdkey[str]{vvpart}{labelhor}{}
347 \define@cmdkey[str]{vvpart}{norma}{}
348 \define@cmdkey[str]{vvpart}{normb}{}
349 \define@cmdkey[str]{vvpart}{nstr}{}
350 \define@cmdkey[str]{vvpart}{permut}{}
351 \define@cmdkey[str]{vvpart}{reflect}{}
352 \define@cmdkey[str]{vvpart}{strwidth}{}
353 \define@cmdkey[str]{vvpart}{type}{}
354 \define@cmdkey[str]{vvpart}{width}{}
355
356 \presetkeys[str]{vvpart}{
357 bend=\cmdstr@strands@bend,
358 bulla=1,
359 bullb=1,
360 bulletends=\cmdstr@strands@bulletsize,
361 floor=0,
362 font=\cmdstr@strands@font,
363 height=\cmdstr@strands@height,
364 labelver=\cmdstr@strands@labelver,
365 labelhor=\cmdstr@strands@labelhor,
366 norma=\cmdstr@strands@norma,
367 normb=\cmdstr@strands@normb,
368 nstr=\cmdstr@strands@nstr,
369 permut=0, % use 1 to draw permutations (to use with \permutation).
370 reflect=0,
371 strwidth=\cmdstr@strands@strwidth,
372 type=3,
373 width=\cmdstr@strands@width
374 }{}
375
376 \newcommand{\vvpartition}[2][]{
377 \setkeys[str]{vvpart}{#1} % set variables.
378 % normalize vertical size.
379 \node[\cmdstr@strands@normcolor]at(0,\cmdstr@vvpart@norma){\cmdstr@strands@normsymbol};
380 \node[\cmdstr@strands@normcolor]at(0,\cmdstr@vvpart@normb){\cmdstr@strands@normsymbol};
381 % number of strands.
382 \StrRemoveBraces{#2}[\nobracespart]
383 \let\oldnumstrands\cmdstr@vvpart@nstr
384 \renewcommand{\cmdstr@vvpart@nstr}
385 {\fpeval{max(abs(min(\nobracespart)),abs(max(\nobracespart)),\fpeval{abs(\oldnumstrands)})}}
386 % bullets and labels.
387 \decoratestrands[
388 bulla=\cmdstr@vvpart@bulla,
389 bullb=\cmdstr@vvpart@bullb,
390 bulletends=\cmdstr@vvpart@bulletends,
391 floor=\cmdstr@vvpart@floor,
392 font=\cmdstr@vvpart@font,
393 height=\cmdstr@vvpart@height,
394 labelver=\cmdstr@vvpart@labelver,
395 labelhor=\cmdstr@vvpart@labelhor,
396 nstr=\cmdstr@vvpart@nstr,
397 type=\cmdstr@vvpart@type,
398 width=\cmdstr@vvpart@width
399 ]
400 % connections: permutation case.
401 \foreach\ind in{0,...,\fpeval{\cmdstr@vvpart@nstr-1}}{
402 \ifnum\cmdstr@vvpart@permut=1
403 \getelem{#2}{\fpeval{\ind+1}}{\index}
404 \draw[line width=\cmdstr@vvpart@strwidth](\fpeval{\ind*\cmdstr@vvpart@width},
405 \fpeval{\cmdstr@vvpart@height+\cmdstr@vvpart@floor*\cmdstr@vvpart@height})to
406 (\fpeval{(\ifnum\fpeval{\index+0}>0 \index\else\fpeval{\ind+1}\fi-1)*
407 \cmdstr@vvpart@width},\cmdstr@vvpart@floor*\cmdstr@vvpart@height);
408 \fi
409 }
410 % connections: general case.
411 \ifnum\cmdstr@vvpart@permut=0 \foreach\block in{#2}{
412 \StrCount{\block}{,}[\numcom]
413 \ifnum\numcom>0\foreach\ind in {2,...,\fpeval{\numcom+1}}{
414 \getelem{\block}{\fpeval{\ind-1}}{\firbul}
415 \getelem{\block}{\ind}{\secbul}
416 \ifnum \cmdstr@vvpart@reflect=1 % reflect connections vertically.
417 \let\oldfirbul\firbul
418 \renewcommand{\firbul}{-\oldfirbul}
419 \let\oldsecbul\secbul
420 \renewcommand{\secbul}{-\oldsecbul}
421 \fi
422 \draw[line width=\cmdstr@vvpart@strwidth]
423 % from.
424 (\fpeval{(abs(\firbul)-1)*\cmdstr@vvpart@width},
425 \ifnum\firbul>0
426 \fpeval{(\cmdstr@vvpart@floor+1)*\cmdstr@vvpart@height}
427 \else
428 \fpeval{\cmdstr@vvpart@floor*\cmdstr@vvpart@height}
429 \fi
430 )
431 % bending.
432 to[bend right=\ifnum \fpeval{\firbul*\secbul}>0
433 \fpeval{(\firbul/abs(\firbul))*((abs(\secbul)-abs(\firbul))/
434 abs(abs(\secbul)-abs(\firbul)))*\cmdstr@vvpart@bend}
435 \else
436 0
437 \fi]
438 % to.
439 (\fpeval{(abs(\secbul)-1)*\cmdstr@vvpart@width},
440 \ifnum\secbul>0
441 \fpeval{(\cmdstr@vvpart@floor+1)*\cmdstr@vvpart@height}
442 \else
443 \fpeval{\cmdstr@vvpart@floor*\cmdstr@vvpart@height}
444 \fi
445 );
446 }\fi
447 }\fi
448 }
449
450 \makeatletter
451 \define@cmdkey[str]{vpart}{bend}{}
452 \define@cmdkey[str]{vpart}{bulla}{}
453 \define@cmdkey[str]{vpart}{bullb}{}
454 \define@cmdkey[str]{vpart}{bulletends}{}
455 \define@cmdkey[str]{vpart}{floor}{}
456 \define@cmdkey[str]{vpart}{font}{}
457 \define@cmdkey[str]{vpart}{height}{}
458 \define@cmdkey[str]{vpart}{labelver}{}
459 \define@cmdkey[str]{vpart}{labelhor}{}
460 \define@cmdkey[str]{vpart}{norma}{}
461 \define@cmdkey[str]{vpart}{normb}{}
462 \define@cmdkey[str]{vpart}{nstr}{}
463 \define@cmdkey[str]{vpart}{permut}{}
464 \define@cmdkey[str]{vpart}{reflect}{}
465 \define@cmdkey[str]{vpart}{rotate}{}
466 \define@cmdkey[str]{vpart}{scale}{}
467 \define@cmdkey[str]{vpart}{strwidth}{}
468 \define@cmdkey[str]{vpart}{tkzpic}{}
469 \define@cmdkey[str]{vpart}{type}{}
470 \define@cmdkey[str]{vpart}{width}{}
471
472 \presetkeys[str]{vpart}{
473 bend=\cmdstr@strands@bend,
474 bulla=1,
475 bullb=1,
476 bulletends=\cmdstr@strands@bulletsize,
477 floor=0,
478 font=\cmdstr@strands@font,
479 height=\cmdstr@strands@height,
480 labelver=\cmdstr@strands@labelver,
481 labelhor=\cmdstr@strands@labelhor,
482 norma=\cmdstr@strands@norma,
483 normb=\cmdstr@strands@normb,
484 nstr=\cmdstr@strands@nstr,
485 permut=0, % use 1 to draw permutations (to use with \permutation).
486 reflect=0,
487 rotate=\cmdstr@strands@rotate,
488 scale=\cmdstr@strands@scale,
489 strwidth=\cmdstr@strands@strwidth,
490 tkzpic=\cmdstr@strands@tkzpic,
491 type=3,
492 width=\cmdstr@strands@width
493 }{}
494
495 \newcommand{\vpartition}[2][]{
496 \setkeys[str]{vpart}{#1} % set variables.
497 \ifthenelse{\equal{\cmdstr@vpart@tkzpic}{1}}{
498 \begin{tikzpicture}[rotate=\cmdstr@vpart@rotate,scale=\cmdstr@vpart@scale]
499 \vvpartition[
500 bend=\cmdstr@vpart@bend,
501 bulla=\cmdstr@vpart@bulla,
502 bullb=\cmdstr@vpart@bullb,
503 bulletends=\cmdstr@vpart@bulletends,
504 floor=\cmdstr@vpart@floor,
505 font=\cmdstr@vpart@font,
506 height=\cmdstr@vpart@height,
507 labelver=\cmdstr@vpart@labelver,
508 labelhor=\cmdstr@vpart@labelhor,
509 norma=\cmdstr@vpart@norma,
510 normb=\cmdstr@vpart@normb,
511 nstr=\cmdstr@vpart@nstr,
512 permut=\cmdstr@vpart@permut,
513 reflect=\cmdstr@vpart@reflect,
514 strwidth=\cmdstr@vpart@strwidth,
515 type=\cmdstr@vpart@type,
516 width=\cmdstr@vpart@width
517 ]{#2}
518 \end{tikzpicture}
519 }{
520 \vvpartition[
521 bend=\cmdstr@vpart@bend,
522 bulla=\cmdstr@vpart@bulla,
523 bullb=\cmdstr@vpart@bullb,
524 bulletends=\cmdstr@vpart@bulletends,
525 floor=\cmdstr@vpart@floor,
526 font=\cmdstr@vpart@font,
527 height=\cmdstr@vpart@height,
528 labelver=\cmdstr@vpart@labelver,
529 labelhor=\cmdstr@vpart@labelhor,
530 norma=\cmdstr@vpart@norma,
531 normb=\cmdstr@vpart@normb,
532 nstr=\cmdstr@vpart@nstr,
533 permut=\cmdstr@vpart@permut,
534 reflect=\cmdstr@vpart@reflect,
535 strwidth=\cmdstr@vpart@strwidth,
536 type=\cmdstr@vpart@type,
537 width=\cmdstr@vpart@width
538 ]{#2}
539 }
540 }
541
542
543 % \arcpartition - macro to draw set partitions via arcs.
544
545 % Example: the set partition {1,4}{2,3,7} of [7] is drawn as follows:
546
547 % \arcpartition[<options>]{{1,4},{2,3,7}}
548
549 % -----------------
550 % | |
551 % ------------- |
552 % | | | |
553 % | ----- | |
554 % | | | | |
555 % 1 2 3 4 5 6 7
556
557 \makeatletter
558 \define@cmdkey[str]{apart}{bend}{}
559 \define@cmdkey[str]{apart}{bull}{}
560 \define@cmdkey[str]{apart}{bulletsize}{}
561 \define@cmdkey[str]{apart}{floor}{}
562 \define@cmdkey[str]{apart}{font}{}
563 \define@cmdkey[str]{apart}{labelver}{}
564 \define@cmdkey[str]{apart}{labelhor}{}
565 \define@cmdkey[str]{apart}{norma}{}
566 \define@cmdkey[str]{apart}{normb}{}
567 \define@cmdkey[str]{apart}{num}{}
568 \define@cmdkey[str]{apart}{rotate}{}
569 \define@cmdkey[str]{apart}{scale}{}
570 \define@cmdkey[str]{apart}{strwidth}{}
571 \define@cmdkey[str]{apart}{tkzpic}{}
572 \define@cmdkey[str]{apart}{type}{}
573 \define@cmdkey[str]{apart}{width}{}
574
575 \presetkeys[str]{apart}{
576 bend=\cmdstr@strands@bend,
577 bull=1,
578 bulletsize=\cmdstr@strands@bulletsize,
579 floor=0,
580 font=\cmdstr@strands@font,
581 labelver=\cmdstr@strands@labelver,
582 labelhor=\cmdstr@strands@labelhor,
583 norma=\cmdstr@strands@norma,
584 normb=\cmdstr@strands@normb,
585 num=\cmdstr@strands@num,
586 rotate=\cmdstr@strands@rotate,
587 scale=\cmdstr@strands@scale,
588 strwidth=\cmdstr@strands@strwidth,
589 tkzpic=\cmdstr@strands@tkzpic,
590 type=1,
591 width=\cmdstr@strands@width
592 }{}
593
594 \newcommand{\arcpartition}[2][]{
595 \setkeys[str]{apart}{#1}
596 \vpartition[
597 bend=\cmdstr@apart@bend,
598 bulla=0, % no bullets above.
599 bullb=\cmdstr@apart@bull,
600 bulletends=\cmdstr@apart@bulletsize,
601 floor=\cmdstr@apart@floor,
602 font=\cmdstr@apart@font,
603 labelver=\cmdstr@apart@labelver,
604 labelhor=\cmdstr@apart@labelhor,
605 norma=\cmdstr@apart@norma,
606 normb=\cmdstr@apart@normb,
607 nstr=\cmdstr@apart@num,
608 reflect=1, % put connections below.
609 rotate=\cmdstr@apart@rotate,
610 scale=\cmdstr@apart@scale,
611 strwidth=\cmdstr@apart@strwidth,
612 tkzpic=\cmdstr@apart@tkzpic,
613 type=-\cmdstr@apart@type,
614 width=\cmdstr@apart@width
615 ]{#2}
616 }
617
618 % \permutation - macro to draw permutations by lines.
619
620 % Example: the permutation 2134 of [4] is drawn as follows:
621
622 % \permutation[<options>]{2,1,3,4}
623
624 % 1 2 3 4
625 % | | | |
626 % - - | |
627 % - | |
628 % - - | |
629 % | | | |
630 % 1 2 3 4
631
632 \makeatletter
633 \define@cmdkey[str]{perm}{bulla}{}
634 \define@cmdkey[str]{perm}{bullb}{}
635 \define@cmdkey[str]{perm}{bulletends}{}
636 \define@cmdkey[str]{perm}{floor}{}
637 \define@cmdkey[str]{perm}{font}{}
638 \define@cmdkey[str]{perm}{height}{}
639 \define@cmdkey[str]{perm}{labelver}{}
640 \define@cmdkey[str]{perm}{labelhor}{}
641 \define@cmdkey[str]{perm}{norma}{}
642 \define@cmdkey[str]{perm}{normb}{}
643 \define@cmdkey[str]{perm}{nstr}{}
644 \define@cmdkey[str]{perm}{rotate}{}
645 \define@cmdkey[str]{perm}{scale}{}
646 \define@cmdkey[str]{perm}{strwidth}{}
647 \define@cmdkey[str]{perm}{tkzpic}{}
648 \define@cmdkey[str]{perm}{type}{}
649 \define@cmdkey[str]{perm}{width}{}
650
651 \presetkeys[str]{perm}{
652 bulla=1,
653 bullb=1,
654 bulletends=\cmdstr@strands@bulletsize,
655 floor=0,
656 font=\cmdstr@strands@font,
657 height=\cmdstr@strands@height,
658 labelver=\cmdstr@strands@labelver,
659 labelhor=\cmdstr@strands@labelhor,
660 norma=\cmdstr@strands@norma,
661 normb=\cmdstr@strands@normb,
662 nstr=\cmdstr@strands@nstr,
663 rotate=\cmdstr@strands@rotate,
664 scale=\cmdstr@strands@scale,
665 strwidth=\cmdstr@strands@strwidth,
666 tkzpic=\cmdstr@strands@tkzpic,
667 type=2,
668 width=\cmdstr@strands@width
669 }{}
670
671 \newcommand{\permutation}[2][]{
672 \setkeys[str]{perm}{#1}
673 \vpartition[
674 bulla=\cmdstr@perm@bulla,
675 bullb=\cmdstr@perm@bullb,
676 bulletends=\cmdstr@perm@bulletends,
677 floor=\cmdstr@perm@floor,
678 font=\cmdstr@perm@font,
679 height=\cmdstr@perm@height,
680 labelver=\cmdstr@perm@labelver,
681 labelhor=\cmdstr@perm@labelhor,
682 norma=\cmdstr@perm@norma,
683 normb=\cmdstr@perm@normb,
684 nstr=\cmdstr@perm@nstr,
685 permut=1, % permutation.
686 rotate=\cmdstr@perm@rotate,
687 scale=\cmdstr@perm@scale,
688 strwidth=\cmdstr@perm@strwidth,
689 tkzpic=\cmdstr@perm@tkzpic,
690 type=\cmdstr@perm@type,
691 width=\cmdstr@perm@width
692 ]{#2}
693 }
694
695 % \tiedpair - macro to draw a tied permutation as a pair.
696
697 % Example: the permutation ({2,4},2134) of [4] is drawn as follows:
698
699 % \tiedpair[<options>]{{2,4}}{2,1,3,4}
700
701 % 2 4
702 % ---------
703 % 1 | 3 |
704 % | | | |
705 % - - | |
706 % - | |
707 % - - | |
708 % | | | |
709 % 1 2 3 4
710
711 \makeatletter
712 \define@cmdkey[str]{tpair}{above}{}
713 \define@cmdkey[str]{tpair}{bend}{}
714 \define@cmdkey[str]{tpair}{bulla}{}
715 \define@cmdkey[str]{tpair}{bullb}{}
716 \define@cmdkey[str]{tpair}{bulletends}{}
717 \define@cmdkey[str]{tpair}{floor}{}
718 \define@cmdkey[str]{tpair}{font}{}
719 \define@cmdkey[str]{tpair}{height}{}
720 \define@cmdkey[str]{tpair}{labelver}{}
721 \define@cmdkey[str]{tpair}{labelhor}{}
722 \define@cmdkey[str]{tpair}{norma}{}
723 \define@cmdkey[str]{tpair}{normb}{}
724 \define@cmdkey[str]{tpair}{nstr}{}
725 \define@cmdkey[str]{tpair}{rotate}{}
726 \define@cmdkey[str]{tpair}{scale}{}
727 \define@cmdkey[str]{tpair}{strwidth}{}
728 \define@cmdkey[str]{tpair}{tkzpic}{}
729 \define@cmdkey[str]{tpair}{type}{}
730 \define@cmdkey[str]{tpair}{width}{}
731
732 \presetkeys[str]{tpair}{
733 above=1,
734 bend=\cmdstr@strands@bend,
735 bulla=1,
736 bullb=1,
737 bulletends=\cmdstr@strands@bulletsize,
738 floor=0,
739 font=\cmdstr@strands@font,
740 height=\cmdstr@strands@height,
741 labelver=\cmdstr@strands@labelver,
742 labelhor=\cmdstr@strands@labelhor,
743 norma=\cmdstr@strands@norma,
744 normb=\cmdstr@strands@normb,
745 nstr=\cmdstr@strands@nstr,
746 rotate=\cmdstr@strands@rotate,
747 scale=\cmdstr@strands@scale,
748 strwidth=\cmdstr@strands@strwidth,
749 tkzpic=\cmdstr@strands@tkzpic,
750 type=-1,
751 width=\cmdstr@strands@width
752 }{}
753
754 \newcommand{\tiedpair}[3][]{
755 \setkeys[str]{tpair}{#1}
756 \ifthenelse{\equal{\cmdstr@tpair@tkzpic}{1}}{
757 \begin{tikzpicture}[rotate=\cmdstr@tpair@rotate,scale=\cmdstr@tpair@scale]
758 \permutation[
759 bulla=\cmdstr@tpair@bulla,
760 bullb=\cmdstr@tpair@bullb,
761 bulletends=\cmdstr@tpair@bulletends,
762 floor=\cmdstr@tpair@floor,
763 font=\cmdstr@tpair@font,
764 height=\cmdstr@tpair@height,
765 labelver=\cmdstr@tpair@labelver,
766 labelhor=\cmdstr@tpair@labelhor,
767 norma=\cmdstr@tpair@norma,
768 normb=\cmdstr@tpair@normb,
769 nstr=\cmdstr@tpair@nstr,
770 strwidth=\cmdstr@tpair@strwidth,
771 tkzpic=0,
772 type=\cmdstr@tpair@type,
773 width=\cmdstr@tpair@width
774 ]{#2}
775 \arcpartition[
776 bend=\cmdstr@tpair@bend,
777 bull=0, % no bullets.
778 bulletsize=\cmdstr@tpair@bulletsize,
779 floor=\fpeval{\cmdstr@tpair@floor+\cmdstr@tpair@above*\cmdstr@tpair@height},
780 tkzpic=0,
781 type=0, % no labels.
782 strwidth=\cmdstr@tpair@strwidth,
783 width=\cmdstr@tpair@width
784 ]{#3}
785 \end{tikzpicture}
786 }{
787 \permutation[
788 bulla=\cmdstr@tpair@bulla,
789 bullb=\cmdstr@tpair@bullb,
790 bulletends=\cmdstr@tpair@bulletends,
791 floor=\cmdstr@tpair@floor,
792 font=\cmdstr@tpair@font,
793 height=\cmdstr@tpair@height,
794 labelver=\cmdstr@tpair@labelver,
795 labelhor=\cmdstr@tpair@labelhor,
796 norma=\cmdstr@tpair@norma,
797 normb=\cmdstr@tpair@normb,
798 nstr=\cmdstr@tpair@nstr,
799 strwidth=\cmdstr@tpair@strwidth,
800 tkzpic=0,
801 type=\cmdstr@tpair@type,
802 width=\cmdstr@tpair@width
803 ]{#2}
804 \arcpartition[
805 bend=\cmdstr@tpair@bend,
806 bull=0, % no bullets.
807 floor=\fpeval{\cmdstr@tpair@floor+\cmdstr@tpair@above*\cmdstr@tpair@height},
808 tkzpic=0,
809 type=0, % no labels.
810 strwidth=\cmdstr@tpair@strwidth,
811 width=\cmdstr@tpair@width
812 ]{#3}
813 }
814 }
815
816 % \tie - macro to draw a tie.
817
818 % \begin{tikzpicture} \tie[height=1.5]{{1,0.8},{3,0.7},{4,0.8}} \end{tikzpicture}
819 % \begin{tikzpicture} \tie[height=1.5]{1,2,5} \end{tikzpicture}
820
821 \makeatletter
822 \define@cmdkey[str]{tie}{bend}{}
823 \define@cmdkey[str]{tie}{bull}{}
824 \define@cmdkey[str]{tie}{bulletie}{}
825 \define@cmdkey[str]{tie}{floor}{}
826 \define@cmdkey[str]{tie}{height}{}
827 \define@cmdkey[str]{tie}{color}{}
828 \define@cmdkey[str]{tie}{snake}{}
829 \define@cmdkey[str]{tie}{snakeamp}{}
830 \define@cmdkey[str]{tie}{snakends}{}
831 \define@cmdkey[str]{tie}{snakelen}{}
832 \define@cmdkey[str]{tie}{style}{}
833 \define@cmdkey[str]{tie}{tieheight}{}
834 \define@cmdkey[str]{tie}{tiewidth}{}
835 \define@cmdkey[str]{tie}{width}{}
836
837 \presetkeys[str]{tie}{
838 bend=\cmdstr@strands@tiebend, % bend of the ties.
839 bull=1, % use 1 to use bullets, 0 otherwise.
840 bulletie=\cmdstr@strands@bulletsize,
841 color=\cmdstr@strands@tiecolor, % color of the ties.
842 floor=0, % the picture starts at floor*height.
843 height=\cmdstr@strands@height, % height of the strands.
844 snake=\cmdstr@strands@tiesnake, % true or false to snake the tie line.
845 snakeamp=\cmdstr@strands@tiesnakeamp, % snake amplitude.
846 snakends=\cmdstr@strands@tiesnakends, % snake lengths of ends.
847 snakelen=\cmdstr@strands@tiesnakelen, % snake lengths.
848 style=\cmdstr@strands@tiestyle, % type of the tie (solid, dashed, dotted, etc).
849 tieheight=\cmdstr@strands@tieheight, % height of the tie respect to the global height.
850 tiewidth=\cmdstr@strands@tiewidth, % width of the tie line.
851 width=\cmdstr@strands@width % width between strands.
852 }{}
853
854 \newcommand{\tie}[2][]{
855 \setkeys[str]{tie}{#1}
856 \foreach\elem[count=\ind]in{#2}{
857 \StrRemoveBraces{\elem}[\nobrace]
858 \getelem{\nobrace}{1}{\elemwidth} % get width of elem.
859 \getelem{\nobrace}{2}{\elemheight} % get height of elem.
860 \StrCount{\nobrace}{,}[\elemcoms]
861 \ifnum\elemcoms=0 \renewcommand{\elemheight}{\cmdstr@tie@tieheight}\fi % update height of elem.
862 \ifnum \cmdstr@tie@bull=1
863 \filldraw[\cmdstr@tie@color](\fpeval{(\elemwidth-1)*\cmdstr@tie@width},
864 \fpeval{\elemheight*\cmdstr@tie@height+\cmdstr@tie@floor*\cmdstr@tie@height})
865 circle(\cmdstr@tie@bulletie);
866 \fi
867 \ifnum\ind>1
868 \getelem{#2}{\fpeval{\ind-1}}{\prevelem}
869 \StrRemoveBraces{\prevelem}[\prevnobrace]
870 \getelem{\prevnobrace}{1}{\prevelemwidth}
871 \getelem{\prevnobrace}{2}{\prevelemheight}
872 \StrCount{\prevnobrace}{,}[\prevelemcoms]
873 \ifnum\prevelemcoms=0 \renewcommand{\prevelemheight}{\cmdstr@tie@tieheight}\fi
874 \draw[
875 bend right=\cmdstr@tie@bend,
876 color=\cmdstr@tie@color,
877 line width=\cmdstr@tie@tiewidth,
878 decorate=\cmdstr@tie@snake,
879 decoration={
880 snake,
881 amplitude=\cmdstr@tie@snakeamp,
882 post length=\cmdstr@tie@snakends,
883 pre length=\cmdstr@tie@snakends,
884 segment length=\cmdstr@tie@snakelen
885 },
886 style=\cmdstr@tie@style
887 ]
888 (\fpeval{(\elemwidth-1)*\cmdstr@tie@width},
889 \fpeval{\elemheight*\cmdstr@tie@height+\cmdstr@tie@floor*\cmdstr@tie@height})to
890 (\fpeval{(\prevelemwidth-1)*\cmdstr@tie@width},
891 \fpeval{\prevelemheight*\cmdstr@tie@height+\cmdstr@tie@floor*\cmdstr@tie@height});
892 \fi
893 }
894 }
895
896 % \bbackstrands - macro to draws a trivial two-strands-braid of double strand width.
897
898 \makeatletter
899 \define@cmdkey[str]{bbackstr}{cdnx}{}
900 \define@cmdkey[str]{bbackstr}{cdny}{}
901 \define@cmdkey[str]{bbackstr}{color}{}
902 \define@cmdkey[str]{bbackstr}{height}{}
903 \define@cmdkey[str]{bbackstr}{strwidth}{}
904 \define@cmdkey[str]{bbackstr}{timeswidth}{}
905 \define@cmdkey[str]{bbackstr}{width}{}
906
907 \presetkeys[str]{bbackstr}{
908 cdnx=nothing,
909 cdny=nothing,
910 height=\cmdstr@strands@height,
911 strwidth=\cmdstr@strands@strwidth,
912 timeswidth=\cmdstr@strands@timeswidth, % times the width of the back line is bigger.
913 width=\cmdstr@strands@width
914 }{}
915
916 \newcommand{\bbackstrands}[1][]{ %
917 \setkeys[str]{bbackstr}{#1}
918 \draw[
919 color=\cmdstr@strands@backcolor,
920 line width=\fpeval{\cmdstr@bbackstr@timeswidth*\cmdstr@bbackstr@strwidth}pt
921 ](\cmdstr@bbackstr@cdnx,\cmdstr@bbackstr@cdny)
922 to(\cmdstr@bbackstr@cdnx,\fpeval{\cmdstr@bbackstr@cdny-\cmdstr@bbackstr@height});
923 \draw[
924 color=\cmdstr@strands@backcolor,
925 line width=\fpeval{\cmdstr@bbackstr@timeswidth*\cmdstr@bbackstr@strwidth}pt
926 ](\fpeval{\cmdstr@bbackstr@cdnx+\cmdstr@bbackstr@width},\cmdstr@bbackstr@cdny)
927 to(\fpeval{\cmdstr@bbackstr@cdnx+\cmdstr@bbackstr@width},
928 \fpeval{\cmdstr@bbackstr@cdny-\cmdstr@bbackstr@height});
929 }
930
931 % \lleftstrand - macro to draws a strand starting from the left.
932
933 \makeatletter
934 \define@cmdkey[str]{lleftstr}{bend}{}
935 \define@cmdkey[str]{lleftstr}{cdnx}{}
936 \define@cmdkey[str]{lleftstr}{cdny}{}
937 \define@cmdkey[str]{lleftstr}{color}{}
938 \define@cmdkey[str]{lleftstr}{height}{}
939 \define@cmdkey[str]{lleftstr}{strwidth}{}
940 \define@cmdkey[str]{lleftstr}{width}{}
941
942 \presetkeys[str]{lleftstr}{
943 bend=\cmdstr@strands@bendbraid,
944 cdnx=nothing,
945 cdny=nothing,
946 color=black,
947 height=\cmdstr@strands@height,
948 strwidth=\cmdstr@strands@strwidth,
949 width=\cmdstr@strands@width
950 }{}
951
952 \newcommand{\lleftstrand}[1][]{
953 \setkeys[str]{lleftstr}{#1}
954 \draw[
955 color=\cmdstr@lleftstr@color,
956 line width=\cmdstr@lleftstr@strwidth pt
957 ](\cmdstr@lleftstr@cdnx,\fpeval{\cmdstr@lleftstr@cdny+\cmdstr@strands@coverunion})
958 to[bend right=\cmdstr@lleftstr@bend]
959 (\fpeval{\cmdstr@lleftstr@cdnx+\cmdstr@lleftstr@width/2},
960 \fpeval{\cmdstr@lleftstr@cdny-\cmdstr@lleftstr@height/2})
961 to[bend left=\cmdstr@lleftstr@bend]
962 (\fpeval{\cmdstr@lleftstr@cdnx+\cmdstr@lleftstr@width},
963 \fpeval{\cmdstr@lleftstr@cdny-\cmdstr@lleftstr@height-\cmdstr@strands@coverunion});
964 }
965
966 % \rrightstrand - macro to draw a strand starting from the right.
967
968 \makeatletter
969 \define@cmdkey[str]{rrightstr}{bend}{}
970 \define@cmdkey[str]{rrightstr}{cdnx}{}
971 \define@cmdkey[str]{rrightstr}{cdny}{}
972 \define@cmdkey[str]{rrightstr}{color}{}
973 \define@cmdkey[str]{rrightstr}{floor}{}
974 \define@cmdkey[str]{rrightstr}{height}{}
975 \define@cmdkey[str]{rrightstr}{strwidth}{}
976 \define@cmdkey[str]{rrightstr}{width}{}
977
978 \presetkeys[str]{rrightstr}{
979 bend=\cmdstr@strands@bendbraid,
980 cdnx=nothing,
981 cdny=nothing,
982 color=black,
983 floor=0,
984 height=\cmdstr@strands@height,
985 strwidth=\cmdstr@strands@strwidth,
986 width=\cmdstr@strands@width
987 }{}
988
989 \newcommand{\rrightstrand}[1][]{ % color / init-x-coordinate / init-y-coordinate.
990 \setkeys[str]{rrightstr}{#1}
991 \draw[
992 color=\cmdstr@rrightstr@color,
993 line width=\cmdstr@rrightstr@strwidth pt
994 ](\fpeval{\cmdstr@rrightstr@cdnx+\cmdstr@rrightstr@width},
995 \fpeval{\cmdstr@rrightstr@cdny+\cmdstr@strands@coverunion})
996 to[bend left=\cmdstr@rrightstr@bend]
997 (\fpeval{\cmdstr@rrightstr@cdnx+\cmdstr@rrightstr@width/2},
998 \fpeval{\cmdstr@rrightstr@cdny-\cmdstr@rrightstr@height/2})
999 to[bend right=\cmdstr@rrightstr@bend]
1000 (\cmdstr@rrightstr@cdnx,
1001 \fpeval{\cmdstr@rrightstr@cdny-\cmdstr@rrightstr@height-\cmdstr@strands@coverunion});
1002 }
1003
1004 % \ccrossback - macro to draw a \backcolor filled circle to create an over-under / under-over crossing.
1005
1006 \makeatletter
1007 \define@cmdkey[str]{ccrossback}{cdnx}{}
1008 \define@cmdkey[str]{ccrossback}{cdny}{}
1009 \define@cmdkey[str]{ccrossback}{height}{}
1010 \define@cmdkey[str]{ccrossback}{width}{}
1011
1012 \presetkeys[str]{ccrossback}{
1013 cdnx=nothing,
1014 cdny=nothing,
1015 height=\cmdstr@strands@height,
1016 width=\cmdstr@strands@width
1017 }{}
1018
1019 \newcommand{\ccrossback}[1][]{
1020 \setkeys[str]{ccrossback}{#1}
1021 \filldraw[\cmdstr@strands@backcolor]
1022 (\fpeval{\cmdstr@ccrossback@cdnx+\cmdstr@ccrossback@width/2},
1023 \fpeval{\cmdstr@ccrossback@cdny-\cmdstr@ccrossback@height/2})
1024 circle(\cmdstr@strands@braidcross pt);
1025 }
1026
1027 % \bbraidgen - macro to draw a braid crossing (classic, virtual or singular).
1028
1029 \makeatletter
1030 \define@cmdkey[str]{bbraidgen}{bend}{}
1031 \define@cmdkey[str]{bbraidgen}{cdnx}{}
1032 \define@cmdkey[str]{bbraidgen}{cdny}{}
1033 \define@cmdkey[str]{bbraidgen}{colorleft}{}
1034 \define@cmdkey[str]{bbraidgen}{coloright}{}
1035 \define@cmdkey[str]{bbraidgen}{colorsingular}{}
1036 \define@cmdkey[str]{bbraidgen}{colorvirtual}{}
1037 \define@cmdkey[str]{bbraidgen}{height}{}
1038 \define@cmdkey[str]{bbraidgen}{strwidth}{}
1039 \define@cmdkey[str]{bbraidgen}{type}{}
1040 \define@cmdkey[str]{bbraidgen}{width}{}
1041
1042 \presetkeys[str]{bbraidgen}{
1043 bend=\cmdstr@strands@bendbraid,
1044 cdnx=0,
1045 cdny=0,
1046 colorleft=black,
1047 coloright=black,
1048 colorsingular=black,
1049 colorvirtual=black,
1050 height=\cmdstr@strands@height,
1051 strwidth=\cmdstr@strands@strwidth,
1052 type=1, % negative-braid=-1 | positive-braid=1 | virtual-braid=2 | singular-braid=3
1053 width=\cmdstr@strands@width
1054 }{}
1055
1056 \tikzset{
1057 cross/.style={ % node style to draw x--crosses inside nodes.
1058 path picture={
1059 \draw[black]
1060 (path picture bounding box.south east)--
1061 (path picture bounding box.north west)
1062 (path picture bounding box.south west)--
1063 (path picture bounding box.north east);
1064 }
1065 }
1066 }
1067
1068 \newcommand{\bbraidgen}[1][]{
1069 \setkeys[str]{bbraidgen}{#1}
1070 \bbackstrands[ % trivial two-strands-braid.
1071 cdnx=\cmdstr@bbraidgen@cdnx,
1072 cdny=\cmdstr@bbraidgen@cdny,
1073 height=\cmdstr@bbraidgen@height,
1074 strwidth=\cmdstr@bbraidgen@strwidth,
1075 width=\cmdstr@bbraidgen@width
1076 ]
1077 \ifnum\cmdstr@bbraidgen@type<1 % negative generator.
1078 \rrightstrand[
1079 bend=\cmdstr@bbraidgen@bend,
1080 cdnx=\cmdstr@bbraidgen@cdnx,
1081 cdny=\cmdstr@bbraidgen@cdny,
1082 color=\cmdstr@bbraidgen@coloright,
1083 height=\cmdstr@bbraidgen@height,
1084 strwidth=\cmdstr@bbraidgen@strwidth,
1085 width=\cmdstr@bbraidgen@width
1086 ]
1087 \ifnum\cmdstr@bbraidgen@type<2
1088 \ccrossback[
1089 cdnx=\cmdstr@bbraidgen@cdnx,
1090 cdny=\cmdstr@bbraidgen@cdny,
1091 height=\cmdstr@bbraidgen@height,
1092 width=\cmdstr@bbraidgen@width
1093 ]
1094 \fi
1095 \lleftstrand[
1096 bend=\cmdstr@bbraidgen@bend,
1097 cdnx=\cmdstr@bbraidgen@cdnx,
1098 cdny=\cmdstr@bbraidgen@cdny,
1099 color=\cmdstr@bbraidgen@colorleft,
1100 height=\cmdstr@bbraidgen@height,
1101 strwidth=\cmdstr@bbraidgen@strwidth,
1102 width=\cmdstr@bbraidgen@width
1103 ]
1104 \else % positive generator.
1105 \lleftstrand[
1106 bend=\cmdstr@bbraidgen@bend,
1107 cdnx=\cmdstr@bbraidgen@cdnx,
1108 cdny=\cmdstr@bbraidgen@cdny,
1109 color=\cmdstr@bbraidgen@colorleft,
1110 height=\cmdstr@bbraidgen@height,
1111 strwidth=\cmdstr@bbraidgen@strwidth,
1112 width=\cmdstr@bbraidgen@width
1113 ]
1114 \ifnum\cmdstr@bbraidgen@type<2 % over-under circle only if type is one.
1115 \ccrossback[
1116 cdnx=\cmdstr@bbraidgen@cdnx,
1117 cdny=\cmdstr@bbraidgen@cdny,
1118 height=\cmdstr@bbraidgen@height,
1119 width=\cmdstr@bbraidgen@width
1120 ]
1121 \fi
1122 \rrightstrand[
1123 bend=\cmdstr@bbraidgen@bend,
1124 cdnx=\cmdstr@bbraidgen@cdnx,
1125 cdny=\cmdstr@bbraidgen@cdny,
1126 color=\cmdstr@bbraidgen@coloright,
1127 height=\cmdstr@bbraidgen@height,
1128 strwidth=\cmdstr@bbraidgen@strwidth,
1129 width=\cmdstr@bbraidgen@width
1130 ]
1131 \ifnum\cmdstr@bbraidgen@type=2 % virtual crossing.
1132 \node[
1133 circle,
1134 cross,
1135 draw=\cmdstr@bbraidgen@colorvirtual,
1136 fill=\cmdstr@strands@backcolor,
1137 inner sep=0,
1138 line width=\cmdstr@bbraidgen@strwidth,
1139 minimum width=\cmdstr@strands@braidvirtcross
1140 ]
1141 at(\fpeval{\cmdstr@bbraidgen@cdnx+\cmdstr@bbraidgen@width/2},
1142 \fpeval{\cmdstr@bbraidgen@cdny-\cmdstr@bbraidgen@height/2}){};
1143 \fi
1144 \ifnum\cmdstr@bbraidgen@type=3 % singular crossing.
1145 \filldraw[\cmdstr@bbraidgen@colorsingular]
1146 (\fpeval{\cmdstr@bbraidgen@cdnx+\cmdstr@bbraidgen@width/2},
1147 \fpeval{\cmdstr@bbraidgen@cdny-\cmdstr@bbraidgen@height/2})
1148 circle(\cmdstr@strands@braidsingcross pt);
1149 \fi
1150 \fi
1151 }
1152
1153 % \ttanglegen - macro to draw a tangle generator.
1154
1155 \makeatletter
1156 \define@cmdkey[str]{ttanglegen}{bend}{}
1157 \define@cmdkey[str]{ttanglegen}{cdnx}{}
1158 \define@cmdkey[str]{ttanglegen}{cdny}{}
1159 \define@cmdkey[str]{ttanglegen}{color}{}
1160 \define@cmdkey[str]{ttanglegen}{height}{}
1161 \define@cmdkey[str]{ttanglegen}{strwidth}{}
1162 \define@cmdkey[str]{ttanglegen}{tiecolor}{}
1163 \define@cmdkey[str]{ttanglegen}{tied}{}
1164 \define@cmdkey[str]{ttanglegen}{tiesnake}{}
1165 \define@cmdkey[str]{ttanglegen}{tiesnakeamp}{}
1166 \define@cmdkey[str]{ttanglegen}{tiesnakelen}{}
1167 \define@cmdkey[str]{ttanglegen}{tiesnakends}{}
1168 \define@cmdkey[str]{ttanglegen}{tiestyle}{}
1169 \define@cmdkey[str]{ttanglegen}{tiewidth}{}
1170 \define@cmdkey[str]{ttanglegen}{width}{}
1171
1172 \presetkeys[str]{ttanglegen}{
1173 bend=\cmdstr@strands@bendtangle,
1174 cdnx=0,
1175 cdny=0,
1176 color=black,
1177 height=\cmdstr@strands@height,
1178 strwidth=\cmdstr@strands@strwidth,
1179 tiecolor=\cmdstr@strands@tiecolor,
1180 tied=0,
1181 tiesnake=\cmdstr@strands@tiesnake,
1182 tiesnakeamp=\cmdstr@strands@tiesnakeamp,
1183 tiesnakelen=\cmdstr@strands@tiesnakelen,
1184 tiesnakends=\cmdstr@strands@tiesnakends,
1185 tiestyle=\cmdstr@strands@tiestyle,
1186 tiewidth=\cmdstr@strands@tiewidth,
1187 width=\cmdstr@strands@width
1188 }{}
1189
1190 \newcommand{\ttanglegen}[1][]{
1191 \setkeys[str]{ttanglegen}{#1}
1192 \bbackstrands[ % trivial two-strands-braid.
1193 cdnx=\cmdstr@ttanglegen@cdnx,
1194 cdny=\cmdstr@ttanglegen@cdny,
1195 height=\cmdstr@ttanglegen@height,
1196 strwidth=\cmdstr@ttanglegen@strwidth,
1197 width=\cmdstr@ttanglegen@width
1198 ]
1199 \draw[
1200 bend right=\cmdstr@strands@bendtangle,
1201 color=\cmdstr@ttanglegen@color,
1202 line width=\cmdstr@strands@strwidth
1203 ](\cmdstr@ttanglegen@cdnx,\fpeval{\cmdstr@ttanglegen@cdny+\cmdstr@strands@coverunion})
1204 to(\fpeval{\cmdstr@ttanglegen@cdnx+\cmdstr@ttanglegen@width/2},
1205 \fpeval{\cmdstr@ttanglegen@cdny-\cmdstr@ttanglegen@height/3+0.03})
1206 to(\fpeval{\cmdstr@ttanglegen@cdnx+\cmdstr@ttanglegen@width},
1207 \fpeval{\cmdstr@ttanglegen@cdny+\cmdstr@strands@coverunion});
1208 \draw[
1209 bend left=\cmdstr@strands@bendtangle,
1210 color=\cmdstr@ttanglegen@color,
1211 line width=\cmdstr@strands@strwidth
1212 ](\cmdstr@ttanglegen@cdnx,
1213 \fpeval{\cmdstr@ttanglegen@cdny-\cmdstr@ttanglegen@height-\cmdstr@strands@coverunion})
1214 to(\fpeval{\cmdstr@ttanglegen@cdnx+\cmdstr@ttanglegen@width/2},
1215 \fpeval{\cmdstr@ttanglegen@cdny-(2*\cmdstr@ttanglegen@height)/3-0.03})
1216 to(\fpeval{\cmdstr@ttanglegen@cdnx+\cmdstr@ttanglegen@width},
1217 \fpeval{\cmdstr@ttanglegen@cdny-\cmdstr@ttanglegen@height-\cmdstr@strands@coverunion});
1218 \ifnum\cmdstr@ttanglegen@tied=1 % tied version.
1219 \draw[
1220 color=\cmdstr@ttanglegen@tiecolor,
1221 line width=\cmdstr@ttanglegen@tiewidth,
1222 decorate=\cmdstr@ttanglegen@tiesnake,
1223 decoration={
1224 snake,
1225 amplitude=\cmdstr@ttanglegen@tiesnakeamp,
1226 post length=\cmdstr@ttanglegen@tiesnakends,
1227 pre length=\cmdstr@ttanglegen@tiesnakends,
1228 segment length=\cmdstr@ttanglegen@tiesnakelen
1229 },
1230 style=\cmdstr@ttanglegen@tiestyle
1231 ](\fpeval{\cmdstr@ttanglegen@cdnx+\cmdstr@ttanglegen@width/2},
1232 \fpeval{\cmdstr@ttanglegen@cdny-\cmdstr@ttanglegen@height/3+0.03})
1233 to(\fpeval{\cmdstr@ttanglegen@cdnx+\cmdstr@ttanglegen@width/2},
1234 \fpeval{\cmdstr@ttanglegen@cdny-(2*\cmdstr@ttanglegen@height)/3-0.03});
1235 \fi
1236 }
1237
1238 % \aaddgen - macro to add a generator on a strand level.
1239
1240 \makeatletter
1241 \define@cmdkey[str]{aaddgen}{bendbraid}{}
1242 \define@cmdkey[str]{aaddgen}{bendtangle}{}
1243 \define@cmdkey[str]{aaddgen}{direction}{}
1244 \define@cmdkey[str]{aaddgen}{floor}{}
1245 \define@cmdkey[str]{aaddgen}{generator}{}
1246 \define@cmdkey[str]{aaddgen}{height}{}
1247 \define@cmdkey[str]{aaddgen}{level}{}
1248 \define@cmdkey[str]{aaddgen}{numlevs}{}
1249 \define@cmdkey[str]{aaddgen}{posx}{}
1250 \define@cmdkey[str]{aaddgen}{posy}{}
1251 \define@cmdkey[str]{aaddgen}{strwidth}{}
1252 \define@cmdkey[str]{aaddgen}{tiebull}{}
1253 \define@cmdkey[str]{aaddgen}{tiebullsize}{}
1254 \define@cmdkey[str]{aaddgen}{tiecolor}{}
1255 \define@cmdkey[str]{aaddgen}{tieheight}{}
1256 \define@cmdkey[str]{aaddgen}{tiesnake}{}
1257 \define@cmdkey[str]{aaddgen}{tiesnakeamp}{}
1258 \define@cmdkey[str]{aaddgen}{tiesnakends}{}
1259 \define@cmdkey[str]{aaddgen}{tiesnakelen}{}
1260 \define@cmdkey[str]{aaddgen}{tiestyle}{}
1261 \define@cmdkey[str]{aaddgen}{tiewidth}{}
1262 \define@cmdkey[str]{aaddgen}{width}{}
1263
1264 \presetkeys[str]{aaddgen}{
1265 bendbraid=\cmdstr@strands@bendbraid,
1266 bendtangle=\cmdstr@strands@bendtangle,
1267 direction=\cmdstr@strands@direction,
1268 floor=0,
1269 generator=s1,
1270 height=\cmdstr@strands@height,
1271 level=0,
1272 numlevs=0,
1273 posx=nothing, % internal.
1274 posy=nothing, % internal.
1275 strwidth=\cmdstr@strands@strwidth,
1276 tiebull=\cmdstr@strands@tiebull,
1277 tiebullsize=\cmdstr@strands@tiebullsize,
1278 tiecolor=\cmdstr@strands@tiecolor,
1279 tieheight=\cmdstr@strands@tieheight,
1280 tiesnake=\cmdstr@strands@tiesnake,
1281 tiesnakeamp=\cmdstr@strands@tiesnakeamp,
1282 tiesnakends=\cmdstr@strands@tiesnakends,
1283 tiesnakelen=\cmdstr@strands@tiesnakelen,
1284 tiestyle=\cmdstr@strands@tiestyle,
1285 tiewidth=\cmdstr@strands@tiewidth,
1286 width=\cmdstr@strands@width
1287 }{}
1288
1289 \newcommand{\aaddgen}[1][]{
1290 \setkeys[str]{aaddgen}{#1}
1291 \StrChar{\cmdstr@aaddgen@generator}{1}[\firstchar]
1292 \StrBehind{\cmdstr@aaddgen@generator}{\firstchar}[\numstrand]
1293 \renewcommand{\cmdstr@aaddgen@posx}{\fpeval{(\numstrand-1)*\cmdstr@aaddgen@width}}
1294 \ifnum\cmdstr@aaddgen@direction=1
1295 \renewcommand{\cmdstr@aaddgen@posy}{\fpeval{(\cmdstr@aaddgen@numlevs+2+\cmdstr@aaddgen@floor-\cmdstr@aaddgen@level)*\cmdstr@aaddgen@height}}
1296 \fi
1297 \ifnum\cmdstr@aaddgen@direction=0
1298 \renewcommand{\cmdstr@aaddgen@posy}{\fpeval{\cmdstr@aaddgen@level*\cmdstr@aaddgen@height}}
1299 \fi
1300 \ifthenelse{\equal{\firstchar}{\cmdstr@strands@gencharnegbraid}}{
1301 \bbraidgen[
1302 bend=\cmdstr@aaddgen@bendbraid,
1303 cdnx=\cmdstr@aaddgen@posx,
1304 cdny=\cmdstr@aaddgen@posy,
1305 height=\cmdstr@aaddgen@height,
1306 strwidth=\cmdstr@aaddgen@strwidth,
1307 type=-1,
1308 width=\cmdstr@aaddgen@width
1309 ]
1310 }{\ifthenelse{\equal{\firstchar}{\cmdstr@strands@gencharposbraid}}{
1311 \bbraidgen[
1312 bend=\cmdstr@aaddgen@bendbraid,
1313 cdnx=\cmdstr@aaddgen@posx,
1314 cdny=\cmdstr@aaddgen@posy,
1315 height=\cmdstr@aaddgen@height,
1316 strwidth=\cmdstr@aaddgen@strwidth,
1317 type=1,
1318 width=\cmdstr@aaddgen@width
1319 ]
1320 }{\ifthenelse{\equal{\firstchar}{\cmdstr@strands@gencharvirtual}}{
1321 \bbraidgen[
1322 bend=\cmdstr@aaddgen@bendbraid,
1323 cdnx=\cmdstr@aaddgen@posx,
1324 cdny=\cmdstr@aaddgen@posy,
1325 height=\cmdstr@aaddgen@height,
1326 strwidth=\cmdstr@aaddgen@strwidth,
1327 type=2,
1328 width=\cmdstr@aaddgen@width
1329 ]
1330 }{\ifthenelse{\equal{\firstchar}{\cmdstr@strands@gencharsingular}}{
1331 \bbraidgen[
1332 bend=\cmdstr@aaddgen@bendbraid,
1333 cdnx=\cmdstr@aaddgen@posx,
1334 cdny=\cmdstr@aaddgen@posy,
1335 height=\cmdstr@aaddgen@height,
1336 strwidth=\cmdstr@aaddgen@strwidth,
1337 type=3,
1338 width=\cmdstr@aaddgen@width
1339 ]
1340 }{\ifthenelse{\equal{\firstchar}{\cmdstr@strands@genchartangle}}{
1341 \ttanglegen[
1342 bend=\cmdstr@aaddgen@bendtangle,
1343 cdnx=\cmdstr@aaddgen@posx,
1344 cdny=\cmdstr@aaddgen@posy,
1345 height=\cmdstr@aaddgen@height,
1346 strwidth=\cmdstr@aaddgen@strwidth,
1347 tied=0,
1348 width=\cmdstr@aaddgen@width
1349 ]
1350 }{\ifthenelse{\equal{\firstchar}{\cmdstr@strands@genchartie}}{
1351 \tie[
1352 bull=\cmdstr@aaddgen@tiebull,
1353 bulletie=\cmdstr@aaddgen@tiebullsize,
1354 color=\cmdstr@aaddgen@tiecolor,
1355 height=\cmdstr@aaddgen@height,
1356 floor=\fpeval{\cmdstr@aaddgen@posy-1},
1357 snake=\cmdstr@aaddgen@tiesnake,
1358 snakeamp=\cmdstr@aaddgen@tiesnakeamp,
1359 snakelen=\cmdstr@aaddgen@tiesnakelen,
1360 snakends=\cmdstr@aaddgen@tiesnakends,
1361 style=\cmdstr@aaddgen@tiestyle,
1362 tieheight=\cmdstr@aaddgen@tieheight,
1363 tiewidth=\cmdstr@aaddgen@tiewidth,
1364 width=\cmdstr@aaddgen@width
1365 ]{\numstrand,\fpeval{\numstrand+1}}
1366 }{\ifthenelse{\equal{\firstchar}{\cmdstr@strands@genchartiedtangle}}{
1367 \ttanglegen[
1368 bend=\cmdstr@aaddgen@bendtangle,
1369 cdnx=\cmdstr@aaddgen@posx,
1370 cdny=\cmdstr@aaddgen@posy,
1371 height=\cmdstr@aaddgen@height,
1372 strwidth=\cmdstr@aaddgen@strwidth,
1373 tiecolor=\cmdstr@aaddgen@tiecolor,
1374 tied=1,
1375 tiesnake=\cmdstr@aaddgen@tiesnake,
1376 tiesnakeamp=\cmdstr@aaddgen@tiesnakeamp,
1377 tiesnakelen=\cmdstr@aaddgen@tiesnakelen,
1378 tiesnakends=\cmdstr@aaddgen@tiesnakends,
1379 tiestyle=\cmdstr@aaddgen@tiestyle,
1380 tiewidth=\cmdstr@aaddgen@tiewidth,
1381 width=\cmdstr@aaddgen@width
1382 ]
1383 }{DO NOTHING!}}}}}}} % \ifthenelse always use "else", so it will do nothing if other letter.
1384 }
1385
1386 % \strands - macro to draw braid-like element via generators (with tikz environment).
1387
1388 \makeatletter
1389 \define@cmdkey[str]{ggens}{bendbraid}{}
1390 \define@cmdkey[str]{ggens}{bendtangle}{}
1391 \define@cmdkey[str]{ggens}{bulla}{}
1392 \define@cmdkey[str]{ggens}{bullb}{}
1393 \define@cmdkey[str]{ggens}{bulletends}{}
1394 \define@cmdkey[str]{ggens}{direction}{}
1395 \define@cmdkey[str]{ggens}{floor}{}
1396 \define@cmdkey[str]{ggens}{font}{}
1397 \define@cmdkey[str]{ggens}{height}{}
1398 \define@cmdkey[str]{ggens}{labelver}{}
1399 \define@cmdkey[str]{ggens}{labelhor}{}
1400 \define@cmdkey[str]{ggens}{nstr}{}
1401 \define@cmdkey[str]{ggens}{nstrsave}{}
1402 \define@cmdkey[str]{ggens}{strwidth}{}
1403 \define@cmdkey[str]{ggens}{tiebull}{}
1404 \define@cmdkey[str]{ggens}{tiebullsize}{}
1405 \define@cmdkey[str]{ggens}{tiecolor}{}
1406 \define@cmdkey[str]{ggens}{tieheight}{}
1407 \define@cmdkey[str]{ggens}{tiesnake}{}
1408 \define@cmdkey[str]{ggens}{tiesnakeamp}{}
1409 \define@cmdkey[str]{ggens}{tiesnakends}{}
1410 \define@cmdkey[str]{ggens}{tiesnakelen}{}
1411 \define@cmdkey[str]{ggens}{tiestyle}{}
1412 \define@cmdkey[str]{ggens}{tiewidth}{}
1413 \define@cmdkey[str]{ggens}{type}{}
1414 \define@cmdkey[str]{ggens}{width}{}
1415
1416 \presetkeys[str]{ggens}{
1417 bendbraid=\cmdstr@strands@bendbraid,
1418 bendtangle=\cmdstr@strands@bendtangle,
1419 bulla=1,
1420 bullb=1,
1421 bulletends=\cmdstr@strands@bulletsize,
1422 direction=\cmdstr@strands@direction,
1423 floor=0,
1424 font=\cmdstr@strands@font,
1425 height=\cmdstr@strands@height,
1426 labelver=\cmdstr@strands@labelver,
1427 labelhor=\cmdstr@strands@labelhor,
1428 nstr=0,
1429 nstrsave=0,
1430 strwidth=\cmdstr@strands@strwidth,
1431 tiebull=\cmdstr@strands@tiebull,
1432 tiebullsize=\cmdstr@strands@tiebullsize,
1433 tiecolor=\cmdstr@strands@tiecolor,
1434 tieheight=\cmdstr@strands@tieheight,
1435 tiesnake=\cmdstr@strands@tiesnake,
1436 tiesnakeamp=\cmdstr@strands@tiesnakeamp,
1437 tiesnakends=\cmdstr@strands@tiesnakends,
1438 tiesnakelen=\cmdstr@strands@tiesnakelen,
1439 tiestyle=\cmdstr@strands@tiestyle,
1440 tiewidth=\cmdstr@strands@tiewidth,
1441 type=3,
1442 width=\cmdstr@strands@width
1443 }{}
1444
1445 \newcounter{levelscounter} % count levels.
1446
1447 \newcommand{\sstrands}[2][]{
1448 \setkeys[str]{ggens}{#1}
1449 % number of strands.
1450 \StrSubstitute{#2}{ }{}[\cmdstr@ggens@nstrsave] % remove whitespaces.
1451 \StrSubstitute{\cmdstr@ggens@nstrsave}{\cmdstr@strands@gencharposbraid}{}[\cmdstr@ggens@nstrsave]
1452 \StrSubstitute{\cmdstr@ggens@nstrsave}{\cmdstr@strands@gencharnegbraid}{}[\cmdstr@ggens@nstrsave]
1453 \StrSubstitute{\cmdstr@ggens@nstrsave}{\cmdstr@strands@gencharvirtual}{}[\cmdstr@ggens@nstrsave]
1454 \StrSubstitute{\cmdstr@ggens@nstrsave}{\cmdstr@strands@gencharsingular}{}[\cmdstr@ggens@nstrsave]
1455 \StrSubstitute{\cmdstr@ggens@nstrsave}{\cmdstr@strands@genchartangle}{}[\cmdstr@ggens@nstrsave]
1456 \StrSubstitute{\cmdstr@ggens@nstrsave}{\cmdstr@strands@genchartie}{}[\cmdstr@ggens@nstrsave]
1457 \StrSubstitute{\cmdstr@ggens@nstrsave}{\cmdstr@strands@genchartiedtangle}{}[\cmdstr@ggens@nstrsave]
1458 \StrSubstitute{\cmdstr@ggens@nstrsave}{\cmdstr@strands@genchartrivial}{}[\cmdstr@ggens@nstrsave]
1459 \StrSubstitute{\cmdstr@ggens@nstrsave}{*}{,}[\cmdstr@ggens@nstrsave]
1460 \StrSubstitute{\cmdstr@ggens@nstrsave}{-}{,}[\cmdstr@ggens@nstrsave]
1461 \let\oldnstr\cmdstr@ggens@nstr
1462 \renewcommand{\cmdstr@ggens@nstr}{\fpeval{max(max(\cmdstr@ggens@nstrsave)+1,\oldnstr)}}
1463 % backstrands.
1464 \StrCount{#2}{*}[\numlevs]
1465 \permutation[ % backstrands.
1466 bulla=0,
1467 bullb=0,
1468 floor=\fpeval{\cmdstr@ggens@floor/((\numlevs+1)*\cmdstr@ggens@height)}, % ??????????????
1469 height=\fpeval{(\numlevs+1)*\cmdstr@ggens@height},
1470 nstr=\cmdstr@ggens@nstr,
1471 tkzpic=0,
1472 type=0
1473 ]{1}
1474 % generators.
1475 \setcounter{levelscounter}{0}
1476 \ForEach{*}{ % for each level.
1477 \stepcounter{levelscounter}
1478 \ForEachSublevel{-}{ % for each generator in level.
1479 \aaddgen[ % add the generator.
1480 bendbraid=\cmdstr@ggens@bendbraid,
1481 bendtangle=\cmdstr@ggens@bendtangle,
1482 direction=\cmdstr@ggens@direction,
1483 floor=\cmdstr@ggens@floor,
1484 generator=\thislevelitem,
1485 height=\cmdstr@ggens@height,
1486 level=\thelevelscounter,
1487 numlevs=\numlevs,
1488 strwidth=\cmdstr@ggens@strwidth,
1489 tiebull=\cmdstr@ggens@tiebull,
1490 tiebullsize=\cmdstr@ggens@tiebullsize,
1491 tiecolor=\cmdstr@ggens@tiecolor,
1492 tieheight=\cmdstr@ggens@tieheight,
1493 tiesnake=\cmdstr@ggens@tiesnake,
1494 tiesnakeamp=\cmdstr@ggens@tiesnakeamp,
1495 tiesnakends=\cmdstr@ggens@tiesnakends,
1496 tiesnakelen=\cmdstr@ggens@tiesnakelen,
1497 tiestyle=\cmdstr@ggens@tiestyle,
1498 tiewidth=\cmdstr@ggens@tiewidth,
1499 width=\cmdstr@ggens@width
1500 ]
1501 }
1502 }{#2}
1503 \decoratestrands[
1504 bulla=\cmdstr@ggens@bulla,
1505 bullb=\cmdstr@ggens@bullb,
1506 bulletends=\cmdstr@ggens@bulletends,
1507 floor=\fpeval{\cmdstr@ggens@floor/((\numlevs+1)*\cmdstr@ggens@height)},
1508 font=\cmdstr@ggens@font,
1509 height=\fpeval{(\numlevs+1)*\cmdstr@ggens@height},
1510 labelver=\cmdstr@ggens@labelver,
1511 labelhor=\cmdstr@ggens@labelhor,
1512 nstr=\cmdstr@ggens@nstr,
1513 type=\cmdstr@ggens@type,
1514 width=\cmdstr@ggens@width
1515 ]
1516 }
1517
1518 \makeatletter
1519 \define@cmdkey[str]{gens}{bendbraid}{}
1520 \define@cmdkey[str]{gens}{bendtangle}{}
1521 \define@cmdkey[str]{gens}{bulla}{}
1522 \define@cmdkey[str]{gens}{bullb}{}
1523 \define@cmdkey[str]{gens}{bulletends}{}
1524 \define@cmdkey[str]{gens}{direction}{}
1525 \define@cmdkey[str]{gens}{floor}{}
1526 \define@cmdkey[str]{gens}{font}{}
1527 \define@cmdkey[str]{gens}{height}{}
1528 \define@cmdkey[str]{gens}{labelver}{}
1529 \define@cmdkey[str]{gens}{labelhor}{}
1530 \define@cmdkey[str]{gens}{nstr}{}
1531 \define@cmdkey[str]{gens}{nstrsave}{}
1532 \define@cmdkey[str]{gens}{rotate}{}
1533 \define@cmdkey[str]{gens}{scale}{}
1534 \define@cmdkey[str]{gens}{strwidth}{}
1535 \define@cmdkey[str]{gens}{tiebull}{}
1536 \define@cmdkey[str]{gens}{tiebullsize}{}
1537 \define@cmdkey[str]{gens}{tiecolor}{}
1538 \define@cmdkey[str]{gens}{tieheight}{}
1539 \define@cmdkey[str]{gens}{tiesnake}{}
1540 \define@cmdkey[str]{gens}{tiesnakeamp}{}
1541 \define@cmdkey[str]{gens}{tiesnakends}{}
1542 \define@cmdkey[str]{gens}{tiesnakelen}{}
1543 \define@cmdkey[str]{gens}{tiestyle}{}
1544 \define@cmdkey[str]{gens}{tiewidth}{}
1545 \define@cmdkey[str]{gens}{tkzpic}{}
1546 \define@cmdkey[str]{gens}{type}{}
1547 \define@cmdkey[str]{gens}{width}{}
1548
1549 \presetkeys[str]{gens}{
1550 bendbraid=\cmdstr@strands@bendbraid,
1551 bendtangle=\cmdstr@strands@bendtangle,
1552 bulla=1,
1553 bullb=1,
1554 bulletends=\cmdstr@strands@bulletsize,
1555 direction=\cmdstr@strands@direction,
1556 floor=0,
1557 font=\cmdstr@strands@font,
1558 height=\cmdstr@strands@height,
1559 labelver=\cmdstr@strands@labelver,
1560 labelhor=\cmdstr@strands@labelhor,
1561 nstr=0,
1562 nstrsave=0,
1563 rotate=\cmdstr@strands@rotate,
1564 scale=\cmdstr@strands@scale,
1565 strwidth=\cmdstr@strands@strwidth,
1566 tiebull=\cmdstr@strands@tiebull,
1567 tiebullsize=\cmdstr@strands@tiebullsize,
1568 tiecolor=\cmdstr@strands@tiecolor,
1569 tieheight=\cmdstr@strands@tieheight,
1570 tiesnake=\cmdstr@strands@tiesnake,
1571 tiesnakeamp=\cmdstr@strands@tiesnakeamp,
1572 tiesnakends=\cmdstr@strands@tiesnakends,
1573 tiesnakelen=\cmdstr@strands@tiesnakelen,
1574 tiestyle=\cmdstr@strands@tiestyle,
1575 tiewidth=\cmdstr@strands@tiewidth,
1576 tkzpic=\cmdstr@strands@tkzpic,
1577 type=3,
1578 width=\cmdstr@strands@width
1579 }{}
1580
1581 \newcommand{\strands}[2][]{
1582 \setkeys[str]{gens}{#1}
1583 \ifthenelse{\equal{\cmdstr@gens@tkzpic}{1}}{
1584 \begin{tikzpicture}[rotate=\cmdstr@gens@rotate,scale=\cmdstr@gens@scale]
1585 \sstrands[
1586 bendbraid=\cmdstr@gens@bendbraid,
1587 bendtangle=\cmdstr@gens@bendtangle,
1588 bulla=\cmdstr@gens@bulla,
1589 bullb=\cmdstr@gens@bullb,
1590 bulletends=\cmdstr@gens@bulletends,
1591 direction=\cmdstr@gens@direction,
1592 floor=\cmdstr@gens@floor,
1593 font=\cmdstr@gens@font,
1594 height=\cmdstr@gens@height,
1595 labelver=\cmdstr@gens@labelver,
1596 labelhor=\cmdstr@gens@labelhor,
1597 nstr=\cmdstr@gens@nstr,
1598 nstrsave=\cmdstr@gens@nstrsave,
1599 strwidth=\cmdstr@gens@strwidth,
1600 tiebull=\cmdstr@gens@tiebull,
1601 tiebullsize=\cmdstr@gens@tiebullsize,
1602 tiecolor=\cmdstr@gens@tiecolor,
1603 tieheight=\cmdstr@gens@tieheight,
1604 tiesnake=\cmdstr@gens@tiesnake,
1605 tiesnakeamp=\cmdstr@gens@tiesnakeamp,
1606 tiesnakends=\cmdstr@gens@tiesnakends,
1607 tiesnakelen=\cmdstr@gens@tiesnakelen,
1608 tiestyle=\cmdstr@gens@tiestyle,
1609 tiewidth=\cmdstr@gens@tiewidth,
1610 type=\cmdstr@gens@type,
1611 width=\cmdstr@gens@width
1612 ]{#2}
1613 \end{tikzpicture}
1614 }{
1615 \sstrands[
1616 bendbraid=\cmdstr@gens@bendbraid,
1617 bendtangle=\cmdstr@gens@bendtangle,
1618 bulla=\cmdstr@gens@bulla,
1619 bullb=\cmdstr@gens@bullb,
1620 bulletends=\cmdstr@gens@bulletends,
1621 direction=\cmdstr@gens@direction,
1622 floor=\cmdstr@gens@floor,
1623 font=\cmdstr@gens@font,
1624 height=\cmdstr@gens@height,
1625 labelver=\cmdstr@gens@labelver,
1626 labelhor=\cmdstr@gens@labelhor,
1627 nstr=\cmdstr@gens@nstr,
1628 nstrsave=\cmdstr@gens@nstrsave,
1629 strwidth=\cmdstr@gens@strwidth,
1630 tiebull=\cmdstr@gens@tiebull,
1631 tiebullsize=\cmdstr@gens@tiebullsize,
1632 tiecolor=\cmdstr@gens@tiecolor,
1633 tieheight=\cmdstr@gens@tieheight,
1634 tiesnake=\cmdstr@gens@tiesnake,
1635 tiesnakeamp=\cmdstr@gens@tiesnakeamp,
1636 tiesnakends=\cmdstr@gens@tiesnakends,
1637 tiesnakelen=\cmdstr@gens@tiesnakelen,
1638 tiestyle=\cmdstr@gens@tiestyle,
1639 tiewidth=\cmdstr@gens@tiewidth,
1640 type=\cmdstr@gens@type,
1641 width=\cmdstr@gens@width
1642 ]{#2}
1643 }
1644 }
1645
1646 % \Finale
1647 \endinput