1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
|
%%
%% This is file `braids.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% braids.dtx (with options: `package')
%% ----------------------------------------------------------------
%% braids --- a style file for drawing braid diagrams with TikZ/PGF
%% E-mail: stacey@math.ntnu.no
%% Released under the LaTeX Project Public License v1.3c or later
%% See http://www.latex-project.org/lppl.txt
%% ----------------------------------------------------------------
%%
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{braids}[2011/05/07 v1.0 Tikz/PGF commands for drawing braid diagrams]
\def\braid@pgfversion{2.10}%
\ifx\pgfversion\braid@pgfversion
\else
\PackageWarning{braids}{This package was designed using PGF2.10; you are using \pgfversion.}%
\fi
\long\def\ge@addto@macro#1#2{%
\begingroup
\toks@\expandafter\expandafter\expandafter{\expandafter#1#2}%
\xdef#1{\the\toks@}%
\endgroup}
\newcommand{\braid}[1][]{%
\begingroup
\braid@start{#1}}
\def\braid@process{%
\afterassignment\braid@handle\let\braid@token=%
}
\def\braid@process@start{%
\afterassignment\braid@handle@start\let\braid@token=%
}
\def\braid@handle@start{%
\let\braid@next=\braid@handle
\ifx\braid@token a
\let\braid@next=\braid@maybe@locate
\else
\ifx\braid@token(%)
\iffalse)\fi %Indentation hack!
\let\braid@next=\braid@assign@name
\else
\ifx\braid@token\@sptoken
\let\braid@next=\braid@process@start
\fi
\fi
\fi
\braid@next%
}
\let\braid@semicolon=;
\let\braid@bar=|
\def\braid@handle{%
\let\braid@next=\braid@process
\ifnum\the\catcode`\;=\active
\expandafter\let\expandafter\braid@semicolon\tikz@activesemicolon
\fi
\ifnum\the\catcode`\|=\active
\expandafter\let\expandafter\braid@bar\tikz@activebar
\fi
\ifx\braid@token\braid@semicolon
\let\braid@next=\braid@render
\else
\ifx\braid@token^
\let\braid@next=\braid@sup
\else
\ifx\braid@token_
\let\braid@next=\braid@sub
\else
\ifx\braid@token-
\braid@increase@levelfalse
\else
\ifx\braid@token[
\let\braid@next=\braid@process@options
\else
\ifx\braid@token\braid@bar
\edef\braid@tmp{,\expandafter\the\value{braid@level}}%
\ge@addto@macro\braid@floors\braid@tmp%
\else
\ifx\braid@token\bgroup
\braid@beginscope
\else
\ifx\braid@token\egroup
\braid@endscope
\else
\ge@addto@macro\braid@label{\braid@token}%
\fi
\fi
\fi
\fi
\fi
\fi
\fi
\fi
\braid@next%
}
\def\braid@maybe@locate{%
\afterassignment\braid@@maybe@locate\let\braid@token=%
}
\def\braid@@maybe@locate{%
\let\braid@next=\braid@handle
\ifx\braid@token t
\let\braid@next=\braid@find@location
\fi
\braid@next%
}
\def\braid@find@location{%
\afterassignment\braid@@find@location\let\braid@token=%
}
\def\braid@@find@location{%
\let\braid@next=\braid@location@error
\ifx\braid@token(%)
\let\braid@next=\braid@locate
\else
\ifx\braid@token\@sptoken
\let\braid@next=\braid@find@location
\fi
\fi
\braid@next%
}
\def\braid@location@error{%
\PackageWarning{braids}{Could not figure out location for braid}%
\braid@process@start%
}
\def\braid@locate#1){%
\tikz@scan@one@point\braid@relocate(#1)%
}
\def\braid@relocate#1{%
#1\relax
\advance\pgf@x by -\braid@width
\pgftransformshift{\pgfqpoint{\pgf@x}{\pgf@y}}
\braid@process@start%
}
\def\braid@assign@name#1){%
\def\braid@name{#1}%
\braid@process@start%
}
\def\braid@process@options#1]{%
\tikzset{#1}%
\braid@process%
}
\def\braid@sup#1_#2{\g@addto@macro\braid@label{_{#2}^{#1}}\braid@add@crossing{#2}{#1}}
\def\braid@sub#1{\@ifnextchar^{\braid@@sub{#1}}{\g@addto@macro\braid@label{_{#1}}\braid@add@crossing{#1}{1}}}
\def\braid@@sub#1^#2{\g@addto@macro\braid@label{_{#1}^{#2}}\braid@add@crossing{#1}{#2}}
\def\braid@ne{1}
\def\braid@add@crossing#1#2{%
\edef\braid@crossing@type{#2}%
\edef\braid@this@strand{#1}%
\pgfmathtruncatemacro{\braid@next@strand}{#1+1}
\ifbraid@increase@level
\stepcounter{braid@level}
\fi
\braid@increase@leveltrue
\braid@tx=\braid@this@strand\braid@width
\braid@ty=\value{braid@level}\braid@height
\advance\braid@ty by \braid@eh
\braid@nx=\braid@tx
\braid@ny=\braid@ty
\advance\braid@nx by \braid@width
\advance\braid@ny by \braid@height
\braid@cy=\braid@ty
\braid@dy=\braid@ny
\advance\braid@cy by .5\braid@height
\advance\braid@dy by -.5\braid@height
\advance\braid@ty by .05\braid@height
\advance\braid@ny by -.05\braid@height
\expandafter\let\expandafter\braid@this@path@origin\csname braid@strand@\braid@this@strand @origin\endcsname
\ifx\braid@this@path@origin\relax
\let\braid@this@path@origin\braid@this@strand
\pgfsyssoftpath@setcurrentpath{\@empty}
\pgfpathmoveto{\pgfpoint{\braid@tx}{0pt}}
\pgfsyssoftpath@getcurrentpath{\braid@this@path}
\else
\expandafter\let\expandafter\braid@this@path\csname braid@strand@\braid@this@path@origin\endcsname
\fi
\expandafter\let\expandafter\braid@next@path@origin\csname braid@strand@\braid@next@strand @origin\endcsname
\ifx\braid@next@path@origin\relax
\let\braid@next@path@origin\braid@next@strand
\pgfsyssoftpath@setcurrentpath{\@empty}
\pgfpathmoveto{\pgfpoint{\braid@nx}{0pt}}
\pgfsyssoftpath@getcurrentpath{\braid@next@path}
\else
\expandafter\let\expandafter\braid@next@path\csname braid@strand@\braid@next@path@origin\endcsname
\fi
\pgfsyssoftpath@setcurrentpath{\braid@this@path}
\pgfpathlineto{\pgfqpoint{\braid@tx}{\braid@ty}}
\ifx\braid@crossing@type\braid@over@cross
\pgfpathcurveto{\pgfqpoint{\braid@tx}{\braid@cy}}{\pgfqpoint{\braid@nx}{\braid@dy}}{\pgfqpoint{\braid@nx}{\braid@ny}}
\else
\pgfpathcurvebetweentimecontinue{0}{.4}{\pgfqpoint{\braid@tx}{\braid@ty}}{\pgfqpoint{\braid@tx}{\braid@cy}}{\pgfqpoint{\braid@nx}{\braid@dy}}{\pgfqpoint{\braid@nx}{\braid@ny}}
\pgfpathcurvebetweentime{.6}{1}{\pgfqpoint{\braid@tx}{\braid@ty}}{\pgfqpoint{\braid@tx}{\braid@cy}}{\pgfqpoint{\braid@nx}{\braid@dy}}{\pgfqpoint{\braid@nx}{\braid@ny}}
\fi
\pgfsyssoftpath@getcurrentpath{\braid@this@path}
\pgfsyssoftpath@setcurrentpath{\braid@next@path}
\pgfpathlineto{\pgfqpoint{\braid@nx}{\braid@ty}}
\ifx\braid@crossing@type\braid@over@cross
\pgfpathcurvebetweentimecontinue{0}{.4}{\pgfqpoint{\braid@nx}{\braid@ty}}{\pgfqpoint{\braid@nx}{\braid@cy}}{\pgfqpoint{\braid@tx}{\braid@dy}}{\pgfqpoint{\braid@tx}{\braid@ny}}
\pgfpathcurvebetweentime{.6}{1}{\pgfqpoint{\braid@nx}{\braid@ty}}{\pgfqpoint{\braid@nx}{\braid@cy}}{\pgfqpoint{\braid@tx}{\braid@dy}}{\pgfqpoint{\braid@tx}{\braid@ny}}
\else
\pgfpathcurveto{\pgfqpoint{\braid@nx}{\braid@cy}}{\pgfqpoint{\braid@tx}{\braid@dy}}{\pgfqpoint{\braid@tx}{\braid@ny}}
\fi
\pgfsyssoftpath@getcurrentpath{\braid@next@path}
\expandafter\let\csname braid@strand@\braid@this@path@origin \endcsname\braid@this@path
\expandafter\let\csname braid@strand@\braid@next@path@origin \endcsname\braid@next@path
\expandafter\let\csname braid@strand@\braid@this@strand @origin\endcsname\braid@next@path@origin
\expandafter\let\csname braid@strand@\braid@next@strand @origin\endcsname\braid@this@path@origin
\pgfmathparse{\value{braid@strands} < \braid@next@strand ? "\noexpand\setcounter{braid@strands}{\braid@next@strand}" : ""}
\pgfmathresult
\braid@process%
}
\def\braid@floors@trim,{}
\def\braid@render@floor{%
\draw (\floorsx,\floorsy) rectangle (\floorex,\floorey);
}
\def\braid@render{
\ifx\braid@floors\@empty
\else
\pgfsys@beginscope
\pgfsyssoftpath@setcurrentpath{\empty}
\edef\braid@floors{\expandafter\braid@floors@trim\braid@floors}
\braid@tx=\braid@width
\advance\braid@tx by \braid@eh
\braid@nx=\value{braid@strands}\braid@width
\advance\braid@nx by -\braid@eh
\foreach \braid@f in \braid@floors {
\pgfsys@beginscope
\braid@ty=\braid@f\braid@height
\advance\braid@ty by \braid@eh
\advance\braid@ty by \braid@height
\braid@ny=\braid@ty
\advance\braid@ny by \braid@height
\edef\floorsx{\the\braid@tx}
\edef\floorsy{\the\braid@ty}
\edef\floorex{\the\braid@nx}
\edef\floorey{\the\braid@ny}
\let\tikz@options=\pgfutil@empty
\expandafter\tikzset\expandafter{\braid@floors@style}
\pgfmathtruncatemacro{\braid@ff}{\braid@f+2}
\expandafter\let\expandafter\braid@floor@style\csname braid@options@floor@\braid@ff\endcsname
\ifx\braid@floor@style\relax
\else
\expandafter\tikzset\expandafter{\braid@floor@style}%
\fi
\tikz@options
\braid@render@floor
\pgfsys@endscope
}
\pgfsys@endscope
\fi
\stepcounter{braid@level}
\foreach \braid@k in {1,...,\value{braid@strands}} {
\pgfsys@beginscope
\tikz@mode@drawtrue%
\let\tikz@mode=\pgfutil@empty
\let\tikz@options=\pgfutil@empty
\braid@tx=\braid@k\braid@width
\braid@ty=\value{braid@level}\braid@height
\advance\braid@ty by 2\braid@eh
\expandafter\let\expandafter\braid@path@origin\csname braid@strand@\braid@k @origin\endcsname
\ifx\braid@path@origin\relax
\pgfsyssoftpath@setcurrentpath{\@empty}
\pgfpathmoveto{\pgfqpoint{\braid@tx}{0pt}}
\let\braid@path@origin\braid@k
\else
\expandafter\let\expandafter\braid@path\csname braid@strand@\braid@path@origin\endcsname
\pgfsyssoftpath@setcurrentpath{\braid@path}
\fi
\pgflineto{\pgfqpoint{\braid@tx}{\braid@ty}}
\expandafter\tikzset\expandafter{\braid@style}
\expandafter\let\expandafter\braid@style\csname braid@options@strand@\braid@path@origin\endcsname
\ifx\braid@style\relax
\else
\expandafter\tikzset\expandafter{\braid@style}
\fi
\braid@options
\tikz@mode
\tikz@options
\edef\tikz@temp{\noexpand\pgfusepath{%
\iftikz@mode@draw draw\fi%
}}%
\tikz@temp
\ifx\braid@name\pgfutil@empty
\else
\coordinate (\braid@name-\braid@path@origin-e) at (\braid@tx,\braid@ty);
\coordinate (\braid@name-rev-\braid@k-e) at (\braid@tx,\braid@ty);
\braid@nx=\braid@path@origin\braid@width
\coordinate (\braid@name-\braid@path@origin-s) at (\braid@nx,0pt);
\coordinate (\braid@name-rev-\braid@k-s) at (\braid@nx,0pt);
\fi
\pgfsys@endscope
}
\ifx\braid@name\pgfutil@empty
\else
\braid@tx=\value{braid@strands}\braid@width
\braid@ty=\value{braid@level}\braid@height
\advance\braid@ty by 2\braid@eh
\advance\braid@tx by \braid@width
\braid@tx=.5\braid@tx
\braid@ty=.5\braid@ty
\coordinate (\braid@name) at (\braid@tx,\braid@ty);
\fi
\pgfsys@endscope
\endgroup}
\def\braid@start#1{%
\pgfsys@beginscope
\setcounter{braid@level}{-1}%
\let\braid@label\@empty
\let\braid@floors\@empty
\let\braid@name\empty
\pgfkeys{/pgf/braid/.cd,#1}
\let\braid@options\tikz@options
\tikz@transform
\setcounter{braid@strands}{\pgfkeysvalueof{/pgf/braid/number of strands}}%
\braid@width=\pgfkeysvalueof{/pgf/braid/width}
\braid@height=\pgfkeysvalueof{/pgf/braid/height}
\braid@eh=\pgfkeysvalueof{/pgf/braid/border height}
\braid@height=-\braid@height
\braid@eh=-\braid@eh
\braid@increase@leveltrue
\braid@process@start
}
\newdimen\braid@width
\newdimen\braid@height
\newdimen\braid@tx
\newdimen\braid@ty
\newdimen\braid@nx
\newdimen\braid@ny
\newdimen\braid@cy
\newdimen\braid@dy
\newdimen\braid@eh
\newif\ifbraid@increase@level
\let\braid@style\pgfutil@empty
\let\braid@floors@style\pgfutil@empty
\def\braid@over@cross{1}
\newcounter{braid@level}
\newcounter{braid@strands}
\pgfkeys{
/tikz/braid/.search also={/pgf},
/pgf/braid/.search also={/pgf,/tikz},
/pgf/braid/.cd,
number of strands/.initial=0,
height/.initial=1cm,
width/.initial=1cm,
border height/.initial=.25cm,
name/.code={%
\def\braid@name{#1}%
},
at/.code={%
\braid@relocate{#1}%
},
floor command/.code={%
\def\braid@render@floor{#1}%
},
style strands/.code 2 args={%
\def\braid@temp{#2}%
\braidset{style each strand/.list={#1}}%
},
style each strand/.code={%
\expandafter\edef\csname braid@options@strand@#1\endcsname{\braid@temp}%
},
style floors/.code 2 args={%
\def\braid@temp{#2}%
\braidset{style each floor/.list={#1}}%
},
style each floor/.code={%
\expandafter\edef\csname braid@options@floor@#1\endcsname{\braid@temp}%
},
style all floors/.code={%
\def\braid@floors@style{#1}
}
}
\def\braidset#1{%
\pgfkeys{/pgf/braid/.cd,#1}}
%%
%% Copyright (C) 2011 by Andrew Stacey <stacey@math.ntnu.no>
%%
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License (LPPL), either
%% version 1.3c of this license or (at your option) any later
%% version. The latest version of this license is in the file:
%%
%% http://www.latex-project.org/lppl.txt
%%
%% This work is "maintained" (as per LPPL maintenance status) by
%% Andrew Stacey.
%%
%% This work consists of the files braids.dtx
%% braids_doc.tex
%% and the derived files README.txt,
%% braids.ins,
%% braids.pdf,
%% braids.sty,
%% braids_doc.pdf.
%%
%%
%% End of file `braids.sty'.
|