brunnian.dtx 71 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050
  1. % \iffalse meta-comment
  2. %<*internal>
  3. \iffalse
  4. %</internal>
  5. %<*readme>
  6. ----------------------------------------------------------------
  7. brunnian --- a style file for drawing link diagrams with TikZ/PGF
  8. E-mail: stacey@math.ntnu.no
  9. Released under the LaTeX Project Public License v1.3c or later
  10. See http://www.latex-project.org/lppl.txt
  11. ----------------------------------------------------------------
  12. This package defines some commands and styles useful for drawing knot and link diagrams with TikZ/PGF.
  13. Some are geared towards drawing very specific links (the iterated Hopf and Brunnian links) whilst others will be more generally useful for arbitrary knots and links.
  14. %</readme>
  15. %<*internal>
  16. \fi
  17. \def\nameofplainTeX{plain}
  18. \ifx\fmtname\nameofplainTeX\else
  19. \expandafter\begingroup
  20. \fi
  21. %</internal>
  22. %<*install>
  23. \input docstrip.tex
  24. \keepsilent
  25. \askforoverwritefalse
  26. \preamble
  27. ----------------------------------------------------------------
  28. brunnian --- a style file for drawing link diagrams with TikZ/PGF
  29. E-mail: stacey@math.ntnu.no
  30. Released under the LaTeX Project Public License v1.3c or later
  31. See http://www.latex-project.org/lppl.txt
  32. ----------------------------------------------------------------
  33. \endpreamble
  34. \postamble
  35. Copyright (C) 2011 by Andrew Stacey <stacey@math.ntnu.no>
  36. This work may be distributed and/or modified under the
  37. conditions of the LaTeX Project Public License (LPPL), either
  38. version 1.3c of this license or (at your option) any later
  39. version. The latest version of this license is in the file:
  40. http://www.latex-project.org/lppl.txt
  41. This work is "maintained" (as per LPPL maintenance status) by
  42. Andrew Stacey.
  43. This work consists of the file brunnian.dtx
  44. and the derived files brunnian.ins,
  45. brunnain.pdf, and
  46. brunnian.sty.
  47. \endpostamble
  48. \usedir{tex/latex/brunnian}
  49. \generate{
  50. \file{\jobname.sty}{\from{\jobname.dtx}{package}}
  51. }
  52. %</install>
  53. %<install>\endbatchfile
  54. %<*internal>
  55. \usedir{source/latex/brunnian}
  56. \generate{
  57. \file{\jobname.ins}{\from{\jobname.dtx}{install}}
  58. }
  59. \nopreamble\nopostamble
  60. \usedir{doc/latex/demopkg}
  61. \generate{
  62. \file{README.txt}{\from{\jobname.dtx}{readme}}
  63. }
  64. \ifx\fmtname\nameofplainTeX
  65. \expandafter\endbatchfile
  66. \else
  67. \expandafter\endgroup
  68. \fi
  69. %</internal>
  70. %<*package>
  71. \NeedsTeXFormat{LaTeX2e}
  72. \ProvidesPackage{brunnian}[2011/03/10 v1.0 Tikz/PGF commands for drawing knots and links]
  73. %</package>
  74. %<*driver>
  75. \documentclass{ltxdoc}
  76. \usepackage[T1]{fontenc}
  77. \usepackage{lmodern}
  78. \usepackage{morefloats}
  79. \usepackage{\jobname}
  80. \usepackage[numbered]{hypdoc}
  81. \definecolor{lstbgcolor}{rgb}{0.9,0.9,0.9}
  82. \usepackage{listings}
  83. \lstloadlanguages{[LaTeX]TeX}
  84. \lstset{breakatwhitespace=true,breaklines=true,language=TeX}
  85. \usepackage{fancyvrb}
  86. \newenvironment{example}
  87. {\VerbatimEnvironment
  88. \begin{VerbatimOut}[gobble=2]{example.out}}
  89. {\end{VerbatimOut}
  90. \begin{center}
  91. \vspace{1ex}
  92. \setlength{\parindent}{0pt}
  93. \fbox{\begin{minipage}{.9\linewidth}
  94. \lstset{breakatwhitespace=true,breaklines=true,language=TeX,basicstyle=\small}
  95. \lstinputlisting[]{example.out}
  96. \end{minipage}}
  97. \fbox{\begin{minipage}{.9\linewidth}
  98. \small\input{example.out}
  99. \end{minipage}}
  100. \vspace{1ex}
  101. \end{center}
  102. }
  103. \EnableCrossrefs
  104. \CodelineIndex
  105. \RecordChanges
  106. \begin{document}
  107. \DocInput{\jobname.dtx}
  108. \end{document}
  109. %</driver>
  110. % \fi
  111. %
  112. % \CheckSum{2860}
  113. %
  114. % \CharacterTable
  115. % {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
  116. % 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
  117. % Digits \0\1\2\3\4\5\6\7\8\9
  118. % Exclamation \! Double quote \" Hash (number) \#
  119. % Dollar \$ Percent \% Ampersand \&
  120. % Acute accent \' Left paren \( Right paren \)
  121. % Asterisk \* Plus \+ Comma \,
  122. % Minus \- Point \. Solidus \/
  123. % Colon \: Semicolon \; Less than \<
  124. % Equals \= Greater than \> Question mark \?
  125. % Commercial at \@ Left bracket \[ Backslash \\
  126. % Right bracket \] Circumflex \^ Underscore \_
  127. % Grave accent \` Left brace \{ Vertical bar \|
  128. % Right brace \} Tilde \~}
  129. %
  130. %
  131. % \changes{1.0}{2011/03/10}{Converted to DTX file}
  132. %
  133. % \DoNotIndex{\newcommand,\newenvironment}
  134. %
  135. % \providecommand*{\url}{\texttt}
  136. % \GetFileInfo{brunnian.dtx}
  137. % \title{The \textsf{brunnian} package}
  138. % \author{Andrew Stacey \\ \url{stacey@math.ntnu.no}}
  139. % \date{\fileversion~from \filedate}
  140. %
  141. % \maketitle
  142. %
  143. % \section{Introduction}
  144. %
  145. % This package defines some commands and styles for drawing knots and links with Ti\emph{k}Z/PGF.
  146. % The original motivation for the commands was to draw iterated Hopf and Brunnian links and so many of the commands are specifically for those diagrams.
  147. % There are also more general styles and commands that will be useful for general knot and link diagrams.
  148. % For example, the trefoil knot can be rendered using the following code.
  149. %
  150. % \begin{example}
  151. % \tikzset{every path/.style={red,line width=2pt},every node/.style={transform shape,knot crossing,inner sep=1.5pt}}
  152. % \begin{center}
  153. % \begin{tikzpicture}
  154. % \foreach \brk in {0,1,2} {
  155. % \begin{scope}[rotate=\brk * 120]
  156. % \node (k\brk) at (0,-1) {};
  157. % \end{scope}
  158. % }
  159. % \foreach \brk in {0,1,2} {
  160. % \pgfmathparse{int(Mod(\brk - 1,3))}
  161. % \edef\brl{\pgfmathresult}
  162. % \draw (k\brk) .. controls (k\brk.4 north west) and (k\brl.4 north east) .. (k\brl.center);
  163. % \draw (k\brk.center) .. controls (k\brk.16 south west) and (k\brl.16 south east) .. (k\brl);
  164. % }
  165. % \end{tikzpicture}
  166. % \end{center}
  167. % \end{example}
  168. %
  169. %
  170. % \section{Usage}
  171. %
  172. % Using this package is very easy.
  173. % Once it is installed, simply put\\
  174. % \Verb+\usepackage{brunnian}+\\
  175. % in the preamble of your document.
  176. % This package automatically loads several other packages: \Verb+xcolor+ (with the \Verb+svgnames+ option), \Verb+tikz+, and \Verb+colorinfo+.
  177. % (These can be loaded before this package, though note that loading \Verb+xcolor+ with a different set of colours will result in an error about option clashes.)
  178. % It also detects whether \Verb+htlatex+ is being used and sets up PGF to produce SVG if so.
  179. %
  180. % \subsection{User Commands}
  181. %
  182. % The user interface provided by this package splits into two parts.
  183. % One part consists of the jigsaw pieces needed to construct complicated link diagrams.
  184. % The other part consists of various Ti\emph{k}Z styles and oddments that are designed to make it easier to draw knots and links.
  185. % As this second part is probably more widely applicable, we shall describe it first.
  186. % \subsubsection{Knots and Links}
  187. %
  188. % This package defines four styles for paths for Ti\emph{k}Z: \Verb+knot+, \Verb+thin knot+, \Verb+thick knot+, and \Verb+string+.
  189. % The first three define paths which have an extra thickness set to the colour of the background meaning that they ``chop out'' part of anything that they pass over.
  190. % To specify a colour for one of these styles, one has to pass the option \Verb+double=colour+ rather than the colour itself.
  191. % This is because the styles work by using the \Verb+double+ style of Ti\emph{k}Z paths, wherein the colour of the path becomes the \emph{outside} colour.
  192. % As we want it to be the inside colour, we have to specify the colour differently.
  193. %
  194. % \begin{example}
  195. % \begin{center}
  196. % \begin{tikzpicture}[every path/.style={double=Red}]
  197. % \draw[thin knot] (-1,-1) -- (1,1);
  198. % \draw[thin knot] (-1,1) -- (1,-1);
  199. % \begin{scope}[xshift=2.5cm]
  200. % \draw[knot] (-1,-1) -- (1,1);
  201. % \draw[knot] (-1,1) -- (1,-1);
  202. % \end{scope}
  203. % \begin{scope}[xshift=5cm]
  204. % \draw[thick knot] (-1,-1) -- (1,1);
  205. % \draw[thick knot] (-1,1) -- (1,-1);
  206. % \end{scope}
  207. % \end{tikzpicture}
  208. % \end{center}
  209. % \end{example}
  210. %
  211. % The last style, \Verb+string+, does not have this overhand but is designed to be compatible with \Verb+knot+ and so can be used whenever the overhang might get in the way.
  212. %
  213. % This package also defines some node shapes to help draw knot and link diagrams.
  214. % The idea with these is to place a node of the appropriate type at each crossing and then link them accordingly.
  215. % The node shapes are \Verb+knot crossing+, \Verb+knot over cross+, \Verb+knot under cross+, \Verb+knot vert+, \Verb+knot horiz+.
  216. % The \Verb+knot over cross+ and \Verb+knot under cross+ two are crossings, \Verb+knot vert+ and \Verb+knot horiz+ are for when resolving the crossings in a diagram.
  217. % By judicious use of the \Verb+\foreach+ command, a family of resolved link diagrams can be produced.
  218. %
  219. % \begin{example}
  220. % \begin{center}
  221. % \begin{tikzpicture}[every node/.style={draw,Red}]
  222. % \node[knot over cross] at (1,0) {};
  223. % \node[knot under cross] at (2,0) {};
  224. % \node[knot vert] at (3,0) {};
  225. % \node[knot horiz] at (4,0) {};
  226. % \end{tikzpicture}
  227. % \end{center}
  228. % \end{example}
  229. %
  230. % The node \Verb+knot crossing+ is not meant to be drawn, it is an empty shape.
  231. % Its value is in that it defines more anchors than the usual rectangle shape.
  232. % For each of the 8 main compass directions, it defines anchors at 2, 4, 8, 16, and 32 times further out.
  233. % This can be useful for designing curves that enter and exit the crossing gracefully at particular directions.
  234. % When using this node shape, the crossing itself is easiest to draw by using the \Verb+center+ anchor for the strands that form the over cross.
  235. %
  236. % \begin{example}
  237. % \begin{center}
  238. % \begin{tikzpicture}[every path/.style={string,Red}, every node/.style={transform shape, knot crossing, inner sep=1.5pt}]
  239. % \node[rotate=45] (tl) at (-1,1) {};
  240. % \node[rotate=-45] (tr) at (1,1) {};
  241. % \node (m) at (0,-1) {};
  242. % \node (b) at (0,-2) {};
  243. % \draw (b) .. controls (b.4 north west) and (m.4 south west) .. (m.center);
  244. % \draw (b.center) .. controls (b.4 north east) and (m.4 south east) .. (m);
  245. % \draw (m) .. controls (m.8 north west) and (tl.3 south west) .. (tl.center);
  246. % \draw (m.center) .. controls (m.8 north east) and (tr.3 south east) .. (tr);
  247. % \draw (tl.center) .. controls (tl.16 north east) and (tr.16 north west) .. (tr);
  248. % \draw (b) .. controls (b.16 south east) and (tr.16 north east) .. (tr.center);
  249. % \draw (b.center) .. controls (b.16 south west) and (tl.16 north west) .. (tl);
  250. % \draw (tl) -- (tr.center);
  251. % \end{tikzpicture}
  252. % \end{center}
  253. % \end{example}
  254. %
  255. % \subsection{Higher Order Link Diagrams}
  256. %
  257. % Many of the commands in this package were developed to draw examples of specific families of higher order links, particularly involving the Brunnian and Hopfian families.
  258. % These commands are built up in sections from some basic jigsaw pieces.
  259. %
  260. % \DescribeMacro{\brunnian}
  261. % \DescribeMacro{\outbrunnian}
  262. % \DescribeMacro{\midbrunnian}
  263. % \DescribeMacro{\hopfring}
  264. % \DescribeMacro{\brunniantwo}
  265. % \DescribeMacro{\outbrunniantwo}
  266. % \DescribeMacro{\hopftwo}
  267. % \DescribeMacro{\outhopftwo}
  268. % \DescribeMacro{\brunnianhopf}
  269. % \DescribeMacro{\hopfbrunnian}
  270. % Let us start with the commands that render a full diagram.
  271. %
  272. % \begin{itemize}
  273. % \item \cmd{\brunnian}\oarg{double}\marg{radius}\marg{number} \\
  274. % \cmd{\outbrunnian}\oarg{double}\marg{radius}\marg{number} \\
  275. % \cmd{\midbrunnian}\oarg{double}\marg{radius}\marg{number}
  276. %
  277. % This draws a Brunnian ring of radius \marg{radius} with \marg{number} components.
  278. % If \oarg{double} is specified (as a positive integer) then each strand is doubled by that amount.
  279. % The default is to draw them with the junctions pointing inwards, the second variant has them outwards whilst the third makes them balanced.
  280. %
  281. % \item \cmd{\hopfring}\marg{radius}\marg{number}
  282. %
  283. % This draws a Hopf ring of radius \marg{radius} with \marg{number} components.
  284. %
  285. % \item \cmd{\brunniantwo}\marg{radius}\marg{level2}\marg{level1} \\
  286. % \cmd{\outbrunniantwo}\marg{radius}\marg{level2}\marg{level1}
  287. %
  288. % This draws a level two Brunnian ring of radius \marg{radius} with \marg{level2} level two families each of \marg{level1} components.
  289. % The \cmd{\outbrunniantwo} variant draws it with the main junctions pointing outwards.
  290. %
  291. % \item \cmd{\hopftwo}\marg{radius}\marg{level2}\marg{level1} \\
  292. % \cmd{\outhopftwo}\marg{radius}\marg{level2}\marg{level1}
  293. %
  294. % This draws a level two Hopf ring of radius \marg{radius} with \marg{level2} level two families each of \marg{level1} components.
  295. % The \cmd{\outhopftwo} variant draws it with the main junctions pointing outwards.
  296. %
  297. % \item \cmd{\brunnianhopf}\marg{radius}\marg{level2}\marg{level1} \\
  298. % \cmd{\hopfbrunnian}\marg{radius}\marg{level2}\marg{level1}
  299. %
  300. % These draw level two structures of radius \marg{radius} with \marg{level2} level two families each of \marg{level1} components.
  301. % The level two families in the first are linked by Brunnian linkages and the level one linkages are Hopfian.
  302. % In the second, these are the other way around.
  303. % \end{itemize}
  304. %
  305. % The main pieces that these diagrams are built from are \emph{linkages}.
  306. % By the term \emph{linkage} we mean that part of a link diagram where crossings occur.
  307. % For the Brunnian links, the command that generates the linkages is the \Verb+\junction+ command.
  308. % The Hopfian links are generated by \Verb+\hopfjunction+.
  309. % There are some other variants as well.
  310. %
  311. % \DescribeMacro{\junction}
  312. % \DescribeMacro{\flatjunction}
  313. % \DescribeMacro{\hopfjunction}
  314. % These commands all take the same arguments.
  315. % For example, \\
  316. % \cmd{\junction}\marg{level}\marg{radius}\marg{direction}\marg{clockwise}\marg{anticlockwise}\\
  317. % renders a Brunnian junction according to the specifications.
  318. % The argument \marg{level} sets the level of iteration of the linkage.
  319. % The \marg{radius} is the starting radius of the junction, whilst \marg{direction} determines whether it points in or out.
  320. % The angles \marg{clockwise} and \marg{anticlockwise} determine how far around the strands will extend on either side of the junction.
  321. % (It is possible that the strands will extend further than the given angles as there is a minimum which depends on the other parameters.)
  322. % The command \Verb+\flatjunction+ renders the same linkage but as part of a flat link diagram (that is, not one that forms a circle).
  323. % At the moment, \Verb+\flatjunction+ does not use the angles; in some future version it will use these as lengths.
  324. % Lastly, \Verb+\hopfjunction+ renders the linkages as used in the various Hopf rings.
  325. % The linkage is drawn at the bottom of the circle, obviously it can be rotated to suit.
  326. %
  327. % \begin{example}
  328. % \begin{center}
  329. % \begin{tikzpicture}
  330. % \colorlet{inner}{ring1}
  331. % \colorlet{outer}{ring2}
  332. % \flatjunction{2}{5}{1}{10}{100}
  333. % \end{tikzpicture}
  334. % \end{center}
  335. % \end{example}
  336. %
  337. % \begin{example}
  338. % \begin{center}
  339. % \begin{tikzpicture}
  340. % \colorlet{inner}{ring1}
  341. % \colorlet{outer}{ring2}
  342. % \hopfjunction{3}{5}{1}{10}{20}
  343. % \end{tikzpicture}
  344. % \end{center}
  345. % \end{example}
  346. %
  347. % The colours of the strands of the link are determined by colours named \Verb+innerINT+ and \Verb+outerINT+, where \Verb+INT+ is an (optional) integer.
  348. % On one side of the linkage, the colour of strand \(N\) is the colour specified in \Verb+innerM+ where \(M \le N\).
  349. % The other side uses the \Verb+outer+ colours.
  350. %
  351. %
  352. % \DescribeMacro{\fillin}
  353. % The more complicated diagrams are built from the various junction commands.
  354. % After all the junctions have been put in place, there are often some gaps that need to be filled in.
  355. % The command\\
  356. % \cmd{\fillin}\marg{radius}\marg{start}\marg{end}\marg{sangle}\marg{eangle}\marg{colour} \\
  357. % draws the arcs which correspond to the strands numbered from \marg{start} to \marg{end} given that the radius of the main diagram is \marg{radius}.
  358. % The arcs are drawn from angle \marg{sangle} to \marg{eangle}, with the proviso that the \(0\) is straight down.
  359. %
  360. %
  361. % \DescribeMacro{\chain}
  362. % \DescribeMacro{\leftchain}
  363. % \DescribeMacro{\rightchain}
  364. % \DescribeMacro{\leftcornerchain}
  365. % \DescribeMacro{\rightcornerchain}
  366. % The commands \cmd{\chain}, \cmd{\leftchain}, \cmd{\rightchain}, \cmd{\leftcornerchain}, and \cmd{\rightcornerchain} all draw the components for Brunnian chain mail.
  367. % The drawings are designed so that superimposing them will result in a correctly rendered diagram.
  368. % The colour of the chain element is determined by the colour \Verb+chain+.
  369. %
  370. % \begin{example}
  371. % \begin{center}
  372. % \begin{tikzpicture}
  373. % \colorlet{chain}{Green}
  374. % \chain
  375. % \begin{scope}[shift={(-2,-2)}]
  376. % \leftchain
  377. % \end{scope}
  378. % \begin{scope}[shift={(4,-2)}]
  379. % \rightcornerchain
  380. % \end{scope}
  381. % \end{tikzpicture}
  382. % \end{center}
  383. % \end{example}
  384. %
  385. %
  386. % \DescribeMacro{\brunnianlink}
  387. % \DescribeMacro{\flatbrunnianlink}
  388. % For the level one Brunnian structures, the pictures drawn are not the most elegant.
  389. % A more pleasing rendition can be obtained by using the pieces rendered by \cmd{\flatbrunnianlink}\marg{scale} and \cmd{\brunnianlink}\marg{scale}\marg{angle}.
  390. %
  391. % \begin{example}
  392. % \begin{center}
  393. % \begin{tikzpicture}
  394. % \pgfmathsetmacro{\brscale}{1}
  395. % \begin{scope}[xshift=6.5 cm]
  396. % \draw[knot,double=ring1] (-6.3*\brscale0,0) circle (\brscale);
  397. % \draw[knot,double=ring2] (-1.5*\brscale,0) circle (\brscale);
  398. % \foreach \brk in {5,...,3} {
  399. % \begin{scope}[xshift=-\brk * \brscale cm]
  400. % \colorlet{chain}{ring\brk}
  401. % \flatbrunnianlink{\brscale}
  402. % \end{scope}
  403. % }
  404. % \end{scope}
  405. % \end{tikzpicture}
  406. % \end{center}
  407. % \end{example}
  408. %
  409. % \DescribeMacro{\brunniantwocpt}
  410. % \DescribeMacro{\brunniancpt}
  411. % \DescribeMacro{\brunniancptouter}
  412. % More complicated link diagrams can be built from components.
  413. % The command
  414. %
  415. % \cmd{\brunniantwocpt}\marg{radius}\marg{lvl2}\marg{lvl1}\marg{colour}
  416. %
  417. % renders a level two component from a Brunnian level two ring with base colour \marg{colour} (which must be one of the ring colours).
  418. % It is rendered as if it were part of a level two Brunnian ring of radius \marg{radius} with \marg{lvl2} components at level two and \marg{lvl1} components at level one.
  419. % The command \cmd{\brunniancpt} is the same but for level one Brunnian rings.
  420. % As this only renders one link component, its colour is specified by the colour \Verb+brunnian+.
  421. %
  422. % \DescribeMacro{\brunnianlinkage}
  423. % \DescribeMacro{\brunniantwoside}
  424. % \DescribeMacro{\dblhopftwoside}
  425. % \DescribeMacro{\dblhopfrctwoside}
  426. % \DescribeMacro{\brunnianhalftwoside}
  427. % \DescribeMacro{\brunnianringonetwoside}
  428. % These commands draw a more schematic diagram of the various linkages.
  429. % The \Verb+twoside+ versions draw two versions with a gap in the middle so that the gap can be filled by linking the various ends to draw different resolutions of the link diagrams.
  430. % The ends of the strands in the middle are Ti\emph{k}Z coordinates with labels \((1)\) to \((8)\) running down the left-hand side and then down the right.
  431. % Certain lengths need to be set before this is used, namely \Verb+\brover+, \Verb+\bradj+, \Verb+\brsep+, and \Verb+\brlen+.
  432. % These control various aspects of how the diagram is rendered.
  433. %
  434. % \begin{example}
  435. % \begin{center}
  436. % \pgfmathsetmacro{\brover}{.25}
  437. % \pgfmathsetmacro{\bradj}{.05}
  438. % \pgfmathsetmacro{\brsep}{.25}
  439. % \pgfmathsetmacro{\brlen}{1}
  440. % \begin{tikzpicture}[every path/.style={thick knot,double=Red},every node/.style={text=black},baseline=0cm]
  441. % \dblhopftwoside
  442. % \draw[double=none,Red,line width=2pt] (1) -- (2) (3) -- (5) (4) -- (6) (7) -- (8) ;
  443. % \end{tikzpicture}
  444. % \end{center}
  445. % \end{example}
  446. %
  447. %
  448. % \subsection{Colours}
  449. %
  450. % \DescribeMacro{\resetbgcolour}
  451. % The method of producing the complicated iterated diagrams is to define certain blocks which can then be put together in the correct fashion.
  452. % The blocks corresponding to junctions (that is, where link components meet) comprise strands from several components.
  453. % It is possible to show only certain strands by setting the colour of the others to the background colour.
  454. % Such strands are not drawn.
  455. % Rather than attempt to discover the \emph{actual} background colour of the picture, this package believes what it is told.
  456. % At the begining of the document, it is told that the background is \Verb+white+.
  457. % The command \cmd{\resetbgcolour} takes one argument, \marg{colour}, which it then believes to be the background (for the current group).
  458. %
  459. % \subsection{Lengths}
  460. %
  461. % \DescribeMacro{\setbrstep}
  462. % Various aspects of the sizes of the various link diagrams are controlled by an internal parameter \cmd{\br@step}.
  463. % The command \cmd{\brstep}\marg{number} is \Verb+let+ to this to enable its use in the main document, but changing \cmd{\brstep} doesn't change \cmd{\br@step}.
  464. % The command \cmd{\setbrstep} takes one argument, \marg{number}, to which it then sets \cmd{\br@step}.
  465. %
  466. %
  467. %
  468. % \StopEventually{}
  469. %
  470. % \section{Implementation}
  471. %
  472. % \iffalse
  473. %<*package>
  474. % \fi
  475. %
  476. % \begin{macrocode}
  477. \ProvidesPackage{brunnian}
  478. % \end{macrocode}
  479. %
  480. % Test for \Verb+htlatex+ by looking for the \Verb+tex4ht+ package.
  481. % If found, set the \Verb+pgfsysdriver+ to the appropriate one
  482. %
  483. % \begin{macrocode}
  484. \newif\ifsvg
  485. \@ifpackageloaded{tex4ht}{
  486. \svgtrue
  487. }{}
  488. \ifsvg
  489. \def\pgfsysdriver{pgfsys-tex4ht.def}
  490. \fi
  491. % \end{macrocode}
  492. %
  493. % Load in required packages
  494. %
  495. % \begin{macrocode}
  496. \RequirePackage[svgnames]{xcolor}
  497. \RequirePackage{tikz}
  498. \RequirePackage{colorinfo}
  499. \usetikzlibrary{calc}
  500. % \end{macrocode}
  501. %
  502. % Handle background colour: set the default to \Verb+white+, define a command to reset it, and at the beginning of the document, we read in the colour information needed to recognise \Verb+white+ when we see it.
  503. % (Not sure why that has to be at the beginning of the document and not here.)
  504. %
  505. % \begin{macrocode}
  506. \xglobal\colorlet{background}{white}
  507. % \end{macrocode}
  508. %
  509. % \begin{macro}{\resetbgcolour}
  510. % Allows for resetting the background colour.
  511. % \begin{macrocode}
  512. \newcommand{\resetbgcolour}[1]{%
  513. \xglobal\colorlet{background}{#1}
  514. \colorInfo{background}
  515. \edef\br@white{\colorValue}
  516. }
  517. % \end{macrocode}
  518. % \end{macro}
  519. %
  520. % \begin{macrocode}
  521. \AtBeginDocument{%
  522. \colorInfo{background}%
  523. \edef\br@white{\colorValue}%
  524. }
  525. % \end{macrocode}
  526. %
  527. % Now we set up the default colours for the rings.
  528. %
  529. % \begin{macrocode}
  530. \xglobal\colorlet{ring1}{Red}
  531. \xglobal\colorlet{ring2}{Green}
  532. \xglobal\colorlet{ring3}{Blue}
  533. \xglobal\colorlet{ring4}{Orange}
  534. \xglobal\colorlet{ring5}{Purple}
  535. \xglobal\colorlet{ring6}{Chartreuse}
  536. \xglobal\colorlet{ring7}{Sienna}
  537. \xglobal\colorlet{ring8}{DeepPink}
  538. \xglobal\colorlet{ring9}{Gold}
  539. \xglobal\colorlet{ring10}{DarkViolet}
  540. \foreach \k in {1,2,3,4} {
  541. \foreach \m in {1,2,3,4} {
  542. \pgfmathparse{int(Mod(\m + \k - 2,4) + 1)}
  543. \xglobal\colorlet{ring\k\m}{ring\k!50!ring\pgfmathresult}
  544. \foreach \l in {1,2,3,4} {
  545. \pgfmathparse{int(Mod(\l + \k - 2,4) + 1)}
  546. \xglobal\colorlet{ring\k\m\l}{ring\k\m!50!ring\pgfmathresult}
  547. }
  548. }
  549. }
  550. % \end{macrocode}
  551. %
  552. % Next step is to initialise the pgf layers.
  553. %
  554. % \begin{macrocode}
  555. \pgfdeclarelayer{back}
  556. \pgfdeclarelayer{front}
  557. \pgfsetlayers{back,main,front}
  558. % \end{macrocode}
  559. %
  560. % Now some default constants
  561. %
  562. % \begin{macrocode}
  563. \pgfmathsetmacro{\br@step}{1/4}
  564. \pgfmathsetmacro{\br@theta}{10}
  565. \let\brstep=\br@step
  566. \edef\br@one{1}
  567. \edef\br@zero{0}
  568. % \end{macrocode}
  569. % \begin{macro}{\setbrste}
  570. % \begin{macrocode}
  571. \newcommand{\setbrstep}[1]{%
  572. \def\br@step{#1}}
  573. % \end{macrocode}
  574. % \end{macro}
  575. %
  576. % These define some Ti\emph{k}Z styles for use with knot and link diagrams.
  577. %
  578. % \begin{macrocode}
  579. \tikzset{knot/.style={double distance=1pt,line width=2pt,background}}
  580. \tikzset{thin knot/.style={double distance=.5pt,line width=1pt,background}}
  581. \tikzset{thick knot/.style={double distance=2pt,line width=4pt,background}}
  582. \tikzset{string/.style={line width=1pt}}
  583. % \end{macrocode}
  584. %
  585. % \begin{macro}{\getangle}
  586. %
  587. % Tells us the angles used by the junction command so we don't have to guess them later on, same parameters as the junction command (actually \cmd{\junction} should call this so we always know we do the same computation).
  588. %
  589. % \begin{macrocode}
  590. \newcommand{\getangle}[5]{%
  591. \pgfmathsetmacro{\br@num}{int(4 ^ (#1 - 1) + .5)}
  592. \pgfmathsetmacro{\br@dir}{#3}
  593. \pgfmathsetmacro{\br@innersep}{#1 == 1 ? 4 : 0}
  594. \pgfmathsetmacro{\br@mr}{#2 -\br@step + (2*\br@num + .5) *\br@step * (1 - \br@dir)}
  595. \pgfmathsetmacro{\br@angle}{atan((6 * \br@num + 2*\br@innersep) * \br@step/\br@mr)}
  596. \ifx\relax#4\relax
  597. \pgfmathparse{ceil(\br@angle)}
  598. \else
  599. \pgfmathparse{int(#4 > \br@angle ? #4 : ceil(\br@angle))}
  600. \fi
  601. \xdef\clockangle{\pgfmathresult}
  602. \ifx\relax#5\relax
  603. \pgfmathparse{ceil(\br@angle)}
  604. \else
  605. \pgfmathparse{int(#5 > \br@angle ? #5 : ceil(\br@angle))}
  606. \fi
  607. \xdef\aclockangle{\pgfmathresult}
  608. \pgfmathparse{int(\clockangle + \aclockangle)}
  609. \xdef\totalangle{\pgfmathresult}
  610. }
  611. % \end{macrocode}
  612. % \end{macro}
  613. %
  614. % \begin{macro}{\junction}
  615. % Main junction command
  616. %
  617. % \begin{macrocode}
  618. \newcommand{\junction}[5]{%
  619. \pgfmathsetmacro{\br@midpt}{#3}
  620. \pgfmathsetmacro{\br@dir}{(\br@midpt == 0 ? 1 : \br@midpt)}
  621. \begin{scope}[xscale=\br@dir]
  622. \pgfmathsetmacro{\br@num}{int(4 ^ (#1 - 1) + .5)}
  623. \pgfmathsetmacro{\br@innersep}{#1 == 1 ? 4 : 0}
  624. \pgfmathsetmacro{\br@mr}{#2 -\br@step + (2*\br@num + .5) *\br@step * (1 - \br@dir)}
  625. \pgfmathsetmacro{\br@angle}{atan((6 * \br@num + 2*\br@innersep) * \br@step/\br@mr)}
  626. \ifx\relax#4\relax
  627. \pgfmathsetmacro{\br@outerangle}{ceil(\br@angle)}
  628. \else
  629. \pgfmathsetmacro{\br@outerangle}{#4 > \br@angle ? #4 : ceil(\br@angle)}
  630. \fi
  631. \ifx\relax#5\relax
  632. \pgfmathsetmacro{\br@innerangle}{ceil(\br@angle)}
  633. \else
  634. \pgfmathsetmacro{\br@innerangle}{#5 > \br@angle ? #5 : ceil(\br@angle)}
  635. \fi
  636. \pgfmathsetmacro{\br@sin}{sin(\br@angle)}
  637. \pgfmathsetmacro{\br@cos}{cos(\br@angle)}
  638. \path (0,0) circle (2pt);
  639. \edef\br@itstart{1}
  640. \pgfmathsetmacro{\br@itend}{2*\br@num}
  641. \edef\br@mcolor{outer}
  642. \foreach \br@m in {\br@itstart,...,\br@itend} {
  643. \@ifundefinedcolor{outer\br@m}{%
  644. }{%
  645. \global\edef\br@mcolor{outer\br@m}
  646. }
  647. \pgfmathsetmacro{\br@inr}{\br@mr + \br@m * \br@dir * \br@step}
  648. \pgfmathsetmacro{\br@outr}{\br@mr + (\br@num * 4 + 1 - \br@m) * \br@dir * \br@step}
  649. \pgfmathsetmacro{\br@x}{-1*\br@inr *\br@sin}
  650. \pgfmathsetmacro{\br@y}{-1*\br@inr *\br@cos}
  651. \pgfmathsetmacro{\br@xx}{-1*\br@outr *\br@sin}
  652. \pgfmathsetmacro{\br@yy}{-1*\br@outr *\br@cos}
  653. \pgfmathsetmacro{\br@r}{(6*\br@num - 2*\br@m + \br@innersep)*\br@step/2}
  654. \pgfmathsetmacro{\br@midr}{(\br@midpt == 0 ? (\br@inr + \br@outr)/2 + \br@r: \br@outr)}
  655. \colorInfo{\br@mcolor}
  656. \ifx\colorValue\br@white
  657. \else
  658. \draw[knot,double=\br@mcolor] (\br@xx,\br@yy) to[out=-\br@angle,in=180] (0,-\br@midr) arc(-\br@dir * 90:\br@dir * 90:\br@r) to[out=180,in=-\br@angle] (\br@x,\br@y);
  659. \draw[knot,double=\br@mcolor] (\br@x,\br@y) arc(-90-\br@angle:-90-\br@outerangle:\br@inr);
  660. \draw[knot,double=\br@mcolor] (\br@xx,\br@yy) arc(-90-\br@angle:-90-\br@outerangle:\br@outr);
  661. \fi
  662. }
  663. \edef\br@itstart{1}
  664. \pgfmathsetmacro{\br@itend}{2*\br@num}
  665. \edef\br@mcolor{inner}
  666. \foreach \br@m in {\br@itstart,...,\br@itend} {
  667. \@ifundefinedcolor{inner\br@m}{%
  668. }{%
  669. \global\edef\br@mcolor{inner\br@m}
  670. }
  671. \pgfmathsetmacro{\br@inward}{2 * (-.5 + (\br@m > \br@num))}
  672. \pgfmathsetmacro{\br@inr}{\br@mr + (\br@num+\br@m) * \br@dir * \br@step}
  673. \pgfmathsetmacro{\br@outr}{\br@mr + (3*\br@num + 1 + \br@inward * 2*\br@num - \br@m) * \br@dir * \br@step}
  674. \pgfmathsetmacro{\br@inmidr}{\br@inr - \br@midpt * \br@innersep * \br@step / 2 - \br@num * \br@midpt * \br@step + .5*\br@midpt * \br@step}
  675. \pgfmathsetmacro{\br@outmidr}{\br@outr - \br@midpt * \br@innersep * \br@step /2 + \br@inward * \br@dir * \br@innersep * \br@step/2 - \br@num * \br@midpt * \br@step + .5*\br@midpt * \br@step}
  676. \pgfmathsetmacro{\br@x}{\br@inr *\br@sin}
  677. \pgfmathsetmacro{\br@y}{-1*\br@inr *\br@cos}
  678. \pgfmathsetmacro{\br@xx}{\br@outr *\br@sin}
  679. \pgfmathsetmacro{\br@yy}{-1*\br@outr *\br@cos}
  680. \pgfmathsetmacro{\br@r}{(\br@num * (1 + \br@inward) - \br@inward * (\br@m - .5)) *\br@step + \br@innersep * \br@step/4}
  681. \colorInfo{\br@mcolor}
  682. \ifx\colorValue\br@white
  683. \else
  684. \begin{pgfonlayer}{front}
  685. \draw[knot,double=\br@mcolor] (\br@xx,\br@yy) to[out=180+\br@angle,in=0] (0,-\br@outmidr) arc(\br@inward *\br@dir * 270:\br@inward *\br@dir * 90:\br@r);
  686. \draw[knot,double=\br@mcolor] (\br@xx,\br@yy) arc(-90+\br@angle:-90+\br@innerangle:\br@outr);
  687. \end{pgfonlayer}
  688. \begin{pgfonlayer}{back}
  689. \draw[knot,double=\br@mcolor] (\br@x,\br@y) to[out=180+\br@angle,in=0] (0,-\br@inmidr);
  690. \draw[knot,double=\br@mcolor] (\br@x,\br@y) arc(-90+\br@angle:-90+\br@innerangle:\br@inr);
  691. \end{pgfonlayer}
  692. \fi
  693. }
  694. \end{scope}
  695. }
  696. % \end{macrocode}
  697. % \end{macro}
  698. %
  699. % \begin{macro}{\flatjunction}
  700. % The flat version of \cmd{\junction}
  701. %
  702. % \begin{macrocode}
  703. \newcommand{\flatjunction}[5]{%
  704. \begin{scope}[xscale=#3]
  705. \pgfmathsetmacro{\br@num}{4 ^ (#1 - 1)}
  706. \pgfmathsetmacro{\br@dir}{#3}
  707. \pgfmathsetmacro{\br@innersep}{#1 == 1 ? 4 : 0}
  708. \pgfmathsetmacro{\br@mr}{0}%#2 -\br@step + (2*\br@num + .5) *\br@step * (1 - \br@dir)}
  709. \edef\br@itstart{1}
  710. \pgfmathsetmacro{\br@itend}{2*\br@num}
  711. \edef\br@mcolor{outer}
  712. \foreach \br@m in {\br@itstart,...,\br@itend} {
  713. \@ifundefinedcolor{outer\br@m}{%
  714. }{%
  715. \global\edef\br@mcolor{outer\br@m}
  716. }
  717. \pgfmathsetmacro{\br@inr}{\br@mr + \br@m * \br@dir * \br@step}
  718. \pgfmathsetmacro{\br@outr}{\br@mr + (\br@num * 4 + 1 - \br@m) * \br@dir * \br@step}
  719. \pgfmathsetmacro{\br@x}{-8*\br@step}
  720. \pgfmathsetmacro{\br@y}{-1*\br@inr}
  721. \pgfmathsetmacro{\br@xx}{-8*\br@step}
  722. \pgfmathsetmacro{\br@yy}{-1*\br@outr}
  723. \pgfmathsetmacro{\br@r}{(6*\br@num - 2*\br@m + \br@innersep)*\br@step/2}
  724. \colorInfo{\br@mcolor}
  725. \ifx\colorValue\br@white
  726. \else
  727. \draw[knot,double=\br@mcolor] (\br@xx,\br@yy) -- ++(8*\br@step,0) arc(-90:-90:\br@outr) arc(-\br@dir * 90:\br@dir * 90:\br@r) to[out=180,in=0] (\br@x,\br@y);
  728. \fi
  729. }
  730. \edef\br@itstart{1}
  731. \pgfmathsetmacro{\br@itend}{2*\br@num}
  732. \edef\br@mcolor{inner}
  733. \foreach \br@m in {\br@itstart,...,\br@itend} {
  734. \@ifundefinedcolor{inner\br@m}{%
  735. }{%
  736. \global\edef\br@mcolor{inner\br@m}
  737. }
  738. \pgfmathsetmacro{\br@inward}{2 * (-.5 + (\br@m > \br@num))}
  739. \pgfmathsetmacro{\br@inr}{\br@mr + (\br@num+\br@m) * \br@dir * \br@step}
  740. \pgfmathsetmacro{\br@outr}{\br@mr + (3*\br@num + 1 + \br@inward * 2*\br@num - \br@m) * \br@dir * \br@step}
  741. \pgfmathsetmacro{\br@inmidr}{\br@inr - \br@dir * \br@innersep * \br@step / 2 - \br@num * \br@dir * \br@step + .5*\br@dir * \br@step}
  742. \pgfmathsetmacro{\br@outmidr}{\br@outr - \br@dir * \br@innersep * \br@step /2 + \br@inward * \br@dir * \br@innersep * \br@step/2 - \br@num * \br@dir * \br@step + .5*\br@dir * \br@step}
  743. \pgfmathsetmacro{\br@x}{8*\br@step}
  744. \pgfmathsetmacro{\br@y}{-1*\br@inr}
  745. \pgfmathsetmacro{\br@xx}{8*\br@step}
  746. \pgfmathsetmacro{\br@yy}{-1*\br@outr}
  747. \pgfmathsetmacro{\br@r}{(\br@num * (1 + \br@inward) - \br@inward * (\br@m - .5)) *\br@step + \br@innersep * \br@step/4}
  748. \colorInfo{\br@mcolor}
  749. \ifx\colorValue\br@white
  750. \else
  751. \draw[knot,double=\br@mcolor] (\br@xx,\br@yy) to[out=180,in=0] (0,-\br@outmidr) arc(\br@inward *\br@dir * 270:\br@inward *\br@dir * 90:\br@r);
  752. \begin{pgfonlayer}{back}
  753. \draw[knot,double=\br@mcolor] (\br@x,\br@y) to[out=180,in=0] (0,-\br@inmidr);
  754. \end{pgfonlayer}
  755. \fi
  756. }
  757. \end{scope}
  758. }
  759. % \end{macrocode}
  760. % \end{macro}
  761. %
  762. % \begin{macro}{\gethopfangle}
  763. % This is the Hopfian version of \cmd{\getangle}.
  764. %
  765. % \begin{macrocode}
  766. \newcommand{\gethopfangle}[5]{%
  767. \pgfmathsetmacro{\br@num}{2 ^ (#1 - 1)}
  768. \pgfmathsetmacro{\br@dir}{#3}
  769. \pgfmathsetmacro{\br@innersep}{2}%{#1 == 1 ? 2 : 0}
  770. \pgfmathsetmacro{\br@mr}{#2 -\br@step + (\br@num + .5) *\br@step * (1 - \br@dir)}
  771. \pgfmathsetmacro{\br@angle}{atan((3 * \br@num + 2*\br@innersep) * \br@step/\br@mr)}
  772. \ifx\relax#4\relax
  773. \pgfmathparse{ceil(\br@angle)}
  774. \else
  775. \pgfmathparse{int(#4 > \br@angle ? #4 : ceil(\br@angle))}
  776. \fi
  777. \xdef\clockangle{\pgfmathresult}
  778. \ifx\relax#5\relax
  779. \pgfmathparse{ceil(\br@angle)}
  780. \else
  781. \pgfmathparse{int(#5 > \br@angle ? #5 : ceil(\br@angle))}
  782. \fi
  783. \xdef\aclockangle{\pgfmathresult}
  784. \pgfmathparse{int(\clockangle + \aclockangle)}
  785. \xdef\totalangle{\pgfmathresult}
  786. }
  787. % \end{macrocode}
  788. % \end{macro}
  789. %
  790. % \begin{macro}{\hopfjunction}
  791. % And the Hopfian version of \cmd{\junction}.
  792. % \begin{macrocode}
  793. \newcommand{\hopfjunction}[5]{%
  794. \begin{scope}[xscale=#3]
  795. \pgfmathsetmacro{\br@num}{2 ^ (#1 - 1)}
  796. \pgfmathsetmacro{\br@dir}{#3}
  797. \pgfmathsetmacro{\br@innersep}{2}%{#1 < 3 ? 2 : 0}
  798. \pgfmathsetmacro{\br@mr}{#2 -\br@step + (\br@num + .5) *\br@step * (1 - \br@dir)}
  799. \pgfmathsetmacro{\br@angle}{atan((3 * \br@num + 2*\br@innersep) * \br@step/\br@mr)}
  800. \ifx\relax#4\relax
  801. \pgfmathsetmacro{\br@outerangle}{ceil(\br@angle)}
  802. \else
  803. \pgfmathsetmacro{\br@outerangle}{#4 > \br@angle ? #4 : ceil(\br@angle)}
  804. \fi
  805. \ifx\relax#5\relax
  806. \pgfmathsetmacro{\br@innerangle}{ceil(\br@angle)}
  807. \else
  808. \pgfmathsetmacro{\br@innerangle}{#5 > \br@angle ? #5 : ceil(\br@angle)}
  809. \fi
  810. \pgfmathsetmacro{\br@sin}{sin(\br@angle)}
  811. \pgfmathsetmacro{\br@cos}{cos(\br@angle)}
  812. \path (0,0) circle (2pt);
  813. \edef\br@itstart{1}
  814. \pgfmathsetmacro{\br@itend}{\br@num}
  815. \edef\br@mcolor{outer}
  816. \foreach \br@m in {\br@itstart,...,\br@itend} {
  817. \@ifundefinedcolor{outer\br@m}{%
  818. }{%
  819. \global\edef\br@mcolor{outer\br@m}
  820. }
  821. \pgfmathsetmacro{\br@inr}{\br@mr + \br@m * \br@dir * \br@step}
  822. \pgfmathsetmacro{\br@outr}{\br@mr + (\br@num * 2 + 1 - \br@m) * \br@dir * \br@step}
  823. \pgfmathsetmacro{\br@x}{-1*\br@inr *\br@sin}
  824. \pgfmathsetmacro{\br@y}{-1*\br@inr *\br@cos}
  825. \pgfmathsetmacro{\br@xx}{-1*\br@outr *\br@sin}
  826. \pgfmathsetmacro{\br@yy}{-1*\br@outr *\br@cos}
  827. \pgfmathsetmacro{\br@r}{(\br@num - \br@m + \br@innersep + .5)*\br@step}
  828. \colorInfo{\br@mcolor}
  829. \ifx\colorValue\br@white
  830. \else
  831. \draw[knot,double=\br@mcolor] (\br@xx,\br@yy) arc(-90-\br@angle:-90:\br@outr) arc(-\br@dir * 90:\br@dir * 90:\br@r) to[out=180,in=-\br@angle] (\br@x,\br@y);
  832. \draw[knot,double=\br@mcolor] (\br@x,\br@y) arc(-90-\br@angle:-90-\br@outerangle:\br@inr);
  833. \draw[knot,double=\br@mcolor] (\br@xx,\br@yy) arc(-90-\br@angle:-90-\br@outerangle:\br@outr);
  834. \fi
  835. }
  836. \edef\br@itstart{1}
  837. \pgfmathsetmacro{\br@itend}{\br@num}
  838. \edef\br@mcolor{inner}
  839. \foreach \br@m in {\br@itstart,...,\br@itend} {
  840. \@ifundefinedcolor{inner\br@m}{%
  841. }{%
  842. \global\edef\br@mcolor{inner\br@m}
  843. }
  844. \pgfmathsetmacro{\br@inr}{\br@mr + \br@m * \br@dir * \br@step}
  845. \pgfmathsetmacro{\br@outr}{\br@mr + (\br@num * 2 + 1 - \br@m) * \br@dir * \br@step}
  846. \pgfmathsetmacro{\br@x}{\br@inr *\br@sin}
  847. \pgfmathsetmacro{\br@y}{-1*\br@inr *\br@cos}
  848. \pgfmathsetmacro{\br@xx}{\br@outr *\br@sin}
  849. \pgfmathsetmacro{\br@yy}{-1*\br@outr *\br@cos}
  850. \pgfmathsetmacro{\br@r}{-(\br@num - \br@m + \br@innersep + .5)*\br@step}
  851. \colorInfo{\br@mcolor}
  852. \ifx\colorValue\br@white
  853. \else
  854. \draw[knot,double=\br@mcolor] (\br@xx,\br@yy) arc(-90+\br@angle:-90:\br@outr) arc(\br@dir * 90:0:\br@r);
  855. \begin{pgfonlayer}{back}
  856. \draw[knot,double=\br@mcolor] (\br@x,\br@y) to[out=180+\br@angle,in=0] (0,-\br@outr - \br@dir * 2*\br@r) arc(-\br@dir * 90:0:\br@r);
  857. \end{pgfonlayer}
  858. \draw[knot,double=\br@mcolor] (\br@x,\br@y) arc(-90+\br@angle:-90+\br@innerangle:\br@inr);
  859. \draw[knot,double=\br@mcolor] (\br@xx,\br@yy) arc(-90+\br@angle:-90+\br@innerangle:\br@outr);
  860. \fi
  861. }
  862. \end{scope}
  863. }
  864. % \end{macrocode}
  865. % \end{macro}
  866. %
  867. %
  868. %
  869. % \begin{macro}{\brunnian}
  870. % Level One: Brunnian rings of radius \#2 with \#3 components, \#1 is a "doubling" parameter
  871. % \begin{macrocode}
  872. \newcommand{\brunnian}[3][1]{%
  873. \pgfmathsetmacro{\br@n}{#3}
  874. \pgfmathsetmacro{\br@phi}{360/\br@n}
  875. \pgfmathsetmacro{\br@psi}{180/\br@n}
  876. \foreach \br@k in {1,...,\br@n} {
  877. \pgfmathparse{int(\br@k == 1 ? \br@n : \br@k - 1)}
  878. \edef\br@m{\pgfmathresult}
  879. \begin{scope}[rotate=\br@m * \br@phi]
  880. \colorlet{outer}{ring\br@m}
  881. \colorlet{inner}{ring\br@k}
  882. \junction{#1}{#2}{1}{\br@psi}{\br@psi}
  883. \end{scope}
  884. }
  885. }
  886. % \end{macrocode}
  887. % \end{macro}
  888. %
  889. % \begin{macro}{\outbrunnian}
  890. % Level One: Outward Brunnian rings of radius \#2 with \#3 components, \#1 is a "doubling" parameter.
  891. % This one points outwards
  892. % \begin{macrocode}
  893. \newcommand{\outbrunnian}[3][1]{%
  894. \pgfmathsetmacro{\br@n}{#3}
  895. \pgfmathsetmacro{\br@phi}{360/\br@n}
  896. \pgfmathsetmacro{\br@psi}{180/\br@n}
  897. \foreach \br@k in {1,...,\br@n} {
  898. \pgfmathparse{int(\br@k == 1 ? \br@n : \br@k - 1)}
  899. \edef\br@m{\pgfmathresult}
  900. \begin{scope}[rotate=\br@m * \br@phi]
  901. \colorlet{inner}{ring\br@m}
  902. \colorlet{outer}{ring\br@k}
  903. \junction{#1}{#2}{-1}{\br@psi}{\br@psi}
  904. \end{scope}
  905. }
  906. }
  907. % \end{macrocode}
  908. % \end{macro}
  909. %
  910. % \begin{macro}{\midbrunnian}
  911. % Level One: Midward Brunnian rings of radius \#2 with \#3 components, \#1 is a "doubling" parameter.
  912. % This one is symmetrical.
  913. %
  914. % \begin{macrocode}
  915. \newcommand{\midbrunnian}[3][1]{%
  916. \pgfmathsetmacro{\br@n}{#3}
  917. \pgfmathsetmacro{\br@phi}{360/\br@n}
  918. \pgfmathsetmacro{\br@psi}{180/\br@n}
  919. \foreach \br@k in {1,...,\br@n} {
  920. \pgfmathparse{int(\br@k == 1 ? \br@n : \br@k - 1)}
  921. \edef\br@m{\pgfmathresult}
  922. \begin{scope}[rotate=\br@m * \br@phi]
  923. \colorlet{outer}{ring\br@m}
  924. \colorlet{inner}{ring\br@k}
  925. \junction{#1}{#2}{0}{\br@psi}{\br@psi}
  926. \end{scope}
  927. }
  928. }
  929. % \end{macrocode}
  930. % \end{macro}
  931. %
  932. % \begin{macro}{\brunniantwo}
  933. % \begin{macrocode}
  934. \newcommand{\brunniantwo}[3]{%
  935. \edef\br@p{#3}
  936. \edef\br@q{#2}
  937. \pgfmathsetmacro{\br@radius}{#1}
  938. \pgfmathparse{int(mod(\br@q,2))}
  939. \edef\br@qodd{\pgfmathresult}
  940. \pgfmathparse{int(\br@q - 1 + \br@qodd)}
  941. \edef\br@qmo{\pgfmathresult}
  942. \pgfmathparse{int(\br@q == 1 ? 1 : 2)}
  943. \edef\br@qtwo{\pgfmathresult}
  944. \pgfmathsetmacro{\br@phi}{360/\br@p}
  945. \pgfmathsetmacro{\br@psi}{180/(\br@p * (ceil(\br@q/2)+1))}
  946. \foreach \br@k in {1,...,\br@p} {
  947. \pgfmathparse{int(\br@k == 1 ? \br@p : \br@k - 1)}
  948. \edef\br@m{\pgfmathresult}
  949. \begin{scope}[rotate=\br@m * \br@phi]
  950. \colorlet{outer}{ring\br@k\br@qtwo}
  951. \colorlet{outer5}{ring\br@k\br@qmo}
  952. \colorlet{inner}{ring\br@m\br@qmo}
  953. \junction{2}{\br@radius}{-1}{\br@psi}{\br@psi}
  954. \begin{scope}[rotate=\br@phi/2]
  955. \foreach \br@i in {1,...,\br@q} {
  956. \pgfmathsetmacro{\br@rho}{(\br@i - (1 - mod(\br@i,2))*(1 - \br@qodd) - ceil(\br@q/2)) * \br@psi}
  957. \begin{scope}[rotate=\br@rho]
  958. \pgfmathsetmacro{\br@mi}{mod(\br@i,2)}
  959. \pgfmathsetmacro{\br@modi}{(-1)^\br@mi}
  960. \pgfmathparse{int(\br@i == 1 || \br@i == \br@q - \br@qodd ? \br@i + \br@qtwo - 1 - 2*(1 - \br@qodd)*(1 - \br@mi) : \br@i + \br@modi * 2)}
  961. \edef\br@j{\pgfmathresult}
  962. \colorlet{outer}{ring\br@k\br@i}
  963. \colorlet{inner}{ring\br@k\br@j}
  964. \junction{1}{\br@radius+12 * \br@mi * \br@step}{\br@modi}{\br@psi}{\br@psi}
  965. \end{scope}
  966. }
  967. \end{scope}
  968. \ifx\br@qodd\br@one
  969. \fillin{\br@radius}{1}{4}{\br@psi}{(1.5 + \br@qodd/2)*\br@psi}{ring\br@k\br@qtwo}
  970. \fillin{\br@radius}{1}{4}{\br@phi -\br@psi}{\br@phi - (1.5 + \br@qodd/2)*\br@psi}{ring\br@k\br@qmo}
  971. \fi
  972. \fillin{\br@radius}{5}{12}{\br@psi}{\br@phi - \br@psi}{ring\br@k\br@qmo}
  973. \end{scope}
  974. }
  975. }
  976. % \end{macrocode}
  977. % \end{macro}
  978. %
  979. %
  980. % \begin{macro}{\fillin}
  981. % \begin{macrocode}
  982. \newcommand{\fillin}[6]{%
  983. \colorInfo{#6}
  984. \ifx\colorValue\br@white
  985. \else
  986. \pgfmathsetmacro{\br@sin}{sin(#4)};
  987. \pgfmathsetmacro{\br@cos}{cos(#4)}
  988. \foreach \br@fk in {#2,...,#3} {
  989. \pgfmathsetmacro{\br@r}{#1 + (\br@fk - 1) * \br@step}
  990. \draw[knot,double=#6] (\br@r * \br@sin, -\br@r * \br@cos) arc(-90+#4:-90+#5:\br@r);
  991. }
  992. \fi
  993. }
  994. % \end{macrocode}
  995. % \end{macro}
  996. %
  997. % \begin{macro}{\hopfring}
  998. % \begin{macrocode}
  999. \newcommand{\hopfring}[2]{%
  1000. \pgfmathsetmacro{\br@n}{#2}
  1001. \pgfmathsetmacro{\br@phi}{360/\br@n}
  1002. \gethopfangle{1}{#1}{1}{}{}
  1003. \pgfmathsetmacro{\br@psi}{360/\br@n - \clockangle}
  1004. \foreach \br@k in {1,...,\br@n} {
  1005. \pgfmathparse{int(\br@k == 1 ? \br@n : \br@k - 1)}
  1006. \edef\br@m{\pgfmathresult}
  1007. \begin{scope}[rotate=\br@m * \br@phi]
  1008. \colorlet{outer}{ring\br@m}
  1009. \colorlet{inner}{ring\br@k}
  1010. \hopfjunction{1}{#1}{1}{}{}
  1011. \pgfmathparse{Mod(\br@k,2) == 0 ? "\noexpand\fillin{#1}{1}{2}{\clockangle}{\br@psi}{inner}" : ""}
  1012. \begin{pgfonlayer}{back}
  1013. \pgfmathresult
  1014. \end{pgfonlayer}
  1015. \pgfmathparse{Mod(\br@k,2) == 0 ? "" : "\noexpand\fillin{#1}{1}{2}{\clockangle}{\br@psi}{inner}"}
  1016. \pgfmathresult
  1017. \end{scope}
  1018. }
  1019. }
  1020. % \end{macrocode}
  1021. % \end{macro}
  1022. %
  1023. % \begin{macro}{\hopftwo}
  1024. % \begin{macrocode}
  1025. \newcommand{\hopftwo}[3]{%
  1026. \edef\br@p{#3}
  1027. \edef\br@q{#2}
  1028. \pgfmathsetmacro{\br@radius}{#1}
  1029. \pgfmathsetmacro{\br@qodd}{mod(\br@q,2)}
  1030. \pgfmathparse{int(\br@q - 1 + \br@qodd)}
  1031. \edef\br@qmo{\pgfmathresult}
  1032. \pgfmathparse{int(\br@q == 1 ? 1 : 2)}
  1033. \edef\br@qtwo{\pgfmathresult}
  1034. \pgfmathsetmacro{\br@phi}{360/\br@p}
  1035. \pgfmathsetmacro{\br@psi}{180/(\br@p * (ceil(\br@q/2)+1))}
  1036. \foreach \br@k in {1,...,\br@p} {
  1037. \pgfmathparse{int(\br@k == 1 ? \br@p : \br@k - 1)}
  1038. \edef\br@m{\pgfmathresult}
  1039. \begin{scope}[rotate=\br@m * \br@phi]
  1040. \colorlet{outer}{ring\br@k\br@qtwo}
  1041. \colorlet{outer5}{ring\br@k\br@qmo}
  1042. \colorlet{inner}{ring\br@m\br@qmo}
  1043. \hopfjunction{2}{\br@radius}{-1}{\br@psi}{\br@psi}
  1044. \begin{scope}[rotate=\br@phi/2]
  1045. \foreach \br@i in {1,...,\br@q} {
  1046. \pgfmathsetmacro{\br@rho}{(\br@i - (1 - mod(\br@i,2))*(1 - \br@qodd) - ceil(\br@q/2)) * \br@psi}
  1047. \begin{scope}[rotate=\br@rho]
  1048. \pgfmathsetmacro{\br@mi}{mod(\br@i,2)}
  1049. \pgfmathsetmacro{\br@modi}{(-1)^\br@mi}
  1050. \pgfmathparse{int(\br@i == 1 || \br@i == \br@q - \br@qodd ? \br@i + \br@qtwo - 1 - 2*(1 - \br@qodd)*(1 - \br@mi) : \br@i + \br@modi * 2)}
  1051. \edef\br@j{\pgfmathresult}
  1052. \colorlet{outer}{ring\br@k\br@i}
  1053. \colorlet{inner}{ring\br@k\br@j}
  1054. \hopfjunction{1}{\br@radius+2 * \br@mi * \br@step}{\br@modi}{\br@psi}{\br@psi}
  1055. \end{scope}
  1056. }
  1057. \end{scope}
  1058. \fillin{\br@radius}{1}{2}{\br@psi}{(1.5 + \br@qodd/2)*\br@psi}{ring\br@k\br@qtwo}
  1059. \fillin{\br@radius}{1}{2}{\br@phi -\br@psi}{\br@phi - (1.5 + \br@qodd/2)*\br@psi}{ring\br@k\br@qmo}
  1060. \end{scope}
  1061. }
  1062. }
  1063. % \end{macrocode}
  1064. % \end{macro}
  1065. %
  1066. %
  1067. % \begin{macro}{\chain}
  1068. % \begin{macrocode}
  1069. \newcommand{\chain}{%
  1070. \begin{scope}
  1071. \begin{pgfonlayer}{back}
  1072. \draw[knot,double=chain] (-1.1,0.7) -- ++(0,-1.8) -- ++(.3,0);
  1073. \draw[knot,double=chain] (1.1,0.7) -- ++(0,-1.8) -- ++(-.3,0);
  1074. \draw[knot,double=chain] (-.9,0.7) -- ++(0,-1.6) -- ++(.1,0);
  1075. \draw[knot,double=chain] (.9,0.7) -- ++(0,-1.6) -- ++(-.1,0);
  1076. \end{pgfonlayer}
  1077. \begin{pgfonlayer}{front}
  1078. \draw[knot,double=chain] (-.8,-.9) -- ++(1.6,0);
  1079. \draw[knot,double=chain] (-.8,-1.1) -- ++(1.6,0);
  1080. \end{pgfonlayer}
  1081. \draw[knot,double=chain] (-1,1) circle (.4);
  1082. \draw[background,line width=1.8mm] (-1,0.5) -- ++(0,.2);
  1083. \draw[knot,double=chain] (-1.1,0.5) -- ++(0,.1);
  1084. \draw[knot,double=chain] (-.9,0.5) -- ++(0,.1);
  1085. \draw[knot,double=chain] (1,1) circle (.4);
  1086. \draw[background,line width=1.8mm] (1,0.5) -- ++(0,.2);
  1087. \draw[knot,double=chain] (1.1,0.5) -- ++(0,.1);
  1088. \draw[knot,double=chain] (.9,0.5) -- ++(0,.1);
  1089. \end{scope}
  1090. }
  1091. % \end{macrocode}
  1092. % \end{macro}
  1093. %
  1094. %
  1095. % \begin{macro}{\leftchain}
  1096. % \begin{macrocode}
  1097. \newcommand{\leftchain}{%
  1098. \begin{scope}
  1099. \begin{pgfonlayer}{back}
  1100. \draw[knot,double=chain] (-1.1,2.7) -- ++(0,-3.8) -- ++(.3,0);
  1101. \draw[knot,double=chain] (1.1,0.7) -- ++(0,-1.8) -- ++(-.3,0);
  1102. \draw[knot,double=chain] (-.9,2.7) -- ++(0,-3.6) -- ++(.1,0);
  1103. \draw[knot,double=chain] (.9,0.7) -- ++(0,-1.6) -- ++(-.1,0);
  1104. \end{pgfonlayer}
  1105. \begin{pgfonlayer}{front}
  1106. \draw[knot,double=chain] (-.8,-.9) -- ++(1.6,0);
  1107. \draw[knot,double=chain] (-.8,-1.1) -- ++(1.6,0);
  1108. \end{pgfonlayer}
  1109. \draw[knot,double=chain] (-1,3) circle (.4);
  1110. \draw[background,line width=1.8mm] (-1,2.5) -- ++(0,.2);
  1111. \draw[knot,double=chain] (-1.1,2.5) -- ++(0,.1);
  1112. \draw[knot,double=chain] (-.9,2.5) -- ++(0,.1);
  1113. \draw[knot,double=chain] (1,1) circle (.4);
  1114. \draw[background,line width=1.8mm] (1,0.5) -- ++(0,.2);
  1115. \draw[knot,double=chain] (1.1,0.5) -- ++(0,.1);
  1116. \draw[knot,double=chain] (.9,0.5) -- ++(0,.1);
  1117. \end{scope}
  1118. }
  1119. % \end{macrocode}
  1120. % \end{macro}
  1121. %
  1122. %
  1123. % \begin{macro}{\rightchain}
  1124. % \begin{macrocode}
  1125. \newcommand{\rightchain}{%
  1126. \begin{scope}
  1127. \begin{pgfonlayer}{back}
  1128. \draw[knot,double=chain] (1.1,2.7) -- ++(0,-3.8) -- ++(-.3,0);
  1129. \draw[knot,double=chain] (-1.1,0.7) -- ++(0,-1.8) -- ++(.3,0);
  1130. \draw[knot,double=chain] (.9,2.7) -- ++(0,-3.6) -- ++(-.1,0);
  1131. \draw[knot,double=chain] (-.9,0.7) -- ++(0,-1.6) -- ++(.1,0);
  1132. \end{pgfonlayer}
  1133. \begin{pgfonlayer}{front}
  1134. \draw[knot,double=chain] (-.8,-.9) -- ++(1.6,0);
  1135. \draw[knot,double=chain] (-.8,-1.1) -- ++(1.6,0);
  1136. \end{pgfonlayer}
  1137. \draw[knot,double=chain] (1,3) circle (.4);
  1138. \draw[background,line width=1.8mm] (1,2.5) -- ++(0,.2);
  1139. \draw[knot,double=chain] (1.1,2.5) -- ++(0,.1);
  1140. \draw[knot,double=chain] (.9,2.5) -- ++(0,.1);
  1141. \draw[knot,double=chain] (-1,1) circle (.4);
  1142. \draw[background,line width=1.8mm] (-1,0.5) -- ++(0,.2);
  1143. \draw[knot,double=chain] (-1.1,0.5) -- ++(0,.1);
  1144. \draw[knot,double=chain] (-.9,0.5) -- ++(0,.1);
  1145. \end{scope}
  1146. }
  1147. % \end{macrocode}
  1148. % \end{macro}
  1149. %
  1150. %
  1151. % \begin{macro}{\leftcornerchain}
  1152. % \begin{macrocode}
  1153. \newcommand{\leftcornerchain}{%
  1154. \begin{scope}
  1155. \begin{pgfonlayer}{back}
  1156. \draw[knot,double=chain] (.5,3.1) -- ++(-1.6,0) -- ++(0,-4.2) -- ++(.3,0);
  1157. \draw[knot,double=chain] (1.1,0.7) -- ++(0,-1.8) -- ++(-.3,0);
  1158. \draw[knot,double=chain] (.5,2.9) -- ++(-1.4,0) -- ++(0,-3.8) -- ++(.1,0);
  1159. \draw[knot,double=chain] (.9,0.7) -- ++(0,-1.6) -- ++(-.1,0);
  1160. \end{pgfonlayer}
  1161. \begin{pgfonlayer}{front}
  1162. \draw[knot,double=chain] (-.8,-.9) -- ++(1.6,0);
  1163. \draw[knot,double=chain] (-.8,-1.1) -- ++(1.6,0);
  1164. \end{pgfonlayer}
  1165. \draw[knot,double=chain] (1,3) circle (.4);
  1166. \draw[background,line width=1.8mm] (.5,3) -- ++(.2,0);
  1167. \draw[knot,double=chain] (.5,3.1) -- ++(.1,0);
  1168. \draw[knot,double=chain] (.5,2.9) -- ++(.1,0);
  1169. \draw[knot,double=chain] (1,1) circle (.4);
  1170. \draw[background,line width=1.8mm] (1,0.5) -- ++(0,.2);
  1171. \draw[knot,double=chain] (1.1,0.5) -- ++(0,.1);
  1172. \draw[knot,double=chain] (.9,0.5) -- ++(0,.1);
  1173. \end{scope}
  1174. }
  1175. % \end{macrocode}
  1176. % \end{macro}
  1177. %
  1178. %
  1179. % \begin{macro}{\rightcornerchain}
  1180. % \begin{macrocode}
  1181. \newcommand{\rightcornerchain}{%
  1182. \begin{scope}
  1183. \begin{pgfonlayer}{back}
  1184. \draw[knot,double=chain] (-.5,3.1) -- ++(1.6,0) -- ++(0,-4.2) -- ++(-.3,0);
  1185. \draw[knot,double=chain] (-1.1,0.7) -- ++(0,-1.8) -- ++(.3,0);
  1186. \draw[knot,double=chain] (-.5,2.9) -- ++(1.4,0) -- ++(0,-3.8) -- ++(-.1,0);
  1187. \draw[knot,double=chain] (-.9,0.7) -- ++(0,-1.6) -- ++(.1,0);
  1188. \end{pgfonlayer}
  1189. \begin{pgfonlayer}{front}
  1190. \draw[knot,double=chain] (-.8,-.9) -- ++(1.6,0);
  1191. \draw[knot,double=chain] (-.8,-1.1) -- ++(1.6,0);
  1192. \end{pgfonlayer}
  1193. \draw[knot,double=chain] (-1,3) circle (.4);
  1194. \draw[background,line width=1.8mm] (-.5,3) -- ++(-.2,0);
  1195. \draw[knot,double=chain] (-.5,3.1) -- ++(-.1,0);
  1196. \draw[knot,double=chain] (-.5,2.9) -- ++(-.1,0);
  1197. \draw[knot,double=chain] (-1,1) circle (.4);
  1198. \draw[background,line width=1.8mm] (-1,0.5) -- ++(0,.2);
  1199. \draw[knot,double=chain] (-1.1,0.5) -- ++(0,.1);
  1200. \draw[knot,double=chain] (-.9,0.5) -- ++(0,.1);
  1201. \end{scope}
  1202. }
  1203. % \end{macrocode}
  1204. % \end{macro}
  1205. %
  1206. %
  1207. % \begin{macro}{\brunnianhopf}
  1208. % \begin{macrocode}
  1209. \newcommand{\brunnianhopf}[3]{%
  1210. \edef\br@p{#3}
  1211. \edef\br@q{#2}
  1212. \pgfmathsetmacro{\br@radius}{#1}
  1213. \pgfmathparse{int(mod(\br@q,2))}
  1214. \edef\br@qodd{\pgfmathresult}
  1215. \pgfmathparse{int(\br@q - 1 + \br@qodd)}
  1216. \edef\br@qmo{\pgfmathresult}
  1217. \pgfmathparse{int(\br@q == 1 ? 1 : 2)}
  1218. \edef\br@qtwo{\pgfmathresult}
  1219. \pgfmathsetmacro{\br@phi}{360/\br@p}
  1220. \pgfmathsetmacro{\br@psi}{180/(\br@p * (ceil(\br@q/2)+1))}
  1221. \foreach \br@k in {1,...,\br@p} {
  1222. \pgfmathparse{int(\br@k == 1 ? \br@p : \br@k - 1)}
  1223. \edef\br@m{\pgfmathresult}
  1224. \begin{scope}[rotate=\br@m * \br@phi]
  1225. \colorlet{outer}{ring\br@k\br@qtwo}
  1226. \colorlet{outer3}{ring\br@k\br@qmo}
  1227. \colorlet{inner}{ring\br@m\br@qmo}
  1228. \junction{1.5}{\br@radius}{-1}{\br@psi}{\br@psi}
  1229. \begin{scope}[rotate=\br@phi/2]
  1230. \foreach \br@i in {1,...,\br@q} {
  1231. \pgfmathsetmacro{\br@rho}{(\br@i - (1 - mod(\br@i,2))*(1 - \br@qodd) - ceil(\br@q/2)) * \br@psi}
  1232. \begin{scope}[rotate=\br@rho]
  1233. \pgfmathsetmacro{\br@mi}{mod(\br@i,2)}
  1234. \pgfmathsetmacro{\br@modi}{(-1)^\br@mi}
  1235. \pgfmathparse{int(\br@i == 1 || \br@i == \br@q - \br@qodd ? \br@i + \br@qtwo - 1 - 2*(1 - \br@qodd)*(1 - \br@mi) : \br@i + \br@modi * 2)}
  1236. \edef\br@j{\pgfmathresult}
  1237. \colorlet{outer}{ring\br@k\br@i}
  1238. \colorlet{inner}{ring\br@k\br@j}
  1239. \hopfjunction{1}{\br@radius+6 * \br@mi * \br@step}{\br@modi}{\br@psi}{\br@psi}
  1240. \end{scope}
  1241. }
  1242. \end{scope}
  1243. \ifx\br@qodd\br@one
  1244. \fillin{\br@radius}{1}{2}{\br@psi}{(1.5 + \br@qodd/2)*\br@psi}{ring\br@k\br@qtwo}
  1245. \fillin{\br@radius}{1}{2}{\br@phi -\br@psi}{\br@phi - (1.5 + \br@qodd/2)*\br@psi}{ring\br@k\br@qmo}
  1246. \fi
  1247. \fillin{\br@radius}{3}{6}{\br@psi}{\br@phi - \br@psi}{ring\br@k\br@qmo}
  1248. \end{scope}
  1249. }
  1250. }
  1251. % \end{macrocode}
  1252. % \end{macro}
  1253. %
  1254. %
  1255. % \begin{macro}{\hopfbrunnian}
  1256. % \begin{macrocode}
  1257. \newcommand{\hopfbrunnian}[3]{%
  1258. \edef\br@p{#3}
  1259. \edef\br@q{#2}
  1260. \pgfmathsetmacro{\br@radius}{#1}
  1261. \pgfmathparse{int(mod(\br@q,2))}
  1262. \edef\br@qodd{\pgfmathresult}
  1263. \pgfmathparse{int(\br@q - 1 + \br@qodd)}
  1264. \edef\br@qmo{\pgfmathresult}
  1265. \pgfmathparse{int(\br@q == 1 ? 1 : 2)}
  1266. \edef\br@qtwo{\pgfmathresult}
  1267. \pgfmathsetmacro{\br@phi}{360/\br@p}
  1268. \pgfmathsetmacro{\br@psi}{180/(\br@p * (ceil(\br@q/2)+1))}
  1269. \foreach \br@k in {1,...,\br@p} {
  1270. \pgfmathparse{int(\br@k == 1 ? \br@p : \br@k - 1)}
  1271. \edef\br@m{\pgfmathresult}
  1272. \begin{scope}[rotate=\br@m * \br@phi]
  1273. \colorlet{outer}{ring\br@k\br@qtwo}
  1274. \colorlet{inner}{ring\br@m\br@qmo}
  1275. \hopfjunction{3}{\br@radius}{-1}{\br@psi}{\br@psi}
  1276. \begin{scope}[rotate=\br@phi/2]
  1277. \foreach \br@i in {1,...,\br@q} {
  1278. \pgfmathsetmacro{\br@rho}{(\br@i - (1 - mod(\br@i,2))*(1 - \br@qodd) - ceil(\br@q/2)) * \br@psi}
  1279. \begin{scope}[rotate=\br@rho]
  1280. \pgfmathsetmacro{\br@mi}{mod(\br@i,2)}
  1281. \pgfmathsetmacro{\br@modi}{(-1)^\br@mi}
  1282. \pgfmathparse{int(\br@i == 1 || \br@i == \br@q - \br@qodd ? \br@i + \br@qtwo - 1 - 2*(1 - \br@qodd)*(1 - \br@mi) : \br@i + \br@modi * 2)}
  1283. \edef\br@j{\pgfmathresult}
  1284. \colorlet{outer}{ring\br@k\br@i}
  1285. \colorlet{inner}{ring\br@k\br@j}
  1286. \junction{1}{\br@radius+4 * \br@mi * \br@step}{\br@modi}{\br@psi}{\br@psi}
  1287. \end{scope}
  1288. }
  1289. \end{scope}
  1290. \ifx\br@qodd\br@one
  1291. \fillin{\br@radius}{1}{4}{\br@psi}{(1.5 + \br@qodd/2)*\br@psi}{ring\br@k\br@qtwo}
  1292. \fillin{\br@radius}{1}{4}{\br@phi -\br@psi}{\br@phi - (1.5 + \br@qodd/2)*\br@psi}{ring\br@k\br@qmo}
  1293. \fi
  1294. \end{scope}
  1295. }
  1296. }
  1297. % \end{macrocode}
  1298. % \end{macro}
  1299. %
  1300. %
  1301. % \begin{macro}{\outerhopftwo}
  1302. % \begin{macrocode}
  1303. \newcommand{\outerhopftwo}[3]{%
  1304. \edef\br@p{#3}
  1305. \edef\br@q{#2}
  1306. \pgfmathsetmacro{\br@radius}{#1}
  1307. \pgfmathsetmacro{\br@qodd}{mod(\br@q,2)}
  1308. \pgfmathparse{int(\br@q - 1 + \br@qodd)}
  1309. \edef\br@qmo{\pgfmathresult}
  1310. \pgfmathparse{int(\br@q == 1 ? 1 : 2)}
  1311. \edef\br@qtwo{\pgfmathresult}
  1312. \pgfmathsetmacro{\br@phi}{360/\br@p}
  1313. \pgfmathsetmacro{\br@psi}{180/(\br@p * (\br@q+1))}
  1314. \foreach \br@k in {1,...,\br@p} {
  1315. \pgfmathparse{int(\br@k == 1 ? \br@p : \br@k - 1)}
  1316. \edef\br@m{\pgfmathresult}
  1317. \begin{scope}[rotate=\br@m * \br@phi]
  1318. \colorlet{outer}{ring\br@k\br@qtwo}
  1319. \colorlet{outer5}{ring\br@k\br@qmo}
  1320. \colorlet{inner}{ring\br@m\br@qtwo}
  1321. \hopfjunction{2}{\br@radius}{-1}{\br@psi}{\br@psi}
  1322. \begin{scope}[rotate=\br@phi/2]
  1323. \foreach \br@i in {1,...,\br@q} {
  1324. \pgfmathsetmacro{\br@rho}{2*(\br@i - (\br@q+1)/2 ) * \br@psi}
  1325. \begin{scope}[rotate=\br@rho]
  1326. \pgfmathsetmacro{\br@mi}{mod(\br@i,2)}
  1327. \pgfmathsetmacro{\br@modi}{(-1)^\br@mi}
  1328. \pgfmathparse{int(\br@i == 1 || \br@i == \br@q - \br@qodd ? \br@i + \br@qtwo - 1 - 2*(1 - \br@qodd)*(1 - \br@mi) : \br@i + \br@modi * 2)}
  1329. \edef\br@j{\pgfmathresult}
  1330. \colorlet{outer}{ring\br@k\br@i}
  1331. \colorlet{inner}{ring\br@k\br@j}
  1332. \hopfjunction{1}{\br@radius+2 * \br@step}{-1}{\br@psi}{\br@psi}
  1333. \end{scope}
  1334. }
  1335. \end{scope}
  1336. \fillin{\br@radius}{1}{2}{\br@psi}{180 - \br@psi}{ring\br@k\br@qtwo}
  1337. \end{scope}
  1338. }
  1339. }
  1340. % \end{macrocode}
  1341. % \end{macro}
  1342. %
  1343. %
  1344. % \begin{macro}{\outerbrunniantwo}
  1345. % \begin{macrocode}
  1346. \newcommand{\outerbrunniantwo}[3]{%
  1347. \edef\br@p{#3}
  1348. \edef\br@q{#2}
  1349. \pgfmathsetmacro{\br@radius}{#1}
  1350. \pgfmathsetmacro{\br@qodd}{mod(\br@q,2)}
  1351. \pgfmathparse{int(\br@q - 1 + \br@qodd)}
  1352. \edef\br@qmo{\pgfmathresult}
  1353. \pgfmathparse{int(\br@q == 1 ? 1 : 2)}
  1354. \edef\br@qtwo{\pgfmathresult}
  1355. \pgfmathsetmacro{\br@phi}{360/\br@p}
  1356. \pgfmathsetmacro{\br@psi}{180/(\br@p * (\br@q+1))}
  1357. \foreach \br@k in {1,...,\br@p} {
  1358. \pgfmathparse{int(\br@k == 1 ? \br@p : \br@k - 1)}
  1359. \edef\br@m{\pgfmathresult}
  1360. \begin{scope}[rotate=\br@m * \br@phi]
  1361. \colorlet{outer}{ring\br@k\br@qtwo}
  1362. \colorlet{inner}{ring\br@m\br@qtwo}
  1363. \junction{2}{\br@radius}{-1}{\br@psi}{\br@psi}
  1364. \begin{scope}[rotate=\br@phi/2]
  1365. \foreach \br@i in {1,...,\br@q} {
  1366. \pgfmathsetmacro{\br@rho}{2*(\br@i - (\br@q+1)/2 ) * \br@psi}
  1367. \begin{scope}[rotate=\br@rho]
  1368. \pgfmathsetmacro{\br@mi}{mod(\br@i,2)}
  1369. \pgfmathsetmacro{\br@modi}{(-1)^\br@mi}
  1370. \pgfmathparse{int(\br@i == 1 || \br@i == \br@q - \br@qodd ? \br@i + \br@qtwo - 1 - 2*(1 - \br@qodd)*(1 - \br@mi) : \br@i + \br@modi * 2)}
  1371. \edef\br@j{\pgfmathresult}
  1372. \colorlet{outer}{ring\br@k\br@i}
  1373. \colorlet{inner}{ring\br@k\br@j}
  1374. \junction{1}{\br@radius+12 * \br@step}{-1}{\br@psi}{\br@psi}
  1375. \end{scope}
  1376. }
  1377. \end{scope}
  1378. \fillin{\br@radius}{1}{12}{\br@psi}{180 - \br@psi}{ring\br@k\br@qtwo}
  1379. \end{scope}
  1380. }
  1381. }
  1382. % \end{macrocode}
  1383. % \end{macro}
  1384. %
  1385. %
  1386. % \begin{macro}{\pgf@sh@@knotanchor}
  1387. % \begin{macrocode}
  1388. \def\pgf@sh@@knotanchor#1#2{%
  1389. \anchor{#2 north west}{%
  1390. \csname pgf@anchor@knot #1@north west\endcsname%
  1391. \pgf@x=#2\pgf@x%
  1392. \pgf@y=#2\pgf@y%
  1393. }%
  1394. \anchor{#2 north east}{%
  1395. \csname pgf@anchor@knot #1@north east\endcsname%
  1396. \pgf@x=#2\pgf@x%
  1397. \pgf@y=#2\pgf@y%
  1398. }%
  1399. \anchor{#2 south west}{%
  1400. \csname pgf@anchor@knot #1@south west\endcsname%
  1401. \pgf@x=#2\pgf@x%
  1402. \pgf@y=#2\pgf@y%
  1403. }%
  1404. \anchor{#2 south east}{%
  1405. \csname pgf@anchor@knot #1@south east\endcsname%
  1406. \pgf@x=#2\pgf@x%
  1407. \pgf@y=#2\pgf@y%
  1408. }%
  1409. \anchor{#2 north}{%
  1410. \csname pgf@anchor@knot #1@north\endcsname%
  1411. \pgf@x=#2\pgf@x%
  1412. \pgf@y=#2\pgf@y%
  1413. }%
  1414. \anchor{#2 east}{%
  1415. \csname pgf@anchor@knot #1@east\endcsname%
  1416. \pgf@x=#2\pgf@x%
  1417. \pgf@y=#2\pgf@y%
  1418. }%
  1419. \anchor{#2 west}{%
  1420. \csname pgf@anchor@knot #1@west\endcsname%
  1421. \pgf@x=#2\pgf@x%
  1422. \pgf@y=#2\pgf@y%
  1423. }%
  1424. \anchor{#2 south}{%
  1425. \csname pgf@anchor@knot #1@south\endcsname%
  1426. \pgf@x=#2\pgf@x%
  1427. \pgf@y=#2\pgf@y%
  1428. }%
  1429. }
  1430. % \end{macrocode}
  1431. % \end{macro}
  1432. %
  1433. % \begin{macrocode}
  1434. \pgfdeclareshape{knot crossing}
  1435. {
  1436. \inheritsavedanchors[from=circle] % this is nearly a circle
  1437. \inheritanchorborder[from=circle]
  1438. \inheritanchor[from=circle]{north}
  1439. \inheritanchor[from=circle]{north west}
  1440. \inheritanchor[from=circle]{north east}
  1441. \inheritanchor[from=circle]{center}
  1442. \inheritanchor[from=circle]{west}
  1443. \inheritanchor[from=circle]{east}
  1444. \inheritanchor[from=circle]{mid}
  1445. \inheritanchor[from=circle]{mid west}
  1446. \inheritanchor[from=circle]{mid east}
  1447. \inheritanchor[from=circle]{base}
  1448. \inheritanchor[from=circle]{base west}
  1449. \inheritanchor[from=circle]{base east}
  1450. \inheritanchor[from=circle]{south}
  1451. \inheritanchor[from=circle]{south west}
  1452. \inheritanchor[from=circle]{south east}
  1453. \inheritanchorborder[from=circle]
  1454. \pgf@sh@@knotanchor{crossing}{2}
  1455. \pgf@sh@@knotanchor{crossing}{3}
  1456. \pgf@sh@@knotanchor{crossing}{4}
  1457. \pgf@sh@@knotanchor{crossing}{8}
  1458. \pgf@sh@@knotanchor{crossing}{16}
  1459. \pgf@sh@@knotanchor{crossing}{32}
  1460. \backgroundpath{
  1461. \pgfutil@tempdima=\radius%
  1462. \pgfmathsetlength{\pgf@xb}{\pgfkeysvalueof{/pgf/outer xsep}}%
  1463. \pgfmathsetlength{\pgf@yb}{\pgfkeysvalueof{/pgf/outer ysep}}%
  1464. \ifdim\pgf@xb<\pgf@yb%
  1465. \advance\pgfutil@tempdima by-\pgf@yb%
  1466. \else%
  1467. \advance\pgfutil@tempdima by-\pgf@xb%
  1468. \fi%
  1469. % \pgfpathcircle{\centerpoint}{\pgfutil@tempdima}%
  1470. }
  1471. }
  1472. \pgfdeclareshape{knot over cross}
  1473. {
  1474. \inheritsavedanchors[from=rectangle] % this is nearly a circle
  1475. \inheritanchorborder[from=rectangle]
  1476. \inheritanchor[from=rectangle]{north}
  1477. \inheritanchor[from=rectangle]{north west}
  1478. \inheritanchor[from=rectangle]{north east}
  1479. \inheritanchor[from=rectangle]{center}
  1480. \inheritanchor[from=rectangle]{west}
  1481. \inheritanchor[from=rectangle]{east}
  1482. \inheritanchor[from=rectangle]{mid}
  1483. \inheritanchor[from=rectangle]{mid west}
  1484. \inheritanchor[from=rectangle]{mid east}
  1485. \inheritanchor[from=rectangle]{base}
  1486. \inheritanchor[from=rectangle]{base west}
  1487. \inheritanchor[from=rectangle]{base east}
  1488. \inheritanchor[from=rectangle]{south}
  1489. \inheritanchor[from=rectangle]{south west}
  1490. \inheritanchor[from=rectangle]{south east}
  1491. \inheritanchorborder[from=rectangle]
  1492. \backgroundpath{
  1493. \southwest \pgf@xa=\pgf@x \pgf@ya=\pgf@y
  1494. \northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
  1495. \pgfpathmoveto{\pgfqpoint{\pgf@xa}{\pgf@ya}}
  1496. \pgfpathlineto{\pgfqpoint{\pgf@xb}{\pgf@yb}}
  1497. }
  1498. \foregroundpath{
  1499. % store lower right in xa/ya and upper right in xb/yb
  1500. \southwest \pgf@xa=\pgf@x \pgf@ya=\pgf@y
  1501. \northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
  1502. \pgfpathmoveto{\pgfqpoint{\pgf@xa}{\pgf@yb}}
  1503. \pgfpathlineto{\pgfqpoint{\pgf@xb}{\pgf@ya}}
  1504. }
  1505. }
  1506. \pgfdeclareshape{knot under cross}
  1507. {
  1508. \inheritsavedanchors[from=rectangle] % this is nearly a circle
  1509. \inheritanchorborder[from=rectangle]
  1510. \inheritanchor[from=rectangle]{north}
  1511. \inheritanchor[from=rectangle]{north west}
  1512. \inheritanchor[from=rectangle]{north east}
  1513. \inheritanchor[from=rectangle]{center}
  1514. \inheritanchor[from=rectangle]{west}
  1515. \inheritanchor[from=rectangle]{east}
  1516. \inheritanchor[from=rectangle]{mid}
  1517. \inheritanchor[from=rectangle]{mid west}
  1518. \inheritanchor[from=rectangle]{mid east}
  1519. \inheritanchor[from=rectangle]{base}
  1520. \inheritanchor[from=rectangle]{base west}
  1521. \inheritanchor[from=rectangle]{base east}
  1522. \inheritanchor[from=rectangle]{south}
  1523. \inheritanchor[from=rectangle]{south west}
  1524. \inheritanchor[from=rectangle]{south east}
  1525. \inheritanchorborder[from=rectangle]
  1526. \backgroundpath{
  1527. \southwest \pgf@xa=\pgf@x \pgf@ya=\pgf@y
  1528. \northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
  1529. \pgfpathmoveto{\pgfqpoint{\pgf@xa}{\pgf@yb}}
  1530. \pgfpathlineto{\pgfqpoint{\pgf@xb}{\pgf@ya}}
  1531. }
  1532. \foregroundpath{
  1533. % store lower right in xa/ya and upper right in xb/yb
  1534. \southwest \pgf@xa=\pgf@x \pgf@ya=\pgf@y
  1535. \northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
  1536. \pgfpathmoveto{\pgfqpoint{\pgf@xa}{\pgf@ya}}
  1537. \pgfpathlineto{\pgfqpoint{\pgf@xb}{\pgf@yb}}
  1538. }
  1539. }
  1540. \pgfdeclareshape{knot vert}
  1541. {
  1542. \inheritsavedanchors[from=rectangle] % this is nearly a circle
  1543. \inheritanchorborder[from=rectangle]
  1544. \inheritanchor[from=rectangle]{north}
  1545. \inheritanchor[from=rectangle]{north west}
  1546. \inheritanchor[from=rectangle]{north east}
  1547. \inheritanchor[from=rectangle]{center}
  1548. \inheritanchor[from=rectangle]{west}
  1549. \inheritanchor[from=rectangle]{east}
  1550. \inheritanchor[from=rectangle]{mid}
  1551. \inheritanchor[from=rectangle]{mid west}
  1552. \inheritanchor[from=rectangle]{mid east}
  1553. \inheritanchor[from=rectangle]{base}
  1554. \inheritanchor[from=rectangle]{base west}
  1555. \inheritanchor[from=rectangle]{base east}
  1556. \inheritanchor[from=rectangle]{south}
  1557. \inheritanchor[from=rectangle]{south west}
  1558. \inheritanchor[from=rectangle]{south east}
  1559. \inheritanchorborder[from=rectangle]
  1560. \backgroundpath{
  1561. % store lower right in xa/ya and upper right in xb/yb
  1562. \southwest \pgf@xa=\pgf@x \pgf@ya=\pgf@y
  1563. \northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
  1564. \pgfpathmoveto{\pgfqpoint{\pgf@xa}{\pgf@ya}}
  1565. \pgfpathlineto{\pgfqpoint{\pgf@xa}{\pgf@yb}}
  1566. \pgfpathmoveto{\pgfqpoint{\pgf@xb}{\pgf@yb}}
  1567. \pgfpathlineto{\pgfqpoint{\pgf@xb}{\pgf@ya}}
  1568. }
  1569. }
  1570. \pgfdeclareshape{knot horiz}
  1571. {
  1572. \inheritsavedanchors[from=rectangle] % this is nearly a circle
  1573. \inheritanchorborder[from=rectangle]
  1574. \inheritanchor[from=rectangle]{north}
  1575. \inheritanchor[from=rectangle]{north west}
  1576. \inheritanchor[from=rectangle]{north east}
  1577. \inheritanchor[from=rectangle]{center}
  1578. \inheritanchor[from=rectangle]{west}
  1579. \inheritanchor[from=rectangle]{east}
  1580. \inheritanchor[from=rectangle]{mid}
  1581. \inheritanchor[from=rectangle]{mid west}
  1582. \inheritanchor[from=rectangle]{mid east}
  1583. \inheritanchor[from=rectangle]{base}
  1584. \inheritanchor[from=rectangle]{base west}
  1585. \inheritanchor[from=rectangle]{base east}
  1586. \inheritanchor[from=rectangle]{south}
  1587. \inheritanchor[from=rectangle]{south west}
  1588. \inheritanchor[from=rectangle]{south east}
  1589. \inheritanchorborder[from=rectangle]
  1590. \foregroundpath{
  1591. % store lower right in xa/ya and upper right in xb/yb
  1592. \southwest \pgf@xa=\pgf@x \pgf@ya=\pgf@y
  1593. \northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
  1594. \pgfpathmoveto{\pgfqpoint{\pgf@xa}{\pgf@ya}}
  1595. \pgfpathlineto{\pgfqpoint{\pgf@xb}{\pgf@ya}}
  1596. \pgfpathmoveto{\pgfqpoint{\pgf@xa}{\pgf@yb}}
  1597. \pgfpathlineto{\pgfqpoint{\pgf@xb}{\pgf@yb}}
  1598. }
  1599. }
  1600. % \end{macrocode}
  1601. %
  1602. % \begin{macro}{\flatbrunnianlink}
  1603. % \begin{macrocode}
  1604. \newcommand{\flatbrunnianlink}[1]{%
  1605. \pgfmathsetmacro{\br@scale}{#1}%
  1606. \pgfmathsetmacro{\br@ctwenty}{cos(20)}
  1607. \pgfmathsetmacro{\br@stwenty}{sin(20)}
  1608. \draw[knot,double=chain] (-.5*\br@scale,0) arc(180:270:.5*\br@scale) node[coordinate] (a) {};
  1609. \draw[knot,double=chain] (-.6*\br@scale,0) arc(180:270:.6*\br@scale) node[coordinate] (c) {};
  1610. \begin{pgfonlayer}{front}
  1611. \draw[knot,double=chain] (1.6*\br@scale,0) ++(-.9*\br@scale *\br@ctwenty,-.9*\br@scale *\br@stwenty) arc(0:-90:.2*\br@scale) to[out=180,in=0] (c);
  1612. \end{pgfonlayer}
  1613. \begin{pgfonlayer}{back}
  1614. \draw[knot,double=chain] (-.5*\br@scale,0) arc(180:90:.5*\br@scale) node[coordinate] (b) {};
  1615. \draw[knot,double=chain] (-.6*\br@scale,0) arc(180:90:.6*\br@scale) node[coordinate] (d) {};
  1616. \draw[knot,double=chain] (1.6*\br@scale,0) ++(-.9*\br@scale *\br@ctwenty,-.9*\br@scale *\br@stwenty) arc(0:135:.2*\br@scale) to[out=-135,in=0] (a);
  1617. \draw[knot,double=chain] (1.6*\br@scale,0) ++(-.9*\br@scale *\br@ctwenty,.9*\br@scale *\br@stwenty) arc(0:-135:.2*\br@scale) to[out=135,in=0] (b);
  1618. \end{pgfonlayer}
  1619. \begin{pgfonlayer}{front}
  1620. \draw[knot,double=chain] (1.6*\br@scale,0) ++(-.9*\br@scale *\br@ctwenty,.9*\br@scale *\br@stwenty) arc(0:90:.2*\br@scale) to[out=180,in=0] (d);
  1621. \end{pgfonlayer}
  1622. }
  1623. % \end{macrocode}
  1624. % \end{macro}
  1625. %
  1626. %
  1627. % \begin{macro}{\brunnianlink}
  1628. % \begin{macrocode}
  1629. \newcommand{\brunnianlink}[2]{%
  1630. \pgfmathsetmacro{\br@scale}{#1}
  1631. \pgfmathsetmacro{\br@angle}{#2}
  1632. \begin{scope}[every path/.style={knot,double=chain}]
  1633. \begin{scope}[rotate=-\br@angle + 5]
  1634. \draw (0,-\br@scale) arc (90:270:2.5*\br@step);
  1635. \draw (0,-\br@scale-\br@step) arc (90:270:1.5*\br@step);
  1636. \draw (0,-\br@scale) arc (-90:-85:\br@scale) coordinate (a);
  1637. \draw (0,-\br@scale-\br@step) arc (-90:-85:\br@scale+\br@step) coordinate (b);
  1638. \draw (0,-\br@scale-4*\br@step) arc (-90:-85:\br@scale+3*\br@step) coordinate (c);
  1639. \draw (0,-\br@scale-5*\br@step) arc (-90:-85:\br@scale+4*\br@step) coordinate (d);
  1640. \end{scope}
  1641. \begin{pgfonlayer}{back}
  1642. \draw (0,-\br@scale-2*\br@step) arc(-90:-100:\br@scale+2*\br@step) coordinate (B);
  1643. \draw (0,-\br@scale-3*\br@step) arc(-90:-100:\br@scale+3*\br@step) coordinate (C);
  1644. \end{pgfonlayer}
  1645. \begin{pgfonlayer}{front}
  1646. \draw (0,-\br@scale) arc (90:-90:\br@step);
  1647. \draw (0,-\br@scale) arc (-90:-100:\br@scale) coordinate (A);
  1648. \draw (0,-\br@scale-3*\br@step) arc (90:-90:\br@step);
  1649. \draw (0,-\br@scale-5*\br@step) arc (-90:-100:\br@scale+5*\br@step)coordinate (D);
  1650. \end{pgfonlayer}
  1651. \pgfmathsetmacro{\br@loose}{\br@angle == 180 ? 1.5 : 1}
  1652. \draw (a) to[out=-\br@angle+10,in=170,looseness=\br@loose] (A);
  1653. \draw (b) to[out=-\br@angle+10,in=170,looseness=\br@loose] (B);
  1654. \draw (c) to[out=-\br@angle+10,in=170,looseness=\br@loose] (C);
  1655. \draw (d) to[out=-\br@angle+10,in=170,looseness=\br@loose] (D);
  1656. \end{scope}
  1657. }
  1658. % \end{macrocode}
  1659. % \end{macro}
  1660. %
  1661. %
  1662. % \begin{macro}{\brunniantwocpt}
  1663. % \begin{macrocode}
  1664. \newcommand{\brunniantwocpt}[4]{%
  1665. \edef\br@p{#3}
  1666. \edef\br@q{#2}
  1667. \edef\br@colour{#4}
  1668. \pgfmathsetmacro{\br@radius}{#1}
  1669. \pgfmathparse{int(mod(\br@q,2))}
  1670. \edef\br@qodd{\pgfmathresult}
  1671. \pgfmathparse{int(\br@q - 1 + \br@qodd)}
  1672. \edef\br@qmo{\pgfmathresult}
  1673. \pgfmathparse{int(\br@q == 1 ? 1 : 2)}
  1674. \edef\br@qtwo{\pgfmathresult}
  1675. \pgfmathsetmacro{\br@phi}{360/\br@p}
  1676. \pgfmathsetmacro{\br@psi}{180/(\br@p * (ceil(\br@q/2)+1))}
  1677. \begin{scope}%[rotate=\br@m * \br@phi]
  1678. \colorlet{outer}{\br@colour\br@qtwo}
  1679. \colorlet{outer5}{\br@colour\br@qmo}
  1680. \colorlet{inner}{background}
  1681. \junction{2}{\br@radius}{-1}{\br@psi}{\br@psi}
  1682. \begin{scope}[rotate=\br@phi]
  1683. \colorlet{outer}{background}
  1684. \colorlet{outer5}{background}
  1685. \colorlet{inner}{\br@colour\br@qmo}
  1686. \junction{2}{\br@radius}{-1}{\br@psi}{\br@psi}
  1687. \end{scope}
  1688. \begin{scope}[rotate=\br@phi/2]
  1689. \foreach \br@i in {1,...,\br@q} {
  1690. \pgfmathsetmacro{\br@rho}{(\br@i - (1 - mod(\br@i,2))*(1 - \br@qodd) - ceil(\br@q/2)) * \br@psi}
  1691. \begin{scope}[rotate=\br@rho]
  1692. \pgfmathsetmacro{\br@mi}{mod(\br@i,2)}
  1693. \pgfmathsetmacro{\br@modi}{(-1)^\br@mi}
  1694. \pgfmathparse{int(\br@i == 1 || \br@i == \br@q - \br@qodd ? \br@i + \br@qtwo - 1 - 2*(1 - \br@qodd)*(1 - \br@mi) : \br@i + \br@modi * 2)}
  1695. \edef\br@j{\pgfmathresult}
  1696. \colorlet{outer}{\br@colour\br@i}
  1697. \colorlet{inner}{\br@colour\br@j}
  1698. \junction{1}{\br@radius+12 * \br@mi * \br@step}{\br@modi}{\br@psi}{\br@psi}
  1699. \end{scope}
  1700. }
  1701. \end{scope}
  1702. \ifx\br@qodd\br@one
  1703. \fillin{\br@radius}{1}{4}{\br@psi}{(1.5 + \br@qodd/2)*\br@psi}{\br@colour\br@qtwo}
  1704. \fillin{\br@radius}{1}{4}{\br@phi -\br@psi}{\br@phi - (1.5 + \br@qodd/2)*\br@psi}{\br@colour\br@qmo}
  1705. \fi
  1706. \fillin{\br@radius}{5}{12}{\br@psi}{\br@phi - \br@psi}{\br@colour\br@qmo}
  1707. \end{scope}
  1708. }
  1709. % \end{macrocode}
  1710. % \end{macro}
  1711. %
  1712. %
  1713. % \begin{macro}{\brunniancpt}
  1714. % \begin{macrocode}
  1715. \newcommand{\brunniancpt}[3][1]{%
  1716. \pgfmathsetmacro{\br@n}{#3}
  1717. \pgfmathsetmacro{\br@phi}{360/\br@n}
  1718. \pgfmathsetmacro{\br@psi}{180/\br@n}
  1719. \colorlet{outer}{brunnian}
  1720. \colorlet{inner}{background}
  1721. \junction{#1}{#2}{1}{\br@psi}{\br@psi}
  1722. \begin{scope}[rotate=-\br@phi]
  1723. \colorlet{inner}{brunnian}
  1724. \colorlet{outer}{background}
  1725. \junction{#1}{#2}{1}{\br@psi}{\br@psi}
  1726. \end{scope}
  1727. }
  1728. % \end{macrocode}
  1729. % \end{macro}
  1730. %
  1731. %
  1732. % \begin{macro}{\brunniancptouter}
  1733. % \begin{macrocode}
  1734. \newcommand{\brunniancptouter}[3][1]{%
  1735. \pgfmathsetmacro{\br@n}{#3}
  1736. \pgfmathsetmacro{\br@phi}{360/\br@n}
  1737. \pgfmathsetmacro{\br@psi}{180/\br@n}
  1738. \colorlet{outer}{brunnian}
  1739. \colorlet{inner}{background}
  1740. \junction{#1}{#2}{-1}{\br@psi}{\br@psi}
  1741. \begin{scope}[rotate=\br@phi]
  1742. \colorlet{inner}{brunnian}
  1743. \colorlet{outer}{background}
  1744. \junction{#1}{#2}{-1}{\br@psi}{\br@psi}
  1745. \end{scope}
  1746. }
  1747. % \end{macrocode}
  1748. % \end{macro}
  1749. %
  1750. %
  1751. % \begin{macro}{\brunnianlinkage}
  1752. % \begin{macrocode}
  1753. \newcommand{\brunnianlinkage}{%
  1754. \node (0) at (0,-\brlen) {};
  1755. \foreach \bri/\brdir/\brnud/\brv in {
  1756. 1/1/1/-1,
  1757. 2/-1/2/-1,
  1758. 3/-1/1/-1,
  1759. 4/1/1/1,
  1760. 5/1/1/-1,
  1761. 6/-1/1/1,
  1762. 7/-1/2/1,
  1763. 8/1/1/1
  1764. } {
  1765. \coordinate (\bri) at (\brover * \brdir * \brnud,-\bri * \brsep + \brv * \bradj);
  1766. \draw (\bri) -- ++(0,-\brv * \bradj) -- +(-\brdir * \brlen - \brover * \brdir * \brnud,0);
  1767. }
  1768. \draw (1) -- (4);
  1769. \draw (2) -- (7);
  1770. \draw (3) -- (6);
  1771. \draw (5) -- (8);
  1772. }
  1773. % \end{macrocode}
  1774. % \end{macro}
  1775. %
  1776. % \begin{macro}{\brunniantwoside}
  1777. % \begin{macrocode}
  1778. \newcommand{\brunniantwoside}{%
  1779. \foreach \bri/\brdir/\brnud/\brv in {
  1780. 1/1/1/-1,
  1781. 2/-1/2/-1,
  1782. 3/-1/1/-1,
  1783. 4/1/1/1,
  1784. 5/1/1/-1,
  1785. 6/-1/1/1,
  1786. 7/-1/2/1,
  1787. 8/1/1/1
  1788. } {
  1789. \coordinate (l\bri) at (\brover * \brdir * \brnud,-\bri * \brsep + \brv * \bradj);
  1790. \draw (l\bri) -- ++(0,-\brv * \bradj) -- +(-\brdir * \brlen - \brover * \brdir * \brnud,0) coordinate (le\bri);
  1791. }
  1792. \draw (l1) -- (l4);
  1793. \draw (l2) -- (l7);
  1794. \draw (l3) -- (l6);
  1795. \draw (l5) -- (l8);
  1796. \begin{scope}[xshift=4cm]
  1797. \foreach \bri/\brdir/\brnud/\brv in {
  1798. 1/1/1/-1,
  1799. 2/-1/2/-1,
  1800. 3/-1/1/-1,
  1801. 4/1/1/1,
  1802. 5/1/1/-1,
  1803. 6/-1/1/1,
  1804. 7/-1/2/1,
  1805. 8/1/1/1
  1806. } {
  1807. \coordinate (r\bri) at (\brover * \brdir * \brnud,-\bri * \brsep + \brv * \bradj);
  1808. \draw (r\bri) -- ++(0,-\brv * \bradj) -- +(-\brdir * \brlen - \brover * \brdir * \brnud,0) coordinate (re\bri);
  1809. }
  1810. \draw (r1) -- (r4);
  1811. \draw (r2) -- (r7);
  1812. \draw (r3) -- (r6);
  1813. \draw (r5) -- (r8);
  1814. \end{scope}
  1815. \draw
  1816. (le2) -- ++(\brsep,0) coordinate (1)
  1817. (le7) -- ++(\brsep,0) coordinate (4)
  1818. (re1) -- ++(-\brsep,0) coordinate (5)
  1819. (re8) -- ++(-\brsep,0) coordinate (8)
  1820. ;
  1821. \path
  1822. coordinate (2) at (le3)
  1823. coordinate (3) at (le6)
  1824. coordinate (6) at (re4)
  1825. coordinate (7) at (re5)
  1826. coordinate (lb) at ($(4)!.5!(8)+(0,-1)$)
  1827. ;
  1828. }
  1829. % \end{macrocode}
  1830. % \end{macro}
  1831. %
  1832. % \begin{macro}{\dblhopftwoside}
  1833. % \begin{macrocode}
  1834. \newcommand{\dblhopftwoside}{%
  1835. \foreach \bri/\brdir/\brnud/\brv in {
  1836. 1/-1/2/-1,
  1837. 2/-1/1/-1,
  1838. 3/1/2/-1,
  1839. 4/1/1/-1,
  1840. 5/-1/1/1,
  1841. 6/-1/2/1,
  1842. 7/1/1/1,
  1843. 8/1/2/1
  1844. } {
  1845. \coordinate (l\bri) at (\brover * \brdir * \brnud,-\bri * \brsep + \brv * \bradj);
  1846. \draw (l\bri) -- ++(0,-\brv * \bradj) -- +(-\brdir * \brlen - \brover * \brdir * \brnud,0) coordinate (le\bri);
  1847. }
  1848. \draw (l1) -- (l6);
  1849. \draw (l2) -- (l5);
  1850. \draw (l3) -- (l8);
  1851. \draw (l4) -- (l7);
  1852. \begin{scope}[xshift=4cm]
  1853. \foreach \bri/\brdir/\brnud/\brv in {
  1854. 1/-1/2/-1,
  1855. 2/-1/1/-1,
  1856. 3/1/2/-1,
  1857. 4/1/1/-1,
  1858. 5/-1/1/1,
  1859. 6/-1/2/1,
  1860. 7/1/1/1,
  1861. 8/1/2/1
  1862. } {
  1863. \coordinate (r\bri) at (\brover * \brdir * \brnud,-\bri * \brsep + \brv * \bradj);
  1864. \draw (r\bri) -- ++(0,-\brv * \bradj) -- +(-\brdir * \brlen - \brover * \brdir * \brnud,0) coordinate (re\bri);
  1865. }
  1866. \draw (r1) -- (r6);
  1867. \draw (r2) -- (r5);
  1868. \draw (r3) -- (r8);
  1869. \draw (r4) -- (r7);
  1870. \end{scope}
  1871. \draw
  1872. (le1) -- ++(\brsep,0) coordinate (1)
  1873. (le6) -- ++(\brsep,0) coordinate (4)
  1874. (re3) -- ++(-\brsep,0) coordinate (5)
  1875. (re8) -- ++(-\brsep,0) coordinate (8)
  1876. ;
  1877. \path
  1878. coordinate (2) at (le2)
  1879. coordinate (3) at (le5)
  1880. coordinate (6) at (re4)
  1881. coordinate (7) at (re7)
  1882. coordinate (lb) at ($(4)!.5!(8)+(0,-1)$)
  1883. ;
  1884. }
  1885. % \end{macrocode}
  1886. % \end{macro}
  1887. %
  1888. % \begin{macro}{\dblhopfrctwoside}
  1889. % \begin{macrocode}
  1890. \newcommand{\dblhopfrctwoside}{%
  1891. \foreach \bri/\brdir/\brnud/\brv in {
  1892. 1/-1/2/-1,
  1893. 2/-1/1/-1,
  1894. 3/1/2/-1,
  1895. 4/1/1/-1,
  1896. 5/-1/1/1,
  1897. 6/-1/2/1,
  1898. 7/1/1/1,
  1899. 8/1/2/1
  1900. } {
  1901. \coordinate (l\bri) at (\brover * \brdir * \brnud,-\bri * \brsep + \brv * \bradj);
  1902. \draw (l\bri) -- ++(0,-\brv * \bradj) -- +(-\brdir * \brlen - \brover * \brdir * \brnud,0) coordinate (le\bri);
  1903. }
  1904. \draw (l1) -- (l6);
  1905. \draw (l2) -- (l5);
  1906. \draw (l3) -- (l8);
  1907. \draw (l4) -- (l7);
  1908. \begin{scope}[xshift=4cm]
  1909. \foreach \bri/\brdir/\brnud/\brv in {
  1910. 1/-1/2/-1,
  1911. 2/-1/1/-1,
  1912. 3/1/2/-1,
  1913. 4/1/1/-1,
  1914. 5/-1/1/1,
  1915. 6/-1/2/1,
  1916. 7/1/1/1,
  1917. 8/1/2/1
  1918. } {
  1919. \coordinate (r\bri) at (\brover * \brdir * \brnud,-\bri * \brsep + \brv * \bradj);
  1920. \draw (r\bri) -- ++(0,-\brv * \bradj) -- +(-\brdir * \brlen - \brover * \brdir * \brnud,0) coordinate (re\bri);
  1921. }
  1922. \draw (r1) -- (r6);
  1923. \draw (r2) -- (r5);
  1924. \draw (r3) -- (r8);
  1925. \draw (r4) -- (r7);
  1926. \end{scope}
  1927. \draw
  1928. (le1) -- ++(\brsep,0) coordinate (1)
  1929. (le6) -- ++(\brsep,0) coordinate (4)
  1930. (re3) -- ++(-\brsep,0) coordinate (5)
  1931. (re8) -- ++(-\brsep,0) coordinate (8)
  1932. ;
  1933. \path
  1934. coordinate (2) at (le2)
  1935. coordinate (3) at (le5)
  1936. coordinate (6) at (re4)
  1937. coordinate (7) at (re7)
  1938. coordinate (lb) at ($(4)!.5!(8)+(0,-1)$)
  1939. ;
  1940. \draw[double=none,Red,line width=2pt] (2) -- (3);
  1941. }
  1942. % \end{macrocode}
  1943. % \end{macro}
  1944. %
  1945. % \begin{macro}{\brunnianhalftwoside}
  1946. % \begin{macrocode}
  1947. \newcommand{\brunnianhalftwoside}{%
  1948. \foreach \bri/\brdir/\brnud/\brv in {
  1949. 1/1/1/-1,
  1950. 2/-1/2/-1,
  1951. 3/-1/1/-1,
  1952. 4/1/1/1,
  1953. 5/1/1/-1,
  1954. 6/-1/1/1,
  1955. 7/-1/2/1,
  1956. 8/1/1/1
  1957. } {
  1958. \coordinate (l\bri) at (\brover * \brdir * \brnud,-\bri * \brsep + \brv * \bradj);
  1959. \draw (l\bri) -- ++(0,-\brv * \bradj) -- +(-\brdir * \brlen - \brover * \brdir * \brnud,0) coordinate (le\bri);
  1960. }
  1961. \draw (l1) -- (l4);
  1962. \draw (l2) -- (l7);
  1963. \draw (l3) -- (l6);
  1964. \draw (l5) -- (l8);
  1965. \begin{scope}[xshift=4cm]
  1966. \foreach \bri/\brdir/\brnud/\brv in {
  1967. 1/1/1/-1,
  1968. 2/-1/2/-1,
  1969. 3/-1/1/-1,
  1970. 4/1/1/1,
  1971. 5/1/1/-1,
  1972. 6/-1/1/1,
  1973. 7/-1/2/1,
  1974. 8/1/1/1
  1975. } {
  1976. \coordinate (r\bri) at (\brover * \brdir * \brnud,-\bri * \brsep + \brv * \bradj);
  1977. \draw (r\bri) -- ++(0,-\brv * \bradj) -- +(-\brdir * \brlen - \brover * \brdir * \brnud,0) coordinate (re\bri);
  1978. }
  1979. \draw (r1) -- (r4);
  1980. \draw (r2) -- (r7);
  1981. \draw (r3) -- (r6);
  1982. \draw (r5) -- (r8);
  1983. \end{scope}
  1984. \draw
  1985. (le2) -- ++(\brsep,0) coordinate (1)
  1986. (le7) -- ++(\brsep,0) coordinate (4)
  1987. (re1) -- ++(-\brsep,0) coordinate (5)
  1988. (re8) coordinate (6)
  1989. ;
  1990. \path
  1991. coordinate (2) at (le3)
  1992. coordinate (3) at (le6)
  1993. coordinate (8) at (re4)
  1994. coordinate (7) at (re5)
  1995. coordinate (lb) at ($(4)!.5!(8)+(0,-1)$)
  1996. ;
  1997. \draw[double=none,Red,line width=2pt] (6) -- (7);
  1998. }
  1999. % \end{macrocode}
  2000. % \end{macro}
  2001. %
  2002. % \begin{macro}{\brunnianringonetwoside}
  2003. % \begin{macrocode}
  2004. \newcommand{\brunnianringonetwoside}{
  2005. \fill[gray] (-\brlen,-.5*\brsep) rectangle (\brlen, .5*\brsep);
  2006. \draw[double=none,Red,line width=2pt]
  2007. (-\brlen,-.5*\brsep)
  2008. ++(-\brsep,-\brsep) coordinate (1)
  2009. ++(-\brsep,-\brsep) coordinate (2)
  2010. ++(-\brsep,-\brsep) coordinate (c3) -- +(\brsep,0) coordinate (3)
  2011. ++(-\brsep,-\brsep) coordinate (c4) -- +(4*\brsep,0) coordinate (4)
  2012. (\brlen,-.5*\brsep)
  2013. ++(\brsep,-\brsep) coordinate (5)
  2014. ++(\brsep,-\brsep) coordinate (6)
  2015. ++(\brsep,-\brsep) coordinate (c7) -- +(-\brsep,0) coordinate (7)
  2016. ++(\brsep,-\brsep) coordinate (c8) -- +(-4*\brsep,0) coordinate (8)
  2017. ;
  2018. \draw[double=none,Red,line width=2pt]
  2019. (1) -- ++(0,3*\brsep) -| (5)
  2020. (2) -- ++(0,5*\brsep) -| (6)
  2021. (c3) -- ++(0,7*\brsep) -| (c7)
  2022. (c4) -- ++(0,9*\brsep) -| (c8)
  2023. ;
  2024. }
  2025. % \end{macrocode}
  2026. % \end{macro}
  2027. %
  2028. %
  2029. % \iffalse
  2030. %</package>
  2031. % \fi
  2032. %
  2033. % \Finale
  2034. \endinput