texlive[51048] Master/texmf-dist: braids (8may19)

commits+karl at tug.org commits+karl at tug.org
Wed May 8 23:15:00 CEST 2019


Revision: 51048
          http://tug.org/svn/texlive?view=revision&revision=51048
Author:   karl
Date:     2019-05-08 23:15:00 +0200 (Wed, 08 May 2019)
Log Message:
-----------
braids (8may19)

Modified Paths:
--------------
    trunk/Master/texmf-dist/tex/latex/braids/braids.sty

Added Paths:
-----------
    trunk/Master/texmf-dist/doc/latex/braids/README.txt
    trunk/Master/texmf-dist/doc/latex/braids/braids.pdf
    trunk/Master/texmf-dist/doc/latex/braids/braids.tex
    trunk/Master/texmf-dist/doc/latex/braids/braids_code.pdf
    trunk/Master/texmf-dist/source/latex/braids/braids_code.dtx
    trunk/Master/texmf-dist/source/latex/braids/braids_code.ins
    trunk/Master/texmf-dist/tex/latex/braids/tikzlibrarybraids.code.tex

Removed Paths:
-------------
    trunk/Master/texmf-dist/doc/latex/braids/README
    trunk/Master/texmf-dist/doc/latex/braids/braids_doc.pdf
    trunk/Master/texmf-dist/doc/latex/braids/braids_doc.tex
    trunk/Master/texmf-dist/source/latex/braids/braids.dtx

Deleted: trunk/Master/texmf-dist/doc/latex/braids/README
===================================================================
--- trunk/Master/texmf-dist/doc/latex/braids/README	2019-05-08 21:09:31 UTC (rev 51047)
+++ trunk/Master/texmf-dist/doc/latex/braids/README	2019-05-08 21:15:00 UTC (rev 51048)
@@ -1,11 +0,0 @@
-----------------------------------------------------------------
-braids --- a style file for drawing braid diagrams with TikZ/PGF
-E-mail: stacey at math.ntnu.no
-Released under the LaTeX Project Public License v1.3c or later
-See http://www.latex-project.org/lppl.txt
-----------------------------------------------------------------
-
-This package defines some commands for drawing braid diagrams with TikZ/PGF.
-It was designed and tested with PGF2.10.
-The initial idea of this package came from a question and answer on the site http://tex.stackexchange.com.
-

Added: trunk/Master/texmf-dist/doc/latex/braids/README.txt
===================================================================
--- trunk/Master/texmf-dist/doc/latex/braids/README.txt	                        (rev 0)
+++ trunk/Master/texmf-dist/doc/latex/braids/README.txt	2019-05-08 21:15:00 UTC (rev 51048)
@@ -0,0 +1,10 @@
+----------------------------------------------------------------
+braids --- a style file for drawing braid diagrams with TikZ/PGF
+E-mail: loopspace at mathforge.org
+Released under the LaTeX Project Public License v1.3c or later
+See http://www.latex-project.org/lppl.txt
+----------------------------------------------------------------
+
+This package defines some commands for drawing braid diagrams with TikZ/PGF.
+The initial idea of this package came from a question and answer on the site http://tex.stackexchange.com.
+


Property changes on: trunk/Master/texmf-dist/doc/latex/braids/README.txt
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: trunk/Master/texmf-dist/doc/latex/braids/braids.pdf
===================================================================
(Binary files differ)

Index: trunk/Master/texmf-dist/doc/latex/braids/braids.pdf
===================================================================
--- trunk/Master/texmf-dist/doc/latex/braids/braids.pdf	2019-05-08 21:09:31 UTC (rev 51047)
+++ trunk/Master/texmf-dist/doc/latex/braids/braids.pdf	2019-05-08 21:15:00 UTC (rev 51048)

Property changes on: trunk/Master/texmf-dist/doc/latex/braids/braids.pdf
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+application/pdf
\ No newline at end of property
Added: trunk/Master/texmf-dist/doc/latex/braids/braids.tex
===================================================================
--- trunk/Master/texmf-dist/doc/latex/braids/braids.tex	                        (rev 0)
+++ trunk/Master/texmf-dist/doc/latex/braids/braids.tex	2019-05-08 21:15:00 UTC (rev 51048)
@@ -0,0 +1,481 @@
+\documentclass{ltxdoc}
+\usepackage[T1]{fontenc}
+\usepackage{lmodern}
+\usepackage{morefloats}
+\usepackage{tikz}
+\usepackage{braids}
+\usetikzlibrary{braids}
+\usepackage[numbered]{hypdoc}
+\definecolor{lstbgcolor}{rgb}{0.9,0.9,0.9} 
+ 
+\usepackage{listings}
+\lstloadlanguages{[LaTeX]TeX}
+\lstset{breakatwhitespace=true,breaklines=true,language=TeX}
+ 
+\usepackage{fancyvrb}
+
+\newenvironment{example}
+  {\VerbatimEnvironment
+   \begin{VerbatimOut}{example.out}}
+  {\end{VerbatimOut}
+   \begin{center}
+   \setlength{\parindent}{0pt}
+   \fbox{\begin{minipage}{.9\linewidth}
+     \lstset{breakatwhitespace=true,breaklines=true,language=TeX,basicstyle=\small}
+     \lstinputlisting[]{example.out}
+   \end{minipage}}
+
+   \fbox{\begin{minipage}{.9\linewidth}
+     \input{example.out}
+   \end{minipage}}
+\end{center}
+}
+
+\providecommand*{\url}{\texttt}
+\GetFileInfo{tikzlibrarybraids.code.tex}
+
+\title{The \textsf{braids} Package: Documentation}
+\author{Andrew Stacey \\ \texttt{loopspace at mathforge.org}}
+\date{\fileversion~from \filedate}
+
+\begin{document}
+
+\maketitle
+
+\begin{center}
+  \begin{tikzpicture}
+  \pic[
+    line width=1.5pt,
+    red,
+    line cap=round,
+    braid/.cd,
+    width=.75cm,
+    height=.5cm,
+    strand 3/.style={gray,line width=1pt},
+    strand 6/.style={gray,line width=1pt},
+    strand 7/.style={gray,line width=1pt},
+    strand 10/.style={gray,line width=1pt},
+    strand 14/.style={gray,line width=1pt},
+    strand 15/.style={gray,line width=1pt},
+    strand 16/.style={gray,line width=1pt},
+    strand 18/.style={gray,line width=1pt},
+  ] {braid={s_1-s_4-s_8-s_{12}-s_{16} s_2-s_5-s_7-s_9-s_{13}-s_{15} s_2-s_5-s_7-s_9-s_{15} s_1-s_4-s_8-s_{16} s_1-s_4-s_7-s_9-s_{17} s_2-s_5-s_{17} s_2-s_{13}-s_{16} s_1-s_{12}-s_{15}}};
+\end{tikzpicture}
+\end{center}
+
+\section{Introduction}
+
+This is a package for drawing braid diagrams using PGF/TikZ.
+An example follows.
+
+\begin{example}
+\begin{center}
+\begin{tikzpicture}
+\pic[
+  rotate=90,
+  braid/.cd,
+  every strand/.style={ultra thick},
+  strand 1/.style={red},
+  strand 2/.style={green},
+  strand 3/.style={blue},
+] {braid={s_1 s_2^{-1} s_1 s_2^{-1} s_1 s_2^{-1}}};
+\end{tikzpicture}
+\end{center}
+\end{example}
+
+\section{TikZ Library Usage}
+
+Version 2.0 changed the implementation to use the TikZ \Verb+pic+ syntax.
+It also converted it to a TikZ library, so to use it put the following in the preamble.
+
+\begin{verbatim}
+\usetikzlibrary{braids}
+\end{verbatim}
+
+(Or add it to the copious list of TikZ libraries that you are already using.)
+
+\bigskip
+
+\DescribeMacro{braid}
+A braid is specified by the pic name \Verb+braid+.
+The usual syntax for this is as follows:
+
+\Verb+\pic[options] at (coordinate) {braid={braid-word}};+
+
+\DescribeMacro{braid-word}
+The \Verb+braid-word+ is an expression in the braid group, such as \Verb+s_1 s_2^{-1} s_{3,5}+.
+The generator labels are not significant.
+If the subscript is a single number, as in \Verb+s_2+, the crossing goes from that number over the next.
+If the subscript is two numbers, as in \Verb+s_{2,4}+, the crossing goes from the first over the second, with both the crossing strands passing over all of the intervening strands.
+The exponent can be \Verb+1+, \Verb+{-1}+, or missing (in which case it defaults to \Verb+1+, note also that the exponent is read as a \TeX-token so \Verb+{1}+ is also legal).
+If the exponent is \(-1\) then the over and under strands swap.
+
+\begin{itemize}
+\item \Verb+s_1+ is strand \(1\) over strand \(2\).
+\item \Verb+s_1^{-1}+ is strand \(2\) over strand \(1\).
+\item \Verb+s_{1,3}+ is strand \(1\) over strand \(3\), and both are over strand \(2\).
+\end{itemize}
+
+Certain other symbols are allowed in the \Verb+braid-word+ which control the rendering of the braid.
+These extras are as follows.
+
+\begin{enumerate}
+\item To get crossings to render at the same height, separate them with a hyphen (note: no check is made to ensure that the crossings can legally be put at the same height; \emph{caveat emptor}).
+For example, \Verb+s_1-s_3+.
+
+\item To draw a \emph{floor} -- which is a rectangle behind the braid occupying some number of levels (the default being one level) -- precede the braid element by a vertical line, as in \Verb+s_1 | s_2+.
+The floor is itself a pic which, by default, consists of a rectangle and two horizontal lines.
+The rectangle picks up any \Verb+fill+ options and the lines any \Verb+draw+ options that are set in the \Verb+braid/every floor+ and \Verb+braid/floor <n>+ styles.
+The \Verb+n+ is the level number, starting at \(1\).
+
+More general floors can be drawn using the key \Verb+braid/add floor+.
+This takes one argument which is a comma separated list of parameters that specifies the position and size floor:
+%
+\begin{verbatim}
+braid/add floor={x,y,width,height,name}
+\end{verbatim}
+%
+The units used are the ``natural'' units of the braid: strand separation and level height.
+The \Verb+name+ is optional and if given can be used to style the floor in that the style \Verb+braid/floor <name>+ is applied to that floor.
+
+Replacing the floor pic will change how it is drawn.
+The coordinate system is set up for the floor pic so that the floor is a unit square with lower left corner at the origin.
+
+\item The identity element can occur in the braid-word.
+It is represented by \Verb+1+.
+This inserts the identity which corresponds to no crossing.
+However, it takes the same amount of space as if there were a crossing.
+
+\end{enumerate}
+
+\subsection{Style Options}
+\label{sec:picstyleopts}
+
+There are various keys that change the behaviour or rendering of the braid.
+All of these are in the \Verb+/tikz/braid/+ namespace.
+
+\DescribeMacro{number of strands} The key \Verb+number of strands+ sets the minimum number of strands for the braid.
+The number of strands will grow according to the terms in the braid word so this merely sets a lower bound.
+If not set, the number of strands will be determined by the terms in the braid word.
+
+\DescribeMacro{height}
+The key \Verb+height+ sets the height of the piece of the braid corresponding to an element in the group.
+This can be negative.
+
+\DescribeMacro{width}
+The key \Verb+width+ sets the separation of the strands in the braid.
+This can be negative.
+
+\DescribeMacro{border height}
+The key \Verb+border height+ adds a little extra length to the strands at the start and end of the braid.
+
+\DescribeMacro{gap}
+The key \Verb+gap+ is used to determine how much of a gap to leave in the under strand at a crossing.
+This should be a number strictly between 0 and .5.
+The curve is drawn using a cubic bezier and the gap is in terms of the time parameter, so the gap will not increase exactly proportionally to the value given by this key, though that is a reasonable approximation.
+
+\DescribeMacro{control factor}
+As just said, the parts of the strands involved in a crossing are drawn using a cubic bezier curve.
+The control points are vertically above or below their respective end point.
+This key determines that vertical separation.
+It is multiplied by the \Verb+height+ so that it scales properly.
+It can be set to 0 whereupon the strands in the crossing are straight lines.
+The default is 0.5.
+
+\DescribeMacro{nudge factor}
+The crossings are not quite placed one after another.
+There is a small ``nudge'' between the end of one crossing and the start of another.
+Due to the way that the strands are lengthened, if there is no ``nudge'' then some PDF renderers produce slightly strange results at certain magnifications.
+This key controls how much that ``nudge'' is, as a factor of the \Verb+height+.
+For the aforementioned reason, it should not be set to 0 (the default is 0.05).
+Note that this does not change the height of a crossing.
+Rather, it nudges the height at which the strands start to cross over.
+
+\DescribeMacro{every strand, strand <n>}
+The style of the strands are controlled by two types of option.
+Style options that are set on the \Verb+pic+ are passed to every strand.
+It is also possible to add style options to individual strands using the keys \Verb+every strand+ and \Verb+strand <n>+.
+The strands are numbered by their starting position.
+
+\DescribeMacro{every floor, floor <n>}
+When a floor is requested behind a crossing, it is rendered as a pic.
+These keys control how the floor is styled.
+
+\subsection{Coordinates and Anchors}
+
+The braid is littered with coordinates.
+Each strand gets a coordinate at each end, and at every level between crossings.
+These are labelled and numbered by the initial strand position and the crossing level.
+They are also labelled and numbered by the final strand position with the prefix \Verb+rev+.
+With a \Verb+name prefix+, the coordinate names look like the following:
+%
+\begin{verbatim}
+<name prefix>-<strand number>-<crossing number>
+<name prefix>-rev-<strand number>-<crossing number>
+\end{verbatim}
+%
+The crossing number can also be either \Verb+s+ or \Verb+e+ for the start and end of the strand.
+Note that \Verb+-1-0+ and \Verb+-1-s+ are slightly different in that \Verb+s+ includes the border height.
+
+\DescribeMacro{anchor}
+The key \Verb+anchor+ (in the \Verb+braid+ name space) can be used to shift the braid so that a different part of it is at the specified location.
+It uses the same syntax as the coordinates, except without the \Verb+<name prefix>-+.
+In the following example, the braid is shifted so that where the third strand starts the second level is at the position \Verb+(1,1)+
+
+\begin{example}
+\begin{center}
+\begin{tikzpicture}
+\fill[purple] (1,1) circle[radius=3mm];
+\pic[braid/anchor=3-2,rotate=90] at (1,1) {braid={s_2 s_1 s_2 s_1}};
+\end{tikzpicture}
+\end{center}
+\end{example}
+
+
+\section{Examples}
+
+Here are more detailed examples.
+
+\begin{example}
+\begin{center}
+\begin{tikzpicture}
+\pic[
+  braid/every floor/.style={fill=yellow},
+  braid/floor 1/.style={draw=black,dashed,fill=yellow!50!green},
+  line width=2pt,
+  braid/strand 1/.style={red},
+  braid/strand 2/.style={blue},
+  braid/strand 3/.style={green},
+  braid/add floor={2,4,3,2,a},
+  braid/floor a/.style={fill=pink},
+  name prefix=braid,
+] at (2,0) {braid={| s_1-s_3-s_5 | s_2^{-1}-s_4| s_1-s_4 s_2^{-1} s_1-s_3 s_2^{-1}-s_4^{-1}}};
+\fill[yellow] (2,0) circle (4pt);
+\node[at=(braid-3-s),pin=north west:strand 3 start] {};
+\node[at=(braid-3-e),pin=south west:strand 3 end] {};
+\node[at=(braid-rev-3-s),pin=north east:strand 3 (from bottom) start] {};
+\node[at=(braid-rev-3-e),pin=south east:strand 3 (from bottom) end] {};
+\end{tikzpicture}
+\end{center}
+\end{example}
+
+\begin{example}
+\begin{center}
+\begin{tikzpicture}
+\pic[
+  braid/.cd,
+  number of strands=3,
+  line width=8pt,
+  strand 1/.style={red},
+  strand 2/.style={green},
+  strand 3/.style={blue},
+  gap=0.1,
+  control factor=0,
+  nudge factor=0,
+  name prefix=braid,
+] {braid={a_2 a_1 a_2^{-1} a_1}};
+\node[circle,draw,fill=white,inner sep=0pt] at (braid-2-1) {\(+\)};
+\node[circle,draw,fill=white,inner sep=0pt] at (braid-3-1) {\(-\)};
+\node[circle,draw,fill=white,inner sep=0pt] at (braid-2-3) {\(+\)};
+\end{tikzpicture}
+\end{center}
+
+\end{example}
+
+\newpage
+
+\section{Original Package Usage (Depreciated)}
+
+The original version was as a separate package.
+This is still included for backwards compatibility.
+To use this package, you need to put the following in the preamble.
+
+\begin{verbatim}
+\usepackage{braids}
+\end{verbatim}
+
+\DescribeMacro{\braid}
+A braid is specified by the command \Verb+\braid+.
+The syntax for this command is as follows:
+
+\Verb+\braid[style options] (name) at (coordinate) braid-word;+
+
+\DescribeMacro{braid-word}
+The \Verb+braid-word+ is an expression in the braid group, such as \Verb+s_1 s_2^{-1}+.
+The generator labels are not significant.
+The exponent can be \Verb+1+, \Verb+{-1}+, or missing (in which case it defaults to \Verb+1+, note also that the exponent is read as a \TeX-token so \Verb+{1}+ is also legal).
+Certain other symbols are allowed in the \Verb+braid-word+ which control the rendering of the braid.
+These extras are as follows.
+
+\begin{enumerate}
+\item To get crossings to render at the same height, separate them with a hyphen (note: no check is made to ensure that the crossings can legally be put at the same height; \emph{caveat emptor}).
+
+\item To draw a \emph{floor}, precede the braid element by a vertical line.
+What happens then is that when the braid is rendered, the coordinates of the rectangle behind that crossing (wide enough to encompass all the strands) is passed to a command.
+The intention is that this command draw something behind the braid.
+The command is configurable by a key (see \ref{sec:styleopts}).
+
+\item The identity element can occur in the braid-word.
+It is represented by \Verb+1+.
+This inserts the identity which corresponds to no crossing.
+However, it takes the same amount of space as if there were a crossing.
+
+\item Strands can be labelled between crossings.
+To do this, the commands \Verb+\label+, \Verb+\olabel+, and \Verb+\clabel+ are provided.
+These take three arguments, the first is optional.
+The result of this command is to place a node on top of a particular strand between the crossings where the command is given.
+The first (optional) argument can be used to pass style options to this node.
+The second argument is the strand number.
+The third argument is the label text.
+
+The three commands differ as to how they interpret the strand number.
+For \Verb+\olabel+, the strand number is taken to mean the strand that starts at that position.
+For \Verb+\clabel+, the strand number is taken to mean the strand that is currently at that position.
+The behaviour of \Verb+\label+ is to choose one or other of these depending on whether the key \Verb+strand label by origin+ is true or false.
+This key only has an effect at the start of the braid-word; it cannot be reset in the middle.
+
+\item Style options can be given in the middle of a braid-word by enclosing them in square brackets.
+There are not many style options that it makes sense to change in the middle of the braid-word, since the strands are rendered all in one go at the end.
+
+\item Scoping is handled by using braces.
+Thus to change a style only briefly, enclose the desired scope in braces.
+\end{enumerate}
+
+\DescribeMacro{name}
+The (optional) \Verb+name+ acts a little like the \Verb+name+ of a TikZ node.
+When it is specified, the routine that renders the braid also saves certain coordinates as if they were node anchors.
+Specifically, \Verb+coordinate+ nodes are placed at the centre of the braid diagram and at the ends of each strand.
+The centre has the label \Verb+name+, the strands are labelled \Verb+name-number-end+ and \Verb+name-rev-number-end+, where \Verb+name+ is the name given to the braid, \Verb+number+ is the number of the strand counting from the left, and \Verb+end+ is either \Verb+s+ for the start or \Verb+e+ for the end.
+If the version with \Verb+rev+ is used then the numbers correspond to the \emph{final} positions of the braids.
+The name can also be specified with the \Verb+name+ key.
+
+\DescribeMacro{at}
+The (optional) \Verb+at (coordinate)+ syntax positions the braid at the \Verb+coordinate+ in the current picture.
+Due to the implementation, the coordinate has to be known at the start, but the width and height of the braid are only known at the end.
+Therefore, the braid is positioned so that the start of the first strand is at \Verb+(coordinate)+.
+This can also be specified using the \Verb+at+ key.
+
+\DescribeMacro{style options}
+The \Verb+style options+ set the style for the braid strands.
+They can be grouped into three types: options that set up the main parameters for the braid, options that set the default style for the strands, and options that set up styles for individual strands.
+The options are as follows.
+
+\subsection{Style Options}
+\label{sec:styleopts}
+
+\DescribeMacro{number of strands} The key \Verb+number of strands+ sets the minimum number of strands for the braid.
+The number of strands will grow according to the terms in the braid word so this merely sets a lower bound.
+If not set, the number of strands will be determined by the terms in the braid word.
+
+\DescribeMacro{height}
+The key \Verb+height+ sets the height of the piece of the braid corresponding to an element in the group.
+
+\DescribeMacro{width}
+The key \Verb+width+ sets the separation of the strands in the braid.
+
+\DescribeMacro{border height}
+The key \Verb+border height+ adds a little extra length to the strands at the start and end of the braid.
+
+\DescribeMacro{gap}
+The key \Verb+gap+ is used to determine how much of a gap to leave in the under strand at a crossing.
+This should be a number strictly between 0 and .5.
+The curve is drawn using a cubic bezier and the gap is in terms of the time parameter, so the gap will not increase exactly proportionally to the value given by this key, though that is a reasonable approximation.
+
+\DescribeMacro{control factor}
+As just said, the parts of the strands involved in a crossing are drawn using a cubic bezier curve.
+The control points are vertically above or below their respective end point.
+This key determines that vertical separation.
+It is multiplied by the \Verb+height+ so that it scales properly.
+It can be set to 0 whereupon the strands in the crossing are straight lines.
+The default is 0.5.
+
+\DescribeMacro{nudge factor}
+The crossings are not quite placed one after another.
+There is a small ``nudge'' between the end of one crossing and the start of another.
+Due to the way that the strands are lengthened, if there is no ``nudge'' then some PDF renderers produce slightly strange results at certain magnifications.
+This key controls how much that ``nudge'' is, as a factor of the \Verb+height+.
+For the aforementioned reason, it should not be set to 0 (the default is 0.05).
+Note that this does not change the height of a crossing.
+Rather, it nudges the height at which the strands start to cross over.
+
+\DescribeMacro{style strands}
+The style of the strands are controlled by two types of option.
+Style options that are set on the \Verb+\braid+ command are passed to every strand.
+It is also possible to add style options to individual strands using the key \Verb+style strands+.
+This takes two options, a comma-delimited list of strand numbers (which could be just a single number) and a list of options to be applied to that strand.
+Thus, the syntax is \Verb+style strands={n,m,...}{options}+.
+The strands are numbered by their starting position.
+Not all of the standard TikZ style options are possible due to the way that the strands are constructed.
+Basically, the options that are allowed are those that do not require changing the path or drawing it more than once.
+
+\DescribeMacro{floor command}
+When a floor is requested behind a crossing, the actual way to render it is determined by a command.
+This key allows the user to define that command.
+The argument to this key should be the code that should be executed for each floor.
+To avoid the hassle of getting the number of hashes right, the command should take no arguments.
+Rather, the coordinates of the rectangle are saved in to macros \Verb+\floorsx+, \Verb+\floorsy+, \Verb+\floorex+, \Verb+\floorey+ (these macros will expand to something like \Verb+10pt+) and the command should use these to position the drawing.
+The default is to draw a line at the top and at the bottom of the rectangle.
+
+\DescribeMacro{style floors}
+\DescribeMacro{style all floors}
+In the spirit of separating \emph{style} and \emph{content}, the style options for the floors can be specified separately to the command (of course, they could be built in to the command).
+One advantage of this over building them in to the command is to allow them to be overridden for individual floors.
+The \Verb+style all floors+ sets up options to be used for \emph{all} floors, whilst the \Verb+style floors={n,m,...}{options}+ sets up options to be used only for the listed floor.
+Anything specified in the \Verb+floor command+ will take precedence over both of these.
+
+Any other style options are passed to the underlying TikZ/PGF system and so may influence how the braid is drawn (but note that not all keys make sense due to the implementation).
+
+
+\section{Examples}
+
+Here are more detailed examples.
+
+\begin{example}
+\begin{center}
+\begin{tikzpicture}
+\braid[
+  style all floors={fill=yellow},
+  style floors={1}{dashed,fill=yellow!50!green},
+  floor command={%
+   \fill (\floorsx,\floorsy) rectangle (\floorex,\floorey);
+   \draw (\floorsx,\floorsy) -- (\floorex,\floorsy);
+  },
+  line width=2pt,
+  style strands={1}{red},
+  style strands={2}{blue},
+  style strands={3}{green}
+] (braid) at (2,0) | s_1-s_3-s_5 | s_2^{-1}-s_4| s_1-s_4 s_2^{-1} s_1-s_3 s_2^{-1}-s_4^{-1};
+\fill[yellow] (2,0) circle (4pt);
+\fill[purple] (braid) circle (4pt);
+\node[at=(braid-3-s),pin=north west:strand 3] {};
+\node[at=(braid-3-e),pin=south west:strand 3] {};
+\node[at=(braid-rev-3-s),pin=north east:strand 3 (from bottom)] {};
+\node[at=(braid-rev-3-e),pin=south east:strand 3 (from bottom)] {};
+\end{tikzpicture}
+\end{center}
+\end{example}
+
+\begin{example}
+\begin{center}
+\begin{tikzpicture}
+\braid[
+  number of strands=3,
+  line width=8pt,
+  style strands={1}{red},
+  style strands={2}{green},
+  style strands={3}{blue},
+  gap=0.1,
+  control factor=0,
+  nudge factor=0,
+  strand label by origin=true,
+  strand label/.style={circle,draw,fill=white,inner sep=0pt},
+  yscale=1] (braid_1) a_2 \label{2}{\(+\)} \clabel{2}{\(-\)} a_1 a_2^{-1} \olabel{2}{\(+\)} a_1;
+\end{tikzpicture}
+\end{center}
+
+\end{example}
+
+\end{document}
+% Local Variables:
+% tex-output-type: "pdf18"
+% End:


Property changes on: trunk/Master/texmf-dist/doc/latex/braids/braids.tex
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: trunk/Master/texmf-dist/doc/latex/braids/braids_code.pdf
===================================================================
(Binary files differ)

Index: trunk/Master/texmf-dist/doc/latex/braids/braids_code.pdf
===================================================================
--- trunk/Master/texmf-dist/doc/latex/braids/braids_code.pdf	2019-05-08 21:09:31 UTC (rev 51047)
+++ trunk/Master/texmf-dist/doc/latex/braids/braids_code.pdf	2019-05-08 21:15:00 UTC (rev 51048)

Property changes on: trunk/Master/texmf-dist/doc/latex/braids/braids_code.pdf
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+application/pdf
\ No newline at end of property
Deleted: trunk/Master/texmf-dist/doc/latex/braids/braids_doc.pdf
===================================================================
(Binary files differ)

Deleted: trunk/Master/texmf-dist/doc/latex/braids/braids_doc.tex
===================================================================
--- trunk/Master/texmf-dist/doc/latex/braids/braids_doc.tex	2019-05-08 21:09:31 UTC (rev 51047)
+++ trunk/Master/texmf-dist/doc/latex/braids/braids_doc.tex	2019-05-08 21:15:00 UTC (rev 51048)
@@ -1,178 +0,0 @@
-\documentclass{ltxdoc}
-\usepackage[T1]{fontenc}
-\usepackage{lmodern}
-\usepackage{morefloats}
-\usepackage{tikz}
-\usepackage{braids}
-\usepackage[numbered]{hypdoc}
-\definecolor{lstbgcolor}{rgb}{0.9,0.9,0.9} 
- 
-\usepackage{listings}
-\lstloadlanguages{[LaTeX]TeX}
-\lstset{breakatwhitespace=true,breaklines=true,language=TeX}
- 
-\usepackage{fancyvrb}
-
-\newenvironment{example}
-  {\VerbatimEnvironment
-   \begin{VerbatimOut}{example.out}}
-  {\end{VerbatimOut}
-   \begin{center}
-   \setlength{\parindent}{0pt}
-   \fbox{\begin{minipage}{.9\linewidth}
-     \lstset{breakatwhitespace=true,breaklines=true,language=TeX,basicstyle=\small}
-     \lstinputlisting[]{example.out}
-   \end{minipage}}
-
-   \fbox{\begin{minipage}{.9\linewidth}
-     \input{example.out}
-   \end{minipage}}
-\end{center}
-}
-
-\providecommand*{\url}{\texttt}
-\GetFileInfo{braids.sty}
-
-\title{The \textsf{braids} Package: Documentation}
-\author{Andrew Stacey \\ \url{stacey at math.ntnu.no}}
-\date{\fileversion~from \filedate}
-
-\begin{document}
-
-\maketitle
-
-\begin{center}
-\begin{tikzpicture}
-\braid[width=.75cm,height=.5cm,line width=1.5pt,red,line cap=round,style strands={3,6,7,10,14,15,16,18}{gray,line width=1pt}] s_1-s_4-s_8-s_{12}-s_{16} s_2-s_5-s_7-s_9-s_{13}-s_{15} s_2-s_5-s_7-s_9-s_{15} s_1-s_4-s_8-s_{16} s_1-s_4-s_7-s_9-s_{17} s_2-s_5-s_{17} s_2-s_{13}-s_{16} s_1-s_{12}-s_{15};
-\end{tikzpicture}
-\end{center}
-
-\section{Introduction}
-
-This is a package for drawing braid diagrams using PGF/TikZ.
-An example follows.
-
-\begin{example}
-\begin{center}
-\begin{tikzpicture}
-\braid[rotate=90,style strands={1}{red},style strands={2}{blue},style strands={3}{green}] s_1 s_2^{-1} s_1 s_2^{-1} s_1 s_2^{-1};
-\end{tikzpicture}
-\end{center}
-\end{example}
-
-\section{Usage}
-
-\DescribeMacro{\braid}
-A braid is specified by the command \Verb+\braid+.
-The syntax for this command is as follows:
-
-\Verb+\braid[style options] (name) at (coordinate) braid-word;+
-
-\DescribeMacro{braid-word}
-The \Verb+braid-word+ is an expression in the braid group, such as \Verb+s_1 s_2^{-1}+.
-The generator labels are not significant.
-The exponent can be \Verb+1+, \Verb+{-1}+, or missing (in which case it defaults to \Verb+1+, note also that the exponent is read as a \TeX-token so \Verb+{1}+ is also legal).
-Certain other symbols are allowed in the \Verb+braid-word+ which control the rendering of the braid.
-To get crossings to render at the same height, separate them with a hyphen (note: no check is made to ensure that the crossings can legally be put at the same height; \emph{caveat emptor}).
-To draw a \emph{floor}, precede the braid element by a vertical line.
-What happens then is that when the braid is rendered, the coordinates of the rectangle behind that crossing (wide enough to encompass all the strands) is passed to a command.
-The intention is that this command draw something behind the braid.
-The command is configurable by a key (see \ref{sec:styleopts}).
-
-\DescribeMacro{name}
-The (optional) \Verb+name+ acts a little like the \Verb+name+ of a TikZ node.
-When it is specified, the routine that renders the braid also saves certain coordinates as if they were node anchors.
-Specifically, \Verb+coordinate+ nodes are placed at the centre of the braid diagram and at the ends of each strand.
-The centre has the label \Verb+name+, the strands are labelled \Verb+name-number-end+ and \Verb+name-rev-number-end+, where \Verb+name+ is the name given to the braid, \Verb+number+ is the number of the strand counting from the left, and \Verb+end+ is either \Verb+s+ for the start or \Verb+e+ for the end.
-If the version with \Verb+rev+ is used then the numbers correspond to the \emph{final} positions of the braids.
-The name can also be specified with the \Verb+name+ key.
-
-\DescribeMacro{at}
-The (optional) \Verb+at (coordinate)+ syntax positions the braid at the \Verb+coordinate+ in the current picture.
-Due to the implementation, the coordinate has to be known at the start, but the width and height of the braid are only known at the end.
-Therefore, the braid is positioned so that the start of the first strand is at \Verb+(coordinate)+.
-This can also be specified using the \Verb+at+ key.
-
-\DescribeMacro{style options}
-The \Verb+style options+ set the style for the braid strands.
-They can be grouped into three types: options that set up the main parameters for the braid, options that set the default style for the strands, and options that set up styles for individual strands.
-The options are as follows.
-
-\subsection{Style Options}
-\label{sec:styleopts}
-
-\DescribeMacro{number of strands} The key \Verb+number of strands+ sets the minimum number of strands for the braid.
-The number of strands will grow according to the terms in the braid word so this merely sets a lower bound.
-If not set, the number of strands will be determined by the terms in the braid word.
-
-\DescribeMacro{height}
-The key \Verb+height+ sets the height of the piece of the braid corresponding to an element in the group.
-
-\DescribeMacro{width}
-The key \Verb+width+ sets the separation of the strands in the braid.
-
-\DescribeMacro{border height}
-The key \Verb+border height+ adds a little extra length to the strands at the start and end of the braid.
-
-\DescribeMacro{style strands}
-The style of the strands are controlled by two types of option.
-Style options that are set on the \Verb+\braid+ command are passed to every strand.
-It is also possible to add style options to individual strands using the key \Verb+style strands+.
-This takes two options, a comma-delimited list of strand numbers (which could be just a single number) and a list of options to be applied to that strand.
-Thus, the syntax is \Verb+style strands={n,m,...}{options}+.
-The strands are numbered by their starting position.
-Not all of the standard TikZ style options are possible due to the way that the strands are constructed.
-Basically, the options that are allowed are those that do not require changing the path or drawing it more than once.
-
-\DescribeMacro{floor command}
-When a floor is requested behind a crossing, the actual way to render it is determined by a command.
-This key allows the user to define that command.
-The argument to this key should be the code that should be executed for each floor.
-To avoid the hassle of getting the number of hashes right, the command should take no arguments.
-Rather, the coordinates of the rectangle are saved in to macros \Verb+\floorsx+, \Verb+\floorsy+, \Verb+\floorex+, \Verb+\floorey+ (these macros will expand to something like \Verb+10pt+) and the command should use these to position the drawing.
-The default is to draw a line at the top and at the bottom of the rectangle.
-
-\DescribeMacro{style floors}
-\DescribeMacro{style all floors}
-In the spirit of separating \emph{style} and \emph{content}, the style options for the floors can be specified separately to the command (of course, they could be built in to the command).
-One advantage of this over building them in to the command is to allow them to be overridden for individual floors.
-The \Verb+style all floors+ sets up options to be used for \emph{all} floors, whilst the \Verb+style floors={n,m,...}{options}+ sets up options to be used only for the listed floor.
-Anything specified in the \Verb+floor command+ will take precedence over both of these.
-
-Any other style options are passed to the underlying TikZ/PGF system and so may influence how the braid is drawn (but note that not all keys make sense due to the implementation).
-
-
-\section{Example}
-
-Here is a more detailed example.
-
-
-\begin{example}
-\begin{center}
-\begin{tikzpicture}
-\braid[
-  style all floors={fill=yellow},
-  style floors={1}{dashed,fill=yellow!50!green},
-  floor command={%
-   \fill (\floorsx,\floorsy) rectangle (\floorex,\floorey);
-   \draw (\floorsx,\floorsy) -- (\floorex,\floorsy);
-  },
-  line width=2pt,
-  style strands={1}{red},
-  style strands={2}{blue},
-  style strands={3}{green}
-] (braid) at (2,0) | s_1-s_3-s_5 | s_2^{-1}-s_4| s_1-s_4 s_2^{-1} s_1-s_3 s_2^{-1}-s_4^{-1};
-\fill[yellow] (2,0) circle (4pt);
-\fill[purple] (braid) circle (4pt);
-\node[at=(braid-3-s),pin=north west:strand 3] {};
-\node[at=(braid-3-e),pin=south west:strand 3] {};
-\node[at=(braid-rev-3-s),pin=north east:strand 3 (from bottom)] {};
-\node[at=(braid-rev-3-e),pin=south east:strand 3 (from bottom)] {};
-\end{tikzpicture}
-\end{center}
-\end{example}
-\end{document}
-
-% Local Variables:
-% tex-output-type: "pdf18"
-% End:

Deleted: trunk/Master/texmf-dist/source/latex/braids/braids.dtx
===================================================================
--- trunk/Master/texmf-dist/source/latex/braids/braids.dtx	2019-05-08 21:09:31 UTC (rev 51047)
+++ trunk/Master/texmf-dist/source/latex/braids/braids.dtx	2019-05-08 21:15:00 UTC (rev 51048)
@@ -1,946 +0,0 @@
-% \iffalse meta-comment
-%<*internal>
-\iffalse
-%</internal>
-%<*readme>
-----------------------------------------------------------------
-braids --- a style file for drawing braid diagrams with TikZ/PGF
-E-mail: stacey at math.ntnu.no
-Released under the LaTeX Project Public License v1.3c or later
-See http://www.latex-project.org/lppl.txt
-----------------------------------------------------------------
-
-This package defines some commands for drawing braid diagrams with TikZ/PGF.
-It was designed and tested with PGF2.10.
-The initial idea of this package came from a question and answer on the site http://tex.stackexchange.com.
-%</readme>
-%<*internal>
-\fi
-\def\nameofplainTeX{plain}
-\ifx\fmtname\nameofplainTeX\else
-  \expandafter\begingroup
-\fi
-%</internal>
-%<*install>
-\input docstrip.tex
-\keepsilent
-\askforoverwritefalse
-\preamble
-----------------------------------------------------------------
-braids --- a style file for drawing braid diagrams with TikZ/PGF
-E-mail: stacey at math.ntnu.no
-Released under the LaTeX Project Public License v1.3c or later
-See http://www.latex-project.org/lppl.txt
-----------------------------------------------------------------
-
-\endpreamble
-\postamble
-
-Copyright (C) 2011 by Andrew Stacey <stacey at math.ntnu.no>
-
-This work may be distributed and/or modified under the
-conditions of the LaTeX Project Public License (LPPL), either
-version 1.3c of this license or (at your option) any later
-version.  The latest version of this license is in the file:
-
-http://www.latex-project.org/lppl.txt
-
-This work is "maintained" (as per LPPL maintenance status) by
-Andrew Stacey.
-
-This work consists of the files  braids.dtx
-                                 braids_doc.tex
-and the derived files            README.txt,
-                                 braids.ins,
-                                 braids.pdf,
-                                 braids.sty,
-                                 braids_doc.pdf.
-
-\endpostamble
-\usedir{tex/latex/braids}
-\generate{
-  \file{\jobname.sty}{\from{\jobname.dtx}{package}}
-}
-%</install>
-%<install>\endbatchfile
-%<*internal>
-\usedir{source/latex/braids}
-\generate{
-  \file{\jobname.ins}{\from{\jobname.dtx}{install}}
-}
-\nopreamble\nopostamble
-\usedir{doc/latex/demopkg}
-\generate{
-  \file{README.txt}{\from{\jobname.dtx}{readme}}
-}
-\ifx\fmtname\nameofplainTeX
-  \expandafter\endbatchfile
-\else
-  \expandafter\endgroup
-\fi
-%</internal>
-%<*package>
-\NeedsTeXFormat{LaTeX2e}
-\ProvidesPackage{braids}[2011/05/07 v1.0 Tikz/PGF commands for drawing braid diagrams]
-%</package>
-%<*driver>
-\documentclass{ltxdoc}
-\usepackage[T1]{fontenc}
-\usepackage{lmodern}
-%\usepackage{morefloats}
-\usepackage{tikz}
-\usepackage{\jobname}
-\usepackage[numbered]{hypdoc}
-\definecolor{lstbgcolor}{rgb}{0.9,0.9,0.9} 
- 
-\usepackage{listings}
-\lstloadlanguages{[LaTeX]TeX}
-\lstset{breakatwhitespace=true,breaklines=true,language=TeX}
- 
-\usepackage{fancyvrb}
-
-\EnableCrossrefs
-\CodelineIndex
-\RecordChanges
-\begin{document}
-  \DocInput{\jobname.dtx}
-\end{document}
-%</driver>
-% \fi
-%
-% \CheckSum{815}
-%
-% \CharacterTable
-%  {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
-%   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
-%   Digits        \0\1\2\3\4\5\6\7\8\9
-%   Exclamation   \!     Double quote  \"     Hash (number) \#
-%   Dollar        \$     Percent       \%     Ampersand     \&
-%   Acute accent  \'     Left paren    \(     Right paren   \)
-%   Asterisk      \*     Plus          \+     Comma         \,
-%   Minus         \-     Point         \.     Solidus       \/
-%   Colon         \:     Semicolon     \;     Less than     \<
-%   Equals        \=     Greater than  \>     Question mark \?
-%   Commercial at \@     Left bracket  \[     Backslash     \\
-%   Right bracket \]     Circumflex    \^     Underscore    \_
-%   Grave accent  \`     Left brace    \{     Vertical bar  \|
-%   Right brace   \}     Tilde         \~}
-%
-%
-% \changes{1.0}{2011/05/03}{Converted to DTX file}
-%
-% \DoNotIndex{\newcommand,\newenvironment}
-%
-% \providecommand*{\url}{\texttt}
-% \GetFileInfo{braids.sty}
-% \title{The \textsf{braids} package: codebase}
-% \author{Andrew Stacey \\ \url{stacey at math.ntnu.no}}
-% \date{\fileversion~from \filedate}
-% 
-% \maketitle
-% 
-% \begin{center}
-% \begin{tikzpicture}
-% \braid[line width=3pt,line cap=round,style strands={1}{blue},number of strands=7] s_1 s_2 s_5^{-1};
-% \end{tikzpicture}
-% \end{center}
-% 
-% \section{Introduction}
-% 
-% This is a package for drawing braid diagrams using PGF/TikZ.
-% Its inspiration was a question and answer on the website \url{http://tex.stackexchange.com}.
-%
-% \StopEventually{}
-%
-% \section{Implementation}
-%
-% \iffalse
-%<*package>
-% \fi
-%
-% Test the version of PGF to see if it's what we expect.
-% If not, issue a warning (but continue anyway; after all, it \emph{might just work}).
-%    \begin{macrocode}
-\def\braid at pgfversion{2.10}%
-\ifx\pgfversion\braid at pgfversion
-\else
-\PackageWarning{braids}{This package was designed using PGF2.10; you are using \pgfversion.}%
-\fi
-%    \end{macrocode}
-% \begin{macro}{\ge at addto@macro}
-% This is an expanded version of \Verb+\g at addto@macro+.
-% Namely, it adds the \emph{expansion} of the second argument to the first.
-%    \begin{macrocode}
-\long\def\ge at addto@macro#1#2{%
-  \begingroup
-  \toks@\expandafter\expandafter\expandafter{\expandafter#1#2}%
-  \xdef#1{\the\toks@}%
-  \endgroup}
-%    \end{macrocode}
-% \end{macro}
-% \begin{macro}{\braid}
-% This is the user command.
-% We start a group to ensure that all our assignments are local, and then call our initialisation code.
-% The optional argument is for any keys to be set.
-%    \begin{macrocode}
-\newcommand{\braid}[1][]{%
-  \begingroup
-  \braid at start{#1}}
-%    \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\braid at process}
-% This is the token swallower.
-% This takes the next token on the braid specification and passes it to the handler command (in the macro \Verb+\braid at token+) which decides what to do next.
-% (Incidentally, the code here is heavily influenced by TikZ.
-% That's probably not very surprising.)
-%    \begin{macrocode}
-\def\braid at process{%
-  \afterassignment\braid at handle\let\braid at token=%
-}
-%    \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\braid at process@start}
-% This is a variant of \Verb+\braid at process+ which is used at the start where we might have a few extra bits and pieces before the braid itself starts.
-% Specifically, we test for the \Verb+at+ and \Verb+(name)+ possibilities.
-%    \begin{macrocode}
-\def\braid at process@start{%
-  \afterassignment\braid at handle@start\let\braid at token=%
-}
-%    \end{macrocode}
-% \end{macro}
-% \begin{macro}{\braid at handle@start}
-% This is the handler in use at the start.
-% It looks for the tokens \Verb+a+ or \Verb+(+ which (might) signal the start of an \Verb+at (coordinate)+ or \Verb+(name)+.
-% If we get anything else (modulo spaces) we decide that we've reached the end of the initialisation stuff and it is time to get started on the braid itself.
-%    \begin{macrocode}
-\def\braid at handle@start{%
-  \let\braid at next=\braid at handle
-  \ifx\braid at token a
-%    \end{macrocode}
-% We got an \Verb+a+ so we might have an \Verb+at (coordinate)+
-%    \begin{macrocode}
-   \let\braid at next=\braid at maybe@locate
-  \else
-  \ifx\braid at token(%)
-%    \end{macrocode}
-% We got an \Verb+(+ so we have a name
-%    \begin{macrocode}
-   \iffalse)\fi %Indentation hack!
-   \let\braid at next=\braid at assign@name
-  \else
-  \ifx\braid at token\@sptoken
-%    \end{macrocode}
-% Space; boring, redo from start
-%    \begin{macrocode}
-   \let\braid at next=\braid at process@start
-  \fi
-  \fi
-  \fi
-  \braid at next%
-}
-%    \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\braid at handle}
-% This is the main handler for parsing the braid word.
-% It decides what action to take depending on what the token is.
-% We have to be a bit careful with catcodes, some packages set
-% \Verb+;+ and \Verb+|+ to be active.
-% We should probably also be careful with \Verb+^+ and \Verb+_+.
-%    \begin{macrocode}
-\let\braid at semicolon=;
-\let\braid at bar=|
-\def\braid at handle{%
-  \let\braid at next=\braid at process
-%    \end{macrocode}
-% Start by checking our catcodes to see what we should check against
-%    \begin{macrocode}
-  \ifnum\the\catcode`\;=\active
-  \expandafter\let\expandafter\braid at semicolon\tikz at activesemicolon
-  \fi
-  \ifnum\the\catcode`\|=\active
-  \expandafter\let\expandafter\braid at bar\tikz at activebar
-  \fi
-  \ifx\braid at token\braid at semicolon
-%    \end{macrocode}
-% Semicolon, means that we're done reading our braid.
-% It's time to render it.
-%    \begin{macrocode}
-   \let\braid at next=\braid at render
-  \else
-  \ifx\braid at token^
-%    \end{macrocode}
-% Superscript character, the next token tells us whether it's an over-crossing or an under-crossing.
-%    \begin{macrocode}
-   \let\braid at next=\braid at sup
-  \else
-  \ifx\braid at token_
-%    \end{macrocode}
-% Subscript character, the next token tells us which strands cross.
-%    \begin{macrocode}
-   \let\braid at next=\braid at sub
-  \else
-  \ifx\braid at token-
-%    \end{macrocode}
-% Hyphen, this is so that we can have more than one crossing on the same level.
-%    \begin{macrocode}
-   \braid at increase@levelfalse
-  \else
-  \ifx\braid at token[
-%    \end{macrocode}
-% Open bracket, this means we have some more options to process.
-%    \begin{macrocode}
-   \let\braid at next=\braid at process@options
-  \else
-  \ifx\braid at token\braid at bar
-%    \end{macrocode}
-% Bar, this tells us that we want a ``floor'' at this point.
-%    \begin{macrocode}
-   \edef\braid at tmp{,\expandafter\the\value{braid at level}}%
-   \ge at addto@macro\braid at floors\braid at tmp%
-  \else
-  \ifx\braid at token\bgroup
-%    \end{macrocode}
-% Begin group, which we reinterpret as begining a scope.
-%    \begin{macrocode}
-   \braid at beginscope
-  \else
-  \ifx\braid at token\egroup
-%    \end{macrocode}
-% End group, which ends the scope
-%    \begin{macrocode}
-   \braid at endscope
-  \else
-%    \end{macrocode}
-% Otherwise, we add the token to the braid label.
-%    \begin{macrocode}
-  \ge at addto@macro\braid at label{\braid at token}%
-  \fi
-  \fi
-  \fi
-  \fi
-  \fi
-  \fi
-  \fi
-  \fi
-  \braid at next%
-}
-%    \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\braid at maybe@locate}
-% If we got an \Verb+a+ token in the \Verb+\braid at handle@start+ then it \emph{might} mean we're looking at \Verb+at (coordinate)+ or it might mean that the user has decided to use \Verb+a+ as the braid parameter.
-% So we examine the next token for a \Verb+t+. 
-%    \begin{macrocode}
-\def\braid at maybe@locate{%
-  \afterassignment\braid@@maybe at locate\let\braid at token=%
-}
-%    \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\braid@@maybe at locate}
-% This is where we test for \Verb+t+ and act appropriately.
-%    \begin{macrocode}
-\def\braid@@maybe at locate{%
-  \let\braid at next=\braid at handle
-  \ifx\braid at token t
-   \let\braid at next=\braid at find@location
-  \fi
-  \braid at next%
-}
-%    \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\braid at find@location}
-% This macro starts us looking for a coordinate.
-%    \begin{macrocode}
-\def\braid at find@location{%
-  \afterassignment\braid@@find at location\let\braid at token=%
-}
-%    \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\braid@@find at location}
-% This is the test for the start of a coordinate.
-% If we get a \Verb+(+ that means we've reached the coordinate.
-% A space means ``carry on''.
-% Anything else is a (non-fatal) error.
-%    \begin{macrocode}
-\def\braid@@find at location{%
-  \let\braid at next=\braid at location@error
-  \ifx\braid at token(%)
-   \let\braid at next=\braid at locate
-  \else
-  \ifx\braid at token\@sptoken
-   \let\braid at next=\braid at find@location
-  \fi
-  \fi
-  \braid at next%
-}
-%    \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\braid at location@error}
-% This is our error message for not getting a location.
-%    \begin{macrocode}
-\def\braid at location@error{%
-  \PackageWarning{braids}{Could not figure out location for braid}%
-  \braid at process@start%
-}
-%    \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\braid at locate}
-% If we reached a \Verb+(+ when looking for a coordinate, everything up to the next \Verb+)+ is that coordinate.
-% Then we parse the coordinate and call the relocation macro.
-%    \begin{macrocode}
-\def\braid at locate#1){%
-  \tikz at scan@one at point\braid at relocate(#1)%
-}
-%    \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\braid at relocate}
-% This is the macro that actually does the relocation.
-%    \begin{macrocode}
-\def\braid at relocate#1{%
-  #1\relax
-  \advance\pgf at x by -\braid at width
-  \pgftransformshift{\pgfqpoint{\pgf at x}{\pgf at y}}
-  \braid at process@start%
-}
-%    \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\braid at assign@name}
-% This macro saves our name.
-%    \begin{macrocode}
-\def\braid at assign@name#1){%
-  \def\braid at name{#1}%
-  \braid at process@start%
-}
-%    \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\braid at process@options}
-% The intention of this macro is to allow setting of style options mid-braid.
-% (At present, this wouldn't make a lot of sense.)
-%    \begin{macrocode}
-\def\braid at process@options#1]{%
-    \tikzset{#1}%
-  \braid at process%
-}
-%    \end{macrocode}
-% \end{macro}
-%
-% The next macros handle the actual braid elements.
-% Everything has to have a subscript, but the superscript is optional and can come before or after the subscript.
-%
-% \begin{macro}{\braid at sup}
-% This handles braid elements of the form \Verb+a^{-1}_2+.
-%    \begin{macrocode}
-\def\braid at sup#1_#2{\g at addto@macro\braid at label{_{#2}^{#1}}\braid at add@crossing{#2}{#1}}
-%    \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\braid at sub}
-%    \begin{macrocode}
-% This handles braid elements of the form \Verb+a_1+ or \Verb+a_1^{-1}+.
-\def\braid at sub#1{\@ifnextchar^{\braid@@sub{#1}}{\g at addto@macro\braid at label{_{#1}}\braid at add@crossing{#1}{1}}}
-%    \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\braid@@sub}
-% Helper macro for \Verb+\braid at sub+.
-%    \begin{macrocode}
-\def\braid@@sub#1^#2{\g at addto@macro\braid at label{_{#1}^{#2}}\braid at add@crossing{#1}{#2}}
-%    \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\braid at ne}
-% Remember what \Verb+1+ looks like for testing against.
-%    \begin{macrocode}
-\def\braid at ne{1}
-%    \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\braid at add@crossing}
-% This is the macro which adds the crossing to the current list of strands.
-% The strands are stored as \emph{soft paths} (see the TikZ/PGF documentation).
-% So this selects the right strands and then extends them according to the crossing type.
-%    \begin{macrocode}
-\def\braid at add@crossing#1#2{%
-%    \end{macrocode}
-% Our crossing type, which is \Verb+#2+, is one of \Verb+1+ or \Verb+-1+.
-% Our strands are \Verb+#1+ and \Verb-#1+1-.
-%    \begin{macrocode}
-  \edef\braid at crossing@type{#2}%
-  \edef\braid at this@strand{#1}%
-  \pgfmathtruncatemacro{\braid at next@strand}{#1+1}
-%    \end{macrocode}
-% Increment the level counter, if requested.
-% The controls whether the crossing is on the same level as the previous one or is one level further on.
-%    \begin{macrocode}
-  \ifbraid at increase@level
-  \stepcounter{braid at level}
-  \fi
-%    \end{macrocode}
-% Default is to request increment so we set it for next time.
-%    \begin{macrocode}
-  \braid at increase@leveltrue
-%    \end{macrocode}
-% Now we figure out the coordinates of the crossing.
-% \Verb+(\braid at tx,\braid at ty)+ is the top-left corner (assuming the braid flows down the page).
-% \Verb+(\braid at nx,\braid at ny)+ is the bottom-right corner (assuming the braid flows down the page).
-% We start by setting \Verb+(\braid at tx,\braid at ty)+ according to the level and strand number, then shift \Verb+\braid at ty+ by \Verb+\braid at eh+ which is the ``edge height'' (the little extra at the start and end of each strand).
-% Then from these values, we set \Verb+(\braid at nx,\braid at ny)+ by adding on the appropriate amount.
-% The heights \Verb+\braid at cy+ and \Verb+\braid at dy+ are for the control points for the strands as they cross.
-% They're actually the same height, but using two gives us the possibility of changing them independently in a later version of this package.
-% Lastly, we bring \Verb+\braid at ty+ and \Verb+\braid at ny+ towards each other just a little so that there is ``clear water'' between subsequent crossings (makes it look a bit better if the same strand is used in subsequent crossings).
-%    \begin{macrocode}
-  \braid at tx=\braid at this@strand\braid at width
-  \braid at ty=\value{braid at level}\braid at height
-  \advance\braid at ty by \braid at eh
-  \braid at nx=\braid at tx
-  \braid at ny=\braid at ty
-  \advance\braid at nx by \braid at width
-  \advance\braid at ny by \braid at height
-  \braid at cy=\braid at ty
-  \braid at dy=\braid at ny
-  \advance\braid at cy by .5\braid at height
-  \advance\braid at dy by -.5\braid at height
-  \advance\braid at ty by .05\braid at height
-  \advance\braid at ny by -.05\braid at height
-%    \end{macrocode}
-% Now we try to find a starting point for the strand ending here.
-% We might not have used this strand before, so it might not exist.
-%    \begin{macrocode}
-  \expandafter\let\expandafter\braid at this@path at origin\csname braid at strand@\braid at this@strand @origin\endcsname
-%    \end{macrocode}
-% If we haven't seen this strand before, that one will be \Verb+\relax+.
-%    \begin{macrocode}
-\ifx\braid at this@path at origin\relax
-%    \end{macrocode}
-% Haven't seen this strand before, so initialise it.
-% Record the initial position of the strand.
-%    \begin{macrocode}
-  \let\braid at this@path at origin\braid at this@strand
-%    \end{macrocode}
-% Start a new soft path.
-%    \begin{macrocode}
-  \pgfsyssoftpath at setcurrentpath{\@empty}
-  \pgfpathmoveto{\pgfpoint{\braid at tx}{0pt}}
-%    \end{macrocode}
-% Save the path as \Verb+\braid at this@path+.
-%    \begin{macrocode}
-  \pgfsyssoftpath at getcurrentpath{\braid at this@path}
-  \else
-%    \end{macrocode}
-% We have seen this before, so we simply copy the associated path in to \Verb+\braid at this@path+.
-%    \begin{macrocode}
-  \expandafter\let\expandafter\braid at this@path\csname braid at strand@\braid at this@path at origin\endcsname
-  \fi
-%    \end{macrocode}
-% Now we do the same again with the other strand in the crossing.
-%    \begin{macrocode}
-  \expandafter\let\expandafter\braid at next@path at origin\csname braid at strand@\braid at next@strand @origin\endcsname
-  \ifx\braid at next@path at origin\relax
-  \let\braid at next@path at origin\braid at next@strand
-  \pgfsyssoftpath at setcurrentpath{\@empty}
-  \pgfpathmoveto{\pgfpoint{\braid at nx}{0pt}}
-  \pgfsyssoftpath at getcurrentpath{\braid at next@path}
-  \else
-  \expandafter\let\expandafter\braid at next@path\csname braid at strand@\braid at next@path at origin\endcsname
-  \fi
-%    \end{macrocode}
-% Now that we have the paths for our two strands, we extend them to the next level.
-% We start by selecting the first path.
-%    \begin{macrocode}
-  \pgfsyssoftpath at setcurrentpath{\braid at this@path}
-%    \end{macrocode}
-% Draw a line down to the current level, note that this line is always non-trivial since we shifted the corners of the crossing in a little. 
-%    \begin{macrocode}
-  \pgfpathlineto{\pgfqpoint{\braid at tx}{\braid at ty}}
-%    \end{macrocode}
-% Curve across to the next position.
-% Depending on the crossing type, we either have a single curve or we have to break it in two.
-%    \begin{macrocode}
-\ifx\braid at crossing@type\braid at over@cross
-%    \end{macrocode}
-% We're on the overpass, so just one curve needed.
-%    \begin{macrocode}
-\pgfpathcurveto{\pgfqpoint{\braid at tx}{\braid at cy}}{\pgfqpoint{\braid at nx}{\braid at dy}}{\pgfqpoint{\braid at nx}{\braid at ny}}
-\else
-%    \end{macrocode}
-% We're on the underpass, so we need to interrupt our path to allow the other curve to go past.
-% The choice of \Verb+.4+ and \Verb+.6+ should probably be configurable.
-%    \begin{macrocode}
-\pgfpathcurvebetweentimecontinue{0}{.4}{\pgfqpoint{\braid at tx}{\braid at ty}}{\pgfqpoint{\braid at tx}{\braid at cy}}{\pgfqpoint{\braid at nx}{\braid at dy}}{\pgfqpoint{\braid at nx}{\braid at ny}}
-\pgfpathcurvebetweentime{.6}{1}{\pgfqpoint{\braid at tx}{\braid at ty}}{\pgfqpoint{\braid at tx}{\braid at cy}}{\pgfqpoint{\braid at nx}{\braid at dy}}{\pgfqpoint{\braid at nx}{\braid at ny}}
-\fi
-%    \end{macrocode}
-% We're done with this path, so now we save it.
-%    \begin{macrocode}
-  \pgfsyssoftpath at getcurrentpath{\braid at this@path}
-%    \end{macrocode}
-% Now do the same with the second path.
-%    \begin{macrocode}
-  \pgfsyssoftpath at setcurrentpath{\braid at next@path}
-  \pgfpathlineto{\pgfqpoint{\braid at nx}{\braid at ty}}
-\ifx\braid at crossing@type\braid at over@cross
-\pgfpathcurvebetweentimecontinue{0}{.4}{\pgfqpoint{\braid at nx}{\braid at ty}}{\pgfqpoint{\braid at nx}{\braid at cy}}{\pgfqpoint{\braid at tx}{\braid at dy}}{\pgfqpoint{\braid at tx}{\braid at ny}}
-\pgfpathcurvebetweentime{.6}{1}{\pgfqpoint{\braid at nx}{\braid at ty}}{\pgfqpoint{\braid at nx}{\braid at cy}}{\pgfqpoint{\braid at tx}{\braid at dy}}{\pgfqpoint{\braid at tx}{\braid at ny}}
-\else
-  \pgfpathcurveto{\pgfqpoint{\braid at nx}{\braid at cy}}{\pgfqpoint{\braid at tx}{\braid at dy}}{\pgfqpoint{\braid at tx}{\braid at ny}}
-\fi
-  \pgfsyssoftpath at getcurrentpath{\braid at next@path}
-%    \end{macrocode}
-% Now save the paths to their proper macros again.
-%    \begin{macrocode}
-  \expandafter\let\csname braid at strand@\braid at this@path at origin \endcsname\braid at this@path
-  \expandafter\let\csname braid at strand@\braid at next@path at origin \endcsname\braid at next@path
-%    \end{macrocode}
-% Now update the origins
-%    \begin{macrocode}
-  \expandafter\let\csname braid at strand@\braid at this@strand @origin\endcsname\braid at next@path at origin
-  \expandafter\let\csname braid at strand@\braid at next@strand @origin\endcsname\braid at this@path at origin
-%    \end{macrocode}
-% increment the strand counter, if necessary
-%    \begin{macrocode}
-  \pgfmathparse{\value{braid at strands} < \braid at next@strand ? "\noexpand\setcounter{braid at strands}{\braid at next@strand}" : ""}
-  \pgfmathresult
-%    \end{macrocode}
-% And merrily go on our way with the next bit of the braid specification.
-%    \begin{macrocode}
-  \braid at process%
-}
-%    \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\braid at floors@trim}
-% The list of floors, if given, will start with a superfluous comma.
-% This removes it.
-%    \begin{macrocode}
-\def\braid at floors@trim,{}
-%    \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\braid at render@floor}
-% This is the default rendering for floors: it draws a rectangle.
-%    \begin{macrocode}
-\def\braid at render@floor{%
-    \draw (\floorsx,\floorsy) rectangle (\floorex,\floorey);
-}
-%    \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\braid at render}
-% This is called at the end of the braid and it renders the braids and floors according to whatever has been built up up to now.
-%    \begin{macrocode}
-\def\braid at render{
-%    \end{macrocode}
-% Check for floors since we do them first.
-%    \begin{macrocode}
-    \ifx\braid at floors\@empty
-    \else
-%    \end{macrocode}
-% Have some floors, start a scope and prepare to render them.
-%    \begin{macrocode}
-    \pgfsys at beginscope
-%    \end{macrocode}
-% Clear the path (just to be sure).
-%    \begin{macrocode}
-    \pgfsyssoftpath at setcurrentpath{\empty}
-%    \end{macrocode}
-% Trim the initial comma off the list of floors.
-%    \begin{macrocode}
-    \edef\braid at floors{\expandafter\braid at floors@trim\braid at floors}
-%    \end{macrocode}
-% Initialise our horizontal coordinates.
-%    \begin{macrocode}
-    \braid at tx=\braid at width
-    \advance\braid at tx by \braid at eh
-    \braid at nx=\value{braid at strands}\braid at width
-    \advance\braid at nx by -\braid at eh
-%    \end{macrocode}
-% Loop over the list of floors.
-%    \begin{macrocode}
-    \foreach \braid at f in \braid at floors {
-      \pgfsys at beginscope
-%    \end{macrocode}
-% Figure out the vertical coordinates for the current floor.
-%    \begin{macrocode}
-      \braid at ty=\braid at f\braid at height
-      \advance\braid at ty by \braid at eh
-      \advance\braid at ty by \braid at height
-      \braid at ny=\braid at ty
-      \advance\braid at ny by \braid at height
-%    \end{macrocode}
-% Save the coordinates for use in the floor rendering macro.
-%    \begin{macrocode}
-      \edef\floorsx{\the\braid at tx}
-      \edef\floorsy{\the\braid at ty}
-      \edef\floorex{\the\braid at nx}
-      \edef\floorey{\the\braid at ny}
-      \let\tikz at options=\pgfutil at empty
-%    \end{macrocode}
-% Load general floor style options.
-%    \begin{macrocode}
-    \expandafter\tikzset\expandafter{\braid at floors@style}
-%    \end{macrocode}
-% Load any style options specific to this floor.
-% We're actually offset by 2 from what the user thinks the floor level is.
-%    \begin{macrocode}
-      \pgfmathtruncatemacro{\braid at ff}{\braid at f+2}
-%    \end{macrocode}
-% Load the relevant floor style, if it exists.
-%    \begin{macrocode}
-    \expandafter\let\expandafter\braid at floor@style\csname braid at options@floor@\braid at ff\endcsname
-    \ifx\braid at floor@style\relax
-    \else
-%    \end{macrocode}
-% There is a floor style for this level, so process it.
-%    \begin{macrocode}
-    \expandafter\tikzset\expandafter{\braid at floor@style}%
-    \fi
-%    \end{macrocode}
-% The \Verb+\tikzset+ just parses the options, we need to call \Verb+\tikz at options+ to actually set them. 
-%    \begin{macrocode}
-\tikz at options
-%    \end{macrocode}
-% Now we call the rendering code.
-%    \begin{macrocode}
-\braid at render@floor
-%    \end{macrocode}
-% Done!
-% End the scope for \emph{this} floor and go again.
-%    \begin{macrocode}
-\pgfsys at endscope
-    }
-%    \end{macrocode}
-% Done rendering floors, end the scope.
-%    \begin{macrocode}
-    \pgfsys at endscope
-    \fi
-%    \end{macrocode}
-% Finished with floors (if we had them), now get on with the strands.
-%    \begin{macrocode}
-  \stepcounter{braid at level}
-  \foreach \braid at k in {1,...,\value{braid at strands}} {
-%    \end{macrocode}
-% Start a local scope to ensure we don't mess with other braids
-%    \begin{macrocode}
-    \pgfsys at beginscope
-%    \end{macrocode}
-% Default is to draw each braid
-%    \begin{macrocode}
-    \tikz at mode@drawtrue%
-    \let\tikz at mode=\pgfutil at empty
-    \let\tikz at options=\pgfutil at empty
-%    \end{macrocode}
-% (x,y) coordinates of bottom of strand
-%    \begin{macrocode}
-    \braid at tx=\braid at k\braid at width
-    \braid at ty=\value{braid at level}\braid at height
-    \advance\braid at ty by 2\braid at eh
-%    \end{macrocode}
-% Try to find the starting point of this strand
-%    \begin{macrocode}
-    \expandafter\let\expandafter\braid at path@origin\csname braid at strand@\braid at k @origin\endcsname
-    \ifx\braid at path@origin\relax
-%    \end{macrocode}
-% If that doesn't exist, we'll just draw a straight line
-% so we move to the top of the current position
-%    \begin{macrocode}
-    \pgfsyssoftpath at setcurrentpath{\@empty}
-    \pgfpathmoveto{\pgfqpoint{\braid at tx}{0pt}}
-    \let\braid at path@origin\braid at k
-    \else
-%    \end{macrocode}
-% If the path does exist, we load it
-%    \begin{macrocode}
-    \expandafter\let\expandafter\braid at path\csname braid at strand@\braid at path@origin\endcsname
-    \pgfsyssoftpath at setcurrentpath{\braid at path}
-    \fi
-%    \end{macrocode}
-% Extend the path to the bottom
-%    \begin{macrocode}
-    \pgflineto{\pgfqpoint{\braid at tx}{\braid at ty}}
-%    \end{macrocode}
-% Load common style options
-%    \begin{macrocode}
-    \expandafter\tikzset\expandafter{\braid at style}
-%    \end{macrocode}
-% Load any style options specific to this strand
-%    \begin{macrocode}
-    \expandafter\let\expandafter\braid at style\csname braid at options@strand@\braid at path@origin\endcsname
-    \ifx\braid at style\relax
-    \else
-    \expandafter\tikzset\expandafter{\braid at style}
-    \fi
-\braid at options
-    \tikz at mode
-    \tikz at options
-%    \end{macrocode}
-% This is the command that actually draws the strand.
-%    \begin{macrocode}
-      \edef\tikz at temp{\noexpand\pgfusepath{%
-          \iftikz at mode@draw draw\fi%
-      }}%
-      \tikz at temp
-%    \end{macrocode}
-% If our braid has a name, we label the ends of the strand.
-%    \begin{macrocode}
-\ifx\braid at name\pgfutil at empty
-\else
-%    \end{macrocode}
-% Label the ends of the strand.
-%    \begin{macrocode}
-\coordinate (\braid at name-\braid at path@origin-e) at (\braid at tx,\braid at ty);
-\coordinate (\braid at name-rev-\braid at k-e) at (\braid at tx,\braid at ty);
-\braid at nx=\braid at path@origin\braid at width
-\coordinate (\braid at name-\braid at path@origin-s) at (\braid at nx,0pt);
-\coordinate (\braid at name-rev-\braid at k-s) at (\braid at nx,0pt);
-\fi
-%    \end{macrocode}
-% Done with this strand, close the scope and do the next one.
-%    \begin{macrocode}
-   \pgfsys at endscope
-  }
-%    \end{macrocode}
-% If our braid has a name, we also want to label the centre.
-%    \begin{macrocode}
-    \ifx\braid at name\pgfutil at empty
-    \else
-    \braid at tx=\value{braid at strands}\braid at width
-    \braid at ty=\value{braid at level}\braid at height
-    \advance\braid at ty by 2\braid at eh
-    \advance\braid at tx by \braid at width
-    \braid at tx=.5\braid at tx
-    \braid at ty=.5\braid at ty
-    \coordinate (\braid at name) at (\braid at tx,\braid at ty);
-    \fi
-%    \end{macrocode}
-% All done now, close the scope and end the group (which was opened right at the start).
-%    \begin{macrocode}
-    \pgfsys at endscope
-  \endgroup}
-%    \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\braid at start}
-% This starts off the braid, initialising a load of stuff.
-% We start a PGF scope, set the level to \(-1\), the label, floors, and name to empty, process any options we're given, and save certain lengths for later use..
-%    \begin{macrocode}
-\def\braid at start#1{%
-      \pgfsys at beginscope
-      \setcounter{braid at level}{-1}%
-      \let\braid at label\@empty
-      \let\braid at floors\@empty
-      \let\braid at name\empty
-      \pgfkeys{/pgf/braid/.cd,#1}
-      \let\braid at options\tikz at options
-  \tikz at transform
-      \setcounter{braid at strands}{\pgfkeysvalueof{/pgf/braid/number of           strands}}%
-    \braid at width=\pgfkeysvalueof{/pgf/braid/width}
-    \braid at height=\pgfkeysvalueof{/pgf/braid/height}
-    \braid at eh=\pgfkeysvalueof{/pgf/braid/border height}
-    \braid at height=-\braid at height
-    \braid at eh=-\braid at eh
-    \braid at increase@leveltrue
-    \braid at process@start
-}
-%    \end{macrocode}
-% \end{macro}
-%
-% These are the lengths we'll use as we construct the braid
-%    \begin{macrocode}
-\newdimen\braid at width
-\newdimen\braid at height
-\newdimen\braid at tx
-\newdimen\braid at ty
-\newdimen\braid at nx
-\newdimen\braid at ny
-\newdimen\braid at cy
-\newdimen\braid at dy
-\newdimen\braid at eh
-%    \end{macrocode}
-%
-% An if to decide whether or not to step to the next level or not
-%    \begin{macrocode}
-\newif\ifbraid at increase@level
-%    \end{macrocode}
-%
-% Some initial values
-%    \begin{macrocode}
-\let\braid at style\pgfutil at empty
-\let\braid at floors@style\pgfutil at empty
-\def\braid at over@cross{1}
-%    \end{macrocode}
-%
-% Counters to track the strands and the levels.
-%    \begin{macrocode}
-\newcounter{braid at level}
-\newcounter{braid at strands}
-%    \end{macrocode}
-%
-% All the keys we'll use.
-%    \begin{macrocode}
-\pgfkeys{
-%    \end{macrocode}
-% Handle unknown keys by passing them to \Verb+pgf+ and \Verb+tikz+.
-%    \begin{macrocode}
-    /tikz/braid/.search also={/pgf},
-    /pgf/braid/.search also={/pgf,/tikz},
-%    \end{macrocode}
-% Our ``namespace'' is \Verb+/pgf/braid+.
-%    \begin{macrocode}
-    /pgf/braid/.cd,
-    number of strands/.initial=0,
-    height/.initial=1cm,
-    width/.initial=1cm,
-    border height/.initial=.25cm,
-    name/.code={%
-      \def\braid at name{#1}%
-    },
-    at/.code={%
-      \braid at relocate{#1}%
-    },
-    floor command/.code={%
-      \def\braid at render@floor{#1}%
-    },
-    style strands/.code 2 args={%
-      \def\braid at temp{#2}%
-      \braidset{style each strand/.list={#1}}%
-    },
-    style each strand/.code={%
-      \expandafter\edef\csname braid at options@strand@#1\endcsname{\braid at temp}%
-    },
-    style floors/.code 2 args={%
-      \def\braid at temp{#2}%
-      \braidset{style each floor/.list={#1}}%
-    },
-    style each floor/.code={%
-      \expandafter\edef\csname braid at options@floor@#1\endcsname{\braid at temp}%
-    },
-    style all floors/.code={%
-      \def\braid at floors@style{#1}
-    }
-}
-%    \end{macrocode}
-% \begin{macro}{\braidset}
-% Shorthand for setting braid-specific keys.
-%    \begin{macrocode}
-\def\braidset#1{%
-  \pgfkeys{/pgf/braid/.cd,#1}}
-%    \end{macrocode}
-% \end{macro}
-% \iffalse
-%</package>
-% \fi
-%
-% \Finale
-
-\endinput

Added: trunk/Master/texmf-dist/source/latex/braids/braids_code.dtx
===================================================================
--- trunk/Master/texmf-dist/source/latex/braids/braids_code.dtx	                        (rev 0)
+++ trunk/Master/texmf-dist/source/latex/braids/braids_code.dtx	2019-05-08 21:15:00 UTC (rev 51048)
@@ -0,0 +1,2321 @@
+% \iffalse meta-comment
+%<*internal>
+\iffalse
+%</internal>
+%<*readme>
+----------------------------------------------------------------
+braids --- a style file for drawing braid diagrams with TikZ/PGF
+E-mail: loopspace at mathforge.org
+Released under the LaTeX Project Public License v1.3c or later
+See http://www.latex-project.org/lppl.txt
+----------------------------------------------------------------
+
+This package defines some commands for drawing braid diagrams with TikZ/PGF.
+The initial idea of this package came from a question and answer on the site http://tex.stackexchange.com.
+%</readme>
+%<*internal>
+\fi
+\def\nameofplainTeX{plain}
+\ifx\fmtname\nameofplainTeX\else
+  \expandafter\begingroup
+\fi
+%</internal>
+%<*install>
+\input l3docstrip.tex
+\keepsilent
+\askforoverwritefalse
+\preamble
+----------------------------------------------------------------
+braids --- a style file for drawing braid diagrams with TikZ/PGF
+E-mail: loopspace at mathforge.org
+Released under the LaTeX Project Public License v1.3c or later
+See http://www.latex-project.org/lppl.txt
+----------------------------------------------------------------
+
+\endpreamble
+\postamble
+
+Copyright (C) 2011-2019 by Andrew Stacey <loopspace at mathforge.org>
+
+This work may be distributed and/or modified under the
+conditions of the LaTeX Project Public License (LPPL), either
+version 1.3c of this license or (at your option) any later
+version.  The latest version of this license is in the file:
+
+http://www.latex-project.org/lppl.txt
+
+This work is "maintained" (as per LPPL maintenance status) by
+Andrew Stacey.
+
+This work consists of the files  braids.dtx
+                                 braids_doc.tex
+and the derived files            README.txt,
+                                 braids.ins,
+                                 braids.pdf,
+                                 braids.sty,
+                                 tikzlibrarybraids.code.tex,
+                                 braids_doc.pdf.
+
+\endpostamble
+\usedir{tex/latex/braids}
+\generate{
+  \file{braids.sty}{\from{\jobname.dtx}{package}}
+}
+\generate{
+  \file{tikzlibrarybraids.code.tex}{\from{\jobname.dtx}{library}}
+}
+%</install>
+%<install>\endbatchfile
+%<*internal>
+\usedir{source/latex/braids}
+\generate{
+  \file{\jobname.ins}{\from{\jobname.dtx}{install}}
+}
+\nopreamble\nopostamble
+\usedir{doc/latex/braids}
+\generate{
+  \file{README.txt}{\from{\jobname.dtx}{readme}}
+}
+\ifx\fmtname\nameofplainTeX
+  \expandafter\endbatchfile
+\else
+  \expandafter\endgroup
+\fi
+%</internal>
+%<*package>
+\NeedsTeXFormat{LaTeX2e}
+\ProvidesPackage{braids}[2011/10/18 v1.1 Tikz/PGF commands for drawing braid diagrams]
+%</package>
+%<*driver>
+\documentclass{l3doc}
+\usepackage[T1]{fontenc}
+\usepackage{lmodern}
+\usepackage{tikz}
+\usepackage{braids}
+\usetikzlibrary{braids}
+                                 
+\EnableCrossrefs
+\CodelineIndex
+\RecordChanges
+\begin{document}
+  \DocInput{\jobname.dtx}
+\end{document}
+%</driver>
+% \fi
+%
+% \CheckSum{1949}
+%
+% \CharacterTable
+%  {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
+%   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
+%   Digits        \0\1\2\3\4\5\6\7\8\9
+%   Exclamation   \!     Double quote  \"     Hash (number) \#
+%   Dollar        \$     Percent       \%     Ampersand     \&
+%   Acute accent  \'     Left paren    \(     Right paren   \)
+%   Asterisk      \*     Plus          \+     Comma         \,
+%   Minus         \-     Point         \.     Solidus       \/
+%   Colon         \:     Semicolon     \;     Less than     \<
+%   Equals        \=     Greater than  \>     Question mark \?
+%   Commercial at \@     Left bracket  \[     Backslash     \\
+%   Right bracket \]     Circumflex    \^     Underscore    \_
+%   Grave accent  \`     Left brace    \{     Vertical bar  \|
+%   Right brace   \}     Tilde         \~}
+%
+%
+% \changes{1.0}{2011/05/03}{Converted to DTX file}
+% \changes{1.1}{2011/05/03}{Extended syntax}
+% \changes{2.0}{2019/03/20}{Converted TikZ library}
+%
+% \DoNotIndex{\newcommand,\newenvironment}
+%
+% \GetFileInfo{tikzlibrarybraids.code.tex}
+% \title{The \textsf{braids} package: codebase}
+% \author{Andrew Stacey \\ \texttt{loopspace at mathforge.org}}
+% \date{\fileversion~from \filedate}
+% 
+% \maketitle
+% 
+% \section{Introduction}
+% 
+% This is a package for drawing braid diagrams using PGF/TikZ.
+% Its inspiration was a question and answer on the website \texttt{http://tex.stackexchange.com}.
+%
+% \section{History}
+%
+% \begin{itemize}
+% \item v1.0 First public release.
+%
+% \item v1.1 Added ability to configure the gap size, the control points, and the ``nudge''.
+% Added ability to add labels to strands between crossings.
+%
+% \item v2 Reimplemented as TikZ library rather than a standalone package.
+% \end{itemize}
+% \StopEventually{}
+%
+% \section{Implementation}
+%
+% \iffalse
+%<*package>
+% \fi
+%
+% Issue a notice that this is a depreciated version of the braids package.
+%    \begin{macrocode}
+\PackageWarning{braids}{%
+  This package has been reimplemented as a TikZ library; if starting with a fresh document, please consider using that instead.%
+}%
+%    \end{macrocode}
+%
+% \begin{macro}[internal]{\ge at addto@macro}
+% This is an expanded version of \Verb+\g at addto@macro+.
+% Namely, it adds the \emph{expansion} of the second argument to the first.
+%    \begin{macrocode}
+\long\def\ge at addto@macro#1#2{%
+  \begingroup
+  \toks@\expandafter\expandafter\expandafter{\expandafter#1#2}%
+  \xdef#1{\the\toks@}%
+  \endgroup}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\braid}
+% This is the user command.
+% We start a group to ensure that all our assignments are local, and then call our initialisation code.
+% The optional argument is for any keys to be set.
+%    \begin{macrocode}
+\newcommand{\braid}[1][]{%
+  \begingroup
+  \braid at start{#1}}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}[internal]{\braid at process}
+% This is the token swallower.
+% This takes the next token on the braid specification and passes it to the handler command (in the macro \Verb+\braid at token+) which decides what to do next.
+% (Incidentally, the code here is heavily influenced by TikZ.
+% That's probably not very surprising.)
+%    \begin{macrocode}
+\def\braid at process{%
+  \afterassignment\braid at handle\let\braid at token=%
+}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}[internal]{\braid at process@start}
+% This is a variant of \Verb+\braid at process+ which is used at the start where we might have a few extra bits and pieces before the braid itself starts.
+% Specifically, we test for the \Verb+at+ and \Verb+(name)+ possibilities.
+%    \begin{macrocode}
+\def\braid at process@start{%
+  \afterassignment\braid at handle@start\let\braid at token=%
+}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}[internal]{\braid at handle@start}
+% This is the handler in use at the start.
+% It looks for the tokens \Verb+a+ or \Verb+(+ which (might) signal the start of an \Verb+at (coordinate)+ or \Verb+(name)+.
+% If we get anything else (modulo spaces) we decide that we've reached the end of the initialisation stuff and it is time to get started on the braid itself.
+%    \begin{macrocode}
+\def\braid at handle@start{%
+  \let\braid at next=\braid at handle
+  \ifx\braid at token a
+%    \end{macrocode}
+% We got an \Verb+a+ so we might have an \Verb+at (coordinate)+
+%    \begin{macrocode}
+   \let\braid at next=\braid at maybe@locate
+  \else
+  \ifx\braid at token(%)
+%    \end{macrocode}
+% We got an \Verb+(+ so we have a name
+%    \begin{macrocode}
+   \iffalse)\fi %Indentation hack!
+   \let\braid at next=\braid at assign@name
+  \else
+  \ifx\braid at token\@sptoken
+%    \end{macrocode}
+% Space; boring, redo from start
+%    \begin{macrocode}
+   \let\braid at next=\braid at process@start
+  \fi
+  \fi
+  \fi
+  \braid at next%
+}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}[internal]{\braid at handle}
+% This is the main handler for parsing the braid word.
+% It decides what action to take depending on what the token is.
+% We have to be a bit careful with catcodes, some packages set
+% \Verb+;+ and \Verb+|+ to be active.
+% We should probably also be careful with \Verb+^+ and \Verb+_+.
+%    \begin{macrocode}
+\let\braid at semicolon=;
+\let\braid at bar=|
+\def\braid at handle{%
+  \let\braid at next=\braid at process
+%    \end{macrocode}
+% Start by checking our catcodes to see what we should check against
+%    \begin{macrocode}
+  \ifnum\the\catcode`\;=\active
+  \expandafter\let\expandafter\braid at semicolon\tikz at activesemicolon
+  \fi
+  \ifnum\the\catcode`\|=\active
+  \expandafter\let\expandafter\braid at bar\tikz at activebar
+  \fi
+  \ifx\braid at token\braid at semicolon
+%    \end{macrocode}
+% Semicolon, means that we're done reading our braid.
+% It's time to render it.
+%    \begin{macrocode}
+   \let\braid at next=\braid at render
+  \else
+  \ifx\braid at token^
+%    \end{macrocode}
+% Superscript character, the next token tells us whether it's an over-crossing or an under-crossing.
+%    \begin{macrocode}
+   \let\braid at next=\braid at sup
+  \else
+  \ifx\braid at token_
+%    \end{macrocode}
+% Subscript character, the next token tells us which strands cross.
+%    \begin{macrocode}
+   \let\braid at next=\braid at sub
+  \else
+  \ifx\braid at token-
+%    \end{macrocode}
+% Hyphen, this is so that we can have more than one crossing on the same level.
+%    \begin{macrocode}
+   \braid at increase@levelfalse
+  \else
+  \ifx\braid at token1%
+%    \end{macrocode}
+% 1: this means the ``identity'' crossing, so no crossing here.
+% Increase the level, unless overriden, and add to the label.
+%    \begin{macrocode}
+   \ifbraid at increase@level
+    \stepcounter{braid at level}
+   \fi
+   \braid at increase@leveltrue
+   \ge at addto@macro\braid at label{\braid at token}%
+  \else
+  \ifx\braid at token[%
+%    \end{macrocode}
+% Open bracket, this means we have some more options to process.
+%    \begin{macrocode}
+   \let\braid at next=\braid at process@options
+  \else
+  \ifx\braid at token\braid at bar
+%    \end{macrocode}
+% Bar, this tells us that we want a ``floor'' at this point.
+%    \begin{macrocode}
+   \edef\braid at tmp{,\expandafter\the\value{braid at level}}%
+   \ge at addto@macro\braid at floors\braid at tmp%
+  \else
+  \ifx\braid at token\bgroup
+%    \end{macrocode}
+% Begin group, which we reinterpret as begining a scope.
+%    \begin{macrocode}
+   \braid at beginscope
+  \else
+  \ifx\braid at token\egroup
+%    \end{macrocode}
+% End group, which ends the scope
+%    \begin{macrocode}
+   \braid at endscope
+  \else
+  \ifx\braid at token\braid at olabel@strand
+   \let\braid at next=\braid at olabel@strand
+  \else
+  \ifx\braid at token\braid at clabel@strand
+   \let\braid at next=\braid at clabel@strand
+  \else
+%    \end{macrocode}
+% Otherwise, we add the token to the braid label.
+%    \begin{macrocode}
+  \ge at addto@macro\braid at label{\braid at token}%
+  \fi
+  \fi
+  \fi
+  \fi
+  \fi
+  \fi
+  \fi
+  \fi
+  \fi
+  \fi
+  \fi
+  \braid at next%
+}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}[internal]{\braid at maybe@locate}
+% If we got an \Verb+a+ token in the \Verb+\braid at handle@start+ then it \emph{might} mean we're looking at \Verb+at (coordinate)+ or it might mean that the user has decided to use \Verb+a+ as the braid parameter.
+% So we examine the next token for a \Verb+t+. 
+%    \begin{macrocode}
+\def\braid at maybe@locate{%
+  \afterassignment\braid@@maybe at locate\let\braid at token=%
+}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}[internal]{\braid@@maybe at locate}
+% This is where we test for \Verb+t+ and act appropriately.
+%    \begin{macrocode}
+\def\braid@@maybe at locate{%
+  \let\braid at next=\braid at handle
+  \ifx\braid at token t
+   \let\braid at next=\braid at find@location
+  \fi
+  \braid at next%
+}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}[internal]{\braid at find@location}
+% This macro starts us looking for a coordinate.
+%    \begin{macrocode}
+\def\braid at find@location{%
+  \afterassignment\braid@@find at location\let\braid at token=%
+}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}[internal]{\braid@@find at location}
+% This is the test for the start of a coordinate.
+% If we get a \Verb+(+ that means we've reached the coordinate.
+% A space means ``carry on''.
+% Anything else is a (non-fatal) error.
+%    \begin{macrocode}
+\def\braid@@find at location{%
+  \let\braid at next=\braid at location@error
+  \ifx\braid at token(%)
+   \let\braid at next=\braid at locate
+  \else
+  \ifx\braid at token\@sptoken
+   \let\braid at next=\braid at find@location
+  \fi
+  \fi
+  \braid at next%
+}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}[internal]{\braid at location@error}
+% This is our error message for not getting a location.
+%    \begin{macrocode}
+\def\braid at location@error{%
+  \PackageWarning{braids}{Could not figure out location for braid}%
+  \braid at process@start%
+}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}[internal]{\braid at locate}
+% If we reached a \Verb+(+ when looking for a coordinate, everything up to the next \Verb+)+ is that coordinate.
+% Then we parse the coordinate and call the relocation macro.
+%    \begin{macrocode}
+\def\braid at locate#1){%
+  \tikz at scan@one at point\braid at relocate(#1)%
+}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}[internal]{\braid at relocate}
+% This is the macro that actually does the relocation.
+%    \begin{macrocode}
+\def\braid at relocate#1{%
+  #1\relax
+  \advance\pgf at x by -\braid at width
+  \pgftransformshift{\pgfqpoint{\pgf at x}{\pgf at y}}
+  \braid at process@start%
+}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}[internal]{\braid at assign@name}
+% This macro saves our name.
+%    \begin{macrocode}
+\def\braid at assign@name#1){%
+  \def\braid at name{#1}%
+  \braid at process@start%
+}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}[internal]{\braid at process@options}
+% The intention of this macro is to allow setting of style options mid-braid.
+% (At present, this wouldn't make a lot of sense.)
+%    \begin{macrocode}
+\def\braid at process@options#1]{%
+    \tikzset{#1}%
+  \braid at process%
+}
+%    \end{macrocode}
+% \end{macro}
+%
+% The next macros handle the actual braid elements.
+% Everything has to have a subscript, but the superscript is optional and can come before or after the subscript.
+%
+% \begin{macro}[internal]{\braid at sup}
+% This handles braid elements of the form \Verb+a^{-1}_2+.
+%    \begin{macrocode}
+\def\braid at sup#1_#2{%
+  \g at addto@macro\braid at label{_{#2}^{#1}}%
+  \braid at add@crossing{#2}{#1}%
+}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}[internal]{\braid at sub}
+%    \begin{macrocode}
+% This handles braid elements of the form \Verb+a_1+ or \Verb+a_1^{-1}+.
+\def\braid at sub#1{%
+  \@ifnextchar^{\braid@@sub{#1}}%
+  {\g at addto@macro\braid at label{_{#1}}\braid at add@crossing{#1}{1}}%
+}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}[internal]{\braid@@sub}
+% Helper macro for \Verb+\braid at sub+.
+%    \begin{macrocode}
+\def\braid@@sub#1^#2{%
+  \g at addto@macro\braid at label{_{#1}^{#2}}%
+  \braid at add@crossing{#1}{#2}%
+}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}[internal]{\braid at ne}
+% Remember what \Verb+1+ looks like for testing against.
+%    \begin{macrocode}
+\def\braid at ne{1}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}[internal]{\braid at add@crossing}
+% This is the macro which adds the crossing to the current list of strands.
+% The strands are stored as \emph{soft paths} (see the TikZ/PGF documentation).
+% So this selects the right strands and then extends them according to the crossing type.
+%    \begin{macrocode}
+\def\braid at add@crossing#1#2{%
+%    \end{macrocode}
+% Our crossing type, which is \Verb+#2+, is one of \Verb+1+ or \Verb+-1+.
+% Our strands are \Verb+#1+ and \Verb-#1+1-.
+%    \begin{macrocode}
+  \edef\braid at crossing@type{#2}%
+  \edef\braid at this@strand{#1}%
+  \pgfmathtruncatemacro{\braid at next@strand}{#1+1}
+%    \end{macrocode}
+% Increment the level counter, if requested.
+% The controls whether the crossing is on the same level as the previous one or is one level further on.
+%    \begin{macrocode}
+  \ifbraid at increase@level
+  \stepcounter{braid at level}
+  \fi
+%    \end{macrocode}
+% Default is to request increment so we set it for next time.
+%    \begin{macrocode}
+  \braid at increase@leveltrue
+%    \end{macrocode}
+% Now we figure out the coordinates of the crossing.
+% \Verb+(\braid at tx,\braid at ty)+ is the top-left corner (assuming the braid flows down the page).
+% \Verb+(\braid at nx,\braid at ny)+ is the bottom-right corner (assuming the braid flows down the page).
+% We start by setting \Verb+(\braid at tx,\braid at ty)+ according to the level and strand number, then shift \Verb+\braid at ty+ by \Verb+\braid at eh+ which is the ``edge height'' (the little extra at the start and end of each strand).
+% Then from these values, we set \Verb+(\braid at nx,\braid at ny)+ by adding on the appropriate amount.
+% The heights \Verb+\braid at cy+ and \Verb+\braid at dy+ are for the control points for the strands as they cross.
+% They're actually the same height, but using two gives us the possibility of changing them independently in a later version of this package.
+% Lastly, we bring \Verb+\braid at ty+ and \Verb+\braid at ny+ towards each other just a little so that there is ``clear water'' between subsequent crossings (makes it look a bit better if the same strand is used in subsequent crossings).
+%    \begin{macrocode}
+  \braid at tx=\braid at this@strand\braid at width
+  \braid at ty=\value{braid at level}\braid at height
+  \advance\braid at ty by \braid at eh
+  \braid at nx=\braid at tx
+  \braid at ny=\braid at ty
+  \advance\braid at nx by \braid at width
+  \advance\braid at ny by \braid at height
+  \advance\braid at ty by \braid at nf\braid at height
+  \advance\braid at ny by -\braid at nf\braid at height
+  \braid at cy=\braid at ty
+  \braid at dy=\braid at ny
+  \advance\braid at cy by \braid at cf\braid at height
+  \advance\braid at dy by -\braid at cf\braid at height
+%    \end{macrocode}
+% Now we try to find a starting point for the strand ending here.
+% We might not have used this strand before, so it might not exist.
+%    \begin{macrocode}
+  \expandafter\let\expandafter\braid at this@path at origin%
+  \csname braid at strand@\braid at this@strand @origin\endcsname
+%    \end{macrocode}
+% If we haven't seen this strand before, that one will be \Verb+\relax+.
+%    \begin{macrocode}
+\ifx\braid at this@path at origin\relax
+%    \end{macrocode}
+% Haven't seen this strand before, so initialise it.
+% Record the initial position of the strand.
+%    \begin{macrocode}
+  \let\braid at this@path at origin\braid at this@strand
+%    \end{macrocode}
+% Start a new soft path.
+%    \begin{macrocode}
+  \pgfsyssoftpath at setcurrentpath{\@empty}
+  \pgfpathmoveto{\pgfpoint{\braid at tx}{0pt}}
+%    \end{macrocode}
+% Save the path as \Verb+\braid at this@path+.
+%    \begin{macrocode}
+  \pgfsyssoftpath at getcurrentpath{\braid at this@path}
+  \else
+%    \end{macrocode}
+% We have seen this before, so we simply copy the associated path in to \Verb+\braid at this@path+.
+%    \begin{macrocode}
+  \expandafter\let\expandafter\braid at this@path%
+  \csname braid at strand@\braid at this@path at origin\endcsname
+  \fi
+%    \end{macrocode}
+% Now we do the same again with the other strand in the crossing.
+%    \begin{macrocode}
+  \expandafter\let\expandafter\braid at next@path at origin%
+  \csname braid at strand@\braid at next@strand @origin\endcsname
+  \ifx\braid at next@path at origin\relax
+  \let\braid at next@path at origin\braid at next@strand
+  \pgfsyssoftpath at setcurrentpath{\@empty}
+  \pgfpathmoveto{\pgfpoint{\braid at nx}{0pt}}
+  \pgfsyssoftpath at getcurrentpath{\braid at next@path}
+  \else
+  \expandafter\let\expandafter\braid at next@path%
+  \csname braid at strand@\braid at next@path at origin\endcsname
+  \fi
+%    \end{macrocode}
+% Now that we have the paths for our two strands, we extend them to the next level.
+% We start by selecting the first path.
+%    \begin{macrocode}
+  \pgfsyssoftpath at setcurrentpath{\braid at this@path}
+%    \end{macrocode}
+% Draw a line down to the current level, note that this line is always non-trivial since we shifted the corners of the crossing in a little. 
+%    \begin{macrocode}
+  \pgfpathlineto{\pgfqpoint{\braid at tx}{\braid at ty}}
+%    \end{macrocode}
+% Curve across to the next position.
+% Depending on the crossing type, we either have a single curve or we have to break it in two.
+% Our gap is to interrupt at times determined by the gap key.
+%    \begin{macrocode}
+\pgfmathsetmacro{\braid at gst}{0.5 - \pgfkeysvalueof{/pgf/braid/gap}}%
+\pgfmathsetmacro{\braid at gend}{0.5 + \pgfkeysvalueof{/pgf/braid/gap}}%
+\ifx\braid at crossing@type\braid at over@cross
+%    \end{macrocode}
+% We're on the overpass, so just one curve needed.
+%    \begin{macrocode}
+  \pgfpathcurveto{\pgfqpoint{\braid at tx}{\braid at cy}}%
+  {\pgfqpoint{\braid at nx}{\braid at dy}}%
+  {\pgfqpoint{\braid at nx}{\braid at ny}}
+\else
+%    \end{macrocode}
+% We're on the underpass, so we need to interrupt our path to allow the other curve to go past.
+%    \begin{macrocode}
+  \pgfpathcurvebetweentimecontinue{0}{\braid at gst}%
+  {\pgfqpoint{\braid at tx}{\braid at ty}}%
+  {\pgfqpoint{\braid at tx}{\braid at cy}}%
+  {\pgfqpoint{\braid at nx}{\braid at dy}}%
+  {\pgfqpoint{\braid at nx}{\braid at ny}}%
+  \pgfpathcurvebetweentime{\braid at gend}{1}%
+  {\pgfqpoint{\braid at tx}{\braid at ty}}%
+  {\pgfqpoint{\braid at tx}{\braid at cy}}%
+  {\pgfqpoint{\braid at nx}{\braid at dy}}%
+  {\pgfqpoint{\braid at nx}{\braid at ny}}
+\fi
+%    \end{macrocode}
+% We're done with this path, so now we save it.
+%    \begin{macrocode}
+  \pgfsyssoftpath at getcurrentpath{\braid at this@path}
+%    \end{macrocode}
+% Now do the same with the second path.
+%    \begin{macrocode}
+  \pgfsyssoftpath at setcurrentpath{\braid at next@path}
+  \pgfpathlineto{\pgfqpoint{\braid at nx}{\braid at ty}}
+\ifx\braid at crossing@type\braid at over@cross
+  \pgfpathcurvebetweentimecontinue{0}{\braid at gst}%
+  {\pgfqpoint{\braid at nx}{\braid at ty}}%
+  {\pgfqpoint{\braid at nx}{\braid at cy}}%
+  {\pgfqpoint{\braid at tx}{\braid at dy}}%
+  {\pgfqpoint{\braid at tx}{\braid at ny}}
+  \pgfpathcurvebetweentime{\braid at gend}{1}%
+  {\pgfqpoint{\braid at nx}{\braid at ty}}%
+  {\pgfqpoint{\braid at nx}{\braid at cy}}%
+  {\pgfqpoint{\braid at tx}{\braid at dy}}%
+  {\pgfqpoint{\braid at tx}{\braid at ny}}
+\else
+  \pgfpathcurveto{\pgfqpoint{\braid at nx}{\braid at cy}}%
+  {\pgfqpoint{\braid at tx}{\braid at dy}}%
+  {\pgfqpoint{\braid at tx}{\braid at ny}}
+\fi
+  \pgfsyssoftpath at getcurrentpath{\braid at next@path}
+%    \end{macrocode}
+% Now save the paths to their proper macros again.
+%    \begin{macrocode}
+  \expandafter\let%
+  \csname braid at strand@\braid at this@path at origin \endcsname%
+  \braid at this@path
+  \expandafter\let%
+  \csname braid at strand@\braid at next@path at origin \endcsname%
+  \braid at next@path
+%    \end{macrocode}
+% Now update the origins
+%    \begin{macrocode}
+  \expandafter\let%
+  \csname braid at strand@\braid at this@strand @origin\endcsname%
+  \braid at next@path at origin
+  \expandafter\let%
+  \csname braid at strand@\braid at next@strand @origin\endcsname%
+  \braid at this@path at origin
+%    \end{macrocode}
+% increment the strand counter, if necessary
+%    \begin{macrocode}
+  \pgfmathparse{\value{braid at strands} < \braid at next@strand ?
+    "\noexpand\setcounter{braid at strands}{\braid at next@strand}" : ""}
+  \pgfmathresult
+%    \end{macrocode}
+% And merrily go on our way with the next bit of the braid specification.
+%    \begin{macrocode}
+  \braid at process%
+}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}[internal]{\braid at olabel@strand}
+% This macro allows us to label a strand just before a crossing.
+% The first argument is the strand number at that particular crossing and the second is the label.
+% We also save the current height.
+% This version takes the strand number as meaning the \emph{original} ordering.
+%    \begin{macrocode}
+\newcommand{\braid at olabel@strand}[3][]{%
+  \edef\braid at tmp{{\the\value{braid at level}}}%
+  \expandafter\ifx\csname braid at strand@#2 at origin\endcsname\relax
+  \g at addto@macro\braid at tmp{{#2}}%
+  \else
+  \edef\braid at tmpa{{\csname braid at strand@#2 at origin\endcsname}}%
+  \ge at addto@macro\braid at tmp{\braid at tmpa}%
+  \fi
+  \g at addto@macro\braid at tmp{{#3}{#1}}%
+  \ge at addto@macro{\braid at strand@labels}{\braid at tmp}%
+  \braid at process%
+}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}[internal]{\braid at clabel@strand}
+% This macro allows us to label a strand just before a crossing.
+% The first argument is the strand number at that particular crossing and the second is the label.
+% We also save the current height.
+% This version takes the strand number as meaning the \emph{current} ordering.
+%    \begin{macrocode}
+\newcommand{\braid at clabel@strand}[3][]{%
+  \edef\braid at tmp{{\the\value{braid at level}}}%
+  \g at addto@macro\braid at tmp{{#2}{#3}{#1}}%
+  \ge at addto@macro{\braid at strand@labels}{\braid at tmp}%
+  \braid at process%
+}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}[internal]{\braid at floors@trim}
+% The list of floors, if given, will start with a superfluous comma.
+% This removes it.
+%    \begin{macrocode}
+\def\braid at floors@trim,{}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}[internal]{\braid at render@floor}
+% This is the default rendering for floors: it draws a rectangle.
+%    \begin{macrocode}
+\def\braid at render@floor{%
+    \draw (\floorsx,\floorsy) rectangle (\floorex,\floorey);
+}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}[internal]{\braid at render@strand at labels}
+% This starts rendering the labels on the strands at the crossings.
+%    \begin{macrocode}
+\def\braid at render@strand at labels#1{%
+  \def\braid at tmp{#1}%
+  \ifx\braid at tmp\pgfutil at empty
+  \let\braid at next=\pgfutil at gobble
+  \else
+  \let\braid at next=\braid@@render at strand@labels
+  \fi
+  \braid at next{#1}%  
+}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}[internal]{\braid@@render at strand@labels}
+% This is the actual renderer.
+%    \begin{macrocode}
+\def\braid@@render at strand@labels#1#2#3#4{%
+  \begingroup
+  \pgfscope
+  \let\tikz at options=\pgfutil at empty
+  \let\tikz at mode=\pgfutil at empty
+  \let\tik at transform=\pgfutil at empty
+  \let\tikz at fig@name=\pgfutil at empty
+  \tikzset{/pgf/braid/strand label,#4}%
+  \braid at nx=#2\braid at width
+  \braid at ny=#1\braid at height
+  \advance\braid at ny by \braid at eh
+  \advance\braid at ny by \braid at height
+  \pgftransformshift{\pgfqpoint{\braid at nx}{\braid at ny}}%
+  \tikz at options
+  \setbox\pgfnodeparttextbox=\hbox%
+  \bgroup%
+  \tikzset{every text node part/.try}%
+  \ifx\tikz at textopacity\pgfutil at empty%
+  \else%
+  \pgfsetfillopacity{\tikz at textopacity}%
+  \pgfsetstrokeopacity{\tikz at textopacity}%
+  \fi%
+  \pgfinterruptpicture%
+  \tikz at textfont%  
+  \ifx\tikz at text@width\pgfutil at empty%
+  \else%
+  \begingroup%
+  \pgfmathsetlength{\pgf at x}{\tikz at text@width}%
+  \pgfutil at minipage[t]{\pgf at x}\leavevmode\hbox{}%
+  \tikz at text@action%
+  \fi%
+  \tikz at atbegin@node%
+  \bgroup%
+  \aftergroup\unskip%
+  \ifx\tikz at textcolor\pgfutil at empty%
+  \else%
+  \pgfutil at colorlet{.}{\tikz at textcolor}%
+  \fi%
+  \pgfsetcolor{.}%
+  \setbox\tikz at figbox=\box\pgfutil at voidb@x%
+  \tikz at uninstallcommands%
+  \tikz at halign@check%
+  \ignorespaces%
+  #3
+  \egroup
+  \tikz at atend@node%
+  \ifx\tikz at text@width\pgfutil at empty%
+  \else%
+  \pgfutil at endminipage%
+  \endgroup%
+  \fi%
+  \endpgfinterruptpicture%
+  \egroup%
+   \ifx\tikz at text@width\pgfutil at empty%
+    \else%
+      \pgfmathsetlength{\pgf at x}{\tikz at text@width}%
+      \wd\pgfnodeparttextbox=\pgf at x%
+    \fi%
+    \ifx\tikz at text@height\pgfutil at empty%
+    \else%
+      \pgfmathsetlength{\pgf at x}{\tikz at text@height}%
+      \ht\pgfnodeparttextbox=\pgf at x%
+    \fi%
+    \ifx\tikz at text@depth\pgfutil at empty%
+    \else%
+      \pgfmathsetlength{\pgf at x}{\tikz at text@depth}%
+      \dp\pgfnodeparttextbox=\pgf at x%
+    \fi%
+  \pgfmultipartnode{\tikz at shape}{\tikz at anchor}{\tikz at fig@name}{%
+    {\begingroup\tikz at finish}%
+  }%
+  \endpgfscope
+  \endgroup
+  \braid at render@strand at labels%
+}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}[internal]{\braid at render}
+% This is called at the end of the braid and it renders the braids and floors according to whatever has been built up up to now.
+%    \begin{macrocode}
+\def\braid at render{
+%    \end{macrocode}
+% Check for floors since we do them first.
+%    \begin{macrocode}
+    \ifx\braid at floors\@empty
+    \else
+%    \end{macrocode}
+% Have some floors, start a scope and prepare to render them.
+%    \begin{macrocode}
+    \pgfsys at beginscope
+%    \end{macrocode}
+% Clear the path (just to be sure).
+%    \begin{macrocode}
+    \pgfsyssoftpath at setcurrentpath{\empty}
+%    \end{macrocode}
+% Trim the initial comma off the list of floors.
+%    \begin{macrocode}
+    \edef\braid at floors{\expandafter\braid at floors@trim\braid at floors}
+%    \end{macrocode}
+% Initialise our horizontal coordinates.
+%    \begin{macrocode}
+    \braid at tx=\braid at width
+    \advance\braid at tx by \braid at eh
+    \braid at nx=\value{braid at strands}\braid at width
+    \advance\braid at nx by -\braid at eh
+%    \end{macrocode}
+% Loop over the list of floors.
+%    \begin{macrocode}
+    \foreach \braid at f in \braid at floors {
+      \pgfsys at beginscope
+%    \end{macrocode}
+% Figure out the vertical coordinates for the current floor.
+%    \begin{macrocode}
+      \braid at ty=\braid at f\braid at height
+      \advance\braid at ty by \braid at eh
+      \advance\braid at ty by \braid at height
+      \braid at ny=\braid at ty
+      \advance\braid at ny by \braid at height
+%    \end{macrocode}
+% Save the coordinates for use in the floor rendering macro.
+%    \begin{macrocode}
+      \edef\floorsx{\the\braid at tx}
+      \edef\floorsy{\the\braid at ty}
+      \edef\floorex{\the\braid at nx}
+      \edef\floorey{\the\braid at ny}
+      \let\tikz at options=\pgfutil at empty
+%    \end{macrocode}
+% Load general floor style options.
+%    \begin{macrocode}
+    \expandafter\tikzset\expandafter{\braid at floors@style}
+%    \end{macrocode}
+% Load any style options specific to this floor.
+% We're actually offset by 2 from what the user thinks the floor level is.
+%    \begin{macrocode}
+      \pgfmathtruncatemacro{\braid at ff}{\braid at f+2}
+%    \end{macrocode}
+% Load the relevant floor style, if it exists.
+%    \begin{macrocode}
+    \expandafter\let\expandafter\braid at floor@style%
+    \csname braid at options@floor@\braid at ff\endcsname
+    \ifx\braid at floor@style\relax
+    \else
+%    \end{macrocode}
+% There is a floor style for this level, so process it.
+%    \begin{macrocode}
+    \expandafter\tikzset\expandafter{\braid at floor@style}%
+    \fi
+%    \end{macrocode}
+% The \Verb+\tikzset+ just parses the options, we need to call \Verb+\tikz at options+ to actually set them. 
+%    \begin{macrocode}
+\tikz at options
+%    \end{macrocode}
+% Now we call the rendering code.
+%    \begin{macrocode}
+\braid at render@floor
+%    \end{macrocode}
+% Done!
+% End the scope for \emph{this} floor and go again.
+%    \begin{macrocode}
+\pgfsys at endscope
+    }
+%    \end{macrocode}
+% Done rendering floors, end the scope.
+%    \begin{macrocode}
+    \pgfsys at endscope
+    \fi
+%    \end{macrocode}
+% Finished with floors (if we had them), now get on with the strands.
+%    \begin{macrocode}
+  \stepcounter{braid at level}
+  \foreach \braid at k in {1,...,\value{braid at strands}} {
+%    \end{macrocode}
+% Start a local scope to ensure we don't mess with other braids
+%    \begin{macrocode}
+    \pgfsys at beginscope
+%    \end{macrocode}
+% Default is to draw each braid
+%    \begin{macrocode}
+    \tikz at mode@drawtrue%
+    \let\tikz at mode=\pgfutil at empty
+    \let\tikz at options=\pgfutil at empty
+%    \end{macrocode}
+% (x,y) coordinates of bottom of strand
+%    \begin{macrocode}
+    \braid at tx=\braid at k\braid at width
+    \braid at ty=\value{braid at level}\braid at height
+    \advance\braid at ty by 2\braid at eh
+%    \end{macrocode}
+% Try to find the starting point of this strand
+%    \begin{macrocode}
+    \expandafter\let\expandafter\braid at path@origin%
+    \csname braid at strand@\braid at k @origin\endcsname
+    \ifx\braid at path@origin\relax
+%    \end{macrocode}
+% If that doesn't exist, we'll just draw a straight line
+% so we move to the top of the current position
+%    \begin{macrocode}
+    \pgfsyssoftpath at setcurrentpath{\@empty}
+    \pgfpathmoveto{\pgfqpoint{\braid at tx}{0pt}}
+    \let\braid at path@origin\braid at k
+    \else
+%    \end{macrocode}
+% If the path does exist, we load it
+%    \begin{macrocode}
+    \expandafter\let\expandafter\braid at path%
+    \csname braid at strand@\braid at path@origin\endcsname
+    \pgfsyssoftpath at setcurrentpath{\braid at path}
+    \fi
+%    \end{macrocode}
+% Extend the path to the bottom
+%    \begin{macrocode}
+    \pgflineto{\pgfqpoint{\braid at tx}{\braid at ty}}
+%    \end{macrocode}
+% Load common style options
+%    \begin{macrocode}
+    \expandafter\tikzset\expandafter{\braid at style}
+%    \end{macrocode}
+% Load any style options specific to this strand
+%    \begin{macrocode}
+    \expandafter\let\expandafter\braid at style%
+    \csname braid at options@strand@\braid at path@origin\endcsname
+    \ifx\braid at style\relax
+    \else
+    \expandafter\tikzset\expandafter{\braid at style}
+    \fi
+\braid at options
+    \tikz at mode
+    \tikz at options
+%    \end{macrocode}
+% This is the command that actually draws the strand.
+%    \begin{macrocode}
+      \edef\tikz at temp{\noexpand\pgfusepath{%
+          \iftikz at mode@draw draw\fi%
+      }}%
+      \tikz at temp
+%    \end{macrocode}
+% If our braid has a name, we label the ends of the strand.
+%    \begin{macrocode}
+\ifx\braid at name\pgfutil at empty
+\else
+%    \end{macrocode}
+% Label the ends of the strand.
+%    \begin{macrocode}
+\coordinate (\braid at name-\braid at path@origin-e) at (\braid at tx,\braid at ty);
+\coordinate (\braid at name-rev-\braid at k-e) at (\braid at tx,\braid at ty);
+\braid at nx=\braid at path@origin\braid at width
+\coordinate (\braid at name-\braid at path@origin-s) at (\braid at nx,0pt);
+\coordinate (\braid at name-rev-\braid at k-s) at (\braid at nx,0pt);
+\fi
+%    \end{macrocode}
+% Done with this strand, close the scope and do the next one.
+%    \begin{macrocode}
+   \pgfsys at endscope
+  }
+%    \end{macrocode}
+% If our braid has a name, we also want to label the centre.
+%    \begin{macrocode}
+    \ifx\braid at name\pgfutil at empty
+    \else
+    \braid at tx=\value{braid at strands}\braid at width
+    \braid at ty=\value{braid at level}\braid at height
+    \advance\braid at ty by 2\braid at eh
+    \advance\braid at tx by \braid at width
+    \braid at tx=.5\braid at tx
+    \braid at ty=.5\braid at ty
+    \coordinate (\braid at name) at (\braid at tx,\braid at ty);
+    \fi
+%    \end{macrocode}
+% Now we label the strands if needed.
+%    \begin{macrocode}
+  \ifx\braid at strand@labels\pgfutil at empty
+  \else
+   \expandafter\braid at render@strand at labels\braid at strand@labels{}%
+  \fi
+%    \end{macrocode}
+% All done now, close the scope and end the group (which was opened right at the start).
+%    \begin{macrocode}
+    \pgfsys at endscope
+  \endgroup}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}[internal]{\braid at start}
+% This starts off the braid, initialising a load of stuff.
+% We start a PGF scope, set the level to \(-1\), the label, floors, and name to empty, process any options we're given, and save certain lengths for later use..
+%    \begin{macrocode}
+\def\braid at start#1{%
+  \pgfsys at beginscope
+  \setcounter{braid at level}{-1}%
+  \let\braid at label\@empty
+  \let\braid at strand@labels\@empty
+  \let\braid at floors\@empty
+  \let\braid at name\empty
+  \let\clabel=\braid at clabel@strand
+  \let\olabel=\braid at olabel@strand
+  \pgfkeys{/pgf/braid/.cd,#1}%
+  \ifbraid at strand@labels at origin
+  \let\label=\braid at olabel@strand
+  \else
+  \let\label=\braid at clabel@strand
+  \fi
+  \let\braid at options\tikz at options
+  \tikz at transform
+  \setcounter{braid at strands}{%
+    \pgfkeysvalueof{/pgf/braid/number of strands}}%
+  \braid at width=\pgfkeysvalueof{/pgf/braid/width}%
+  \braid at height=\pgfkeysvalueof{/pgf/braid/height}%
+  \braid at eh=\pgfkeysvalueof{/pgf/braid/border height}%
+  \pgfkeysgetvalue{/pgf/braid/control factor}{\braid at cf}%
+  \pgfkeysgetvalue{/pgf/braid/nudge factor}{\braid at nf}%
+  \braid at height=-\braid at height
+  \braid at eh=-\braid at eh
+  \braid at increase@leveltrue
+  \braid at process@start
+}
+%    \end{macrocode}
+% \end{macro}
+%
+% These are the lengths we'll use as we construct the braid
+%    \begin{macrocode}
+\newdimen\braid at width
+\newdimen\braid at height
+\newdimen\braid at tx
+\newdimen\braid at ty
+\newdimen\braid at nx
+\newdimen\braid at ny
+\newdimen\braid at cy
+\newdimen\braid at dy
+\newdimen\braid at eh
+%    \end{macrocode}
+%
+% An if to decide whether or not to step to the next level or not
+%    \begin{macrocode}
+\newif\ifbraid at increase@level
+%    \end{macrocode}
+% An if to decide whether label indices should be absolute or not
+%    \begin{macrocode}
+\newif\ifbraid at strand@labels at origin
+%    \end{macrocode}
+%
+%
+% Some initial values
+%    \begin{macrocode}
+\let\braid at style\pgfutil at empty
+\let\braid at floors@style\pgfutil at empty
+\def\braid at over@cross{1}
+%    \end{macrocode}
+%
+% Counters to track the strands and the levels.
+%    \begin{macrocode}
+\newcounter{braid at level}
+\newcounter{braid at strands}
+%    \end{macrocode}
+%
+% All the keys we'll use.
+%    \begin{macrocode}
+\pgfkeys{
+%    \end{macrocode}
+% Handle unknown keys by passing them to \Verb+pgf+ and \Verb+tikz+.
+%    \begin{macrocode}
+    /tikz/braid/.search also={/pgf},
+    /pgf/braid/.search also={/pgf,/tikz},
+%    \end{macrocode}
+% Our ``namespace'' is \Verb+/pgf/braid+.
+%    \begin{macrocode}
+    /pgf/braid/.cd,
+    number of strands/.initial=0,
+    height/.initial=1cm,
+    width/.initial=1cm,
+    gap/.initial=.1,
+    border height/.initial=.25cm,
+    control factor/.initial=.5,
+    nudge factor/.initial=.05,
+    name/.code={%
+      \def\braid at name{#1}%
+    },
+    at/.code={%
+      \braid at relocate{#1}%
+    },
+    floor command/.code={%
+      \def\braid at render@floor{#1}%
+    },
+    style strands/.code 2 args={%
+      \def\braid at temp{#2}%
+      \braidset{style each strand/.list={#1}}%
+    },
+    style each strand/.code={%
+      \expandafter\edef%
+      \csname braid at options@strand@#1\endcsname{\braid at temp}%
+    },
+    style floors/.code 2 args={%
+      \def\braid at temp{#2}%
+      \braidset{style each floor/.list={#1}}%
+    },
+    style each floor/.code={%
+      \expandafter\edef%
+      \csname braid at options@floor@#1\endcsname{\braid at temp}%
+    },
+    style all floors/.code={%
+      \def\braid at floors@style{#1}
+    },
+    strand label/.style={},
+    strand label by origin/.is if=braid at strand@labels at origin,
+}
+%    \end{macrocode}
+% \begin{macro}{\braidset}
+% Shorthand for setting braid-specific keys.
+%    \begin{macrocode}
+\def\braidset#1{%
+  \pgfkeys{/pgf/braid/.cd,#1}}
+%    \end{macrocode}
+% \end{macro}
+%
+% \iffalse
+%</package>
+% \fi
+%    \begin{macrocode}
+%<*library>
+%<@@=braid>
+%    \end{macrocode}
+%
+% \section{Reimplementation as a TikZ Library}
+%
+% Life is so much easier with \LaTeX3.
+%    \begin{macrocode}
+\ProvidesFile{tikzlibrarybraids.code.tex}[%
+  2019/03/20 v2.0 Tikz/PGF library for drawing braid diagrams%
+]
+\RequirePackage{expl3}
+\ExplSyntaxOn
+%    \end{macrocode}
+% Define all the variables we'll be using.
+%    \begin{macrocode}
+\tl_new:N \l_@@_tmpa_tl
+\tl_new:N \l_@@_tmpb_tl
+\tl_new:N \l_@@_tmpc_tl
+\tl_new:N \l_@@_tmpd_tl
+\tl_new:N \l_@@_anchor_strand_tl
+\tl_new:N \l_@@_anchor_level_tl
+\fp_new:N \l_@@_height_fp
+\fp_new:N \l_@@_width_fp
+\fp_new:N \l_@@_nudge_fp
+\fp_new:N \l_@@_control_fp
+\fp_new:N \l_@@_ctrlax_fp
+\fp_new:N \l_@@_ctrlay_fp
+\fp_new:N \l_@@_ctrlbx_fp
+\fp_new:N \l_@@_ctrlby_fp
+\fp_new:N \l_@@_endx_fp
+\fp_new:N \l_@@_endy_fp
+\fp_new:N \l_@@_anchor_x_fp
+\fp_new:N \l_@@_anchor_y_fp
+\int_new:N \l_@@_tmpa_int
+\int_new:N \l_@@_length_int
+\int_new:N \l_@@_strands_int
+\int_new:N \l_@@_crossing_int
+\int_new:N \l_@@_anchor_level_int
+\int_new:N \l_@@_floor_int
+\seq_new:N \l_@@_word_seq
+\seq_new:N \l_@@_crossing_seq
+\seq_new:N \l_@@_anchor_seq
+\seq_new:N \l_@@_floors_seq
+\str_new:N \l_@@_tmpa_str
+\str_new:N \l_@@_sup_str
+\str_set:Nn \l_@@_sup_str {^}
+\str_new:N \l_@@_sub_str
+\str_set:Nn \l_@@_sub_str {_}
+\str_new:N \l_@@_hyphen_str
+\str_set:Nn \l_@@_hyphen_str {-}
+\str_new:N \l_@@_bar_str
+\str_set:Nn \l_@@_bar_str {|}
+\str_new:N \l_@@_one_str
+\str_set:Nn \l_@@_one_str {1}
+\bool_new:N \l_@@_step_level_bool
+\bool_new:N \l_@@_swap_crossing_bool
+\bool_new:N \l_@@_floor_bool
+\prop_new:N \l_@@_strands_prop
+\prop_new:N \l_@@_permutation_prop
+\prop_new:N \l_@@_crossing_permutation_prop
+\prop_new:N \l_@@_inverse_prop
+\prop_new:N \l_@@_anchor_prop
+%    \end{macrocode}
+% Our interface is through a TikZ pic.
+%    \begin{macrocode}
+\tikzset{
+   braid/.pic={
+     code={
+       \@@_parse_word:n {#1}
+       \@@_count:
+       \@@_render:
+     }
+   },
+   floor/.pic={
+     code={
+       \path[pic~ actions, draw=none] (0,0) rectangle (1,1);
+       \path[pic~ actions, fill=none] (0,0) -- (1,0) (0,1) -- (1,1);
+     }
+   },
+   /tikz/braid/.search~ also={/tikz},
+   braid/.cd,
+%    \end{macrocode}
+% The various TikZ parameters for the braid.
+%
+% The anchor determines which part of the braid is located at the position specified by the pic.
+% It can be of the form \Verb+n-m+ where \Verb+n+ is a strand number and +m+ is a crossing level.
+% The strand number can be either a number or \Verb+rev-n+ to use the ending numbering of the strands.
+% The crossing level can also be \Verb+s+ or \Verb+e+ which means the actual start or end of the strand (including the border).
+%
+%    \begin{macrocode}
+   anchor/.initial=1-s,
+%    \end{macrocode}
+% \Verb+number of strands+ sets a minimum for the number of strands in the braid (otherwise, it is set by the strands used in the specified crossings).
+%    \begin{macrocode}
+   number~ of~ strands/.initial=0,
+%    \end{macrocode}
+% \Verb+height+ is the distance between crossings (can be negative).
+%    \begin{macrocode}
+   height/.initial=-1cm,
+%    \end{macrocode}
+% \Verb+width+ is the distance between strands (can be negative).
+%    \begin{macrocode}
+   width/.initial=1cm,
+%    \end{macrocode}
+% \Verb+gap+ is for determining the gap in the under-strand of a crossing.
+%    \begin{macrocode}
+   gap/.initial=.05,
+%    \end{macrocode}
+% \Verb+border height+ is a length added at the start and end of each strand.
+%    \begin{macrocode}
+   border~ height/.initial=.25cm,
+%    \end{macrocode}
+% \Verb+floor border+ is added to the width of any floors
+%    \begin{macrocode}
+   floor~ border/.initial=.25cm,
+%    \end{macrocode}
+% \Verb+floors+ is a list of floors to draw, specified as a cslist of coordinates as (x,y,w,h,a) in which the units are numbers of strands and crossing levels.
+% The parameters are: coordinates of lower left corner, width, height, (optional) name for styling.
+%    \begin{macrocode}
+   add~ floor/.code={
+     \seq_push:Nn \l_@@_floors_seq {#1}
+   },
+%    \end{macrocode}
+% \Verb+control factor+ determines the proportion of the \Verb+height+ used for the control points.
+%    \begin{macrocode}
+   control~ factor/.initial=.5,
+%    \end{macrocode}
+% \Verb+nudge factor+ is used to compress each crossing slightly within its rectangle.
+%    \begin{macrocode}
+   nudge~ factor/.initial=.05
+}
+%    \end{macrocode}
+%
+% \begin{macro}[internal]{\@@_parse_word:Nn}
+% Parse the braid word as a token list and convert it into a sequence.
+%    \begin{macrocode}
+\cs_new_nopar:Npn \@@_parse_word:n #1
+{
+  \seq_clear:N \l_@@_word_seq
+  \tl_clear:N \l_@@_tmpa_tl
+  \tl_set:Nn \l_@@_tmpb_tl {#1}
+
+  \bool_until_do:nn { \tl_if_empty_p:N \l_@@_tmpb_tl }
+  {
+%    \end{macrocode}
+% We step through the braid specification, looking for special characters.
+% To avoid catcode issues, the comparison is as strings.    
+% Some actions may involve consuming more tokens from the list so we can't do a simple \Verb+map_inline+ but have to keep stripping off the head token.
+%
+% The idea is to store information about the current crossing in a token list (noting that it may be specified in a variety of orders) and then when we're sure we have all the information we add it to our sequence of crossings.    
+%    \begin{macrocode}
+    \str_set:Nx \l_@@_tmpa_str {\tl_head:N \l_@@_tmpb_tl}
+    \tl_set:Nx \l_@@_tmpb_tl {\tl_tail:N \l_@@_tmpb_tl}
+%    \end{macrocode}
+%
+%    \begin{macrocode}
+    \str_case_e:nnTF {\l_@@_tmpa_str}
+    {
+%    \end{macrocode}
+% Underscore introduces the crossing numbers
+%    \begin{macrocode}
+      {_}
+     {
+       \tl_put_right:Nx \l_@@_tmpa_tl
+       {
+         \exp_not:N \@@_parse_index:n {\tl_head:N \l_@@_tmpb_tl}
+       }
+       \tl_set:Nx \l_@@_tmpb_tl {\tl_tail:N \l_@@_tmpb_tl}
+     }
+%    \end{macrocode}
+% Power is used to indicate inverse.
+%    \begin{macrocode}
+     {^}
+     {
+       \tl_put_left:Nx \l_@@_tmpa_tl
+       {
+         \exp_not:N \@@_parse_exponent:n {\tl_head:N \l_@@_tmpb_tl}
+       }
+       \tl_set:Nx \l_@@_tmpb_tl {\tl_tail:N \l_@@_tmpb_tl}
+     }
+%    \end{macrocode}
+% Bar is for floors.
+%    \begin{macrocode}
+     {|}
+     {
+      \tl_if_empty:NF \l_@@_tmpa_tl
+      {
+        \seq_put_right:NV \l_@@_word_seq \l_@@_tmpa_tl
+        \tl_clear:N \l_@@_tmpa_tl
+      }
+
+      \tl_set:Nn \l_@@_tmpa_tl {
+        \bool_set_false:N \l_@@_step_level_bool
+        \bool_set_true:N \l_@@_floor_bool
+      }
+      \seq_put_right:NV \l_@@_word_seq \l_@@_tmpa_tl
+      \tl_clear:N \l_@@_tmpa_tl
+     }
+%    \end{macrocode}
+% Hyphen says the next crossing is on the same level as the current one.
+%    \begin{macrocode}
+     {-}
+     {
+       \tl_put_right:Nn \l_@@_tmpa_tl
+       {
+         \bool_set_false:N \l_@@_step_level_bool
+       }
+     }
+%    \end{macrocode}
+% \(1\) is for the identity (i.e., no crossing but still have a level).
+% We put a nop token on the list so that it is no longer empty.     
+%    \begin{macrocode}
+     {1}
+     {
+      \tl_if_empty:NF \l_@@_tmpa_tl
+      {
+        \seq_put_right:NV \l_@@_word_seq \l_@@_tmpa_tl
+        \tl_clear:N \l_@@_tmpa_tl
+      }
+       \tl_put_right:Nn \l_@@_tmpa_tl {\@@_do_identity:}
+     }
+%    \end{macrocode}
+% Ignore spaces.
+%    \begin{macrocode}
+     {~}
+     {
+     }
+    }
+    {
+    }
+    {
+%    \end{macrocode}
+% If we get an unrecognised token, it's our trigger to start accumulating information for the next crossing.
+%    \begin{macrocode}
+      \tl_if_empty:NF \l_@@_tmpa_tl
+      {
+        \seq_put_right:NV \l_@@_word_seq \l_@@_tmpa_tl
+        \tl_clear:N \l_@@_tmpa_tl
+      }
+    }
+  }
+%    \end{macrocode}
+% At the end, we also put our current token list on the word sequence.
+%    \begin{macrocode}
+  \tl_if_empty:NF \l_@@_tmpa_tl
+  {
+    \seq_put_right:NV \l_@@_word_seq \l_@@_tmpa_tl
+    \tl_clear:N \l_@@_tmpa_tl
+  }
+}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\@@_parse_index:n}
+% Parse an index, saving it in a sequence with the two indices such that the first goes over the second.
+%    \begin{macrocode}
+\cs_new_nopar:Npn \@@_parse_index:n #1
+{
+  \seq_set_from_clist:Nn \l_@@_crossing_seq {#1}
+  \int_compare:nT {\seq_count:N \l_@@_crossing_seq == 1}
+  {
+    \seq_put_right:Nx \l_@@_crossing_seq {\int_eval:n {#1 + 1} }
+  }
+  \bool_if:NT \l_@@_swap_crossing_bool
+  {
+    \seq_pop_left:NN \l_@@_crossing_seq \l_@@_tmpa_tl
+    \seq_put_right:NV \l_@@_crossing_seq \l_@@_tmpa_tl
+  }
+}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\@@_parse_exponent:n}
+% Parse an exponent, basically testing to see if it is \(-1\) in which case our crossing numbers should be reversed..
+%    \begin{macrocode}
+\cs_new_nopar:Npn \@@_parse_exponent:n #1
+{
+  \int_compare:nTF {#1 == -1}
+  {
+    \bool_set_true:N \l_@@_swap_crossing_bool
+  }
+  {
+    \bool_set_false:N \l_@@_swap_crossing_bool
+  }
+}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\@@_do_identity:}
+%    \begin{macrocode}
+\cs_new_nopar:Npn \@@_do_identity:
+{
+}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\@@_count:NNN}
+% Work out how big the braid is by counting strands and levels.
+% We also figure out the permutation from the start to end of the strands.
+% This is useful for labelling various parts of the braid.
+%    \begin{macrocode}
+\cs_new_nopar:Npn \@@_count:
+{
+  \int_zero:N \l_@@_length_int
+  \int_set:Nn \l_@@_strands_int {\@@_value:n {number~of~strands}}
+  \prop_clear:N \l_@@_permutation_prop
+  \prop_clear:N \l_@@_crossing_permutation_prop
+  \prop_clear:N \l_@@_anchor_prop
+  \prop_clear:N \l_@@_inverse_prop
+  
+  \seq_map_inline:Nn \l_@@_word_seq
+  {
+%    \end{macrocode}
+% Clear the crossing sequence and assume we're going to step the level.
+%    \begin{macrocode}
+    \seq_clear:N \l_@@_crossing_seq
+    \bool_set_true:N \l_@@_step_level_bool
+    \bool_set_false:N \l_@@_swap_crossing_bool
+%    \end{macrocode}
+% Run the details of this crossing.
+%    \begin{macrocode}
+    ##1
+%    \end{macrocode}
+% If we're increasing the level (no hyphen), do so.
+%    \begin{macrocode}
+    \bool_if:NT \l_@@_step_level_bool
+    {
+      \int_incr:N \l_@@_length_int
+    }
+%    \end{macrocode}    
+% If we have a crossing, check we have enough strands to cover it.
+%    \begin{macrocode}
+    \seq_if_empty:NF \l_@@_crossing_seq
+    {
+      \int_set:Nn \l_@@_strands_int
+      {
+        \int_max:nn
+        {
+          \int_max:nn {\l_@@_strands_int}
+          { \seq_item:Nn \l_@@_crossing_seq {1}}
+        }
+        {
+          \seq_item:Nn \l_@@_crossing_seq {2}
+        }
+      }
+    }
+  }
+%    \end{macrocode}
+% Now that we know how many strands we have, we can initialise our permutation props.
+% One will hold the overall permutation, the other will keep track of our current permutation.
+%    \begin{macrocode}
+  \int_step_inline:nnnn {1} {1} {\l_@@_strands_int}
+  {
+    \prop_put:Nnn \l_@@_permutation_prop {##1} {##1}
+    \prop_put:Nnn \l_@@_anchor_prop {##1} {##1}
+    \prop_put:Nnn \l_@@_crossing_permutation_prop {##1} {##1}
+  }
+%    \end{macrocode}
+% Now we step through the braid word again and record the permutations so that we can calculate the overall permutation defined by the braid.
+%
+% We will also figure out our shift from the anchor, so first we need to get some information about the anchor.
+%    \begin{macrocode}
+  \tl_set:Nx \l_@@_tmpa_tl {\@@_value:n {anchor}}
+  \seq_set_split:NnV \l_@@_anchor_seq {-} \l_@@_tmpa_tl
+
+  \tl_set:Nx \l_@@_tmpa_tl {\seq_item:Nn \l_@@_anchor_seq {1}}
+  \tl_if_eq:VnTF \l_@@_tmpa_tl {rev}
+  {
+    \tl_set:Nx \l_@@_anchor_strand_tl {\seq_item:Nn \l_@@_anchor_seq {2}}
+    \tl_set:Nx \l_@@_anchor_level_tl {\seq_item:Nn \l_@@_anchor_seq {3}}
+  }
+  {
+    \tl_set:Nx \l_@@_anchor_strand_tl {\seq_item:Nn \l_@@_anchor_seq {1}}
+    \tl_set:Nx \l_@@_anchor_level_tl {\seq_item:Nn \l_@@_anchor_seq {2}}
+  }
+%    \end{macrocode}
+% The important information is as to the level at which the requested anchor resides.
+% If it is at the end or start of a strand, we set the level to \(-1\) so that it never matches a level number. 
+%    \begin{macrocode}
+  \tl_if_eq:VnTF \l_@@_anchor_level_tl {s}
+  {
+    \int_set:Nn \l_@@_anchor_level_int {-1}
+  }
+  {
+    \tl_if_eq:VnTF \l_@@_anchor_level_tl {e}
+    {
+      \int_set:Nn \l_@@_anchor_level_int {-1}
+    }
+    {
+      \int_set:Nn \l_@@_anchor_level_int
+      {\tl_use:N \l_@@_anchor_level_tl}
+    }
+  }
+  
+  \int_zero:N \l_@@_crossing_int
+  \int_incr:N \l_@@_crossing_int
+%    \end{macrocode}
+%
+%    \begin{macrocode}
+  \seq_map_inline:Nn \l_@@_word_seq
+  {
+    \bool_set_true:N \l_@@_step_level_bool
+    \seq_clear:N \l_@@_crossing_seq
+    \bool_set_false:N \l_@@_swap_crossing_bool
+    ##1
+    \seq_if_empty:NF \l_@@_crossing_seq
+    {
+      \prop_get:NxN \l_@@_permutation_prop
+      {
+        \seq_item:Nn \l_@@_crossing_seq {1}
+      } \l_@@_tmpa_tl
+      \prop_get:NxN \l_@@_permutation_prop
+      {
+        \seq_item:Nn \l_@@_crossing_seq {2}
+      } \l_@@_tmpb_tl
+
+      \prop_put:NxV \l_@@_permutation_prop
+      {
+        \seq_item:Nn \l_@@_crossing_seq {2}
+      } \l_@@_tmpa_tl
+      \prop_put:NxV \l_@@_permutation_prop
+      {
+        \seq_item:Nn \l_@@_crossing_seq {1}
+      } \l_@@_tmpb_tl
+    }
+%    \end{macrocode}
+% See if the current level is what was requested by the anchor.
+%    \begin{macrocode}
+    \int_compare:nT {\l_@@_crossing_int = \l_@@_anchor_level_int}
+    {
+      \prop_set_eq:NN \l_@@_anchor_prop \l_@@_permutation_prop
+    }
+    \bool_if:NT \l_@@_step_level_bool
+    {
+      \int_incr:N \l_@@_crossing_int
+    }
+  }
+%    \end{macrocode}
+% This inverts the anchor permutation.
+%    \begin{macrocode}
+  \int_step_inline:nnnn {1} {1} {\l_@@_strands_int}
+  {
+    \prop_get:NnN \l_@@_anchor_prop {##1} \l_@@_tmpa_tl
+    \prop_put:NVn \l_@@_inverse_prop \l_@@_tmpa_tl {##1}
+  }
+  \prop_set_eq:NN \l_@@_anchor_prop \l_@@_inverse_prop
+%    \end{macrocode}
+% This inverts the full permutation.
+%    \begin{macrocode}
+  \int_step_inline:nnnn {1} {1} {\l_@@_strands_int}
+  {
+    \prop_get:NnN \l_@@_permutation_prop {##1} \l_@@_tmpa_tl
+    \prop_put:NVn \l_@@_inverse_prop \l_@@_tmpa_tl {##1}
+  }
+%    \end{macrocode}
+% Now that we have the inverse, we can figure out our anchor.
+% First, see if we requested a strand by its position at the end of the braid.
+%    \begin{macrocode}
+  \tl_set:Nx \l_@@_tmpa_tl {\seq_item:Nn \l_@@_anchor_seq {1}}
+  \tl_if_eq:VnT \l_@@_tmpa_tl {rev}
+  {
+    \prop_get:NVN \l_@@_permutation_prop
+    \l_@@_anchor_strand_tl \l_@@_anchor_strand_tl
+  }
+  \tl_if_eq:VnF \l_@@_anchor_level_tl {s}
+  {
+    \tl_if_eq:VnTF \l_@@_anchor_level_tl {e}
+    {
+      \prop_get:NVN \l_@@_inverse_prop
+      \l_@@_anchor_strand_tl \l_@@_anchor_strand_tl
+    }
+    {
+      \prop_get:NVN \l_@@_anchor_prop
+      \l_@@_anchor_strand_tl \l_@@_anchor_strand_tl
+    }
+  }
+%    \end{macrocode}
+%    \begin{macrocode}
+}
+%    \end{macrocode}    
+%
+%
+% \end{macro}
+%
+%
+% \begin{macro}{\@@_dim_value:n, \@@_value:n}
+% Extract a length or a value from a PGF key.
+%    \begin{macrocode}
+\cs_new_nopar:Npn \@@_dim_value:n #1
+{
+  \dim_to_fp:n {\pgfkeysvalueof{/tikz/braid/#1}}
+}
+\cs_new_nopar:Npn \@@_value:n #1
+{
+  \pgfkeysvalueof{/tikz/braid/#1}
+}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\@@_render:}
+% This is the macro that converts the braid word into TikZ paths.
+%    \begin{macrocode}
+\cs_generate_variant:Nn \prop_get:NnN {NxN}
+\cs_generate_variant:Nn \prop_put:Nnn {NxV}
+\cs_generate_variant:Nn \tl_if_eq:nnTF {VnTF}
+\cs_generate_variant:Nn \tl_if_eq:nnF {VnF}
+\cs_generate_variant:Nn \tl_if_eq:nnT {VnT}
+
+\cs_new_nopar:Npn \@@_render:
+{
+%    \end{macrocode}
+%
+%    \begin{macrocode}
+  \fp_set:Nn \l_@@_anchor_x_fp { - 1 * (\tl_use:N \l_@@_anchor_strand_tl - 1) * \@@_dim_value:n {width} }
+
+  \tl_if_eq:VnTF \l_@@_anchor_level_tl {s}
+  {
+    \fp_set:Nn \l_@@_anchor_y_fp {0}
+  }
+  {
+    \tl_if_eq:VnTF \l_@@_anchor_level_tl {e}
+    {
+      \fp_set:Nn \l_@@_anchor_y_fp {
+        -1 * \l_@@_length_int * \@@_dim_value:n {height}
+        - sign(\@@_dim_value:n {height})
+        * 2 * \@@_dim_value:n {border~ height}
+      }
+    }
+    {
+      \fp_set:Nn \l_@@_anchor_y_fp {
+        -1 * \l_@@_anchor_level_tl * \@@_dim_value:n {height}
+        - sign(\@@_dim_value:n {height})
+        * \@@_dim_value:n {border~ height}
+      }
+    }
+  }
+  
+  \begin{scope}[
+    shift={
+      (\fp_to_decimal:N \l_@@_anchor_x_fp pt,
+      \fp_to_decimal:N \l_@@_anchor_y_fp pt
+      )
+    }
+  ]
+%    \end{macrocode}
+% Initialise a prop for the individual strands.
+%    \begin{macrocode}
+  \prop_clear:N \l_@@_strands_prop
+%    \end{macrocode}  
+% Initialise some lengths.
+%    \begin{macrocode}
+  \fp_zero:N \l_@@_height_fp
+  \fp_zero:N \l_@@_nudge_fp
+  \fp_zero:N \l_@@_control_fp
+%    \end{macrocode}  
+% This holds our current \Verb+height+ of our strands.
+%    \begin{macrocode}
+  \fp_set:Nn \l_@@_height_fp
+  {
+    sign(\@@_dim_value:n {height})
+    * \@@_dim_value:n {border~ height}
+  }
+%    \end{macrocode}  
+% This holds the total \Verb+width+ of our strands.
+%    \begin{macrocode}
+  \fp_set:Nn \l_@@_width_fp
+  {
+    (\l_@@_strands_int - 1) * \@@_dim_value:n {width}
+    + 2 * sign(\@@_dim_value:n{width})
+    * \@@_dim_value:n {floor~ border}
+  }
+%    \end{macrocode}
+% Each crossing actually starts a little bit into the crossing space, as defined by the \Verb+nudge factor+.
+%    \begin{macrocode}
+  \fp_set:Nn \l_@@_nudge_fp
+  {
+    \@@_value:n {nudge~ factor} * \@@_dim_value:n {height}
+  }
+%    \end{macrocode}
+% This sets where the control points for the crossing curves will be. 
+%    \begin{macrocode}
+  \fp_set:Nn \l_@@_control_fp
+  {
+    \@@_value:n {control~ factor} * \@@_dim_value:n {height}
+  }
+  \fp_sub:Nn \l_@@_control_fp {\l_@@_nudge_fp}
+%    \end{macrocode}
+% Initialise our strand paths with a \Verb+\draw+.
+%    \begin{macrocode}
+  \int_step_inline:nnnn {1} {1} {\l_@@_strands_int}
+  {
+    \prop_get:NnN \l_@@_inverse_prop {##1} \l_@@_tmpa_tl
+    \prop_put:Nnx \l_@@_strands_prop {##1}
+    {
+      \exp_not:N \draw[
+        braid/every~ strand/.try,
+        braid/strand~ ##1/.try
+      ]
+      \exp_not:N \@@_moveto:nn {
+        \fp_eval:n {(##1 - 1) * \@@_dim_value:n {width} }
+      } {0}
+      \exp_not:N \@@_lineto:nn  {
+        \fp_eval:n {(##1 - 1) * \@@_dim_value:n {width} }
+      } { \fp_to_decimal:N \l_@@_height_fp} 
+    }
+%    \end{macrocode}
+% Add a load of coordinates at the start of each strand, indexed by both forward and backward strand numbers.
+%    \begin{macrocode}
+    \@@_coordinate:xxxx {-##1-s} {-rev-\l_@@_tmpa_tl-s}
+    {\fp_eval:n {(##1 - 1) * \@@_dim_value:n {width} }} {0}
+
+    \@@_coordinate:xxxx {-##1-0} {-rev-\l_@@_tmpa_tl-0}
+    {\fp_eval:n {(##1 - 1) * \@@_dim_value:n {width} }}
+    { \fp_to_decimal:N \l_@@_height_fp} 
+  }
+%    \end{macrocode}
+%
+% Run through any extra floors requested.
+%    \begin{macrocode}
+  \seq_map_inline:Nn \l_@@_floors_seq
+  {
+    \tl_set:Nx \l_@@_tmpa_tl {\clist_item:nn {##1} {5}}
+    \@@_do_floor:Vxxxx \l_@@_tmpa_tl
+    {\fp_eval:n
+      {
+        -1*sign(\@@_dim_value:n{width})
+        * \@@_dim_value:n {floor~ border}
+        + (\@@_dim_value:n {width}) * (\clist_item:nn {##1} {1} - 1)
+      }
+      pt
+    }
+    {\fp_eval:n
+      {
+        \l_@@_height_fp + ( \@@_dim_value:n {height} ) * (\clist_item:nn {##1} {2})
+      }
+      pt
+    }
+    {\fp_eval:n {
+        ( (\clist_item:nn {##1} {3}) * \@@_dim_value:n {width}
+        + 2 * sign(\@@_dim_value:n{width})
+        * \@@_dim_value:n {floor~ border} ) / \dim_to_fp:n {1cm}
+      }
+    }
+    {\fp_eval:n {
+        (\clist_item:nn {##1} {4}) * ( \@@_dim_value:n {height} ) / \dim_to_fp:n {1cm}
+      }
+    }
+  }
+%    \end{macrocode}
+%
+% Keep track of the crossing level for the floor.
+%    \begin{macrocode}
+  \int_zero:N \l_@@_crossing_int
+  \int_incr:N \l_@@_crossing_int
+
+  \seq_map_inline:Nn \l_@@_word_seq
+  {
+%    \end{macrocode}
+% Clear the flags for this segment of the braid word
+%    \begin{macrocode}
+    \seq_clear:N \l_@@_crossing_seq
+    \bool_set_true:N \l_@@_step_level_bool
+    \bool_set_false:N \l_@@_floor_bool
+    \bool_set_false:N \l_@@_swap_crossing_bool
+    ##1
+%    \end{macrocode}
+% If we're drawing a floor, do so straightaway.
+%    \begin{macrocode}
+    \bool_if:NT \l_@@_floor_bool
+    {
+      \@@_do_floor:Vxxxx \l_@@_crossing_int
+      {\fp_eval:n
+        {
+          -1*sign(\@@_dim_value:n{width})
+          * \@@_dim_value:n {floor~ border}
+        }
+        pt
+      }
+      {\fp_to_decimal:N \l_@@_height_fp pt}
+      {\fp_eval:n { \l_@@_width_fp / \dim_to_fp:n {1cm} }}
+      {\fp_eval:n { ( \@@_dim_value:n {height} ) / \dim_to_fp:n {1cm}}}
+    }
+%    \end{macrocode}
+% If we have a crossing, process it.
+%    \begin{macrocode}
+    \seq_if_empty:NF \l_@@_crossing_seq
+    {
+%    \end{macrocode}
+% Keep track of the current permutation.      
+%    \begin{macrocode}
+      \prop_get:NxN \l_@@_crossing_permutation_prop
+      {\seq_item:Nn \l_@@_crossing_seq {1}} \l_@@_tmpa_tl
+      \prop_get:NxN \l_@@_crossing_permutation_prop
+      {\seq_item:Nn \l_@@_crossing_seq {2}} \l_@@_tmpb_tl
+
+      \prop_put:NxV \l_@@_crossing_permutation_prop
+      {\seq_item:Nn \l_@@_crossing_seq {2}} \l_@@_tmpa_tl
+      \prop_put:NxV \l_@@_crossing_permutation_prop
+      {\seq_item:Nn \l_@@_crossing_seq {1}} \l_@@_tmpb_tl
+%    \end{macrocode}
+% Now get the strands corresponding to the ones involved in the crossing.
+%    \begin{macrocode}
+      \prop_get:NxN \l_@@_strands_prop
+      {\seq_item:Nn \l_@@_crossing_seq {1}} \l_@@_tmpa_tl
+      \prop_get:NxN \l_@@_strands_prop
+      {\seq_item:Nn \l_@@_crossing_seq {2}} \l_@@_tmpb_tl
+%    \end{macrocode}
+% The over-strand is easy as that's a single curve.
+%    \begin{macrocode}
+      \tl_put_right:Nx \l_@@_tmpa_tl
+      {
+        \exp_not:N \@@_lineto:nn
+      
+        {\fp_eval:n
+          {
+            (\seq_item:Nn \l_@@_crossing_seq {1} - 1)
+            * \@@_dim_value:n {width}
+          }
+        }
+        {\fp_eval:n { \l_@@_height_fp + \l_@@_nudge_fp } }
+
+        \exp_not:N \@@_curveto:nnnnnn
+
+        {0}
+        {\fp_eval:n { \l_@@_control_fp}}
+
+        {0}
+        {\fp_eval:n {- \l_@@_control_fp}}
+
+        {\fp_eval:n
+          {
+            (\seq_item:Nn \l_@@_crossing_seq {2} - 1)
+            * \@@_dim_value:n {width}
+          }
+        }
+        {\fp_eval:n
+          {
+            \l_@@_height_fp
+            + \@@_dim_value:n {height}
+            - \l_@@_nudge_fp
+          }
+        }
+      }
+%    \end{macrocode}
+% The under-strand is a bit more complicated as we need to break it in the middle.
+%    \begin{macrocode}
+      \tl_put_right:Nx \l_@@_tmpb_tl
+      {
+        \exp_not:N \@@_lineto:nn
+      
+        {\fp_eval:n
+          {
+            (\seq_item:Nn \l_@@_crossing_seq {2} - 1)
+            * \@@_dim_value:n {width}
+          }
+        }
+        {\fp_eval:n { \l_@@_height_fp + \l_@@_nudge_fp } }
+
+        \exp_not:N \@@_curveto:nnnnnn
+
+        {0}
+        {
+          \fp_eval:n {
+            \l_@@_control_fp  * (.5 - \@@_value:n {gap} )
+          }
+        }
+
+        {
+          \fp_eval:n {
+            - (.5 - \@@_value:n {gap} ) / 3 *
+            \@@_bezier_tangent:nnnnn
+            {.5 - \@@_value:n {gap} }
+            {0}
+            {0}
+            {
+              (\seq_item:Nn \l_@@_crossing_seq {1}
+              - \seq_item:Nn \l_@@_crossing_seq {2})
+              * \@@_dim_value:n {width}
+            }
+            {
+              (\seq_item:Nn \l_@@_crossing_seq {1}
+              - \seq_item:Nn \l_@@_crossing_seq {2})
+              * \@@_dim_value:n {width}
+            }
+          }
+        }
+        {
+          \fp_eval:n {
+            -(.5 - \@@_value:n {gap} ) / 3 *
+            \@@_bezier_tangent:nnnnn
+            {.5 - \@@_value:n {gap} }
+            {0}
+            {\l_@@_control_fp}
+            {
+              \@@_dim_value:n {height}
+              - 2* \l_@@_nudge_fp
+              - \l_@@_control_fp
+            }
+            {\@@_dim_value:n {height} - 2* \l_@@_nudge_fp}
+          }
+        }
+
+        {
+          \fp_eval:n {
+            (\seq_item:Nn \l_@@_crossing_seq {2} - 1)
+            * \@@_dim_value:n {width} +
+            \@@_bezier_point:nnnnn
+            {.5 - \@@_value:n {gap} }
+            {0}
+            {0}
+            {
+              (\seq_item:Nn \l_@@_crossing_seq {1}
+              - \seq_item:Nn \l_@@_crossing_seq {2})
+              * \@@_dim_value:n {width}
+            }
+            {
+              (\seq_item:Nn \l_@@_crossing_seq {1}
+              - \seq_item:Nn \l_@@_crossing_seq {2})
+              * \@@_dim_value:n {width}
+            }
+          }
+        }
+        {
+          \fp_eval:n {
+          \l_@@_height_fp + \l_@@_nudge_fp +
+            \@@_bezier_point:nnnnn
+            {.5 - \@@_value:n {gap} }
+            {0}
+            {\l_@@_control_fp}
+            {
+              \@@_dim_value:n {height}
+              - 2* \l_@@_nudge_fp
+              - \l_@@_control_fp
+            }
+            {\@@_dim_value:n {height} - 2* \l_@@_nudge_fp}
+          }
+        }
+
+        \exp_not:N \@@_moveto:nn
+        {
+          \fp_eval:n {
+            (\seq_item:Nn \l_@@_crossing_seq {2} - 1)
+            * \@@_dim_value:n {width} +
+            \@@_bezier_point:nnnnn
+            {.5 + \@@_value:n {gap} }
+            {0}
+            {0}
+            {
+              (\seq_item:Nn \l_@@_crossing_seq {1}
+              - \seq_item:Nn \l_@@_crossing_seq {2})
+              * \@@_dim_value:n {width}
+            }
+            {
+              (\seq_item:Nn \l_@@_crossing_seq {1}
+              - \seq_item:Nn \l_@@_crossing_seq {2})
+              * \@@_dim_value:n {width}
+            }
+          }
+        }
+        {
+          \fp_eval:n {
+          \l_@@_height_fp + \l_@@_nudge_fp +
+            \@@_bezier_point:nnnnn
+            {.5 + \@@_value:n {gap} }
+            {0}
+            {\l_@@_control_fp}
+            {
+              \@@_dim_value:n {height} - 2* \l_@@_nudge_fp
+              - \l_@@_control_fp
+            }
+            {\@@_dim_value:n {height} - 2* \l_@@_nudge_fp}
+          }
+        }
+
+        \exp_not:N \@@_curveto:nnnnnn
+
+        {
+          \fp_eval:n {
+            (.5 - \@@_value:n {gap} ) / 3 *
+            \@@_bezier_tangent:nnnnn
+            {.5 + \@@_value:n {gap} }
+            {0}
+            {0}
+            {
+              (\seq_item:Nn \l_@@_crossing_seq {1}
+              - \seq_item:Nn \l_@@_crossing_seq {2})
+              * \@@_dim_value:n {width}
+            }
+            {
+              (\seq_item:Nn \l_@@_crossing_seq {1}
+              - \seq_item:Nn \l_@@_crossing_seq {2})
+              * \@@_dim_value:n {width}
+            }
+          }
+        }
+        {
+          \fp_eval:n {
+            (.5 - \@@_value:n {gap} ) / 3 *
+            \@@_bezier_tangent:nnnnn
+            {.5 + \@@_value:n {gap} }
+            {0}
+            {\l_@@_control_fp}
+            {
+              \@@_dim_value:n {height} - 2* \l_@@_nudge_fp
+              - \l_@@_control_fp
+            }
+            {\@@_dim_value:n {height} - 2* \l_@@_nudge_fp}
+          }
+        }
+
+        {0}
+        { \fp_eval:n {
+            -\l_@@_control_fp  * (.5 - \@@_value:n {gap} )
+          }
+        }
+
+
+        {\fp_eval:n
+          {
+            (\seq_item:Nn \l_@@_crossing_seq {1} - 1)
+            * \@@_dim_value:n {width}
+          }
+        }
+        {\fp_eval:n
+          {
+            \l_@@_height_fp + \@@_dim_value:n {height}
+            - \l_@@_nudge_fp
+          }
+        }
+        
+      }
+%    \end{macrocode}
+% Now put those new strands back in the prop.
+%    \begin{macrocode}
+      \prop_put:NxV \l_@@_strands_prop
+      {\seq_item:Nn \l_@@_crossing_seq {2}} \l_@@_tmpa_tl
+      \prop_put:NxV \l_@@_strands_prop
+      {\seq_item:Nn \l_@@_crossing_seq {1}} \l_@@_tmpb_tl
+%    \end{macrocode}
+% If the strands are more than one apart, the intermediate strands need to be broken as well.
+%    \begin{macrocode}
+      \int_compare:nT
+      {
+        \int_max:nn
+        {
+          \seq_item:Nn \l_@@_crossing_seq {1}
+        }
+        {
+          \seq_item:Nn \l_@@_crossing_seq {2}
+        }
+        -
+        \int_min:nn
+        {
+          \seq_item:Nn \l_@@_crossing_seq {1}
+        }
+        {
+          \seq_item:Nn \l_@@_crossing_seq {2}
+        }
+        > 1
+      }
+      {
+        \int_step_inline:nnnn
+        {
+          \int_min:nn
+          {
+            \seq_item:Nn \l_@@_crossing_seq {1}
+          }
+          {
+            \seq_item:Nn \l_@@_crossing_seq {2}
+          }
+          + 1}
+        {1}
+        {
+          \int_max:nn
+          {
+            \seq_item:Nn \l_@@_crossing_seq {1}
+          }
+          {
+            \seq_item:Nn \l_@@_crossing_seq {2}
+          }
+          - 1
+        }
+        {
+
+          \prop_get:NnN \l_@@_strands_prop {####1} \l_@@_tmpa_tl
+          \tl_put_right:Nx \l_@@_tmpa_tl
+            {
+              \exp_not:N \@@_lineto:nn
+              {\fp_eval:n {(####1 - 1) * \@@_dim_value:n {width} }}
+              {\fp_eval:n
+                {
+                  \l_@@_height_fp + \l_@@_nudge_fp
+                  + .5 * \l_@@_control_fp
+                }
+              }
+              \exp_not:N \@@_moveto:nn
+              {\fp_eval:n {(####1 - 1) * \@@_dim_value:n {width} }}
+              {\fp_eval:n
+                {
+                  \l_@@_height_fp + \@@_dim_value:n {height}
+                  - \l_@@_nudge_fp - .5 * \l_@@_control_fp
+                }
+              }
+            }
+
+            \prop_put:NnV \l_@@_strands_prop {####1} \l_@@_tmpa_tl
+          }
+      }
+    }
+%    \end{macrocode}
+% If we're to step the level, increase the height and add a load of coordinates. 
+%    \begin{macrocode}
+    \bool_if:NT \l_@@_step_level_bool
+    {
+      \fp_add:Nn \l_@@_height_fp { \@@_dim_value:n {height} }
+      
+      \int_step_inline:nnnn {1} {1} {\l_@@_strands_int}
+      {
+        \prop_get:NnN \l_@@_crossing_permutation_prop
+        {####1} \l_@@_tmpb_tl
+        \prop_get:NVN \l_@@_inverse_prop
+        \l_@@_tmpb_tl \l_@@_tmpa_tl
+
+        \@@_coordinate:xxxx
+        {-\l_@@_tmpb_tl-\int_use:N \l_@@_crossing_int}
+        {-rev-\l_@@_tmpa_tl-\int_use:N \l_@@_crossing_int }
+        {\fp_eval:n { (####1 - 1) * \@@_dim_value:n {width} }}
+        {\fp_to_decimal:N \l_@@_height_fp}
+      }
+      
+      \int_incr:N \l_@@_crossing_int
+    }
+  }
+
+  \fp_add:Nn \l_@@_height_fp
+  {
+    sign(\@@_dim_value:n {height})
+    * \@@_dim_value:n {border~ height}
+  }
+%    \end{macrocode}
+% Add a little bit to the end of each strand, together with some coordinates.
+%    \begin{macrocode}  
+  \int_step_inline:nnnn {1} {1} {\l_@@_strands_int}
+  {
+    \prop_get:NxN \l_@@_strands_prop {##1} \l_@@_tmpa_tl
+    \prop_get:NxN \l_@@_permutation_prop {##1} \l_@@_tmpb_tl
+
+    \tl_put_right:Nx \l_@@_tmpa_tl {
+      \exp_not:N \@@_lineto:nn
+      {\fp_eval:n { (##1 - 1) * \@@_dim_value:n {width} }}
+      {\fp_to_decimal:N \l_@@_height_fp}
+      coordinate (-rev-##1-e)
+      coordinate (-\l_@@_tmpb_tl-e)
+      ;
+    }
+    
+    \prop_put:NnV \l_@@_strands_prop {##1} \l_@@_tmpa_tl
+  }
+%    \end{macrocode}
+% This is where we actually carry out the drawing commands.
+%    \begin{macrocode}
+  \int_step_inline:nnnn {1} {1} {\l_@@_strands_int}
+  {
+    \prop_get:NnN \l_@@_strands_prop {##1} \l_@@_tmpa_tl
+    \tl_use:N \l_@@_tmpa_tl
+  }
+  \end{scope}
+}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\@@_moveto:nn, \@@_lineto:nn, \@@_curveto:nnnnnn, \@@_coordinate:nnnn}
+% These are our interfaces to the TikZ code.
+%    \begin{macrocode}
+\cs_new_nopar:Npn \@@_moveto:nn #1#2
+{
+  (#1 pt, #2 pt)
+}
+\cs_new_nopar:Npn \@@_lineto:nn #1#2
+{
+  -- (#1 pt, #2 pt)
+}
+\cs_new_nopar:Npn \@@_curveto:nnnnnn #1#2#3#4#5#6
+{
+  .. controls +(#1 pt, #2 pt) and +(#3 pt, #4 pt)
+  .. (#5 pt, #6 pt)
+}
+\cs_new_nopar:Npn \@@_coordinate:nnnn #1#2#3#4
+{
+  \coordinate[alias=#2] (#1) at (#3 pt,#4 pt);
+}
+\cs_generate_variant:Nn \@@_coordinate:nnnn {xxxx}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}[internal]{\@@_bezier_point:nnnnn, \@@_bezier_tangent:nnnnn}
+% Used to calculate intermediate points and tangents on a bezier curve.
+%    \begin{macrocode}
+\cs_new_nopar:Npn \@@_bezier_point:nnnnn #1#2#3#4#5
+{
+  \fp_eval:n
+  {
+    (1 - (#1)) * (1 - (#1)) * (1 - (#1)) * (#2)
+    +
+    3 * (1 - (#1)) * (1 - (#1)) * (#1) * (#3)
+    +
+    3 * (1 - (#1)) * (#1) * (#1) * (#4)
+    +
+    (#1) * (#1) * (#1) * (#5)
+  }
+}
+\cs_new_nopar:Npn \@@_bezier_tangent:nnnnn #1#2#3#4#5
+{
+  \fp_eval:n
+  {
+    3 * (1 - (#1)) * (1 - (#1)) * (#3 - (#2))
+    +
+    6 * (1 - (#1)) * (#1) * (#4 - (#3))
+    +
+    3 * (#1) * (#1) * (#5 - (#4))
+  }
+}
+\cs_new_nopar:Npn \@@_do_floor:nnnnn #1#2#3#4#5
+{
+  \pic[pic~ type=floor,
+    xscale=#4,
+    yscale=#5,
+    at={(#2,#3)},
+    braid/every~ floor/.try,
+    braid/floor~#1/.try,
+  ];
+}
+\cs_generate_variant:Nn \@@_do_floor:nnnnn {Vxxxx}
+%    \end{macrocode}
+% \end{macro}
+%    \begin{macrocode}
+\ExplSyntaxOff
+%    \end{macrocode}
+%
+% \iffalse
+%</library>
+% \fi
+%
+% \Finale
+
+\endinput


Property changes on: trunk/Master/texmf-dist/source/latex/braids/braids_code.dtx
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: trunk/Master/texmf-dist/source/latex/braids/braids_code.ins
===================================================================
--- trunk/Master/texmf-dist/source/latex/braids/braids_code.ins	                        (rev 0)
+++ trunk/Master/texmf-dist/source/latex/braids/braids_code.ins	2019-05-08 21:15:00 UTC (rev 51048)
@@ -0,0 +1,83 @@
+%%
+%% This is file `braids_code.ins',
+%% generated with the docstrip utility.
+%%
+%% The original source files were:
+%%
+%% braids_code.dtx  (with options: `install')
+%% ----------------------------------------------------------------
+%% braids --- a style file for drawing braid diagrams with TikZ/PGF
+%% E-mail: loopspace at mathforge.org
+%% Released under the LaTeX Project Public License v1.3c or later
+%% See http://www.latex-project.org/lppl.txt
+%% ----------------------------------------------------------------
+%% 
+\input l3docstrip.tex
+\keepsilent
+\askforoverwritefalse
+\preamble
+----------------------------------------------------------------
+braids --- a style file for drawing braid diagrams with TikZ/PGF
+E-mail: loopspace at mathforge.org
+Released under the LaTeX Project Public License v1.3c or later
+See http://www.latex-project.org/lppl.txt
+----------------------------------------------------------------
+
+\endpreamble
+\postamble
+
+Copyright (C) 2011-2019 by Andrew Stacey <loopspace at mathforge.org>
+
+This work may be distributed and/or modified under the
+conditions of the LaTeX Project Public License (LPPL), either
+version 1.3c of this license or (at your option) any later
+version.  The latest version of this license is in the file:
+
+http://www.latex-project.org/lppl.txt
+
+This work is "maintained" (as per LPPL maintenance status) by
+Andrew Stacey.
+
+This work consists of the files  braids.dtx
+                                 braids_doc.tex
+and the derived files            README.txt,
+                                 braids.ins,
+                                 braids.pdf,
+                                 braids.sty,
+                                 tikzlibrarybraids.code.tex,
+                                 braids_doc.pdf.
+
+\endpostamble
+\usedir{tex/latex/braids}
+\generate{
+  \file{braids.sty}{\from{\jobname.dtx}{package}}
+}
+\generate{
+  \file{tikzlibrarybraids.code.tex}{\from{\jobname.dtx}{library}}
+}
+\endbatchfile
+
+%% 
+%% Copyright (C) 2011-2019 by Andrew Stacey <loopspace at mathforge.org>
+%% 
+%% This work may be distributed and/or modified under the
+%% conditions of the LaTeX Project Public License (LPPL), either
+%% version 1.3c of this license or (at your option) any later
+%% version.  The latest version of this license is in the file:
+%% 
+%% http://www.latex-project.org/lppl.txt
+%% 
+%% This work is "maintained" (as per LPPL maintenance status) by
+%% Andrew Stacey.
+%% 
+%% This work consists of the files  braids.dtx
+%%                                  braids_doc.tex
+%% and the derived files            README.txt,
+%%                                  braids.ins,
+%%                                  braids.pdf,
+%%                                  braids.sty,
+%%                                  tikzlibrarybraids.code.tex,
+%%                                  braids_doc.pdf.
+%% 
+%%
+%% End of file `braids_code.ins'.

Modified: trunk/Master/texmf-dist/tex/latex/braids/braids.sty
===================================================================
--- trunk/Master/texmf-dist/tex/latex/braids/braids.sty	2019-05-08 21:09:31 UTC (rev 51047)
+++ trunk/Master/texmf-dist/tex/latex/braids/braids.sty	2019-05-08 21:15:00 UTC (rev 51048)
@@ -4,21 +4,19 @@
 %%
 %% The original source files were:
 %%
-%% braids.dtx  (with options: `package')
+%% braids_code.dtx  (with options: `package')
 %% ----------------------------------------------------------------
 %% braids --- a style file for drawing braid diagrams with TikZ/PGF
-%% E-mail: stacey at math.ntnu.no
+%% E-mail: loopspace at mathforge.org
 %% Released under the LaTeX Project Public License v1.3c or later
 %% See http://www.latex-project.org/lppl.txt
 %% ----------------------------------------------------------------
 %% 
 \NeedsTeXFormat{LaTeX2e}
-\ProvidesPackage{braids}[2011/05/07 v1.0 Tikz/PGF commands for drawing braid diagrams]
-\def\braid at pgfversion{2.10}%
-\ifx\pgfversion\braid at pgfversion
-\else
-\PackageWarning{braids}{This package was designed using PGF2.10; you are using \pgfversion.}%
-\fi
+\ProvidesPackage{braids}[2011/10/18 v1.1 Tikz/PGF commands for drawing braid diagrams]
+\PackageWarning{braids}{%
+  This package has been reimplemented as a TikZ library; if starting with a fresh document, please consider using that instead.%
+}%
 \long\def\ge at addto@macro#1#2{%
   \begingroup
   \toks@\expandafter\expandafter\expandafter{\expandafter#1#2}%
@@ -71,7 +69,14 @@
   \ifx\braid at token-
    \braid at increase@levelfalse
   \else
-  \ifx\braid at token[
+  \ifx\braid at token1%
+   \ifbraid at increase@level
+    \stepcounter{braid at level}
+   \fi
+   \braid at increase@leveltrue
+   \ge at addto@macro\braid at label{\braid at token}%
+  \else
+  \ifx\braid at token[%
    \let\braid at next=\braid at process@options
   \else
   \ifx\braid at token\braid at bar
@@ -84,6 +89,12 @@
   \ifx\braid at token\egroup
    \braid at endscope
   \else
+  \ifx\braid at token\braid at olabel@strand
+   \let\braid at next=\braid at olabel@strand
+  \else
+  \ifx\braid at token\braid at clabel@strand
+   \let\braid at next=\braid at clabel@strand
+  \else
   \ge at addto@macro\braid at label{\braid at token}%
   \fi
   \fi
@@ -93,6 +104,9 @@
   \fi
   \fi
   \fi
+  \fi
+  \fi
+  \fi
   \braid at next%
 }
 \def\braid at maybe@locate{%
@@ -140,9 +154,18 @@
     \tikzset{#1}%
   \braid at process%
 }
-\def\braid at sup#1_#2{\g at addto@macro\braid at label{_{#2}^{#1}}\braid at add@crossing{#2}{#1}}
-\def\braid at sub#1{\@ifnextchar^{\braid@@sub{#1}}{\g at addto@macro\braid at label{_{#1}}\braid at add@crossing{#1}{1}}}
-\def\braid@@sub#1^#2{\g at addto@macro\braid at label{_{#1}^{#2}}\braid at add@crossing{#1}{#2}}
+\def\braid at sup#1_#2{%
+  \g at addto@macro\braid at label{_{#2}^{#1}}%
+  \braid at add@crossing{#2}{#1}%
+}
+\def\braid at sub#1{%
+  \@ifnextchar^{\braid@@sub{#1}}%
+  {\g at addto@macro\braid at label{_{#1}}\braid at add@crossing{#1}{1}}%
+}
+\def\braid@@sub#1^#2{%
+  \g at addto@macro\braid at label{_{#1}^{#2}}%
+  \braid at add@crossing{#1}{#2}%
+}
 \def\braid at ne{1}
 \def\braid at add@crossing#1#2{%
   \edef\braid at crossing@type{#2}%
@@ -159,13 +182,14 @@
   \braid at ny=\braid at ty
   \advance\braid at nx by \braid at width
   \advance\braid at ny by \braid at height
+  \advance\braid at ty by \braid at nf\braid at height
+  \advance\braid at ny by -\braid at nf\braid at height
   \braid at cy=\braid at ty
   \braid at dy=\braid at ny
-  \advance\braid at cy by .5\braid at height
-  \advance\braid at dy by -.5\braid at height
-  \advance\braid at ty by .05\braid at height
-  \advance\braid at ny by -.05\braid at height
-  \expandafter\let\expandafter\braid at this@path at origin\csname braid at strand@\braid at this@strand @origin\endcsname
+  \advance\braid at cy by \braid at cf\braid at height
+  \advance\braid at dy by -\braid at cf\braid at height
+  \expandafter\let\expandafter\braid at this@path at origin%
+  \csname braid at strand@\braid at this@strand @origin\endcsname
 \ifx\braid at this@path at origin\relax
   \let\braid at this@path at origin\braid at this@strand
   \pgfsyssoftpath at setcurrentpath{\@empty}
@@ -172,9 +196,11 @@
   \pgfpathmoveto{\pgfpoint{\braid at tx}{0pt}}
   \pgfsyssoftpath at getcurrentpath{\braid at this@path}
   \else
-  \expandafter\let\expandafter\braid at this@path\csname braid at strand@\braid at this@path at origin\endcsname
+  \expandafter\let\expandafter\braid at this@path%
+  \csname braid at strand@\braid at this@path at origin\endcsname
   \fi
-  \expandafter\let\expandafter\braid at next@path at origin\csname braid at strand@\braid at next@strand @origin\endcsname
+  \expandafter\let\expandafter\braid at next@path at origin%
+  \csname braid at strand@\braid at next@strand @origin\endcsname
   \ifx\braid at next@path at origin\relax
   \let\braid at next@path at origin\braid at next@strand
   \pgfsyssoftpath at setcurrentpath{\@empty}
@@ -181,38 +207,172 @@
   \pgfpathmoveto{\pgfpoint{\braid at nx}{0pt}}
   \pgfsyssoftpath at getcurrentpath{\braid at next@path}
   \else
-  \expandafter\let\expandafter\braid at next@path\csname braid at strand@\braid at next@path at origin\endcsname
+  \expandafter\let\expandafter\braid at next@path%
+  \csname braid at strand@\braid at next@path at origin\endcsname
   \fi
   \pgfsyssoftpath at setcurrentpath{\braid at this@path}
   \pgfpathlineto{\pgfqpoint{\braid at tx}{\braid at ty}}
+\pgfmathsetmacro{\braid at gst}{0.5 - \pgfkeysvalueof{/pgf/braid/gap}}%
+\pgfmathsetmacro{\braid at gend}{0.5 + \pgfkeysvalueof{/pgf/braid/gap}}%
 \ifx\braid at crossing@type\braid at over@cross
-\pgfpathcurveto{\pgfqpoint{\braid at tx}{\braid at cy}}{\pgfqpoint{\braid at nx}{\braid at dy}}{\pgfqpoint{\braid at nx}{\braid at ny}}
+  \pgfpathcurveto{\pgfqpoint{\braid at tx}{\braid at cy}}%
+  {\pgfqpoint{\braid at nx}{\braid at dy}}%
+  {\pgfqpoint{\braid at nx}{\braid at ny}}
 \else
-\pgfpathcurvebetweentimecontinue{0}{.4}{\pgfqpoint{\braid at tx}{\braid at ty}}{\pgfqpoint{\braid at tx}{\braid at cy}}{\pgfqpoint{\braid at nx}{\braid at dy}}{\pgfqpoint{\braid at nx}{\braid at ny}}
-\pgfpathcurvebetweentime{.6}{1}{\pgfqpoint{\braid at tx}{\braid at ty}}{\pgfqpoint{\braid at tx}{\braid at cy}}{\pgfqpoint{\braid at nx}{\braid at dy}}{\pgfqpoint{\braid at nx}{\braid at ny}}
+  \pgfpathcurvebetweentimecontinue{0}{\braid at gst}%
+  {\pgfqpoint{\braid at tx}{\braid at ty}}%
+  {\pgfqpoint{\braid at tx}{\braid at cy}}%
+  {\pgfqpoint{\braid at nx}{\braid at dy}}%
+  {\pgfqpoint{\braid at nx}{\braid at ny}}%
+  \pgfpathcurvebetweentime{\braid at gend}{1}%
+  {\pgfqpoint{\braid at tx}{\braid at ty}}%
+  {\pgfqpoint{\braid at tx}{\braid at cy}}%
+  {\pgfqpoint{\braid at nx}{\braid at dy}}%
+  {\pgfqpoint{\braid at nx}{\braid at ny}}
 \fi
   \pgfsyssoftpath at getcurrentpath{\braid at this@path}
   \pgfsyssoftpath at setcurrentpath{\braid at next@path}
   \pgfpathlineto{\pgfqpoint{\braid at nx}{\braid at ty}}
 \ifx\braid at crossing@type\braid at over@cross
-\pgfpathcurvebetweentimecontinue{0}{.4}{\pgfqpoint{\braid at nx}{\braid at ty}}{\pgfqpoint{\braid at nx}{\braid at cy}}{\pgfqpoint{\braid at tx}{\braid at dy}}{\pgfqpoint{\braid at tx}{\braid at ny}}
-\pgfpathcurvebetweentime{.6}{1}{\pgfqpoint{\braid at nx}{\braid at ty}}{\pgfqpoint{\braid at nx}{\braid at cy}}{\pgfqpoint{\braid at tx}{\braid at dy}}{\pgfqpoint{\braid at tx}{\braid at ny}}
+  \pgfpathcurvebetweentimecontinue{0}{\braid at gst}%
+  {\pgfqpoint{\braid at nx}{\braid at ty}}%
+  {\pgfqpoint{\braid at nx}{\braid at cy}}%
+  {\pgfqpoint{\braid at tx}{\braid at dy}}%
+  {\pgfqpoint{\braid at tx}{\braid at ny}}
+  \pgfpathcurvebetweentime{\braid at gend}{1}%
+  {\pgfqpoint{\braid at nx}{\braid at ty}}%
+  {\pgfqpoint{\braid at nx}{\braid at cy}}%
+  {\pgfqpoint{\braid at tx}{\braid at dy}}%
+  {\pgfqpoint{\braid at tx}{\braid at ny}}
 \else
-  \pgfpathcurveto{\pgfqpoint{\braid at nx}{\braid at cy}}{\pgfqpoint{\braid at tx}{\braid at dy}}{\pgfqpoint{\braid at tx}{\braid at ny}}
+  \pgfpathcurveto{\pgfqpoint{\braid at nx}{\braid at cy}}%
+  {\pgfqpoint{\braid at tx}{\braid at dy}}%
+  {\pgfqpoint{\braid at tx}{\braid at ny}}
 \fi
   \pgfsyssoftpath at getcurrentpath{\braid at next@path}
-  \expandafter\let\csname braid at strand@\braid at this@path at origin \endcsname\braid at this@path
-  \expandafter\let\csname braid at strand@\braid at next@path at origin \endcsname\braid at next@path
-  \expandafter\let\csname braid at strand@\braid at this@strand @origin\endcsname\braid at next@path at origin
-  \expandafter\let\csname braid at strand@\braid at next@strand @origin\endcsname\braid at this@path at origin
-  \pgfmathparse{\value{braid at strands} < \braid at next@strand ? "\noexpand\setcounter{braid at strands}{\braid at next@strand}" : ""}
+  \expandafter\let%
+  \csname braid at strand@\braid at this@path at origin \endcsname%
+  \braid at this@path
+  \expandafter\let%
+  \csname braid at strand@\braid at next@path at origin \endcsname%
+  \braid at next@path
+  \expandafter\let%
+  \csname braid at strand@\braid at this@strand @origin\endcsname%
+  \braid at next@path at origin
+  \expandafter\let%
+  \csname braid at strand@\braid at next@strand @origin\endcsname%
+  \braid at this@path at origin
+  \pgfmathparse{\value{braid at strands} < \braid at next@strand ?
+    "\noexpand\setcounter{braid at strands}{\braid at next@strand}" : ""}
   \pgfmathresult
   \braid at process%
 }
+\newcommand{\braid at olabel@strand}[3][]{%
+  \edef\braid at tmp{{\the\value{braid at level}}}%
+  \expandafter\ifx\csname braid at strand@#2 at origin\endcsname\relax
+  \g at addto@macro\braid at tmp{{#2}}%
+  \else
+  \edef\braid at tmpa{{\csname braid at strand@#2 at origin\endcsname}}%
+  \ge at addto@macro\braid at tmp{\braid at tmpa}%
+  \fi
+  \g at addto@macro\braid at tmp{{#3}{#1}}%
+  \ge at addto@macro{\braid at strand@labels}{\braid at tmp}%
+  \braid at process%
+}
+\newcommand{\braid at clabel@strand}[3][]{%
+  \edef\braid at tmp{{\the\value{braid at level}}}%
+  \g at addto@macro\braid at tmp{{#2}{#3}{#1}}%
+  \ge at addto@macro{\braid at strand@labels}{\braid at tmp}%
+  \braid at process%
+}
 \def\braid at floors@trim,{}
 \def\braid at render@floor{%
     \draw (\floorsx,\floorsy) rectangle (\floorex,\floorey);
 }
+\def\braid at render@strand at labels#1{%
+  \def\braid at tmp{#1}%
+  \ifx\braid at tmp\pgfutil at empty
+  \let\braid at next=\pgfutil at gobble
+  \else
+  \let\braid at next=\braid@@render at strand@labels
+  \fi
+  \braid at next{#1}%
+}
+\def\braid@@render at strand@labels#1#2#3#4{%
+  \begingroup
+  \pgfscope
+  \let\tikz at options=\pgfutil at empty
+  \let\tikz at mode=\pgfutil at empty
+  \let\tik at transform=\pgfutil at empty
+  \let\tikz at fig@name=\pgfutil at empty
+  \tikzset{/pgf/braid/strand label,#4}%
+  \braid at nx=#2\braid at width
+  \braid at ny=#1\braid at height
+  \advance\braid at ny by \braid at eh
+  \advance\braid at ny by \braid at height
+  \pgftransformshift{\pgfqpoint{\braid at nx}{\braid at ny}}%
+  \tikz at options
+  \setbox\pgfnodeparttextbox=\hbox%
+  \bgroup%
+  \tikzset{every text node part/.try}%
+  \ifx\tikz at textopacity\pgfutil at empty%
+  \else%
+  \pgfsetfillopacity{\tikz at textopacity}%
+  \pgfsetstrokeopacity{\tikz at textopacity}%
+  \fi%
+  \pgfinterruptpicture%
+  \tikz at textfont%
+  \ifx\tikz at text@width\pgfutil at empty%
+  \else%
+  \begingroup%
+  \pgfmathsetlength{\pgf at x}{\tikz at text@width}%
+  \pgfutil at minipage[t]{\pgf at x}\leavevmode\hbox{}%
+  \tikz at text@action%
+  \fi%
+  \tikz at atbegin@node%
+  \bgroup%
+  \aftergroup\unskip%
+  \ifx\tikz at textcolor\pgfutil at empty%
+  \else%
+  \pgfutil at colorlet{.}{\tikz at textcolor}%
+  \fi%
+  \pgfsetcolor{.}%
+  \setbox\tikz at figbox=\box\pgfutil at voidb@x%
+  \tikz at uninstallcommands%
+  \tikz at halign@check%
+  \ignorespaces%
+  #3
+  \egroup
+  \tikz at atend@node%
+  \ifx\tikz at text@width\pgfutil at empty%
+  \else%
+  \pgfutil at endminipage%
+  \endgroup%
+  \fi%
+  \endpgfinterruptpicture%
+  \egroup%
+   \ifx\tikz at text@width\pgfutil at empty%
+    \else%
+      \pgfmathsetlength{\pgf at x}{\tikz at text@width}%
+      \wd\pgfnodeparttextbox=\pgf at x%
+    \fi%
+    \ifx\tikz at text@height\pgfutil at empty%
+    \else%
+      \pgfmathsetlength{\pgf at x}{\tikz at text@height}%
+      \ht\pgfnodeparttextbox=\pgf at x%
+    \fi%
+    \ifx\tikz at text@depth\pgfutil at empty%
+    \else%
+      \pgfmathsetlength{\pgf at x}{\tikz at text@depth}%
+      \dp\pgfnodeparttextbox=\pgf at x%
+    \fi%
+  \pgfmultipartnode{\tikz at shape}{\tikz at anchor}{\tikz at fig@name}{%
+    {\begingroup\tikz at finish}%
+  }%
+  \endpgfscope
+  \endgroup
+  \braid at render@strand at labels%
+}
 \def\braid at render{
     \ifx\braid at floors\@empty
     \else
@@ -237,7 +397,8 @@
       \let\tikz at options=\pgfutil at empty
     \expandafter\tikzset\expandafter{\braid at floors@style}
       \pgfmathtruncatemacro{\braid at ff}{\braid at f+2}
-    \expandafter\let\expandafter\braid at floor@style\csname braid at options@floor@\braid at ff\endcsname
+    \expandafter\let\expandafter\braid at floor@style%
+    \csname braid at options@floor@\braid at ff\endcsname
     \ifx\braid at floor@style\relax
     \else
     \expandafter\tikzset\expandafter{\braid at floor@style}%
@@ -257,18 +418,21 @@
     \braid at tx=\braid at k\braid at width
     \braid at ty=\value{braid at level}\braid at height
     \advance\braid at ty by 2\braid at eh
-    \expandafter\let\expandafter\braid at path@origin\csname braid at strand@\braid at k @origin\endcsname
+    \expandafter\let\expandafter\braid at path@origin%
+    \csname braid at strand@\braid at k @origin\endcsname
     \ifx\braid at path@origin\relax
     \pgfsyssoftpath at setcurrentpath{\@empty}
     \pgfpathmoveto{\pgfqpoint{\braid at tx}{0pt}}
     \let\braid at path@origin\braid at k
     \else
-    \expandafter\let\expandafter\braid at path\csname braid at strand@\braid at path@origin\endcsname
+    \expandafter\let\expandafter\braid at path%
+    \csname braid at strand@\braid at path@origin\endcsname
     \pgfsyssoftpath at setcurrentpath{\braid at path}
     \fi
     \pgflineto{\pgfqpoint{\braid at tx}{\braid at ty}}
     \expandafter\tikzset\expandafter{\braid at style}
-    \expandafter\let\expandafter\braid at style\csname braid at options@strand@\braid at path@origin\endcsname
+    \expandafter\let\expandafter\braid at style%
+    \csname braid at options@strand@\braid at path@origin\endcsname
     \ifx\braid at style\relax
     \else
     \expandafter\tikzset\expandafter{\braid at style}
@@ -300,25 +464,40 @@
     \braid at ty=.5\braid at ty
     \coordinate (\braid at name) at (\braid at tx,\braid at ty);
     \fi
+  \ifx\braid at strand@labels\pgfutil at empty
+  \else
+   \expandafter\braid at render@strand at labels\braid at strand@labels{}%
+  \fi
     \pgfsys at endscope
   \endgroup}
 \def\braid at start#1{%
-      \pgfsys at beginscope
-      \setcounter{braid at level}{-1}%
-      \let\braid at label\@empty
-      \let\braid at floors\@empty
-      \let\braid at name\empty
-      \pgfkeys{/pgf/braid/.cd,#1}
-      \let\braid at options\tikz at options
+  \pgfsys at beginscope
+  \setcounter{braid at level}{-1}%
+  \let\braid at label\@empty
+  \let\braid at strand@labels\@empty
+  \let\braid at floors\@empty
+  \let\braid at name\empty
+  \let\clabel=\braid at clabel@strand
+  \let\olabel=\braid at olabel@strand
+  \pgfkeys{/pgf/braid/.cd,#1}%
+  \ifbraid at strand@labels at origin
+  \let\label=\braid at olabel@strand
+  \else
+  \let\label=\braid at clabel@strand
+  \fi
+  \let\braid at options\tikz at options
   \tikz at transform
-      \setcounter{braid at strands}{\pgfkeysvalueof{/pgf/braid/number of           strands}}%
-    \braid at width=\pgfkeysvalueof{/pgf/braid/width}
-    \braid at height=\pgfkeysvalueof{/pgf/braid/height}
-    \braid at eh=\pgfkeysvalueof{/pgf/braid/border height}
-    \braid at height=-\braid at height
-    \braid at eh=-\braid at eh
-    \braid at increase@leveltrue
-    \braid at process@start
+  \setcounter{braid at strands}{%
+    \pgfkeysvalueof{/pgf/braid/number of strands}}%
+  \braid at width=\pgfkeysvalueof{/pgf/braid/width}%
+  \braid at height=\pgfkeysvalueof{/pgf/braid/height}%
+  \braid at eh=\pgfkeysvalueof{/pgf/braid/border height}%
+  \pgfkeysgetvalue{/pgf/braid/control factor}{\braid at cf}%
+  \pgfkeysgetvalue{/pgf/braid/nudge factor}{\braid at nf}%
+  \braid at height=-\braid at height
+  \braid at eh=-\braid at eh
+  \braid at increase@leveltrue
+  \braid at process@start
 }
 \newdimen\braid at width
 \newdimen\braid at height
@@ -330,6 +509,7 @@
 \newdimen\braid at dy
 \newdimen\braid at eh
 \newif\ifbraid at increase@level
+\newif\ifbraid at strand@labels at origin
 \let\braid at style\pgfutil at empty
 \let\braid at floors@style\pgfutil at empty
 \def\braid at over@cross{1}
@@ -342,7 +522,10 @@
     number of strands/.initial=0,
     height/.initial=1cm,
     width/.initial=1cm,
+    gap/.initial=.1,
     border height/.initial=.25cm,
+    control factor/.initial=.5,
+    nudge factor/.initial=.05,
     name/.code={%
       \def\braid at name{#1}%
     },
@@ -357,7 +540,8 @@
       \braidset{style each strand/.list={#1}}%
     },
     style each strand/.code={%
-      \expandafter\edef\csname braid at options@strand@#1\endcsname{\braid at temp}%
+      \expandafter\edef%
+      \csname braid at options@strand@#1\endcsname{\braid at temp}%
     },
     style floors/.code 2 args={%
       \def\braid at temp{#2}%
@@ -364,17 +548,20 @@
       \braidset{style each floor/.list={#1}}%
     },
     style each floor/.code={%
-      \expandafter\edef\csname braid at options@floor@#1\endcsname{\braid at temp}%
+      \expandafter\edef%
+      \csname braid at options@floor@#1\endcsname{\braid at temp}%
     },
     style all floors/.code={%
       \def\braid at floors@style{#1}
-    }
+    },
+    strand label/.style={},
+    strand label by origin/.is if=braid at strand@labels at origin,
 }
 \def\braidset#1{%
   \pgfkeys{/pgf/braid/.cd,#1}}
 
 %% 
-%% Copyright (C) 2011 by Andrew Stacey <stacey at math.ntnu.no>
+%% Copyright (C) 2011-2019 by Andrew Stacey <loopspace at mathforge.org>
 %% 
 %% This work may be distributed and/or modified under the
 %% conditions of the LaTeX Project Public License (LPPL), either
@@ -392,6 +579,7 @@
 %%                                  braids.ins,
 %%                                  braids.pdf,
 %%                                  braids.sty,
+%%                                  tikzlibrarybraids.code.tex,
 %%                                  braids_doc.pdf.
 %% 
 %%

Added: trunk/Master/texmf-dist/tex/latex/braids/tikzlibrarybraids.code.tex
===================================================================
--- trunk/Master/texmf-dist/tex/latex/braids/tikzlibrarybraids.code.tex	                        (rev 0)
+++ trunk/Master/texmf-dist/tex/latex/braids/tikzlibrarybraids.code.tex	2019-05-08 21:15:00 UTC (rev 51048)
@@ -0,0 +1,916 @@
+%%
+%% This is file `tikzlibrarybraids.code.tex',
+%% generated with the docstrip utility.
+%%
+%% The original source files were:
+%%
+%% braids_code.dtx  (with options: `library')
+%% ----------------------------------------------------------------
+%% braids --- a style file for drawing braid diagrams with TikZ/PGF
+%% E-mail: loopspace at mathforge.org
+%% Released under the LaTeX Project Public License v1.3c or later
+%% See http://www.latex-project.org/lppl.txt
+%% ----------------------------------------------------------------
+%% 
+\ProvidesFile{tikzlibrarybraids.code.tex}[%
+  2019/03/20 v2.0 Tikz/PGF library for drawing braid diagrams%
+]
+\RequirePackage{expl3}
+\ExplSyntaxOn
+\tl_new:N \l__braid_tmpa_tl
+\tl_new:N \l__braid_tmpb_tl
+\tl_new:N \l__braid_tmpc_tl
+\tl_new:N \l__braid_tmpd_tl
+\tl_new:N \l__braid_anchor_strand_tl
+\tl_new:N \l__braid_anchor_level_tl
+\fp_new:N \l__braid_height_fp
+\fp_new:N \l__braid_width_fp
+\fp_new:N \l__braid_nudge_fp
+\fp_new:N \l__braid_control_fp
+\fp_new:N \l__braid_ctrlax_fp
+\fp_new:N \l__braid_ctrlay_fp
+\fp_new:N \l__braid_ctrlbx_fp
+\fp_new:N \l__braid_ctrlby_fp
+\fp_new:N \l__braid_endx_fp
+\fp_new:N \l__braid_endy_fp
+\fp_new:N \l__braid_anchor_x_fp
+\fp_new:N \l__braid_anchor_y_fp
+\int_new:N \l__braid_tmpa_int
+\int_new:N \l__braid_length_int
+\int_new:N \l__braid_strands_int
+\int_new:N \l__braid_crossing_int
+\int_new:N \l__braid_anchor_level_int
+\int_new:N \l__braid_floor_int
+\seq_new:N \l__braid_word_seq
+\seq_new:N \l__braid_crossing_seq
+\seq_new:N \l__braid_anchor_seq
+\seq_new:N \l__braid_floors_seq
+\str_new:N \l__braid_tmpa_str
+\str_new:N \l__braid_sup_str
+\str_set:Nn \l__braid_sup_str {^}
+\str_new:N \l__braid_sub_str
+\str_set:Nn \l__braid_sub_str {_}
+\str_new:N \l__braid_hyphen_str
+\str_set:Nn \l__braid_hyphen_str {-}
+\str_new:N \l__braid_bar_str
+\str_set:Nn \l__braid_bar_str {|}
+\str_new:N \l__braid_one_str
+\str_set:Nn \l__braid_one_str {1}
+\bool_new:N \l__braid_step_level_bool
+\bool_new:N \l__braid_swap_crossing_bool
+\bool_new:N \l__braid_floor_bool
+\prop_new:N \l__braid_strands_prop
+\prop_new:N \l__braid_permutation_prop
+\prop_new:N \l__braid_crossing_permutation_prop
+\prop_new:N \l__braid_inverse_prop
+\prop_new:N \l__braid_anchor_prop
+\tikzset{
+   braid/.pic={
+     code={
+       \__braid_parse_word:n {#1}
+       \__braid_count:
+       \__braid_render:
+     }
+   },
+   floor/.pic={
+     code={
+       \path[pic~ actions, draw=none] (0,0) rectangle (1,1);
+       \path[pic~ actions, fill=none] (0,0) -- (1,0) (0,1) -- (1,1);
+     }
+   },
+   /tikz/braid/.search~ also={/tikz},
+   braid/.cd,
+   anchor/.initial=1-s,
+   number~ of~ strands/.initial=0,
+   height/.initial=-1cm,
+   width/.initial=1cm,
+   gap/.initial=.05,
+   border~ height/.initial=.25cm,
+   floor~ border/.initial=.25cm,
+   add~ floor/.code={
+     \seq_push:Nn \l__braid_floors_seq {#1}
+   },
+   control~ factor/.initial=.5,
+   nudge~ factor/.initial=.05
+}
+\cs_new_nopar:Npn \__braid_parse_word:n #1
+{
+  \seq_clear:N \l__braid_word_seq
+  \tl_clear:N \l__braid_tmpa_tl
+  \tl_set:Nn \l__braid_tmpb_tl {#1}
+
+  \bool_until_do:nn { \tl_if_empty_p:N \l__braid_tmpb_tl }
+  {
+    \str_set:Nx \l__braid_tmpa_str {\tl_head:N \l__braid_tmpb_tl}
+    \tl_set:Nx \l__braid_tmpb_tl {\tl_tail:N \l__braid_tmpb_tl}
+    \str_case_e:nnTF {\l__braid_tmpa_str}
+    {
+      {_}
+     {
+       \tl_put_right:Nx \l__braid_tmpa_tl
+       {
+         \exp_not:N \__braid_parse_index:n {\tl_head:N \l__braid_tmpb_tl}
+       }
+       \tl_set:Nx \l__braid_tmpb_tl {\tl_tail:N \l__braid_tmpb_tl}
+     }
+     {^}
+     {
+       \tl_put_left:Nx \l__braid_tmpa_tl
+       {
+         \exp_not:N \__braid_parse_exponent:n {\tl_head:N \l__braid_tmpb_tl}
+       }
+       \tl_set:Nx \l__braid_tmpb_tl {\tl_tail:N \l__braid_tmpb_tl}
+     }
+     {|}
+     {
+      \tl_if_empty:NF \l__braid_tmpa_tl
+      {
+        \seq_put_right:NV \l__braid_word_seq \l__braid_tmpa_tl
+        \tl_clear:N \l__braid_tmpa_tl
+      }
+
+      \tl_set:Nn \l__braid_tmpa_tl {
+        \bool_set_false:N \l__braid_step_level_bool
+        \bool_set_true:N \l__braid_floor_bool
+      }
+      \seq_put_right:NV \l__braid_word_seq \l__braid_tmpa_tl
+      \tl_clear:N \l__braid_tmpa_tl
+     }
+     {-}
+     {
+       \tl_put_right:Nn \l__braid_tmpa_tl
+       {
+         \bool_set_false:N \l__braid_step_level_bool
+       }
+     }
+     {1}
+     {
+      \tl_if_empty:NF \l__braid_tmpa_tl
+      {
+        \seq_put_right:NV \l__braid_word_seq \l__braid_tmpa_tl
+        \tl_clear:N \l__braid_tmpa_tl
+      }
+       \tl_put_right:Nn \l__braid_tmpa_tl {\__braid_do_identity:}
+     }
+     {~}
+     {
+     }
+    }
+    {
+    }
+    {
+      \tl_if_empty:NF \l__braid_tmpa_tl
+      {
+        \seq_put_right:NV \l__braid_word_seq \l__braid_tmpa_tl
+        \tl_clear:N \l__braid_tmpa_tl
+      }
+    }
+  }
+  \tl_if_empty:NF \l__braid_tmpa_tl
+  {
+    \seq_put_right:NV \l__braid_word_seq \l__braid_tmpa_tl
+    \tl_clear:N \l__braid_tmpa_tl
+  }
+}
+\cs_new_nopar:Npn \__braid_parse_index:n #1
+{
+  \seq_set_from_clist:Nn \l__braid_crossing_seq {#1}
+  \int_compare:nT {\seq_count:N \l__braid_crossing_seq == 1}
+  {
+    \seq_put_right:Nx \l__braid_crossing_seq {\int_eval:n {#1 + 1} }
+  }
+  \bool_if:NT \l__braid_swap_crossing_bool
+  {
+    \seq_pop_left:NN \l__braid_crossing_seq \l__braid_tmpa_tl
+    \seq_put_right:NV \l__braid_crossing_seq \l__braid_tmpa_tl
+  }
+}
+\cs_new_nopar:Npn \__braid_parse_exponent:n #1
+{
+  \int_compare:nTF {#1 == -1}
+  {
+    \bool_set_true:N \l__braid_swap_crossing_bool
+  }
+  {
+    \bool_set_false:N \l__braid_swap_crossing_bool
+  }
+}
+\cs_new_nopar:Npn \__braid_do_identity:
+{
+}
+\cs_new_nopar:Npn \__braid_count:
+{
+  \int_zero:N \l__braid_length_int
+  \int_set:Nn \l__braid_strands_int {\__braid_value:n {number~of~strands}}
+  \prop_clear:N \l__braid_permutation_prop
+  \prop_clear:N \l__braid_crossing_permutation_prop
+  \prop_clear:N \l__braid_anchor_prop
+  \prop_clear:N \l__braid_inverse_prop
+
+  \seq_map_inline:Nn \l__braid_word_seq
+  {
+    \seq_clear:N \l__braid_crossing_seq
+    \bool_set_true:N \l__braid_step_level_bool
+    \bool_set_false:N \l__braid_swap_crossing_bool
+    ##1
+    \bool_if:NT \l__braid_step_level_bool
+    {
+      \int_incr:N \l__braid_length_int
+    }
+    \seq_if_empty:NF \l__braid_crossing_seq
+    {
+      \int_set:Nn \l__braid_strands_int
+      {
+        \int_max:nn
+        {
+          \int_max:nn {\l__braid_strands_int}
+          { \seq_item:Nn \l__braid_crossing_seq {1}}
+        }
+        {
+          \seq_item:Nn \l__braid_crossing_seq {2}
+        }
+      }
+    }
+  }
+  \int_step_inline:nnnn {1} {1} {\l__braid_strands_int}
+  {
+    \prop_put:Nnn \l__braid_permutation_prop {##1} {##1}
+    \prop_put:Nnn \l__braid_anchor_prop {##1} {##1}
+    \prop_put:Nnn \l__braid_crossing_permutation_prop {##1} {##1}
+  }
+  \tl_set:Nx \l__braid_tmpa_tl {\__braid_value:n {anchor}}
+  \seq_set_split:NnV \l__braid_anchor_seq {-} \l__braid_tmpa_tl
+
+  \tl_set:Nx \l__braid_tmpa_tl {\seq_item:Nn \l__braid_anchor_seq {1}}
+  \tl_if_eq:VnTF \l__braid_tmpa_tl {rev}
+  {
+    \tl_set:Nx \l__braid_anchor_strand_tl {\seq_item:Nn \l__braid_anchor_seq {2}}
+    \tl_set:Nx \l__braid_anchor_level_tl {\seq_item:Nn \l__braid_anchor_seq {3}}
+  }
+  {
+    \tl_set:Nx \l__braid_anchor_strand_tl {\seq_item:Nn \l__braid_anchor_seq {1}}
+    \tl_set:Nx \l__braid_anchor_level_tl {\seq_item:Nn \l__braid_anchor_seq {2}}
+  }
+  \tl_if_eq:VnTF \l__braid_anchor_level_tl {s}
+  {
+    \int_set:Nn \l__braid_anchor_level_int {-1}
+  }
+  {
+    \tl_if_eq:VnTF \l__braid_anchor_level_tl {e}
+    {
+      \int_set:Nn \l__braid_anchor_level_int {-1}
+    }
+    {
+      \int_set:Nn \l__braid_anchor_level_int
+      {\tl_use:N \l__braid_anchor_level_tl}
+    }
+  }
+
+  \int_zero:N \l__braid_crossing_int
+  \int_incr:N \l__braid_crossing_int
+  \seq_map_inline:Nn \l__braid_word_seq
+  {
+    \bool_set_true:N \l__braid_step_level_bool
+    \seq_clear:N \l__braid_crossing_seq
+    \bool_set_false:N \l__braid_swap_crossing_bool
+    ##1
+    \seq_if_empty:NF \l__braid_crossing_seq
+    {
+      \prop_get:NxN \l__braid_permutation_prop
+      {
+        \seq_item:Nn \l__braid_crossing_seq {1}
+      } \l__braid_tmpa_tl
+      \prop_get:NxN \l__braid_permutation_prop
+      {
+        \seq_item:Nn \l__braid_crossing_seq {2}
+      } \l__braid_tmpb_tl
+
+      \prop_put:NxV \l__braid_permutation_prop
+      {
+        \seq_item:Nn \l__braid_crossing_seq {2}
+      } \l__braid_tmpa_tl
+      \prop_put:NxV \l__braid_permutation_prop
+      {
+        \seq_item:Nn \l__braid_crossing_seq {1}
+      } \l__braid_tmpb_tl
+    }
+    \int_compare:nT {\l__braid_crossing_int = \l__braid_anchor_level_int}
+    {
+      \prop_set_eq:NN \l__braid_anchor_prop \l__braid_permutation_prop
+    }
+    \bool_if:NT \l__braid_step_level_bool
+    {
+      \int_incr:N \l__braid_crossing_int
+    }
+  }
+  \int_step_inline:nnnn {1} {1} {\l__braid_strands_int}
+  {
+    \prop_get:NnN \l__braid_anchor_prop {##1} \l__braid_tmpa_tl
+    \prop_put:NVn \l__braid_inverse_prop \l__braid_tmpa_tl {##1}
+  }
+  \prop_set_eq:NN \l__braid_anchor_prop \l__braid_inverse_prop
+  \int_step_inline:nnnn {1} {1} {\l__braid_strands_int}
+  {
+    \prop_get:NnN \l__braid_permutation_prop {##1} \l__braid_tmpa_tl
+    \prop_put:NVn \l__braid_inverse_prop \l__braid_tmpa_tl {##1}
+  }
+  \tl_set:Nx \l__braid_tmpa_tl {\seq_item:Nn \l__braid_anchor_seq {1}}
+  \tl_if_eq:VnT \l__braid_tmpa_tl {rev}
+  {
+    \prop_get:NVN \l__braid_permutation_prop
+    \l__braid_anchor_strand_tl \l__braid_anchor_strand_tl
+  }
+  \tl_if_eq:VnF \l__braid_anchor_level_tl {s}
+  {
+    \tl_if_eq:VnTF \l__braid_anchor_level_tl {e}
+    {
+      \prop_get:NVN \l__braid_inverse_prop
+      \l__braid_anchor_strand_tl \l__braid_anchor_strand_tl
+    }
+    {
+      \prop_get:NVN \l__braid_anchor_prop
+      \l__braid_anchor_strand_tl \l__braid_anchor_strand_tl
+    }
+  }
+}
+\cs_new_nopar:Npn \__braid_dim_value:n #1
+{
+  \dim_to_fp:n {\pgfkeysvalueof{/tikz/braid/#1}}
+}
+\cs_new_nopar:Npn \__braid_value:n #1
+{
+  \pgfkeysvalueof{/tikz/braid/#1}
+}
+\cs_generate_variant:Nn \prop_get:NnN {NxN}
+\cs_generate_variant:Nn \prop_put:Nnn {NxV}
+\cs_generate_variant:Nn \tl_if_eq:nnTF {VnTF}
+\cs_generate_variant:Nn \tl_if_eq:nnF {VnF}
+\cs_generate_variant:Nn \tl_if_eq:nnT {VnT}
+
+\cs_new_nopar:Npn \__braid_render:
+{
+  \fp_set:Nn \l__braid_anchor_x_fp { - 1 * (\tl_use:N \l__braid_anchor_strand_tl - 1) * \__braid_dim_value:n {width} }
+
+  \tl_if_eq:VnTF \l__braid_anchor_level_tl {s}
+  {
+    \fp_set:Nn \l__braid_anchor_y_fp {0}
+  }
+  {
+    \tl_if_eq:VnTF \l__braid_anchor_level_tl {e}
+    {
+      \fp_set:Nn \l__braid_anchor_y_fp {
+        -1 * \l__braid_length_int * \__braid_dim_value:n {height}
+        - sign(\__braid_dim_value:n {height})
+        * 2 * \__braid_dim_value:n {border~ height}
+      }
+    }
+    {
+      \fp_set:Nn \l__braid_anchor_y_fp {
+        -1 * \l__braid_anchor_level_tl * \__braid_dim_value:n {height}
+        - sign(\__braid_dim_value:n {height})
+        * \__braid_dim_value:n {border~ height}
+      }
+    }
+  }
+
+  \begin{scope}[
+    shift={
+      (\fp_to_decimal:N \l__braid_anchor_x_fp pt,
+      \fp_to_decimal:N \l__braid_anchor_y_fp pt
+      )
+    }
+  ]
+  \prop_clear:N \l__braid_strands_prop
+  \fp_zero:N \l__braid_height_fp
+  \fp_zero:N \l__braid_nudge_fp
+  \fp_zero:N \l__braid_control_fp
+  \fp_set:Nn \l__braid_height_fp
+  {
+    sign(\__braid_dim_value:n {height})
+    * \__braid_dim_value:n {border~ height}
+  }
+  \fp_set:Nn \l__braid_width_fp
+  {
+    (\l__braid_strands_int - 1) * \__braid_dim_value:n {width}
+    + 2 * sign(\__braid_dim_value:n{width})
+    * \__braid_dim_value:n {floor~ border}
+  }
+  \fp_set:Nn \l__braid_nudge_fp
+  {
+    \__braid_value:n {nudge~ factor} * \__braid_dim_value:n {height}
+  }
+  \fp_set:Nn \l__braid_control_fp
+  {
+    \__braid_value:n {control~ factor} * \__braid_dim_value:n {height}
+  }
+  \fp_sub:Nn \l__braid_control_fp {\l__braid_nudge_fp}
+  \int_step_inline:nnnn {1} {1} {\l__braid_strands_int}
+  {
+    \prop_get:NnN \l__braid_inverse_prop {##1} \l__braid_tmpa_tl
+    \prop_put:Nnx \l__braid_strands_prop {##1}
+    {
+      \exp_not:N \draw[
+        braid/every~ strand/.try,
+        braid/strand~ ##1/.try
+      ]
+      \exp_not:N \__braid_moveto:nn {
+        \fp_eval:n {(##1 - 1) * \__braid_dim_value:n {width} }
+      } {0}
+      \exp_not:N \__braid_lineto:nn  {
+        \fp_eval:n {(##1 - 1) * \__braid_dim_value:n {width} }
+      } { \fp_to_decimal:N \l__braid_height_fp}
+    }
+    \__braid_coordinate:xxxx {-##1-s} {-rev-\l__braid_tmpa_tl-s}
+    {\fp_eval:n {(##1 - 1) * \__braid_dim_value:n {width} }} {0}
+
+    \__braid_coordinate:xxxx {-##1-0} {-rev-\l__braid_tmpa_tl-0}
+    {\fp_eval:n {(##1 - 1) * \__braid_dim_value:n {width} }}
+    { \fp_to_decimal:N \l__braid_height_fp}
+  }
+  \seq_map_inline:Nn \l__braid_floors_seq
+  {
+    \tl_set:Nx \l__braid_tmpa_tl {\clist_item:nn {##1} {5}}
+    \__braid_do_floor:Vxxxx \l__braid_tmpa_tl
+    {\fp_eval:n
+      {
+        -1*sign(\__braid_dim_value:n{width})
+        * \__braid_dim_value:n {floor~ border}
+        + (\__braid_dim_value:n {width}) * (\clist_item:nn {##1} {1} - 1)
+      }
+      pt
+    }
+    {\fp_eval:n
+      {
+        \l__braid_height_fp + ( \__braid_dim_value:n {height} ) * (\clist_item:nn {##1} {2})
+      }
+      pt
+    }
+    {\fp_eval:n {
+        ( (\clist_item:nn {##1} {3}) * \__braid_dim_value:n {width}
+        + 2 * sign(\__braid_dim_value:n{width})
+        * \__braid_dim_value:n {floor~ border} ) / \dim_to_fp:n {1cm}
+      }
+    }
+    {\fp_eval:n {
+        (\clist_item:nn {##1} {4}) * ( \__braid_dim_value:n {height} ) / \dim_to_fp:n {1cm}
+      }
+    }
+  }
+  \int_zero:N \l__braid_crossing_int
+  \int_incr:N \l__braid_crossing_int
+
+  \seq_map_inline:Nn \l__braid_word_seq
+  {
+    \seq_clear:N \l__braid_crossing_seq
+    \bool_set_true:N \l__braid_step_level_bool
+    \bool_set_false:N \l__braid_floor_bool
+    \bool_set_false:N \l__braid_swap_crossing_bool
+    ##1
+    \bool_if:NT \l__braid_floor_bool
+    {
+      \__braid_do_floor:Vxxxx \l__braid_crossing_int
+      {\fp_eval:n
+        {
+          -1*sign(\__braid_dim_value:n{width})
+          * \__braid_dim_value:n {floor~ border}
+        }
+        pt
+      }
+      {\fp_to_decimal:N \l__braid_height_fp pt}
+      {\fp_eval:n { \l__braid_width_fp / \dim_to_fp:n {1cm} }}
+      {\fp_eval:n { ( \__braid_dim_value:n {height} ) / \dim_to_fp:n {1cm}}}
+    }
+    \seq_if_empty:NF \l__braid_crossing_seq
+    {
+      \prop_get:NxN \l__braid_crossing_permutation_prop
+      {\seq_item:Nn \l__braid_crossing_seq {1}} \l__braid_tmpa_tl
+      \prop_get:NxN \l__braid_crossing_permutation_prop
+      {\seq_item:Nn \l__braid_crossing_seq {2}} \l__braid_tmpb_tl
+
+      \prop_put:NxV \l__braid_crossing_permutation_prop
+      {\seq_item:Nn \l__braid_crossing_seq {2}} \l__braid_tmpa_tl
+      \prop_put:NxV \l__braid_crossing_permutation_prop
+      {\seq_item:Nn \l__braid_crossing_seq {1}} \l__braid_tmpb_tl
+      \prop_get:NxN \l__braid_strands_prop
+      {\seq_item:Nn \l__braid_crossing_seq {1}} \l__braid_tmpa_tl
+      \prop_get:NxN \l__braid_strands_prop
+      {\seq_item:Nn \l__braid_crossing_seq {2}} \l__braid_tmpb_tl
+      \tl_put_right:Nx \l__braid_tmpa_tl
+      {
+        \exp_not:N \__braid_lineto:nn
+
+        {\fp_eval:n
+          {
+            (\seq_item:Nn \l__braid_crossing_seq {1} - 1)
+            * \__braid_dim_value:n {width}
+          }
+        }
+        {\fp_eval:n { \l__braid_height_fp + \l__braid_nudge_fp } }
+
+        \exp_not:N \__braid_curveto:nnnnnn
+
+        {0}
+        {\fp_eval:n { \l__braid_control_fp}}
+
+        {0}
+        {\fp_eval:n {- \l__braid_control_fp}}
+
+        {\fp_eval:n
+          {
+            (\seq_item:Nn \l__braid_crossing_seq {2} - 1)
+            * \__braid_dim_value:n {width}
+          }
+        }
+        {\fp_eval:n
+          {
+            \l__braid_height_fp
+            + \__braid_dim_value:n {height}
+            - \l__braid_nudge_fp
+          }
+        }
+      }
+      \tl_put_right:Nx \l__braid_tmpb_tl
+      {
+        \exp_not:N \__braid_lineto:nn
+
+        {\fp_eval:n
+          {
+            (\seq_item:Nn \l__braid_crossing_seq {2} - 1)
+            * \__braid_dim_value:n {width}
+          }
+        }
+        {\fp_eval:n { \l__braid_height_fp + \l__braid_nudge_fp } }
+
+        \exp_not:N \__braid_curveto:nnnnnn
+
+        {0}
+        {
+          \fp_eval:n {
+            \l__braid_control_fp  * (.5 - \__braid_value:n {gap} )
+          }
+        }
+
+        {
+          \fp_eval:n {
+            - (.5 - \__braid_value:n {gap} ) / 3 *
+            \__braid_bezier_tangent:nnnnn
+            {.5 - \__braid_value:n {gap} }
+            {0}
+            {0}
+            {
+              (\seq_item:Nn \l__braid_crossing_seq {1}
+              - \seq_item:Nn \l__braid_crossing_seq {2})
+              * \__braid_dim_value:n {width}
+            }
+            {
+              (\seq_item:Nn \l__braid_crossing_seq {1}
+              - \seq_item:Nn \l__braid_crossing_seq {2})
+              * \__braid_dim_value:n {width}
+            }
+          }
+        }
+        {
+          \fp_eval:n {
+            -(.5 - \__braid_value:n {gap} ) / 3 *
+            \__braid_bezier_tangent:nnnnn
+            {.5 - \__braid_value:n {gap} }
+            {0}
+            {\l__braid_control_fp}
+            {
+              \__braid_dim_value:n {height}
+              - 2* \l__braid_nudge_fp
+              - \l__braid_control_fp
+            }
+            {\__braid_dim_value:n {height} - 2* \l__braid_nudge_fp}
+          }
+        }
+
+        {
+          \fp_eval:n {
+            (\seq_item:Nn \l__braid_crossing_seq {2} - 1)
+            * \__braid_dim_value:n {width} +
+            \__braid_bezier_point:nnnnn
+            {.5 - \__braid_value:n {gap} }
+            {0}
+            {0}
+            {
+              (\seq_item:Nn \l__braid_crossing_seq {1}
+              - \seq_item:Nn \l__braid_crossing_seq {2})
+              * \__braid_dim_value:n {width}
+            }
+            {
+              (\seq_item:Nn \l__braid_crossing_seq {1}
+              - \seq_item:Nn \l__braid_crossing_seq {2})
+              * \__braid_dim_value:n {width}
+            }
+          }
+        }
+        {
+          \fp_eval:n {
+          \l__braid_height_fp + \l__braid_nudge_fp +
+            \__braid_bezier_point:nnnnn
+            {.5 - \__braid_value:n {gap} }
+            {0}
+            {\l__braid_control_fp}
+            {
+              \__braid_dim_value:n {height}
+              - 2* \l__braid_nudge_fp
+              - \l__braid_control_fp
+            }
+            {\__braid_dim_value:n {height} - 2* \l__braid_nudge_fp}
+          }
+        }
+
+        \exp_not:N \__braid_moveto:nn
+        {
+          \fp_eval:n {
+            (\seq_item:Nn \l__braid_crossing_seq {2} - 1)
+            * \__braid_dim_value:n {width} +
+            \__braid_bezier_point:nnnnn
+            {.5 + \__braid_value:n {gap} }
+            {0}
+            {0}
+            {
+              (\seq_item:Nn \l__braid_crossing_seq {1}
+              - \seq_item:Nn \l__braid_crossing_seq {2})
+              * \__braid_dim_value:n {width}
+            }
+            {
+              (\seq_item:Nn \l__braid_crossing_seq {1}
+              - \seq_item:Nn \l__braid_crossing_seq {2})
+              * \__braid_dim_value:n {width}
+            }
+          }
+        }
+        {
+          \fp_eval:n {
+          \l__braid_height_fp + \l__braid_nudge_fp +
+            \__braid_bezier_point:nnnnn
+            {.5 + \__braid_value:n {gap} }
+            {0}
+            {\l__braid_control_fp}
+            {
+              \__braid_dim_value:n {height} - 2* \l__braid_nudge_fp
+              - \l__braid_control_fp
+            }
+            {\__braid_dim_value:n {height} - 2* \l__braid_nudge_fp}
+          }
+        }
+
+        \exp_not:N \__braid_curveto:nnnnnn
+
+        {
+          \fp_eval:n {
+            (.5 - \__braid_value:n {gap} ) / 3 *
+            \__braid_bezier_tangent:nnnnn
+            {.5 + \__braid_value:n {gap} }
+            {0}
+            {0}
+            {
+              (\seq_item:Nn \l__braid_crossing_seq {1}
+              - \seq_item:Nn \l__braid_crossing_seq {2})
+              * \__braid_dim_value:n {width}
+            }
+            {
+              (\seq_item:Nn \l__braid_crossing_seq {1}
+              - \seq_item:Nn \l__braid_crossing_seq {2})
+              * \__braid_dim_value:n {width}
+            }
+          }
+        }
+        {
+          \fp_eval:n {
+            (.5 - \__braid_value:n {gap} ) / 3 *
+            \__braid_bezier_tangent:nnnnn
+            {.5 + \__braid_value:n {gap} }
+            {0}
+            {\l__braid_control_fp}
+            {
+              \__braid_dim_value:n {height} - 2* \l__braid_nudge_fp
+              - \l__braid_control_fp
+            }
+            {\__braid_dim_value:n {height} - 2* \l__braid_nudge_fp}
+          }
+        }
+
+        {0}
+        { \fp_eval:n {
+            -\l__braid_control_fp  * (.5 - \__braid_value:n {gap} )
+          }
+        }
+
+        {\fp_eval:n
+          {
+            (\seq_item:Nn \l__braid_crossing_seq {1} - 1)
+            * \__braid_dim_value:n {width}
+          }
+        }
+        {\fp_eval:n
+          {
+            \l__braid_height_fp + \__braid_dim_value:n {height}
+            - \l__braid_nudge_fp
+          }
+        }
+
+      }
+      \prop_put:NxV \l__braid_strands_prop
+      {\seq_item:Nn \l__braid_crossing_seq {2}} \l__braid_tmpa_tl
+      \prop_put:NxV \l__braid_strands_prop
+      {\seq_item:Nn \l__braid_crossing_seq {1}} \l__braid_tmpb_tl
+      \int_compare:nT
+      {
+        \int_max:nn
+        {
+          \seq_item:Nn \l__braid_crossing_seq {1}
+        }
+        {
+          \seq_item:Nn \l__braid_crossing_seq {2}
+        }
+        -
+        \int_min:nn
+        {
+          \seq_item:Nn \l__braid_crossing_seq {1}
+        }
+        {
+          \seq_item:Nn \l__braid_crossing_seq {2}
+        }
+        > 1
+      }
+      {
+        \int_step_inline:nnnn
+        {
+          \int_min:nn
+          {
+            \seq_item:Nn \l__braid_crossing_seq {1}
+          }
+          {
+            \seq_item:Nn \l__braid_crossing_seq {2}
+          }
+          + 1}
+        {1}
+        {
+          \int_max:nn
+          {
+            \seq_item:Nn \l__braid_crossing_seq {1}
+          }
+          {
+            \seq_item:Nn \l__braid_crossing_seq {2}
+          }
+          - 1
+        }
+        {
+
+          \prop_get:NnN \l__braid_strands_prop {####1} \l__braid_tmpa_tl
+          \tl_put_right:Nx \l__braid_tmpa_tl
+            {
+              \exp_not:N \__braid_lineto:nn
+              {\fp_eval:n {(####1 - 1) * \__braid_dim_value:n {width} }}
+              {\fp_eval:n
+                {
+                  \l__braid_height_fp + \l__braid_nudge_fp
+                  + .5 * \l__braid_control_fp
+                }
+              }
+              \exp_not:N \__braid_moveto:nn
+              {\fp_eval:n {(####1 - 1) * \__braid_dim_value:n {width} }}
+              {\fp_eval:n
+                {
+                  \l__braid_height_fp + \__braid_dim_value:n {height}
+                  - \l__braid_nudge_fp - .5 * \l__braid_control_fp
+                }
+              }
+            }
+
+            \prop_put:NnV \l__braid_strands_prop {####1} \l__braid_tmpa_tl
+          }
+      }
+    }
+    \bool_if:NT \l__braid_step_level_bool
+    {
+      \fp_add:Nn \l__braid_height_fp { \__braid_dim_value:n {height} }
+
+      \int_step_inline:nnnn {1} {1} {\l__braid_strands_int}
+      {
+        \prop_get:NnN \l__braid_crossing_permutation_prop
+        {####1} \l__braid_tmpb_tl
+        \prop_get:NVN \l__braid_inverse_prop
+        \l__braid_tmpb_tl \l__braid_tmpa_tl
+
+        \__braid_coordinate:xxxx
+        {-\l__braid_tmpb_tl-\int_use:N \l__braid_crossing_int}
+        {-rev-\l__braid_tmpa_tl-\int_use:N \l__braid_crossing_int }
+        {\fp_eval:n { (####1 - 1) * \__braid_dim_value:n {width} }}
+        {\fp_to_decimal:N \l__braid_height_fp}
+      }
+
+      \int_incr:N \l__braid_crossing_int
+    }
+  }
+
+  \fp_add:Nn \l__braid_height_fp
+  {
+    sign(\__braid_dim_value:n {height})
+    * \__braid_dim_value:n {border~ height}
+  }
+  \int_step_inline:nnnn {1} {1} {\l__braid_strands_int}
+  {
+    \prop_get:NxN \l__braid_strands_prop {##1} \l__braid_tmpa_tl
+    \prop_get:NxN \l__braid_permutation_prop {##1} \l__braid_tmpb_tl
+
+    \tl_put_right:Nx \l__braid_tmpa_tl {
+      \exp_not:N \__braid_lineto:nn
+      {\fp_eval:n { (##1 - 1) * \__braid_dim_value:n {width} }}
+      {\fp_to_decimal:N \l__braid_height_fp}
+      coordinate (-rev-##1-e)
+      coordinate (-\l__braid_tmpb_tl-e)
+      ;
+    }
+
+    \prop_put:NnV \l__braid_strands_prop {##1} \l__braid_tmpa_tl
+  }
+  \int_step_inline:nnnn {1} {1} {\l__braid_strands_int}
+  {
+    \prop_get:NnN \l__braid_strands_prop {##1} \l__braid_tmpa_tl
+    \tl_use:N \l__braid_tmpa_tl
+  }
+  \end{scope}
+}
+\cs_new_nopar:Npn \__braid_moveto:nn #1#2
+{
+  (#1 pt, #2 pt)
+}
+\cs_new_nopar:Npn \__braid_lineto:nn #1#2
+{
+  -- (#1 pt, #2 pt)
+}
+\cs_new_nopar:Npn \__braid_curveto:nnnnnn #1#2#3#4#5#6
+{
+  .. controls +(#1 pt, #2 pt) and +(#3 pt, #4 pt)
+  .. (#5 pt, #6 pt)
+}
+\cs_new_nopar:Npn \__braid_coordinate:nnnn #1#2#3#4
+{
+  \coordinate[alias=#2] (#1) at (#3 pt,#4 pt);
+}
+\cs_generate_variant:Nn \__braid_coordinate:nnnn {xxxx}
+\cs_new_nopar:Npn \__braid_bezier_point:nnnnn #1#2#3#4#5
+{
+  \fp_eval:n
+  {
+    (1 - (#1)) * (1 - (#1)) * (1 - (#1)) * (#2)
+    +
+    3 * (1 - (#1)) * (1 - (#1)) * (#1) * (#3)
+    +
+    3 * (1 - (#1)) * (#1) * (#1) * (#4)
+    +
+    (#1) * (#1) * (#1) * (#5)
+  }
+}
+\cs_new_nopar:Npn \__braid_bezier_tangent:nnnnn #1#2#3#4#5
+{
+  \fp_eval:n
+  {
+    3 * (1 - (#1)) * (1 - (#1)) * (#3 - (#2))
+    +
+    6 * (1 - (#1)) * (#1) * (#4 - (#3))
+    +
+    3 * (#1) * (#1) * (#5 - (#4))
+  }
+}
+\cs_new_nopar:Npn \__braid_do_floor:nnnnn #1#2#3#4#5
+{
+  \pic[pic~ type=floor,
+    xscale=#4,
+    yscale=#5,
+    at={(#2,#3)},
+    braid/every~ floor/.try,
+    braid/floor~#1/.try,
+  ];
+}
+\cs_generate_variant:Nn \__braid_do_floor:nnnnn {Vxxxx}
+\ExplSyntaxOff
+
+%% 
+%% Copyright (C) 2011-2019 by Andrew Stacey <loopspace at mathforge.org>
+%% 
+%% This work may be distributed and/or modified under the
+%% conditions of the LaTeX Project Public License (LPPL), either
+%% version 1.3c of this license or (at your option) any later
+%% version.  The latest version of this license is in the file:
+%% 
+%% http://www.latex-project.org/lppl.txt
+%% 
+%% This work is "maintained" (as per LPPL maintenance status) by
+%% Andrew Stacey.
+%% 
+%% This work consists of the files  braids.dtx
+%%                                  braids_doc.tex
+%% and the derived files            README.txt,
+%%                                  braids.ins,
+%%                                  braids.pdf,
+%%                                  braids.sty,
+%%                                  tikzlibrarybraids.code.tex,
+%%                                  braids_doc.pdf.
+%% 
+%%
+%% End of file `tikzlibrarybraids.code.tex'.


Property changes on: trunk/Master/texmf-dist/tex/latex/braids/tikzlibrarybraids.code.tex
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property


More information about the tex-live-commits mailing list