summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/latex/spath3
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2013-04-13 22:58:30 +0000
committerKarl Berry <karl@freefriends.org>2013-04-13 22:58:30 +0000
commit2990bdaecab058888c965905ed0bd12587a292aa (patch)
tree25198bedccfa37fe48865a1bdcc03bd4f7de8cc9 /Master/texmf-dist/doc/latex/spath3
parent5cc36a171f8092e44ab898ee2e44446b5c4a2949 (diff)
spath3 (12apr13)
git-svn-id: svn://tug.org/texlive/trunk@29898 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/doc/latex/spath3')
-rw-r--r--Master/texmf-dist/doc/latex/spath3/README.txt9
-rw-r--r--Master/texmf-dist/doc/latex/spath3/calligraphy_doc.pdfbin0 -> 288357 bytes
-rw-r--r--Master/texmf-dist/doc/latex/spath3/calligraphy_doc.tex258
-rw-r--r--Master/texmf-dist/doc/latex/spath3/knots_doc.pdfbin0 -> 385130 bytes
-rw-r--r--Master/texmf-dist/doc/latex/spath3/knots_doc.tex484
5 files changed, 751 insertions, 0 deletions
diff --git a/Master/texmf-dist/doc/latex/spath3/README.txt b/Master/texmf-dist/doc/latex/spath3/README.txt
new file mode 100644
index 00000000000..a9d1fe62103
--- /dev/null
+++ b/Master/texmf-dist/doc/latex/spath3/README.txt
@@ -0,0 +1,9 @@
+----------------------------------------------------------------
+spath3 --- LaTeX3 functions for manipulating PGF soft paths
+E-mail: stacey@math.ntnu.no
+Released under the LaTeX Project Public License v1.3c or later
+See http://www.latex-project.org/lppl.txt
+----------------------------------------------------------------
+
+This package defines some functions used to manipulate PGFs soft paths.
+As applications of its use, included are a package for drawing calligraphic paths and a package for drawing knot diagrams.
diff --git a/Master/texmf-dist/doc/latex/spath3/calligraphy_doc.pdf b/Master/texmf-dist/doc/latex/spath3/calligraphy_doc.pdf
new file mode 100644
index 00000000000..68bd15498e3
--- /dev/null
+++ b/Master/texmf-dist/doc/latex/spath3/calligraphy_doc.pdf
Binary files differ
diff --git a/Master/texmf-dist/doc/latex/spath3/calligraphy_doc.tex b/Master/texmf-dist/doc/latex/spath3/calligraphy_doc.tex
new file mode 100644
index 00000000000..c1b88c9e8e7
--- /dev/null
+++ b/Master/texmf-dist/doc/latex/spath3/calligraphy_doc.tex
@@ -0,0 +1,258 @@
+\immediate\write18{tex spath3.dtx}
+\documentclass{ltxdoc}
+\usepackage[T1]{fontenc}
+\usepackage{trace}
+\usepackage{lmodern}
+\usepackage{morefloats}
+\usepackage{tikz}
+\usetikzlibrary{decorations.pathreplacing,calligraphy,matrix}
+\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{spath3.sty}
+
+\title{The \textsf{calligraphy} Package: Documentation}
+\author{Andrew Stacey \\ \url{stacey@math.ntnu.no}}
+\date{\fileversion~from \filedate}
+
+\begin{document}
+
+\maketitle
+% \section{Introduction}
+The \Verb+calligraphy+ TikZ library is designed to enable calligraphic style drawings in TikZ.
+The idea is to be able to ``stroke'' a line with a ``pen''.
+As a simple example, compare the two lines in the following picture.
+
+\begin{example}
+\begin{center}
+\begin{tikzpicture}
+\pen (-135:.25) -- (45:.25);
+\draw[line width=.5cm] (0,0) .. controls +(45:1) and +(-135:1) .. ++(3,0);
+\calligraphy (0,-1) .. controls +(45:1) and +(-135:1) .. ++(3,0);
+\end{tikzpicture}
+\end{center}
+\end{example}
+
+The paths are identical in definition but the first is drawn using the standard TikZ path with a line width of .5cm.
+The second is ``stroked'' with a calligraphic pen of width .5cm angled at 45 degrees.
+\section{How It Works}
+To know how to use this library, it is worth knowing a little about how it works.
+A ``pen'' is a path, as is the line that is the template for the pen stroke.
+The two paths are joined together to form a region which is filled.
+Thus in constructing the example given in the introduction, the following path is built.
+\begin{center}
+\begin{tikzpicture}
+\draw (0,-1) .. controls +(45:1) and +(-135:1) .. node (op) {} ++(3,0) -- node (pp) {} ++(45:.5) .. controls +(-135:1) and +(45:1) .. node (opr) {} ++(-3,0) -- node (ppr) {} (0,-1);
+\draw[<-] (op) -- ++(0,-.5) node[anchor=north] {original path};
+\draw[<-] (pp) -- ++(.5,0) node[anchor=west] {pen path};
+\draw[<-] (opr) -- ++(0,.5) node[anchor=south] {original path reversed};
+\draw[<-] (ppr) -- ++(-.5,0) node[anchor=east] {pen path reversed};
+\end{tikzpicture}
+\end{center}
+What is important to note about this is that the ``pen'' isn't \emph{actually} dragged along the path, it is merely a simulation.
+This can be shown with the following simple example.
+The first is a continuous path that goes past the angle of the pen and thus the upstroke would involve pushing the pen.
+The second is how it is meant to be done, the second line is drawn from top to bottom.
+However, as the direction of the path isn't important, the same effect can be obtained by ``lifting the nib'' between the lines.
+\begin{example}
+\begin{center}
+\begin{tikzpicture}
+\pen (-135:.125) -- (45:.125);
+\calligraphy (0,0) -- (1,0) -- (1,1);
+\calligraphy (2,0) -- (3,0) (3,1) -- (3,0);
+\calligraphy (4,0) -- (5,0) +(0,0) -- (5,1);
+\end{tikzpicture}
+\end{center}
+\end{example}
+It should work as expected providing the following golden rule is not violated:
+\begin{quotation}
+Never \emph{push} a calligraphic pen.
+\end{quotation}
+This is good advice for ordinary calligraphy as well, so a path that is realisable as an honest calligraphic path should be fine with this library.
+Actually since, as remarked above, the direction of the path isn't important, a more accurate golden rule would be that one should never swap from pushing to pulling or vice versa without lifting the pen off the paper; but that isn't as succinct.
+The paths for both pens and templates can be reasonably complicated.
+They can contain gaps, but should not contain closed paths, nor rectangles.
+The implementation works by breaking a path into its constituent pieces (broken up by ``move to''s) and working bit by bit.
+\begin{example}
+\begin{center}
+\begin{tikzpicture}
+\pen (-135:.25) -- (-135:.125) (45:.125) -- (45:.25);
+\calligraphy (0,0) .. controls +(45:1) and +(-135:1) .. +(3,0) ++(1.5,0) .. controls +(-135:2) and +(45:2) .. +(0,-4) (0,-4) .. controls +(45:1) and +(-135:1) .. +(3,0);
+\end{tikzpicture}
+\end{center}
+\end{example}
+\section{Copperplate}
+Copperplate pens are somewhat special.
+They are ``thin'' so don't need the same treatment as a ``thick'' pen, but one should be able to vary the pressure with a copperplate pen to get a variation of thickness.
+Specifying a copperplate pen is straightforward: it is a pen with no thickness.
+\begin{example}
+\begin{center}
+\begin{tikzpicture}[line width=2pt]
+\pen (0,0);
+\calligraphy[heavy] (0,0) .. controls +(45:1) and +(-135:1) .. +(3,0) ++(1.5,0) .. controls +(-135:2) and +(45:2) .. +(0,-3) (0,-3) .. controls +(45:1) and +(-135:1) .. +(3,0);
+\calligraphy[light] (4,0) .. controls +(45:1) and +(-135:1) .. +(3,0) ++(1.5,0) .. controls +(-135:2) and +(45:2) .. +(0,-3) (4,-3) .. controls +(45:1) and +(-135:1) .. +(3,0);
+\end{tikzpicture}
+\end{center}
+\end{example}
+With a copperplate pen, the segments of a path are tapered.
+Copperplate and normal pens can be mixed.
+Any part of the pen specification that has no length is treated as a copperplate pen.
+\begin{example}
+\begin{center}
+\begin{tikzpicture}[line width=1pt]
+\pen (-135:.125) -- (0,0) (45:.125);
+\calligraphy (0,0) .. controls +(45:1) and +(-135:1) .. +(3,0) ++(1.5,0) .. controls +(-135:2) and +(45:2) .. +(0,-3) (0,-3) .. controls +(45:1) and +(-135:1) .. +(3,0);
+\end{tikzpicture}
+\end{center}
+\end{example}
+%% \section{Annotations}
+%% As an addition, calligraphic paths can be annotated to show how they were constructed.
+%% A path with an arrow is drawn at a set offset from the last part of the path.
+%% \begin{example}
+%% \begin{center}
+%% \begin{tikzpicture}[line width=1pt]
+%% \pen (-135:.125) -- (0,0) (45:.125);
+%% \calligraphy[annotate] (0,0) .. controls +(45:1) and +(-135:1) .. +(3,0) ++(1.5,0) .. controls +(-135:2) and +(45:2) .. +(0,-3) (0,-3) .. controls +(45:1) and +(-135:1) .. +(3,0);
+%% \end{tikzpicture}
+%% \end{center}
+%% \end{example}
+\section{Style Options}
+There are plenty of options for styling the paths and pens.
+\subsection{Definition Options}
+Internally, making a pen is a two-step process.
+First a pen has to be \emph{defined} and then \emph{processed}.
+To define a pen, the user has to specify a path.
+That path is stored in a global macro and so can be accessed in throughout the document.
+However, before being used, the pen has to be processed.
+At this stage, the pen is converted from a macro in to a special object.
+These special objects are local and cannot (at present) be made global.
+Thus whilst a pen can be \emph{defined} inside a group, the \emph{processing} stage has to happen in the outermost group in which the pen is going to be used.
+There is a shortcut command that (via a bit of suspicious hackery) does all this within a \Verb+tikzpicture+ group.
+However, if a pen is to be used in several different pictures, it must be processed outside the group in which it is defined.
+The following macros and keys are used to set up and use a pen.
+%All the keys are in the \Verb+/pgf/calligraphy+ family.
+\begin{itemize}
+\item \DescribeMacro{define pen}If the \Verb+define pen+ key is specified on a path then that path will be used to define a pen.
+It can take one option which will be the pen name, if not specified then \Verb+default+ is assumed.
+The resulting path will not be counted for bounding box considerations.
+When the pen is used, the origin will correspond to the path along which it is dragged.
+\item \DescribeMacro{pen name}The key \Verb+pen name=name+ sets the name for the current pen.
+This can be used either when defining or using a pen.
+\item \DescribeMacro{\pen}\DescribeMacro{\definepen}The macros \Verb+\pen+ and \Verb+\definepen+ are analogous to the TikZ commands \Verb+\draw+ or \Verb+\fill+ in that they act like a path command but store the path as a pen.
+The difference between them is that \Verb+\definepen+ is to be used outside a TikZ picture (it contains its own \Verb+\tikz+ command) and \Verb+\pen+ inside.
+%% These macros also change the ``key family'' to \Verb+/pgf/calligraphy+ so that any further options do not need their full path.
+%% \item \DescribeMacro{\processpen}The macro \Verb+\processpen+ processes a pen so that it is set up for using later on.
+%% As remarked earlier, it has to be given at least at the outermost grouping of where it will be used.
+%% It takes an optional argument which is the pen name.
+%% This is only needed if the pen will be used in a group other than the one in which it is defined (or if the hackery that means this isn't needed with the \Verb+\pen+ command fails for some unknown reason).
+\item \DescribeMacro{use pen}The key \Verb+use pen=name+ on a path means that that path should be ``stroked'' with the pen (\Verb+default+ if no name is given, or none specified via the \Verb+pen name+ key).
+%% \item \DescribeMacro{\calligraphy}The macro \Verb+\calligraphy+ is a shortcut for specifying a path with the key \Verb+use pen+ already set.
+%% This macro also changes the ``key family'' to \Verb+/pgf/calligraphy+ so that any further options do not need their full path.
+\end{itemize}
+\subsection{Style Options}
+There are various options available for styling the calligraphic paths.
+%% All of these are in the \Verb+/pgf/calligraphy+ key family, but the \Verb+\calligraphy+ command automatically switches to that family so the key path is not needed.
+%% Any unknown keys are processed as follows:
+%% \begin{enumerate}
+%% \item A check is made to see if a pen of that name has been defined.
+%% If so, that pen is used.
+%% This is similar to the \Verb+\node[shape]+ syntax
+%% \item A check is made to see if the unknown key corresponds to a colour.
+%% If so, that colour is installed as the pen colour.
+%% This is similar to the colour handling of TikZ paths.
+%% (In fact, it uses the same code.)
+%% \item All other unknown options are passed on to TikZ.
+%% \end{enumerate}
+The style options are as follows.
+\begin{itemize}
+\item \DescribeMacro{pen colour}The \Verb+pen colour+ style defines the default colour to be used.
+Since calligraphic paths are sometimes filled and sometimes stroked, this ensures that the colour is used correctly.
+\item \DescribeMacro{nib style}It is possible to style particular ``nibs'' (i.e., segments of the pen path) separately.
+This is the \Verb+nib style+ option, which takes two arguments.
+The first is the index of the part of the nib and the second is the style options to be applied.
+\item \DescribeMacro{stroke style}It is also possible to style particular parts of the template path.
+One way to do this is to use the \Verb+stroke style+ key, which takes two arguments.
+The first is the index of the part of the stroke and the second is the style options to be applied.
+\item \DescribeMacro{this stroke style}It is also possible to style particular parts of the template path as the path is constructed.
+This is done by putting \Verb+[this stroke style={}]+ in the template path at the relevant part.
+The style is saved and applied to that segment of the template path.
+\item \DescribeMacro{taper}The tapering of copperplate paths can be controled by the \Verb+taper+ option.
+It takes arguments \Verb+none+, \Verb+both+, \Verb+start+, and \Verb+end+.
+\item \DescribeMacro{weight}\DescribeMacro{heavy}\DescribeMacro{light}Copperplate paths come in two ``weights'': \emph{heavy} and \emph{light}.
+The weight also affects the tapering: by default a light path is tapered to nothing whilst a heavy path is tapered to the width of a light path.
+Weights can be specified by either \Verb+weight=weight+ or just \Verb+heavy+ and \Verb+light+.
+It is possible to change the weight for different components of a path using the \Verb+stroke style+ key.
+With tapering, this means that one can easily vary from a light stroke to a heavy one.
+The relevant widths are controlled by the keys \DescribeMacro{heavy line width}\Verb+heavy line width+ and the \DescribeMacro{light line width}\Verb+light line width+.
+The \DescribeMacro{taper line width}\Verb+taper line width+, is set automatically by the weight but can be altered afterwards using the \Verb+taper line width+ key.
+%% \item \DescribeMacro{annotate}The key \Verb+annotate+ switches on annotations.
+%% The style of the annotations is controlled by the keys \DescribeMacro{annotation style}\Verb+annotation style+, \DescribeMacro{annotation shift}\Verb+annotation shift+ which controls how the annotation path is shifted from the final component of the calligraphic path, \DescribeMacro{annotation nodes style}\Verb+annotation nodes style+ for global style of the nodes, \DescribeMacro{annotation node style}\Verb+annotation node style+ for styling of particular nodes.
+%% This latter takes two options: the node number and the style to be applied.
+%% The annotation path and annotation node styles take ordinary TikZ styling options.
+\end{itemize}
+\begin{example}
+\begin{center}
+\begin{tikzpicture}
+\calligraphy[pen colour=green,nib style={2}{color=red}] (0,0) .. controls +(45:1) and +(-135:1) .. +(3,0) ++(1.5,0) .. controls +(-135:2) and +(45:2) .. +(0,-3) (0,-3) .. controls +(45:1) and +(-135:1) .. +(3,0);
+\calligraphy[line width=1pt] (0,-4) .. controls +(45:1) and +(-135:1) .. +(3,0) ++(1.5,0) .. controls +(-135:2) and +(45:2) .. +(0,-3) (0,-7) .. controls +(45:1) and +(-135:1) .. +(3,0);
+\end{tikzpicture}
+\end{center}
+\end{example}
+\section{Decorations}
+If a TikZ/PGF decorations library is loaded prior to this library, then the \Verb+calligraphy+ library defines some decorations that use the calligraphic paths, specifically with the copperplate nib.
+The current decorations are:
+\begin{itemize}
+\item \DescribeMacro{calligraphic brace}\Verb+calligraphic brace+ for a brace.
+\item \DescribeMacro{calligraphic straight parenthesis}\Verb+calligraphic straight parenthesis+ for a parenthesis with straight middle component.
+\item \DescribeMacro{calligraphic curved parenthesis}\Verb+calligraphic curved parenthesis+ for a parenthesis with a curved middle component.
+\end{itemize}
+All the above use the \Verb+amplitude+ option to specify their size.
+The following is an example of their use, together with the standard \Verb+brace+ and the \Verb+delimiter+ key from the \Verb+matrix+ library for comparison.
+\begin{example}
+\begin{center}
+\begin{tikzpicture}
+\draw[decorate,decoration={calligraphic brace,amplitude=4mm},ultra thick] (0,0) -- (0,8);
+\draw[line width=2pt,decorate,decoration={brace,amplitude=10},line cap=round] (1,0) -- ++(0,8);
+\node[anchor=south west,minimum height=8cm,outer sep=0pt,left delimiter=\{] (a) at (2,0) {};
+\draw[decorate,decoration={calligraphic straight parenthesis,amplitude=4mm},ultra thick] (3,0) -- ++(0,8);
+\draw[decorate,decoration={calligraphic curved parenthesis,amplitude=4mm},ultra thick] (4,0) -- ++(0,8);
+\node[anchor=south west,minimum height=8cm,outer sep=0pt,left delimiter=(] (a) at (5,0) {};
+\end{tikzpicture}
+\end{center}
+\end{example}
+\section{Pre-Defined Pens}
+The following pens are predefined:
+\begin{itemize}
+\item \DescribeMacro{copperplate}\Verb+copperplate+:
+\begin{example}
+\begin{center}
+\tikz \calligraphy[copperplate] (0,0) .. controls +(1,-1) and +(-1,1) .. ++(3,0) [this stroke style={light,taper=start}] +(0,0) .. controls +(1,-1) and +(-1,1) .. ++(3,0) [this stroke style={heavy}] +(0,0) .. controls +(1,-1) and +(-1,1) .. ++(3,0) [this stroke style={light,taper=end}];
+\end{center}
+\end{example}
+\end{itemize}
+
+\end{document} \ No newline at end of file
diff --git a/Master/texmf-dist/doc/latex/spath3/knots_doc.pdf b/Master/texmf-dist/doc/latex/spath3/knots_doc.pdf
new file mode 100644
index 00000000000..3427e22b951
--- /dev/null
+++ b/Master/texmf-dist/doc/latex/spath3/knots_doc.pdf
Binary files differ
diff --git a/Master/texmf-dist/doc/latex/spath3/knots_doc.tex b/Master/texmf-dist/doc/latex/spath3/knots_doc.tex
new file mode 100644
index 00000000000..67c23ca1287
--- /dev/null
+++ b/Master/texmf-dist/doc/latex/spath3/knots_doc.tex
@@ -0,0 +1,484 @@
+\immediate\write18{tex spath3.dtx}
+\documentclass{ltxdoc}
+\usepackage[T1]{fontenc}
+\usepackage{trace}
+\usepackage{lmodern}
+\usepackage{morefloats}
+\usepackage{tikz}
+\usetikzlibrary{knots}
+\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}
+ \centering
+ \input{example.out}
+ \end{minipage}}
+\end{center}
+}
+
+\providecommand*{\url}{\texttt}
+\GetFileInfo{spath3.sty}
+
+\title{The \textsf{knots} Package: Documentation}
+\author{Andrew Stacey \\ \url{stacey@math.ntnu.no}}
+\date{\fileversion~from \filedate}
+
+\begin{document}
+
+\maketitle
+
+\section{Introduction}
+
+The \Verb+knots+ package is a TikZ library for drawing knot (and similar) diagrams.
+It provides a few useful styles and node shapes but its main contribution is the \Verb+knot+ environment.
+The \Verb+knot+ environment allows you to draw some strands of a knot (or braid or tangle or whatever -- we shall use the imprecise term ``knot'' to refer to any similar diagram) and then to modify the crossings via a simple interface.
+
+The main part of this package was developed in response to a question on the \href{http://tex.stackexchange.com}{TeX-SX} site by Jamie Vicary.
+The original question was \href{http://tex.stackexchange.com/q/32125/86}{Braid diagrams in TikZ}.
+Jamie's comment (quoted below) was the inspiration for the mechanism of the \Verb+knot+ environment.
+
+\begin{quotation}
+[It] would be really cool if it was possible to draw the curves, let TikZ calculate all the intersection points automatically, and then tell it to redraw the intersections according to an under/over specification... do you think this is in the realm of plausibility?
+\end{quotation}
+
+\section{Examples}
+
+Let us begin with an example.
+To use the library, simply load the \Verb+tikz+ package and add \Verb+knots+ to the list of TikZ libraries that you load.
+For example, the following in your preamble would work:
+
+\begin{verbatim}
+\usepackage{tikz}
+\usetikzlibrary{knots}
+\end{verbatim}
+
+Let's draw a simple tangle (actually a braid).
+
+\begin{example}
+\begin{tikzpicture}
+\draw[red,ultra thick] (0,0) .. controls +(1,0) and +(-1,0) .. (2,1) .. controls +(1,0) and +(-1,0) .. (4,0);
+\draw[blue,ultra thick] (0,1) .. controls +(1,0) and +(-1,0) .. (2,0) .. controls +(1,0) and +(-1,0) .. (4,1);
+\end{tikzpicture}
+\end{example}
+
+Now a common way to draw crossings for knots is to draw a gap in the under strand through which the over strand passes.
+One way to achieve this in TikZ is to draw the over strand twice, the first time with a thicker line width and the colour of the background.
+We'll draw it twice, once with background a different colour to illustrate this.
+
+\begin{example}
+\begin{tikzpicture}
+\draw[red,ultra thick] (0,0) .. controls +(1,0) and +(-1,0) .. (2,1) .. controls +(1,0) and +(-1,0) .. (4,0);
+\draw[pink,double=blue,ultra thick,double distance=1.6pt] (0,1) .. controls +(1,0) and +(-1,0) .. (2,0) .. controls +(1,0) and +(-1,0) .. (4,1);
+\draw[xshift=5cm,red,ultra thick] (0,0) .. controls +(1,0) and +(-1,0) .. (2,1) .. controls +(1,0) and +(-1,0) .. (4,0);
+\draw[xshift=5cm,white,double=blue,ultra thick,double distance=1.6pt] (0,1) .. controls +(1,0) and +(-1,0) .. (2,0) .. controls +(1,0) and +(-1,0) .. (4,1);
+\end{tikzpicture}
+\end{example}
+
+Now the problem with this method is that there is no way to draw the red and blue paths so that the blue is the over strand at the first crossing and the red at the second.
+Either the blue path is always on top (as shown) or the red.
+One way to resolve this is to split the paths and draw one of them in segments:
+
+\begin{example}
+\begin{tikzpicture}
+\draw[red,ultra thick] (0,0) .. controls +(1,0) and +(-1,0) .. (2,1);
+\draw[white,double=blue,ultra thick,double distance=1.6pt] (0,1) .. controls +(1,0) and +(-1,0) .. (2,0) .. controls +(1,0) and +(-1,0) .. (4,1);
+\draw[white,double=red,double distance=1.6pt,ultra thick] (2,1) .. controls +(1,0) and +(-1,0) .. (4,0);
+\end{tikzpicture}
+\end{example}
+
+Another method (employed by the \Verb+braids+ package) is to break the under path either side of the crossing and not draw it there.
+This means that the order of drawing doesn't matter.
+
+Both of these methods have their drawbacks (particularly for general knots as opposed to the more structured braids) in that they require a detailed knowledge of the pieces of the paths and the positions of the crossings.
+As pointed out by Jamie Vicary in the above-{}quoted comment, TikZ should be able to compute these itself.
+
+That's what this package does.
+
+Let's do the above example using this package.
+The main changes to the drawing are that we use the command \Verb+\strand+ rather than \Verb+\draw+ and we enclose it in the \Verb+knot+ environment.
+When initially drawing the strands it is useful to provide the option \Verb+draft mode=strands+.
+That's because the detailed computation can take a little time and so it is best only to do it when necessary.
+So on first run through we get the following.
+
+\begin{example}
+\begin{tikzpicture}
+\begin{knot}[
+ draft mode=strands
+]
+\strand[red,thick] (0,0) .. controls +(1,0) and +(-1,0) .. (2,1) .. controls +(1,0) and +(-1,0) .. (4,0);
+\strand[blue,thick] (0,1) .. controls +(1,0) and +(-1,0) .. (2,0) .. controls +(1,0) and +(-1,0) .. (4,1);
+\end{knot}
+\end{tikzpicture}
+\end{example}
+
+Once we're happy with the positioning of the strands, we change the option \Verb+draft mode=strands+ to \Verb+draft mode=crossings+.
+
+\begin{example}
+\begin{tikzpicture}
+\path (2,1.5) (2,-.5);
+\begin{knot}[
+ draft mode=crossings,
+ clip width=5,
+]
+\strand[red,ultra thick] (0,0) .. controls +(1,0) and +(-1,0) .. (2,1) .. controls +(1,0) and +(-1,0) .. (4,0);
+\strand[blue,ultra thick] (0,1) .. controls +(1,0) and +(-1,0) .. (2,0) .. controls +(1,0) and +(-1,0) .. (4,1);
+\end{knot}
+\end{tikzpicture}
+\end{example}
+
+The \Verb+\path (2,1.5) (2,-.5);+ is to extend the bounding box of the picture a little upwards.
+The extra pieces are not used when computing the bounding box of the picture so that it doesn't change position on the page.
+
+The extra information is that the strands and the crossings have been numbered.
+The crossings have also been rendered (the \Verb+clip width+ option enlarges the crossing gap to make it more obvious).
+Unfortunately, for both crossings the red path is on top.
+We need to flip one of these crossings (the first).
+To do this, we either use the command \Verb+flipcrossings+ or the \Verb+flip crossing+ key.
+
+\begin{example}
+\begin{tikzpicture}
+\path (2,1.5) (2,-.5);
+\begin{knot}[
+ draft mode=crossings,
+ clip width=5,
+ flip crossing=1,
+]
+\strand[red,ultra thick] (0,0) .. controls +(1,0) and +(-1,0) .. (2,1) .. controls +(1,0) and +(-1,0) .. (4,0);
+\strand[blue,ultra thick] (0,1) .. controls +(1,0) and +(-1,0) .. (2,0) .. controls +(1,0) and +(-1,0) .. (4,1);
+\end{knot}
+\end{tikzpicture}
+\end{example}
+
+Once we're happy with it, we remove the \Verb+draft mode+ option to render it in its final form.
+
+\begin{example}
+\begin{tikzpicture}
+\begin{knot}[
+ clip width=5,
+ flip crossing=1,
+]
+\strand[red,ultra thick] (0,0) .. controls +(1,0) and +(-1,0) .. (2,1) .. controls +(1,0) and +(-1,0) .. (4,0);
+\strand[blue,ultra thick] (0,1) .. controls +(1,0) and +(-1,0) .. (2,0) .. controls +(1,0) and +(-1,0) .. (4,1);
+\end{knot}
+\end{tikzpicture}
+\end{example}
+
+Here's a more complicated example.
+
+\begin{example}
+\begin{tikzpicture}
+\node (A) at (0,4) [draw,minimum width=30pt,minimum height=10pt,thick] {};
+\begin{knot}[
+ clip width=5,
+ clip radius=8pt,
+]
+\strand [thick,only when rendering/.style={dashed}] (0,0)
+to [out=up, in=down] (-1,1)
+to [out=up, in=down] (0,2)
+to [out=up, in=down] (-1.2,4)
+to [out=up, in=down, looseness=0.7] (0,5.5)
+to [out=up, in=down] (-2,7);
+\strand [thick] (-1,0)
+to [out=up, in=down] (1,2)
+to [out=up, in=down] (A.south);
+\strand [thick,blue] (1,0)
+to [out=up, in=down] (-1,2)
+to [out=up, in=down] (1.5,4)
+to [out=up, in=right] (0,5.5)to [out=left, in=up] (-2,4)
+to [out=down, in=up] (-2,0);
+\strand [thick] (A.150)
+to [out=up, in=down] (0.7,5.5)
+to [out=up, in=down] (0,7);
+\strand [thick] (A.30)
+to [out=up, in=down] (-1,6)
+to [out=up, in=down] (2,7);
+\flipcrossings{6,2,9,5,11}
+\end{knot}
+\end{tikzpicture}
+\end{example}
+
+One feature about this example is the \Verb+only when rendering+ key.
+The gaps are made by drawing the strand again with extra thickness in the background colour.
+If the \Verb+dashed+ option were always in play for that strand, the gap would be dashed which would spoil the effect.
+So the \Verb+only when rendering+ key gathers those options (such as a dash pattern) which should only be applied to the rendered strand and not to the redraw that creates the gap.
+
+Here's another example.
+
+\begin{example}
+\newcommand{\motif}[1]{
+ to ++(180+#1:0.50) arc (270+#1:150+#1:0.15)
+ to ++( 60+#1:0.50) arc (-30+#1:150+#1:0.15)
+ to ++(240+#1:0.25) arc (150+#1:330+#1:0.25)
+ to ++( 60+#1:0.55) arc (150+#1: 30+#1:0.20)
+}
+\newcommand{\celticknot}{\motif{0}\motif{120}\motif{240}}
+\begin{tikzpicture}
+\begin{knot}[
+ line width=2pt,
+ line join=round,
+ clip width=2,
+ scale=5,
+ consider self intersections,
+ ignore endpoint intersections=false,
+ background color=white,
+ only when rendering/.style={
+ draw=red,
+ double=white,
+ double distance=6pt,
+ line cap=round,
+ }
+]
+\strand (0,0) \celticknot;
+\flipcrossings{1,3,6,8,10}
+\end{knot}
+\end{tikzpicture}
+\end{example}
+
+In this case the strand is a single path.
+In the standard case crossings are only considered between separate strands (since the algorithm used by TikZ means that a strand intersects itself infinitely often).
+The key \Verb+consider self intersections+ gets round this by ``exploding'' the strand into segments and considering each as a separate path with regard to finding the intersections.
+
+A path consists of a series of lines and B\'ezier cubics.
+The ``explosion'' of a path uses this decomposition.
+Unfortunately, even that is not always enough as it is possible for a B\'ezier cubic to self-intersect.
+The \Verb+consider self intersections+ also splits these B\'ezier curves in two to ensure that this doesn't happen\footnote{Computing when this is strictly necessary is difficult so it splits more than it needs to to ensure that enough are done.}.
+To disable this, use the \Verb+consider self intersections=no splits+ option.
+This is the recommended option.
+
+\begin{example}
+\begin{tikzpicture}
+\begin{knot}[
+ consider self intersections,
+ draft mode=crossings,
+]
+\strand (0,0) .. controls +(3,1) and +(-3,1) .. (1,0);
+\end{knot}
+\begin{knot}[
+ xshift=3cm,
+ consider self intersections=no splits,
+ draft mode=crossings,
+]
+\strand (0,0) .. controls +(3,1) and +(-3,1) .. (1,0);
+\end{knot}
+\end{tikzpicture}
+\end{example}
+
+Finally, given that TikZ has to do some heavy computation to find the intersections, it is worth considering using the \Verb+external+ library of TikZ to avoid having to do this on every run.
+
+\section{Usage}
+
+\subsection{The \texttt{knot} Environment}
+
+\DescribeMacro{knot}
+\DescribeMacro{\strand}
+This package provides a \Verb+knot+ environment for including in a \Verb+tikzpicture+ to render a knot.
+This takes an optional argument which is passed to \Verb+\tikzset+ and can be used to configure the knot.
+Within that environment, specific strands are defined using the \Verb+\strand+ command (in place of a \Verb+\path+ or \Verb+\draw+).
+Further keys can be specified on the strands.
+
+\DescribeMacro{flip crossing}
+\DescribeMacro{\flipcrossings}
+Specifying the crossings to be flipped can be done either using the key \Verb+flip crossing+ or the macro \Verb+\flipcrossings+.
+The latter can take a comma separated list of crossings to flip.
+The former takes a single crossing but can be extended to a comma separated list using the \Verb+.list+ handler as in \Verb+flip crossing/.list={1,2,3}+ (this is what \Verb+\flipcrossings+ does internally).
+
+\DescribeMacro{\redraw}
+There is also a macro \Verb+\redraw+ which redraws a strand in the neighbourhood of a point.
+This is effectively what happens for the crossings and can be used to fix something that wasn't done correctly by the main algorithm.
+It takes two arguments, the strand number and the point at which to render the strand, as in \Verb+\redraw{2}{(1,1)}+.
+
+\subsection{Keys}
+
+The various keys are as follows.
+The majority of the keys are in the \Verb+/tikz/knot diagram+ family, but it does its best to pass unknown keys down to \Verb+/tikz/+.
+The keys processed by the \Verb+knot+ environment are automatically in this family but the keys processed by the \Verb+\strand+ command are not.
+If a standard key (in the option to the \Verb+knot+ environment) doesn't work, try prefixing it with \Verb+/tikz/+ or \Verb+/pgf/+.
+
+\begin{itemize}
+\item \DescribeMacro{every knot diagram}
+The style \Verb+every knot diagram+ is executed at the start of the \Verb+knot+ environment.
+
+Note that it is inside the \Verb+knot diagram+ family so if setting it outside (say, in the preamble) use \Verb+\tikzset{knot diagram/every knot diagram}+.
+
+\item \DescribeMacro{name}
+The crossings of a knot are given coordinates of the form \Verb+<name> <number>+.
+The default name is \Verb+knot+.
+The \Verb+name+ key renames it.
+
+\item \DescribeMacro{every strand}
+The contents of \Verb+every strand+ are applied to every strand.
+By default this contains the \Verb+draw+ key so if resetting it you should probably ensure that it still has the \Verb+draw+ key.
+
+Note that it is inside the \Verb+knot diagram+ family so if setting it outside (say, in the preamble) use \Verb+\tikzset{knot diagram/every knot diagram}+.
+
+\item \DescribeMacro{only when rendering}
+The key \Verb+only when rendering={<style>}+ is applied to the strand only when it is actually drawn and not when it is used to cut out part of the underlying path.
+
+Note that there are actually two versions of this key: one in the \Verb+knot diagram+ family and one in the \Verb+/tikz+ family.
+This is so that it works equally well in the argument to the \Verb+knot+ environment and the \Verb+\strand+ command.
+
+\item \DescribeMacro{ignore endpoint intersections}
+When a strand is split into pieces then the intersection library finds ``false positives'' in that neighbouring pieces intersect at their endpoints.
+The code ignores such intersections between neighbouring pieces.
+The \Verb+ignore endpoint intersections+ (which is true by default) means that all intersections that are near an endpoint are ignored whether or not they are with the next or previous piece of that strand.
+The celtic knot example of the previous section sets this to false to ensure that it gets all intersections.
+
+\item \DescribeMacro{consider self intersections}
+The key \Verb+consider self intersections=<option>+ handles the splitting facility so that strands can self intersect.
+The options are \Verb+true+, \Verb+false+, and \Verb+no splits+.
+It is \Verb+false+ at the start, and the default option is \Verb+true+.
+The difference between \Verb+true+ and \Verb+no splits+ is as to whether segments are further split to avoid \emph{all} self intersections.
+
+\item \DescribeMacro{clip radius}
+The \Verb+clip radius=<length>+ is the radius of the clip region around each crossing.
+
+\item \DescribeMacro{end tolerance}
+The \Verb+end tolerance=<length>+ is the distance at which an intersection is considered as being near an endpoint (for simplicity, it uses the \(\ell^1\)--metric).
+
+\item \DescribeMacro{clip width}
+The \Verb+clip width=<factor>+ is the multiplier for the thickness of the ``wipeout'' path relative to the line width of the actual path.
+
+\item \DescribeMacro{flip crossing}
+The \Verb+flip crossing=<number>+ key flips the \Verb+<number>+ crossing.
+
+\item \DescribeMacro{background colour} \DescribeMacro{background color}
+The keys \Verb+background colour=<colour>+ and \Verb+background color=<color>+ set the background colour for the crossings.
+
+\item \DescribeMacro{intersection <number>}
+The style in \Verb+intersection <number>+ is applied just before that crossing is drawn so can be used to modify the crossing style just for that crossing.
+
+
+\item \DescribeMacro{draft mode}
+The key \Verb+draft mode=<option>+ sets the different styles for aiding with rendering the knot.
+The options are \Verb+strands+, \Verb+crossings+, or \Verb+off+.
+The \Verb+strands+ option just renders the strands with no crossings.
+The \Verb+crossings+ option renders the crossings and labels the strands and crossings.
+The \Verb+off+ option renders the crossings without the labels.
+
+\item \DescribeMacro{draft/crossing label}
+The style \Verb+draft/crossing label+ is applied to each of the crossing labels.
+The labels are actually \Verb+pin+s attached to coordinates at the crossings.
+This style is applied to the \Verb+pin+ itself.
+The default is:
+
+\begin{lstlisting}
+overlay,
+fill=white,
+fill opacity=.5,
+text opacity=1,
+text=blue,
+pin edge={blue,<-}
+\end{lstlisting}
+
+\item \DescribeMacro{draft/strand label}
+The style \Verb+draft/strand label+ is applied to each of the strand labels.
+The default is:
+
+\begin{lstlisting}
+overlay,
+circle,
+draw=purple,
+fill=white,
+fill opacity=.5,
+text opacity=1,
+text=purple,
+inner sep=0pt
+\end{lstlisting}
+\end{itemize}
+
+\subsection{Other Styles}
+
+The other things defined by this package are for drawing knot diagrams when the user knows in advance either the locations of the crossings or can arrange that the paths are drawn in the correct order.
+In these circumstances the \Verb+knot+ environment is overkill.
+
+\DescribeMacro{knot}
+\DescribeMacro{knot gap}
+This \Verb+knot=<colour>+ style sets up a doubled path with inner colour the given colour (or the current draw colour if not given) and outer colour the knot background colour.
+The width of the inner line is the current line width and the full width is controlled by the \Verb+knot gap=<factor>+ key which is initially set to \(3\) (thus giving a line's width either side).
+
+\begin{example}
+\begin{tikzpicture}[knot gap=7]
+\draw[thin,knot=red] (-1,-1) -- (1,1);
+\draw[thin,knot=red] (-1,1) -- (1,-1);
+\begin{scope}[xshift=2.5cm]
+\draw[knot=red] (-1,-1) -- (1,1);
+\draw[knot=red] (-1,1) -- (1,-1);
+\end{scope}
+\begin{scope}[xshift=5cm]
+\draw[thick,knot=red] (-1,-1) -- (1,1);
+\draw[thick,knot=red] (-1,1) -- (1,-1);
+\end{scope}
+\end{tikzpicture}
+\end{example}
+
+\DescribeMacro{knot crossing}
+\DescribeMacro{knot over cross}
+\DescribeMacro{knot under cross}
+\DescribeMacro{knot horiz}
+\DescribeMacro{knot vert}
+This package also defines some node shapes to help draw knot and link diagrams.
+The idea with these is to place a node of the appropriate type at each crossing and then link them accordingly.
+The node shapes are \Verb+knot crossing+, \Verb+knot over cross+, \Verb+knot under cross+, \Verb+knot vert+, \Verb+knot horiz+.
+The two styles \Verb+knot over cross+ and \Verb+knot under cross+ are crossings, \Verb+knot vert+ and \Verb+knot horiz+ are for when resolving the crossings in a diagram.
+By judicious use of the \Verb+\foreach+ command, a family of resolved link diagrams can be produced.
+
+\begin{example}
+\begin{tikzpicture}[every node/.style={draw,red}]
+\node[knot over cross] at (1,0) {};
+\node[knot under cross] at (2,0) {};
+\node[knot vert] at (3,0) {};
+\node[knot horiz] at (4,0) {};
+\end{tikzpicture}
+\end{example}
+
+The node \Verb+knot crossing+ is not meant to be drawn, it is an empty shape.
+Its value is in that it defines more anchors than the usual rectangle shape.
+For each of the 8 main compass directions, it defines anchors at 2, 4, 8, 16, and 32 times further out.
+This can be useful for designing curves that enter and exit the crossing gracefully at particular directions.
+When using this node shape, the crossing itself is easiest to draw by using the \Verb+center+ anchor for the strands that form the over cross.
+
+\begin{example}
+\begin{tikzpicture}[every path/.style={red,thick}, every node/.style={transform shape, knot crossing, inner sep=1.5pt}]
+\node[rotate=45] (tl) at (-1,1) {};
+\node[rotate=-45] (tr) at (1,1) {};
+\node (m) at (0,-1) {};
+\node (b) at (0,-2) {};
+\draw (b) .. controls (b.4 north west) and (m.4 south west) .. (m.center);
+\draw (b.center) .. controls (b.4 north east) and (m.4 south east) .. (m);
+\draw (m) .. controls (m.8 north west) and (tl.3 south west) .. (tl.center);
+\draw (m.center) .. controls (m.8 north east) and (tr.3 south east) .. (tr);
+\draw (tl.center) .. controls (tl.16 north east) and (tr.16 north west) .. (tr);
+\draw (b) .. controls (b.16 south east) and (tr.16 north east) .. (tr.center);
+\draw (b.center) .. controls (b.16 south west) and (tl.16 north west) .. (tl);
+\draw (tl) -- (tr.center);
+\end{tikzpicture}
+\end{example}
+
+\section{Other Relevant Packages by the Same Author}
+
+Another tool for drawing knot diagrams is provided by the \Verb+hobby+ package which draws smooth curves through a prescribed set of points.
+This can be combined with the facilities of this package but also has some features of its own that make it suitable for drawing knot diagrams.
+
+For braids themselves, there is the \Verb+braids+ package which allows input specification in the form of a word in the braid group.
+
+\end{document}
+% Local Variables:
+% tex-output-type: "pdf18"
+% End: