diff options
author | Karl Berry <karl@freefriends.org> | 2011-10-02 23:03:46 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2011-10-02 23:03:46 +0000 |
commit | af940299969ece442832d1700f8359006f70dff7 (patch) | |
tree | a94f207db432534918f3d4ddecfd51f9f45a617d /Master/texmf-dist | |
parent | f2e64dc85c57c00dc715e42fef686c3bec7e7188 (diff) |
new tikz package tqft (1oct11)
git-svn-id: svn://tug.org/texlive/trunk@24169 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist')
-rw-r--r-- | Master/texmf-dist/doc/latex/tqft/README.txt | 9 | ||||
-rw-r--r-- | Master/texmf-dist/doc/latex/tqft/tqft_doc.pdf | bin | 0 -> 317362 bytes | |||
-rw-r--r-- | Master/texmf-dist/doc/latex/tqft/tqft_doc.tex | 406 | ||||
-rw-r--r-- | Master/texmf-dist/source/latex/tqft/tqft.dtx | 1212 | ||||
-rw-r--r-- | Master/texmf-dist/source/latex/tqft/tqft.ins | 72 | ||||
-rw-r--r-- | Master/texmf-dist/tex/latex/tqft/tqft.sty | 753 |
6 files changed, 2452 insertions, 0 deletions
diff --git a/Master/texmf-dist/doc/latex/tqft/README.txt b/Master/texmf-dist/doc/latex/tqft/README.txt new file mode 100644 index 00000000000..c18773e7300 --- /dev/null +++ b/Master/texmf-dist/doc/latex/tqft/README.txt @@ -0,0 +1,9 @@ +---------------------------------------------------------------- +tqft --- a style file for drawing TQFT diagrams with TikZ/PGF +E-mail: stacey@math.ntnu.no +Released under the LaTeX Project Public License v1.3c or later +See http://www.latex-project.org/lppl.txt +---------------------------------------------------------------- + +This package defines some node shapes useful for drawing TQFT diagrams with TikZ/PGF. + diff --git a/Master/texmf-dist/doc/latex/tqft/tqft_doc.pdf b/Master/texmf-dist/doc/latex/tqft/tqft_doc.pdf Binary files differnew file mode 100644 index 00000000000..cdb00af732c --- /dev/null +++ b/Master/texmf-dist/doc/latex/tqft/tqft_doc.pdf diff --git a/Master/texmf-dist/doc/latex/tqft/tqft_doc.tex b/Master/texmf-dist/doc/latex/tqft/tqft_doc.tex new file mode 100644 index 00000000000..35ab6e36180 --- /dev/null +++ b/Master/texmf-dist/doc/latex/tqft/tqft_doc.tex @@ -0,0 +1,406 @@ +\documentclass{ltxdoc} +\usepackage[T1]{fontenc} +\usepackage{lmodern} +\usepackage{morefloats} +\usepackage[svgnames]{xcolor} +\usepackage{tikz} +\usepackage{tqft} +\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{tqft.sty} + +\title{The \textsf{tqft} Package: Documentation} +\author{Andrew Stacey \\ \url{stacey@math.ntnu.no}} +\date{\fileversion~from \filedate} + +\begin{document} + +\maketitle + +\begin{center} +\begin{tikzpicture}[scale=.5,every tqft/.style={fill=DarkMagenta,draw,ultra thick},every node/.style={tqft cobordism,transform shape}] + \node[ + tqft, + incoming boundary components=0, + outgoing boundary components=3, + ] (a) {}; + \node[ + tqft cylinder, + anchor=incoming boundary 1, + ] at (a.outgoing boundary 2) (b) {}; + \node[ + tqft, + incoming boundary components=0, + outgoing boundary components=2, + anchor=outgoing boundary 1, + ] at (a outgoing 3.next) (c) {}; + \node[ + tqft, + incoming boundary components=3, + outgoing boundary components=1, + offset=2.5, + anchor=incoming boundary 1, + boundary separation=1cm, + cobordism height=2.5cm, + ] at (c.outgoing boundary 1) (d) {}; + \node[ + tqft, + flow=east, + incoming boundary components=0, + outgoing boundary components=3, + ] at (c outgoing 2.next) (e) {}; + \node[ + tqft cylinder, + flow=east, + anchor=incoming boundary 1, + ] at (e.outgoing boundary 1) (f) {}; + \node[ + tqft cylinder, + flow=east, + anchor=incoming boundary 1, + ] at (e.outgoing boundary 2) (g) {}; + \node[ + tqft, + incoming boundary components=0, + outgoing boundary components=3, + anchor=outgoing boundary 1, + ] at (g outgoing 1.below) (h) {}; + \node[ + tqft cylinder, + anchor=incoming boundary 1, + ] at (h.outgoing boundary 2) (i) {}; +\end{tikzpicture} +\end{center} + +\section{Introduction} +This package defines some TikZ/PGF node shapes that can be used to construct the diagrams common in Topological Quantum Field Theory (TQFT). +An example follows: + +\begin{example} +\begin{tikzpicture} +\node[draw,tqft/pair of pants] (a) {}; +\node[draw,tqft/cylinder to next,anchor=incoming boundary 1] (c) at (a.outgoing boundary 1) {}; +\node[draw,tqft/reverse pair of pants, anchor=incoming boundary 1] at (a.outgoing boundary 2) (b) {}; +\end{tikzpicture} +\end{example} + +Before giving any details, a word is in order about the keys involved in this package. +There are many options and keys that can be set via the \Verb+\pgfkeys+ system (which is used for setting options in Ti\emph{k}Z). +Such keys live in a ``directory'' but often that can be omitted. +For example, in the Ti\emph{k}Z command \Verb+\draw[red] (0,0) -- (1,0);+ the key \Verb+red+ is actually in the ``directory'' \Verb+/tikz+ but it is not necessary to specify that as it is assumed. +Defining a ``directory'' helps separate keys and ensure that there is no conflict. +The keys in this package are (mostly) defined in the directory \Verb+/pgf/tqft+ but the very first call to a \Verb+tqft+ key will (in general) set the ``current directory'' to \Verb+/pgf/tqft+ and so all subsequent keys do not need prefixing. +Moreover, any unknown keys are passed on to the \Verb+/tikz+ directory so there is (or should be!) no harm in mixing \Verb+tqft+ specific keys with ordinary Ti\emph{k}Z keys. +Some examples take advantage of this switch so when copying and modifying examples from this document, it is important to remember that the first \Verb+tqft+ specific key needs an explicit \Verb+tqft/+ prefix. +More detailed information is in the section on styling. + +\section{The Shapes} + +There are only two shapes, \Verb+tqft cobordism+ and \Verb+tqft boundary circle+. +The first, which is the main shape, is a cobordism between a number of incoming circles and a number of outgoing circles, where the numbers of boundary components can be specified as options to the shape. +The second is just the boundary circle. +It is used as a sub-node of the first to add extra anchors, but can be used by itself. +There are certain common shapes that are predefined as aliases to the main shape with specified boundaries. +The list of predefined shapes follows. +The names are all in the \Verb+tqft+ family, but an alias is made so that \Verb+tqft nodeshape+ will work without any further qualification. + +\begin{enumerate} +\item \Verb+pair of pants+ + +\begin{tikzpicture} +\node[draw,tqft/pair of pants] (a) {}; +\end{tikzpicture} + +\item \Verb+reverse pair of pants+ + +\begin{tikzpicture} +\node[draw,tqft/reverse pair of pants] (a) {}; +\end{tikzpicture} + +\item \Verb+cylinder to prior+ + +This is a cylinder that has been skewed to one side, thus following the same path as the \Verb+pair of pants+ cobordism but with only one outgoing boundary component. +The name \Verb+to prior+ is because it goes towards the lower-numbered component on the \Verb+pair of pants+. + +\begin{tikzpicture} +\node[draw,tqft/cylinder to prior] (a) {}; +\end{tikzpicture} + +\item \Verb+cylinder to next+ + +This is a cylinder that has been skewed to one side, thus following the same path as the \Verb+pair of pants+ cobordism but with only one outgoing boundary component. +The name \Verb+to next+ is because it goes towards the higher-numbered component on the \Verb+pair of pants+. + +\begin{tikzpicture} +\node[draw,tqft/cylinder to next] (a) {}; +\end{tikzpicture} + +\item \Verb+cylinder+ + +This is a straight cylinder. + +\begin{tikzpicture} +\node[draw,tqft/cylinder] (a) {}; +\end{tikzpicture} + +\item \Verb+cap+ + +This is a cap. + +\begin{tikzpicture} +\node[draw,tqft/cap] (a) {}; +\end{tikzpicture} + +\item \Verb+cup+ + +This is a cup (an upside-down cap). + +\begin{tikzpicture} +\node[draw,tqft/cup] (a) {}; +\end{tikzpicture} + +\end{enumerate} + +The general shape is controlled by the following keys: + +\begin{itemize} +\item \DescribeMacro{flow} A cobordism ``flows'' from its incoming to its outgoing boundaries. +This key controls the direction of that flow. +The shape is transformed so that the incoming-outgoing axis aligns with the argument. +However, the transformation may be more than just a rotation as the shape is set up so that the numbering of the boundary components is always left-to-right or top-to-bottom (as appropriate). +Currently, this key can take the values \Verb+north+, \Verb+south+ (default), \Verb+east+, and \Verb+west+. + +\item \DescribeMacro{view from} To get a simulated 3D effect, the cobordism is drawn as if viewed from a slight angle. +The value of this key determines whether the cobordism is viewed from the direction of the incoming boundary components or the outgoing ones. +This key can take the values \Verb+incoming+ and \Verb+outgoing+. +The default is \Verb+outgoing+. +\item \DescribeMacro{cobordism height} This is the height of the cobordism (``height'' interpreted in its own internal coordinate system). +With no offset (q.v.), this would be the distance between the centres of the first incoming and first outgoing boundary components. + +\item \DescribeMacro{boundary separation} This is the distance between the centres of the boundary components of the same type. + +\item \DescribeMacro{circle width} This is the half-width of the boundary circles. + +\item \DescribeMacro{circle depth} This is the half-depth of the boundary circles (``depth'' since, in the internal coordinate system, this corresponds to the \(z\)-axis out of the page). + +\item \DescribeMacro{incoming boundary components} The number of incoming boundary components (can be zero). + +\item \DescribeMacro{outgoing boundary components} The number of outgoing boundary components (can be zero). + +\item \DescribeMacro{offset} This offsets the first outgoing boundary component horizontally relative to the first incoming boundary component. +It is a dimensionless number (not necessarily an integer) and is interpreted so that a value of \(1\) aligns the first outgoing boundary component with the second incoming boundary component. +\end{itemize} + +\section{Styling} + +There are various options for styling the diagrams. +To understand how they work, it is important to know the order in which a cobordism is drawn and how many pieces it decomposes into. +This is the following list, with the corresponding key: + +\begin{enumerate} +\item The boundary circles are drawn. +\Verb+boundary style+ +\item The lower edges of the boundary circles are redrawn. +\Verb+boundary lower style+ +\item The cobordism itself is drawn. +\item The non-boundary edge of the cobordism is redrawn. +\Verb+cobordism style+ +\item The upper edges of the boundary circles are redrawn. +\Verb+boundary upper style+ +\end{enumerate} + +The fact that there are so many is to allow different style to be applied to different pieces. +The duplication is to allow certain composite pieces to be \emph{filled}. +All of these items can be styled separately. +The style given to the node itself is passed on to the third item in that list, the cobordism itself. +The styles of the others are controlled by a series of keys, each of should be a list of styles to be applied to that component. +Not all options make sense, in particular only the first and third can be filled. +(That is, the \Verb+fill+ style is ignored on the other components.) +Here is a progressively built up cobordism. + +\begin{example} +\begin{tikzpicture} +\begin{scope}[tqft/boundary style={fill=purple,fill opacity=1}] +\node[tqft/cylinder] at (1,0) {}; +\begin{scope}[tqft/boundary lower style={draw,dashed,green,thick}] +\node[tqft/cylinder] at (2,0) {}; +\begin{scope} +\node[tqft/cylinder,fill=yellow,fill opacity=.7] at (3,0) {}; +\begin{scope}[tqft/cobordism style={draw,thick,blue}] +\node[tqft/cylinder,fill=yellow,fill opacity=.7] at (4,0) {}; +\begin{scope}[tqft/boundary upper style={draw,thick,orange}] +\node[tqft/cylinder,fill=yellow,fill opacity=.7] at (5,0) {}; +\end{scope} +\end{scope} +\end{scope} +\end{scope} +\end{scope} +\end{tikzpicture} +\end{example} + +\section{Anchors} + +As with all PGF node shapes, there are certain anchors defined by the \Verb+tqft+ shape. +These are the \Verb+center+ (and \Verb+centre+) anchors and the \Verb+incoming boundary n+, \Verb+outgoing boundary n+ anchors. +The positioning of the \Verb+center+ anchor is slightly unusual in that if there are no, say, incoming boundary components then the centre anchor is still at the same height above the outgoing boundary components as if there were incoming boundary components. +The reason for this is two-fold: computing the \emph{actual} centre of the shape in such circumstances would be tricky, and when aligning these shapes it is more useful to have the anchors consistent across shapes of varying boundary components. + +There are also the directional anchors \Verb+north+, \Verb+south+, \Verb+east+, \Verb+west+, \Verb+north east+, \Verb+north west+, \Verb+south east+, \Verb+south west+. +The \Verb+east+ and \Verb+west+ anchors are placed at the midpoints of the sides. +The \Verb+north+ and \Verb+south+ anchors are placed in a vertical line with the \Verb+center+ anchor and vertically aligned with the centres of the corresponding boundary circles. +The other four directional anchors are placed at the corners of the cobordism (the placement of these anchors in the case that there are no boundary circles in the corresponding direction may change in future versions). + +The \Verb+incoming boundary n+ and \Verb+outgoing boundary n+ are placed at the centres of the corresponding boundary components, with the numbering starting at the left or the top as appropriate to the flow of the cobordism. +A hack borrowed from the \Verb+regular polygon+ shape ensures that there are always enough anchors for the boundary components. + +There are also anchors placed at the midpoint of the cobordism edge between the boundary circles. +The names of these are \Verb+after incoming boundary n+ and \Verb+after outgoing boundary n+. + +The above anchors can all be ``floated'' off the cobordism using the keys \Verb+outer sep+, \Verb+outer xsep+, and \Verb+outer ysep+. +The last two are the ones actually used, the first is a shortcut for setting both simultaneously. + +There are also ``sub-nodes''. +Provding the main node is named, each boundary circle is covered by a \Verb+tqft boundary circle+ node. +This means that the anchors of the \Verb+tqft boundary circle+ can be used. +These cannot be used for placing the main shape, but can be used afterwards. +These are not affected by the \Verb+outer (x/y)sep+ keys. +The names of these sub-nodes are of the form \Verb+name incoming n+ and \Verb+name outgoing n+ where \Verb+name+ is the name of the main node. +The \Verb+tqft boundary circle+ shape is based on an ellipse and defines a boundary so the syntax \Verb+(name.angle)+ works as expected. +It also defines anchors \Verb+next+, \Verb+prior+, \Verb+above+, and \Verb+below+. +These correspond to where the boundary circle in the prescribed direction should be placed. + +\begin{example} +\begin{tikzpicture} +\node[tqft, incoming boundary components=2,outgoing boundary components=4,offset=-1,draw] (a) {}; +\foreach \anchor/\placement in +{ +north/above, +south/below, +east/right, +west/left, +north west/left, +south west/left, +north east/right, +south east/right, +incoming boundary 1/above left, +incoming boundary 2/above right, +outgoing boundary 1/below left, +outgoing boundary 4/below right, +after outgoing boundary 1/below} +\draw[shift=(a.\anchor)] plot[mark=x] coordinates{(0,0)} node[\placement] {\scriptsize\texttt{(a.\anchor)}}; +\end{tikzpicture} +\end{example} + +\begin{example} +\begin{tikzpicture} +\node[tqft,cylinder, circle width=2cm, circle depth=1cm, cobordism height=4cm,boundary separation=3cm,draw] (b) {}; +\foreach \anchor/\placement in +{ +prior/left, +next/right, +above/above, +below/below, +0/right, +60/right, +200/left} +\draw[shift=(b incoming 1.\anchor)] plot[mark=x] coordinates{(0,0)} node[\placement] {\scriptsize\texttt{(b incoming 1.\anchor)}}; +\end{tikzpicture} +\end{example} + +\section{Improvements} + +Here are some ideas for extending this, and some minor ``bugs''. + +\begin{enumerate} +\item Make \Verb+incoming boundary+ an alias of \Verb+incoming boundary 1+ so that if there is only one incoming boundary component then we don't need to specify the number (ditto outgoing). +\item No thought has been given as to where the text gets placed if it is specified. +\item Add the ability to hide certain boundary components. +This is useful if the shapes are not specified in their natural order so certain boundary components should be hidden behind earlier drawn shapes. +\item Some style options on the main node get passed to the other pieces (\Verb+fill opacity+ being one). +This shouldn't happen, or should happen by design not by accident. +\item The bounding box isn't as good as it could be. +\item Add a way to specify more directions for the flow. +\item Add the ability to apply different styles to the incoming and outgoing components. +\end{enumerate} + +\section{More Examples} + +\begin{example} +\begin{tikzpicture}[tqft/cobordism height=1.5cm,tqft/boundary separation=1.5cm] +\foreach \coord/\style in { +{(0,0)}/{tqft/view from=outgoing,fill}, +{(5,0)}/{tqft/view from=incoming,draw}, +{(0,-8)}/{fill=orange,fill opacity=.5,tqft/boundary lower style={draw,blue,ultra thin,dashed},tqft/boundary upper style={draw,green},tqft/cobordism style={draw,purple},tqft/boundary style={fill=yellow}}, +{(5,-8)}/{fill=orange,fill opacity=.5,tqft/cobordism style={draw,purple},tqft/boundary style={fill=yellow,draw=green}} +} { +\begin{scope} +\edef\styleit{\noexpand\tikzset{every node/.style={\style}}} +\styleit +\node[tqft/cap] (h) at \coord {}; +\node[tqft/pair of pants,anchor=incoming boundary 1] (a) at (h.outgoing boundary 1) {}; +\node[tqft/cylinder to next,anchor=incoming boundary 1] (d) at (a.incoming boundary 2) {}; +\node[tqft/reverse pair of pants,anchor=incoming boundary 1] (b) at (a.outgoing boundary 2) {}; +\node[tqft/cylinder to prior,anchor=incoming boundary 1] (c) at (b.outgoing boundary 1) {}; +\node[tqft/cylinder,anchor=incoming boundary 1] (e) at (a.outgoing boundary 1) {}; +\node[tqft/cylinder,anchor=incoming boundary 1] (f) at (e.outgoing boundary 1) {}; +\node[tqft/reverse pair of pants,anchor=incoming boundary 1] (g) at (f.outgoing boundary 1) {}; +\node[tqft/cup,anchor=incoming boundary 1] (i) at (g.outgoing boundary 1) {}; +\end{scope} +} +\end{tikzpicture} +\end{example} + +\begin{example} +\begin{tikzpicture} +\node[draw,tqft/pair of pants] (a) {}; +\node[draw,tqft/cap,anchor=outgoing boundary 1] at (a.incoming boundary 1) {}; +\node[fill,tqft/cup,anchor=incoming boundary 1] at (a.outgoing boundary 1) {}; +\node[draw,tqft/cup,anchor=incoming boundary 1] at (a.outgoing boundary 2) {}; +\begin{scope}[tqft/flow=east] +\node[draw,tqft/pair of pants] (a) at (4,0) {}; +\node[draw,tqft/cap,anchor=outgoing boundary 1] at (a.incoming boundary 1) {}; +\node[fill,tqft/cup,anchor=incoming boundary 1] at (a.outgoing boundary 1) {}; +\node[draw,tqft/cup,anchor=incoming boundary 1] at (a.outgoing boundary 2) {}; +\end{scope} +\begin{scope}[tqft/flow=north] +\node[draw,tqft/pair of pants] (a) at (0,-4) {}; +\node[draw,tqft/cap,anchor=outgoing boundary 1] at (a.incoming boundary 1) {}; +\node[fill,tqft/cup,anchor=incoming boundary 1] at (a.outgoing boundary 1) {}; +\node[draw,tqft/cup,anchor=incoming boundary 1] at (a.outgoing boundary 2) {}; +\end{scope} +\begin{scope}[tqft/flow=west] +\node[draw,tqft/pair of pants] (a) at (4,-4) {}; +\node[draw,tqft/cap,anchor=outgoing boundary 1] at (a.incoming boundary 1) {}; +\node[fill,tqft/cup,anchor=incoming boundary 1] at (a.outgoing boundary 1) {}; +\node[draw,tqft/cup,anchor=incoming boundary 1] at (a.outgoing boundary 2) {}; +\end{scope} +\end{tikzpicture} +\end{example} + +\end{document}
\ No newline at end of file diff --git a/Master/texmf-dist/source/latex/tqft/tqft.dtx b/Master/texmf-dist/source/latex/tqft/tqft.dtx new file mode 100644 index 00000000000..769cf8018a7 --- /dev/null +++ b/Master/texmf-dist/source/latex/tqft/tqft.dtx @@ -0,0 +1,1212 @@ +% \iffalse meta-comment +%<*internal> +\iffalse +%</internal> +%<*readme> +---------------------------------------------------------------- +tqft --- a style file for drawing TQFT diagrams with TikZ/PGF +E-mail: stacey@math.ntnu.no +Released under the LaTeX Project Public License v1.3c or later +See http://www.latex-project.org/lppl.txt +---------------------------------------------------------------- + +This package defines some node shapes useful for drawing TQFT diagrams with TikZ/PGF. +%</readme> +%<*internal> +\fi +\def\nameofplainTeX{plain} +\ifx\fmtname\nameofplainTeX\else + \expandafter\begingroup +\fi +%</internal> +%<*install> +\input docstrip.tex +\keepsilent +\askforoverwritefalse +\preamble +---------------------------------------------------------------- +tqft --- a style file for drawing TQFT diagrams with TikZ/PGF +E-mail: stacey@math.ntnu.no +Released under the LaTeX Project Public License v1.3c or later +See http://www.latex-project.org/lppl.txt +---------------------------------------------------------------- + +\endpreamble +\postamble + +Copyright (C) 2011 by Andrew Stacey <stacey@math.ntnu.no> + +This work may be distributed and/or modified under the +conditions of the LaTeX Project Public License (LPPL), either +version 1.3c of this license or (at your option) any later +version. The latest version of this license is in the file: + +http://www.latex-project.org/lppl.txt + +This work is "maintained" (as per LPPL maintenance status) by +Andrew Stacey. + +This work consists of the file tqft.dtx +and the derived files tqft.ins, + tqft.pdf, and + tqft.sty. + +\endpostamble +\usedir{tex/latex/tqft} +\generate{ + \file{\jobname.sty}{\from{\jobname.dtx}{package}} +} +%</install> +%<install>\endbatchfile +%<*internal> +\usedir{source/latex/tqft} +\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{tqft}[2011/05/03 v1.0 Tikz/PGF commands for drawing TQFT 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{1595} +% +% \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{tqft.dtx} +% \title{The \textsf{tqft} package: codebase} +% \author{Andrew Stacey \\ \url{stacey@math.ntnu.no}} +% \date{\fileversion~from \filedate} +% +% \maketitle +% +% +% \begin{tikzpicture}[every node/.style={tqft/cobordism style={draw,thick,red}}] +% \node[ +% tqft, +% fill=orange, +% fill opacity=.5, +% boundary style={fill=purple}, +% cobordism style={draw,thick,red}, +% boundary lower style={draw,dashed,thick,blue}, +% boundary upper style={draw,green,thick}, +% incoming boundary components=4, +% outgoing boundary components=6, +% offset=-1.5, +% ] (a) {}; +% \node[pin=north:1] at (a.incoming boundary 1) {}; +% \node[pin=north:3] at (a.incoming boundary 3) {}; +% \node[pin=south:1] at (a.outgoing boundary 1) {}; +% \node[pin=south:4] at (a.outgoing boundary 4) {}; +% \node[pin=south:6] at (a.outgoing boundary 6) {}; +% \end{tikzpicture} +% +% \section{Introduction} +% +% This is a package for drawing TQFT diagrams using PGF/TikZ. +% Its inspiration was a question and answer on the website \url{http://tex.stackexchance.com}. +% +% +% \StopEventually{} +% +% \section{Implementation} +% +% \iffalse +%<*package> +% \fi +% \begin{macrocode} +\RequirePackage{pgfkeys} +\RequirePackage{pgf} +% \end{macrocode} +% +% We can view the cobordisms from the \emph{input} or \emph{output} ends, the implementation of the choice is to draw an arc from 0 to 180 or from 0 to -180 so we just need to track minus signs. +% These macros are for that. +% \begin{macrocode} +\def\pgf@tqft@minus{-} +\let\pgf@tqft@upper\@empty +\let\pgf@tqft@lower\pgf@tqft@minus +% \end{macrocode} +% Some helpful extra functions. +% +% \Verb+\tqftset+ is our equivalent of \Verb+\tikzset+. +% \begin{macrocode} +\def\tqftset#1{\pgfkeys{/pgf/tqft/.cd,#1}} +% \end{macrocode} +% \begin{macro}{\tqft@process} +% This macro applies our flow transformation to the given coordinates, % with the result stored in \Verb+\pgf@x+ and \Verb+\pgf@y+. +% \begin{macrocode} +\def\tqft@process#1#2{% + \edef\tqft@px{#1} + \edef\tqft@py{#2} + \pgf@process{ + \pgftransformreset + \let\tikz@transform=\pgfutil@empty + \expandafter\tikzset\expandafter{\tqft@transformation} + \tikz@transform + \pgfpointtransformed{\pgfqpoint{\tqft@px}{\tqft@py}} + } +} +% \end{macrocode} +% \end{macro} +% +% Declare some dimension registers to hold the specifications of the cobordism. +% \begin{macrocode} +\newdimen\tqft@xa +\newdimen\tqft@xb +\newdimen\tqft@c +\newdimen\tqft@ch +\newdimen\tqft@h +\newdimen\tqft@s +\newdimen\tqft@w +\newif\iftqft@within@node +% \end{macrocode} +% Now we set up all the keys that we'll need in the course of this shape +% \begin{macrocode} +\pgfkeys{ +% \end{macrocode} +% This key is our basic installer key, setting the shape and putting us in the right key family. +% \begin{macrocode} + /tikz/tqft/.style={% + /tikz/shape=tqft cobordism, + /pgf/tqft, + /tikz/every tqft + }, +% \end{macrocode} +% This deals with unknown keys, passing them on to TikZ. +% \begin{macrocode} + /pgf/tqft/.unknown/.code={% + \let\tqft@searchname=\pgfkeyscurrentname% + \pgfkeysalso{% + /tikz/\tqft@searchname=#1 + } + }, +% \end{macrocode} +% Here we have the standard \Verb+every something+ style. +% \begin{macrocode} + /tikz/every tqft/.style={}, +% \end{macrocode} +% We might get called in \Verb+/tikz+ or \Verb+/pgf+, this passes off anything in \Verb+/tikz/tqft+ to \Verb+/pgf/tqft+. +% \begin{macrocode} + /tikz/tqft/.unknown/.code={% + \let\tqft@searchname=\pgfkeyscurrentname% + \pgfkeysalso{% + /pgf/tqft/\tqft@searchname=#1 + } + }, +% \end{macrocode} +% Let's play happy families! +% \begin{macrocode} + /pgf/tqft/.is family, + /pgf/tqft, +% \end{macrocode} +% This sets our shape to be the boundary circle +% \begin{macrocode} + boundary circle/.style={ + /tikz/shape=tqft boundary circle + }, +% \end{macrocode} +% These set our number of boundary components +% \begin{macrocode} + incoming boundary components/.initial=5, + outgoing boundary components/.initial=4, +% \end{macrocode} +% This is the ``horizontal'' offset of the first outgoing component from the first incoming one. +% \begin{macrocode} + offset/.initial=0, +% \end{macrocode} +% This is the ``vertical'' separation between boundary components. +% \begin{macrocode} + cobordism height/.initial=2cm, +% \end{macrocode} +% This is the ``horizontal'' separation between boundary components. +% \begin{macrocode} + boundary separation/.initial=2cm, +% \end{macrocode} +% These are the ``horizontal'' and ``vertical'' radii, respectively, of the boundary components (perhaps poorly named!). +% \begin{macrocode} + circle width/.initial=10pt, + circle depth/.initial=5pt, +% \end{macrocode} +% These control the separation between the node and its anchors. +% \begin{macrocode} + outer xsep/.initial=0pt, + outer ysep/.initial=0pt, + outer sep/.style={ + outer xsep=#1, + outer ysep=#1 + }, +% \end{macrocode} +% This is our flow control. The \Verb+flow+ key installs a transformation to be applied to our node shape. +% The possible transformations are stored in the following keys. +% They aren't just rotations so that the numbering is always ``top to bottom'' or ``left to right''. +% \begin{macrocode} + flow/.code={% + \pgfkeys{/pgf/tqft/flow transformation/.expand twice/.expand once=\pgfkeysvalueof{/pgf/tqft/flow transformation #1}} + }, + flow transformation south/.initial={}, + flow transformation north/.initial={% + xscale=-1,rotate=180 + }, + flow transformation east/.initial={% + rotate=90,xscale=-1 + }, + flow transformation west/.initial={% + rotate=270 + }, + flow transformation/.initial={}, +% \end{macrocode} +% These control the direction from which we view the cobordism. +% \begin{macrocode} + view from/.is choice, + view from/incoming/.code={% + \let\pgf@tqft@upper\pgf@tqft@minus + \let\pgf@tqft@lower\@empty + }, + view from/outgoing/.code={% + \let\pgf@tqft@lower\pgf@tqft@minus + \let\pgf@tqft@upper\@empty + }, +% \end{macrocode} +% The next set of keys are for styling the different pieces of a cobordism. +% \begin{macrocode} + boundary lower style contents/.initial={}, + boundary lower style/.code={% + \pgfkeys{/pgf/tqft/boundary lower style contents/.style={% + /tikz/.cd,#1 + } + } + }, + boundary style contents/.initial={}, + boundary style/.code={% + \pgfkeys{/pgf/tqft/boundary style contents/.style={% + /tikz/.cd,#1 + } + } + }, + boundary upper style contents/.initial={}, + boundary upper style/.code={% + \pgfkeys{/pgf/tqft/boundary upper style contents/.style={% + /tikz/.cd,#1 + } + } + }, + cobordism style contents/.initial={}, + cobordism style/.code={% + \pgfkeys{/pgf/tqft/cobordism style contents/.style={% + /tikz/.cd,#1% + } + } + }, +% \end{macrocode} +% The next set of keys define some default shapes. +% \begin{macrocode} + pair of pants/.style={ + /tikz/tqft, + incoming boundary components=1, + outgoing boundary components=2, + offset=-.5 + }, + /tikz/tqft pair of pants/.style={ + /pgf/tqft/pair of pants, + }, + reverse pair of pants/.style={ + /tikz/tqft, + incoming boundary components=2, + outgoing boundary components=1, + offset=.5 + }, + /tikz/tqft reverse pair of pants/.style={ + /pgf/tqft/reverse pair of pants, + }, + cylinder to prior/.style={ + /tikz/tqft, + incoming boundary components=1, + outgoing boundary components=1, + offset=-.5 + }, + /tikz/tqft cylinder to prior/.style={ + /pgf/tqft/cylinder to prior, + }, + cylinder to next/.style={ + /tikz/tqft, + incoming boundary components=1, + outgoing boundary components=1, + offset=.5 + }, + /tikz/tqft cylinder to next/.style={ + /pgf/tqft/cylinder to next, + }, + cylinder/.style={ + /tikz/tqft, + incoming boundary components=1, + outgoing boundary components=1 + }, + /tikz/tqft cylinder/.style={ + /pgf/tqft/cylinder, + }, + cup/.style={ + /tikz/tqft, + incoming boundary components=1, + outgoing boundary components=0 + }, + /tikz/tqft cup/.style={ + /pgf/tqft/cup, + }, + cap/.style={ + /tikz/tqft, + incoming boundary components=0, + outgoing boundary components=1 + }, + /tikz/tqft cap/.style={ + /pgf/tqft/cap, + }, +} +% \end{macrocode} +% +% \begin{macro}{tqft shape} +% This is a generic cobordism shape +% \begin{macrocode} +\pgfdeclareshape{tqft cobordism}{ +% \end{macrocode} +% Save our specifications: incoming and outgoing boundary components +% \begin{macrocode} + \savedmacro{\tqft@incoming}{\edef\tqft@incoming{\pgfkeysvalueof{/pgf/tqft/incoming boundary components}}} + \savedmacro{\tqft@outgoing}{\edef\tqft@outgoing{\pgfkeysvalueof{/pgf/tqft/outgoing boundary components}}} +% \end{macrocode} +% and the offset (in units of boundary components) between the leading incoming and outgoing components (regarded as a shift of the outgoing components relative to the incoming) +% \begin{macrocode} + \savedmacro{\tqft@offset}{\edef\tqft@offset{\pgfkeysvalueof{/pgf/tqft/offset}}} +% \end{macrocode} +% Now we save our dimensions: height, separation, the radii of the boundary circles, and outer seps, and the heights of the control points. +% \begin{macrocode} + \saveddimen{\tqft@height}{\pgf@x=\pgfkeysvalueof{/pgf/tqft/cobordism height}} + \saveddimen{\tqft@separation}{\pgf@x=\pgfkeysvalueof{/pgf/tqft/boundary separation}} + \saveddimen{\tqft@width}{\pgf@x=\pgfkeysvalueof{/pgf/tqft/circle width}} + \saveddimen{\tqft@depth}{\pgf@x=\pgfkeysvalueof{/pgf/tqft/circle depth}} + \saveddimen{\tqft@outerxsep}{\pgf@x=\pgfkeysvalueof{/pgf/tqft/outer xsep}} + \saveddimen{\tqft@outerysep}{\pgf@x=\pgfkeysvalueof{/pgf/tqft/outer ysep}} + \saveddimen{\tqft@control}{ + \pgfkeysgetvalue{/pgf/tqft/cobordism height}{\tqft@tempa} + \pgfkeysgetvalue{/pgf/tqft/circle depth}{\tqft@tempb} + \pgfmathsetlength{\pgf@x}{.5 * \tqft@tempa - 4 * \tqft@tempb} +} +% \end{macrocode} +% This is the internal transformation that is in place +% \begin{macrocode} + \savedmacro{\tqft@transformation}{% + \pgfkeysgetvalue{/pgf/tqft/flow transformation}{\tqft@transformation} +} +% \end{macrocode} +% For the externally available anchors, we need to save a few things as well. +% +% Position of first incoming boundary in internal coordinates +% \begin{macrocode} + \savedanchor{\tqft@start@incoming}{% + \pgfmathsetlength{\pgf@x}{-(max(\pgfkeysvalueof{/pgf/tqft/incoming boundary components} - 1,\pgfkeysvalueof{/pgf/tqft/outgoing boundary components} - 1 + \pgfkeysvalueof{/pgf/tqft/offset}) + min(0,\pgfkeysvalueof{/pgf/tqft/offset}) )*\pgfkeysvalueof{/pgf/tqft/boundary separation}/2} + \pgfmathsetlength{\pgf@y}{.5 * \pgfkeysvalueof{/pgf/tqft/cobordism height}} +} +% \end{macrocode} +% Position of first outgoing boundary in internal coordinates +% \begin{macrocode} + \savedanchor{\tqft@start@outgoing}{% + \pgfmathsetlength{\pgf@x}{-(max(\pgfkeysvalueof{/pgf/tqft/incoming boundary components} - 1,\pgfkeysvalueof{/pgf/tqft/outgoing boundary components} - 1 + \pgfkeysvalueof{/pgf/tqft/offset}) + min(0,\pgfkeysvalueof{/pgf/tqft/offset})- 2*\pgfkeysvalueof{/pgf/tqft/offset})*\pgfkeysvalueof{/pgf/tqft/boundary separation}/2} + \pgfmathsetlength{\pgf@y}{-.5 * \pgfkeysvalueof{/pgf/tqft/cobordism height}} +} +% \end{macrocode} +% For completeness, we record the size of the text box (not that we expect any text, but you never know) +% \begin{macrocode} +\savedanchor{\tqft@textsize}{% + \pgf@y=-.5\ht\pgfnodeparttextbox% + \pgf@x=-.5\wd\pgfnodeparttextbox% +} +% \end{macrocode} +% +% These are our externally available anchors +% \begin{macrocode} + \anchor{centre}{\pgfpointorigin} + \anchor{center}{\pgfpointorigin} +\anchor{text}{ + \tqft@textsize +} +\anchor{north}{% + \pgf@ya=\tqft@height\relax + \pgf@yb=.5\pgf@ya + \advance\pgf@yb by \tqft@outerysep\relax + \tqft@process{0pt}{\the\pgf@yb} +} +\anchor{south}{% + \pgf@yb=\tqft@height\relax + \pgf@ya=.5\pgf@yb + \advance\pgf@ya by \tqft@outerysep\relax + \pgf@yb=-\pgf@ya + \tqft@process{0pt}{\the\pgf@yb} +} +\anchor{west}{% + \tqft@start@incoming + \pgf@xa=\pgf@x + \advance\pgf@xa by -\tqft@width + \pgf@ya=\pgf@y + \tqft@start@outgoing + \pgf@xb=\pgf@x + \advance\pgf@xb by -\tqft@width + \pgf@yb=\pgf@y + \pgf@xc=.5\pgf@xa + \advance\pgf@xc by .5\pgf@xb + \pgf@yc=.5\pgf@ya + \advance\pgf@yc by .5\pgf@yb + \advance\pgf@xc by -\tqft@outerxsep\relax + \tqft@process{\the\pgf@xc}{\the\pgf@yc} +} +\anchor{east}{% + \tqft@start@incoming + \pgf@xa=\pgf@x + \pgfmathsetlength{\pgf@xa}{\pgf@xa + (\tqft@incoming - 1) * \tqft@separation} + \advance\pgf@xa by \tqft@width\relax + \pgf@ya=\pgf@y + \tqft@start@outgoing + \pgf@xb=\pgf@x + \pgfmathsetlength{\pgf@xb}{\pgf@xb + (\tqft@outgoing - 1) * \tqft@separation} + \advance\pgf@xb by \tqft@width\relax + \pgf@yb=\pgf@y + \pgf@xc=.5\pgf@xa + \advance\pgf@xc by .5\pgf@xb + \pgf@yc=.5\pgf@ya + \advance\pgf@yc by .5\pgf@yb + \advance\pgf@xc by \tqft@outerxsep\relax + \tqft@process{\the\pgf@xc}{\the\pgf@yc} +} +\anchor{north west}{ + \tqft@start@incoming + \pgf@xc=\pgf@x + \pgf@yc=\pgf@y + \advance\pgf@xc by -\tqft@width\relax + \advance\pgf@yc by \tqft@outerysep\relax + \advance\pgf@xc by -\tqft@outerxsep\relax + \tqft@process{\the\pgf@xc}{\the\pgf@yc} +} +\anchor{south west}{ + \tqft@start@outgoing + \pgf@xc=\pgf@x + \pgf@yc=\pgf@y + \advance\pgf@xc by -\tqft@width\relax + \advance\pgf@yc by -\tqft@outerysep\relax + \advance\pgf@xc by -\tqft@outerxsep\relax + \tqft@process{\the\pgf@xc}{\the\pgf@yc} +} +\anchor{north east}{ + \tqft@start@incoming + \pgf@xc=\pgf@x + \pgfmathsetlength{\pgf@xc}{\pgf@xc + (\tqft@incoming - 1)*\tqft@separation} + \pgf@yc=\pgf@y + \advance\pgf@xc by \tqft@width\relax + \advance\pgf@yc by \tqft@outerysep\relax + \advance\pgf@xc by \tqft@outerxsep\relax + \tqft@process{\the\pgf@xc}{\the\pgf@yc} +} +\anchor{south east}{ + \tqft@start@outgoing + \pgf@xc=\pgf@x + \pgfmathsetlength{\pgf@xc}{\pgf@xc + (\tqft@outgoing - 1)*\tqft@separation} + \pgf@yc=\pgf@y + \advance\pgf@xc by \tqft@width\relax + \advance\pgf@yc by -\tqft@outerysep\relax + \advance\pgf@xc by \tqft@outerxsep\relax + \tqft@process{\the\pgf@xc}{\the\pgf@yc} +} +% \end{macrocode} +% To define anchors at the boundary components requires a bit of trickery borrowed from the ``regular polygon'' shape. +% \begin{macrocode} +\expandafter\pgfutil@g@addto@macro\csname pgf@sh@s@tqft cobordism\endcsname{% + \c@pgf@counta\tqft@incoming\relax% + \pgfmathloop% + \ifnum\c@pgf@counta>0\relax% + \pgfutil@ifundefined{pgf@anchor@tqft cobordism@incoming boundary\space\the\c@pgf@counta}{% + \expandafter\xdef\csname pgf@anchor@tqft cobordism@incoming boundary\space\the\c@pgf@counta\endcsname{% + \noexpand\tqft@start@incoming + \noexpand\pgfmathsetlength{\noexpand\pgf@y}{\noexpand\pgf@y + \noexpand\tqft@outerysep} + \noexpand\pgfmathsetlength{\noexpand\pgf@x}{\noexpand\pgf@x + (\the\c@pgf@counta - 1) * \noexpand\tqft@separation} + \noexpand\tqft@process{\noexpand\the\noexpand\pgf@x}{\noexpand\the\noexpand\pgf@y} + } + }{\c@pgf@counta0\relax}% + \advance\c@pgf@counta-1\relax% + \repeatpgfmathloop% +} +\expandafter\pgfutil@g@addto@macro\csname pgf@sh@s@tqft cobordism\endcsname{% + \c@pgf@counta\tqft@outgoing\relax% + \pgfmathloop% + \ifnum\c@pgf@counta>0\relax% + \pgfutil@ifundefined{pgf@anchor@tqft cobordism@outgoing boundary\space\the\c@pgf@counta}{% + \expandafter\xdef\csname pgf@anchor@tqft cobordism@outgoing boundary\space\the\c@pgf@counta\endcsname{% + \noexpand\tqft@start@outgoing + \noexpand\pgfmathsetlength{\noexpand\pgf@y}{\noexpand\pgf@y - \noexpand\tqft@outerysep} + \noexpand\pgfmathsetlength{\noexpand\pgf@x}{\noexpand\pgf@x + (\the\c@pgf@counta - 1) * \noexpand\tqft@separation} + \noexpand\tqft@process{\noexpand\the\noexpand\pgf@x}{\noexpand\the\noexpand\pgf@y} + } + }{\c@pgf@counta0\relax}% + \advance\c@pgf@counta-1\relax% + \repeatpgfmathloop% +} +\expandafter\pgfutil@g@addto@macro\csname pgf@sh@s@tqft cobordism\endcsname{% + \c@pgf@counta\tqft@incoming\relax% + \advance\c@pgf@counta-1\relax + \pgfmathloop% + \ifnum\c@pgf@counta>0\relax% + \pgfutil@ifundefined{pgf@anchor@tqft cobordism@after incoming boundary\space\the\c@pgf@counta}{% + \expandafter\xdef\csname pgf@anchor@tqft cobordism@after incoming boundary\space\the\c@pgf@counta\endcsname{% + \noexpand\tqft@start@incoming + \noexpand\pgfmathsetlength{\noexpand\pgf@y}{.25 * \noexpand\pgf@y +.75 * \noexpand\tqft@control + \noexpand\tqft@outerysep} + \noexpand\pgfmathsetlength{\noexpand\pgf@x}{\noexpand\pgf@x + (\the\c@pgf@counta - .5) * \noexpand\tqft@separation} + \noexpand\tqft@process{\noexpand\the\noexpand\pgf@x}{\noexpand\the\noexpand\pgf@y} + } + }{\c@pgf@counta0\relax}% + \advance\c@pgf@counta-1\relax% + \repeatpgfmathloop% +} +\expandafter\pgfutil@g@addto@macro\csname pgf@sh@s@tqft cobordism\endcsname{% + \c@pgf@counta\tqft@outgoing\relax% + \advance\c@pgf@counta-1\relax + \pgfmathloop% + \ifnum\c@pgf@counta>0\relax% + \pgfutil@ifundefined{pgf@anchor@tqft cobordism@after outgoing boundary\space\the\c@pgf@counta}{% + \expandafter\xdef\csname pgf@anchor@tqft cobordism@after outgoing boundary\space\the\c@pgf@counta\endcsname{% + \noexpand\tqft@start@outgoing + \noexpand\pgfmathsetlength{\noexpand\pgf@y}{.25 * \noexpand\pgf@y -.75 * \noexpand\tqft@control - \noexpand\tqft@outerysep} + \noexpand\pgfmathsetlength{\noexpand\pgf@x}{\noexpand\pgf@x + (\the\c@pgf@counta - .5) * \noexpand\tqft@separation} + \noexpand\tqft@process{\noexpand\the\noexpand\pgf@x}{\noexpand\the\noexpand\pgf@y} + } + }{\c@pgf@counta0\relax}% + \advance\c@pgf@counta-1\relax% + \repeatpgfmathloop% +} +% \end{macrocode} +% Now we define the background path. +% This is the upper part of the cobordism. +% \begin{macrocode} + \backgroundpath{ +% \end{macrocode} +% Apply the internal transformation +% \begin{macrocode} + \let\tikz@transform=\pgfutil@empty + \expandafter\tikzset\expandafter{\tqft@transformation} + \tikz@transform +% \end{macrocode} +% Convert the boundary separation and width to lengths +% \begin{macrocode} + \pgfmathsetlength{\tqft@s}{\tqft@separation} + \pgfmathsetlength{\tqft@w}{2*\tqft@width} +% \end{macrocode} +% Compute the starting position of the incoming boundary components so that we get the centre anchor on the centre of the cobordism +% \begin{macrocode} +\tqft@start@incoming +\tqft@xa=\pgf@x + \advance\tqft@xa by -.5\tqft@w\relax +\tqft@h=\pgf@y + \tqft@xb=\tqft@xa + \advance\tqft@xb by \tqft@w\relax +\tqft@c=\tqft@control\relax +% \end{macrocode} +% Do we have any incoming boundary components at all? +% \begin{macrocode} + \ifnum\tqft@incoming>0 +% \end{macrocode} +% Yes, so move to the position of the first and draw it +% \begin{macrocode} + \pgfpathmoveto{\pgfqpoint{\tqft@xa}{\tqft@h}} + \pgfpatharc{\pgf@tqft@upper180}{0}{\tqft@width and \tqft@depth} +% \end{macrocode} +% Do we have any more incoming boundary components? +% \begin{macrocode} + \ifnum\tqft@incoming>1 +% \end{macrocode} +% Yes, so iterate over the remaining incoming boundary components +% \begin{macrocode} + \foreach \tqft@k in {2,...,\tqft@incoming} { + \advance\tqft@xa by \tqft@k\tqft@s + \advance\tqft@xb by \tqft@k\tqft@s + \advance\tqft@xb by -2\tqft@s + \advance\tqft@xa by -\tqft@s + \pgfpathcurveto{\pgfqpoint{\tqft@xb}{\tqft@c}}{\pgfqpoint{\tqft@xa}{\tqft@c}}{\pgfqpoint{\tqft@xa}{\tqft@h}} + \pgfpatharc{\pgf@tqft@upper180}{0}{\tqft@width and \tqft@depth} + } + \fi +% \end{macrocode} +% If we don't have any outgoing boundary components, may as well close up now. +% \begin{macrocode} + \ifnum\tqft@outgoing=0 + \advance\tqft@xb by \tqft@incoming\tqft@s + \advance\tqft@xb by -\tqft@s + \pgfmathsetlength{\tqft@ch}{min(0,max(-\tqft@h,\tqft@h - (\tqft@h - \tqft@c) * ((abs(\tqft@xb - \tqft@xa) - \tqft@w)/\tqft@s + 1)))} + \pgfpathcurveto{\pgfqpoint{\tqft@xb}{\tqft@ch}}{\pgfqpoint{\tqft@xa}{\tqft@ch}}{\pgfqpoint{\tqft@xa}{\tqft@h}} + \fi + \fi +% \end{macrocode} +% Shift down to the outgoing components, if we have any +% \begin{macrocode} + \ifnum\tqft@outgoing>0 + \advance\tqft@xb by \tqft@incoming\tqft@s + \advance\tqft@xb by -\tqft@s + \pgfmathsetlength{\tqft@xa}{\tqft@xa + (\tqft@outgoing - 1 + \tqft@offset) * \tqft@separation + 2*\tqft@width} +% \end{macrocode} +% If we had incoming boundaries, this is a curveto, otherwise it's a moveto +% \begin{macrocode} + \ifnum\tqft@incoming>0 + \pgfmathsetlength{\tqft@ch}{min(0,max(-\tqft@h,\tqft@h - (\tqft@h - \tqft@c) * ((abs(\tqft@xb - \tqft@xa) - \tqft@w)/\tqft@s + 1)))} + \pgfpathcurveto{\pgfqpoint{\tqft@xb}{\tqft@ch}}{\pgfqpoint{\tqft@xa}{-\tqft@ch}}{\pgfqpoint{\tqft@xa}{-\tqft@h}} + \else + \pgfpathmoveto{\pgfqpoint{\tqft@xa}{-\tqft@h}} + \fi + \tqft@xb=\tqft@xa + \advance\tqft@xb by -\tqft@w +% \end{macrocode} +% Now draw the lower components +% \begin{macrocode} + \pgfpatharc{0}{\pgf@tqft@upper180}{\tqft@width and \tqft@depth} +% \end{macrocode} +% Now iterate over the remaining outgoing boundary components +% \begin{macrocode} + \ifnum\tqft@outgoing>1 + \foreach \tqft@k in {2,...,\tqft@outgoing} { + \advance\tqft@xa by -\tqft@k\tqft@s + \advance\tqft@xb by -\tqft@k\tqft@s + \advance\tqft@xb by 2\tqft@s + \advance\tqft@xa by \tqft@s + \pgfpathcurveto{\pgfqpoint{\tqft@xb}{-\tqft@c}}{\pgfqpoint{\tqft@xa}{-\tqft@c}}{\pgfqpoint{\tqft@xa}{-\tqft@h}} + \pgfpatharc{0}{\pgf@tqft@upper180}{\tqft@width and \tqft@depth} + } + \fi +% \end{macrocode} +% Shift back up to the incoming components, if we had any, otherwise arc back to our starting point +% \begin{macrocode} + \advance\tqft@xb by -\tqft@outgoing\tqft@s + \advance\tqft@xb by \tqft@s + \ifnum\tqft@incoming>0 + \pgfmathsetlength{\tqft@xa}{\tqft@xa - (\tqft@outgoing -1 + \tqft@offset) * \tqft@separation - 2*\tqft@width} + \pgfmathsetlength{\tqft@ch}{min(0,max(-\tqft@h,\tqft@h - (\tqft@h - \tqft@c) * ((abs(\tqft@xb - \tqft@xa) - \tqft@w)/\tqft@s + 1)))} + \pgfpathcurveto{\pgfqpoint{\tqft@xb}{-\tqft@ch}}{\pgfqpoint{\tqft@xa}{\tqft@ch}}{\pgfqpoint{\tqft@xa}{\tqft@h}} + \else + \pgfmathsetlength{\tqft@ch}{min(0,max(-\tqft@h,\tqft@h - (\tqft@h - \tqft@c) * ((abs(\tqft@xb - \tqft@xa) - \tqft@w)/\tqft@s + 1)))} + \pgfpathcurveto{\pgfqpoint{\tqft@xb}{-\tqft@ch}}{\pgfqpoint{\tqft@xa}{-\tqft@ch}}{\pgfqpoint{\tqft@xa}{-\tqft@h}} + \fi + \fi +% \end{macrocode} +% Close the path +% \begin{macrocode} + \pgfpathclose + } +% \end{macrocode} +% End of background path +% Now we define the behind background path. +% This is the lower part of the boundary circles. +% \begin{macrocode} + \behindbackgroundpath{ +% \end{macrocode} +% Apply the internal transformation +% \begin{macrocode} + \let\tikz@transform=\pgfutil@empty + \expandafter\tikzset\expandafter{\tqft@transformation} + \tikz@transform +% \end{macrocode} +% Convert the boundary separation and width to lengths +% \begin{macrocode} + \pgfmathsetlength{\tqft@s}{\tqft@separation} + \pgfmathsetlength{\tqft@w}{2*\tqft@width} +% \end{macrocode} +% Compute the starting position of the incoming boundary components so that we get the centre anchor on the centre of the cobordism +% \begin{macrocode} + \pgfmathsetlength{\tqft@xa}{-(max(\tqft@incoming - 1,\tqft@outgoing - 1 + \tqft@offset) + min(0,\tqft@offset) + 2)*\tqft@separation/2} + \pgfmathsetlength{\tqft@h}{.5 * \tqft@height} +% \end{macrocode} +% This section draws the boundary circles +% \begin{macrocode} + { +% \end{macrocode} +% Initialise the TikZ path settings and read in the style options for the boundary +% \begin{macrocode} + \tikz@mode@fillfalse% + \tikz@mode@drawfalse% + \let\tikz@mode=\pgfutil@empty + \let\tikz@options=\pgfutil@empty + \tqftset{boundary style contents} + \tikz@mode + \tikz@options +% \end{macrocode} +% Do we have any incoming boundary components at all? +% \begin{macrocode} + \ifnum\tqft@incoming>0 +% \end{macrocode} +% Yes, so iterate over them +% \begin{macrocode} + \foreach \tqft@k in {1,...,\tqft@incoming} { + \advance\tqft@xa by \tqft@k\tqft@s + \pgfpathellipse{\pgfqpoint{\tqft@xa}{\tqft@h}}{\pgfqpoint{\tqft@width}{0pt}}{\pgfqpoint{0pt}{\tqft@depth}} + } + \fi +% \end{macrocode} +% Now iterate over the outgoing boundary components, if we have any +% \begin{macrocode} + \ifnum\tqft@outgoing>0 + \pgfmathsetlength{\tqft@xa}{\tqft@xa + (\tqft@outgoing + \tqft@offset + 1) * \tqft@separation} + \foreach \tqft@k in {1,...,\tqft@outgoing} { + \advance\tqft@xa by -\tqft@k\tqft@s +% \advance\tqft@xa by \tqft@s + \pgfpathellipse{\pgfqpoint{\tqft@xa}{-\tqft@h}}{\pgfqpoint{\tqft@width}{0pt}}{\pgfqpoint{0pt}{\tqft@depth}} + } + \fi +% \end{macrocode} +% \begin{macrocode} + \edef\tikz@temp{\noexpand\pgfusepath{% + \iftikz@mode@fill fill,\fi% + \iftikz@mode@draw draw\fi% + }}% + \tikz@temp + } +% \end{macrocode} +% This section draws the lower parts of the boundary circles +% \begin{macrocode} + { +% \end{macrocode} +% Initialise the TikZ path settings and read in the style options for the boundary +% \begin{macrocode} + \tikz@mode@fillfalse% + \tikz@mode@drawfalse% + \let\tikz@mode=\pgfutil@empty + \let\tikz@options=\pgfutil@empty + \tqftset{boundary lower style contents} + \tikz@mode + \tikz@options + \advance\tqft@xa by .5\tqft@w +% \end{macrocode} +% Do we have any incoming boundary components at all? +% \begin{macrocode} + \ifnum\tqft@incoming>0 +% \end{macrocode} +% Yes, so iterate over them +% \begin{macrocode} + \foreach \tqft@k in {1,...,\tqft@incoming} { + \advance\tqft@xa by \tqft@k\tqft@s + \pgfpathmoveto{\pgfqpoint{\tqft@xa}{\tqft@h}} + \pgfpatharc{0}{\pgf@tqft@lower180}{\tqft@width and \tqft@depth} + } + \fi +% \end{macrocode} +% Now iterate over the outgoing boundary components, if we have any +% \begin{macrocode} + \ifnum\tqft@outgoing>0 + \pgfmathsetlength{\tqft@xa}{\tqft@xa + (\tqft@outgoing + \tqft@offset + 1) * \tqft@separation} + \foreach \tqft@k in {1,...,\tqft@outgoing} { + \advance\tqft@xa by -\tqft@k\tqft@s +% \advance\tqft@xa by \tqft@s + \pgfpathmoveto{\pgfqpoint{\tqft@xa}{-\tqft@h}} + \pgfpatharc{0}{\pgf@tqft@lower180}{\tqft@width and \tqft@depth} + } + \fi +% \end{macrocode} +% \begin{macrocode} + \edef\tikz@temp{\noexpand\pgfusepath{% + \iftikz@mode@fill fill,\fi% + \iftikz@mode@draw draw\fi% + }}% + \tikz@temp + } + } +% \end{macrocode} +% End of behind background path. +% +% Now we define the before background path. +% This is the upper part of the boundary circles and the cobordism edge. +% \begin{macrocode} + \beforebackgroundpath{ +% \end{macrocode} +% We \emph{don't} apply the internal transformation as it is already in place from the \Verb+\backgroundpath+. +% Convert the boundary separation and width to lengths +% \begin{macrocode} + \pgfmathsetlength{\tqft@s}{\tqft@separation} + \pgfmathsetlength{\tqft@w}{2*\tqft@width} +% \end{macrocode} +% Compute the starting position of the incoming boundary components so that we get the centre anchor on the centre of the cobordism +% \begin{macrocode} + \pgfmathsetlength{\tqft@xa}{-(max(\tqft@incoming - 1,\tqft@outgoing - 1 + \tqft@offset) + min(0,\tqft@offset))*\tqft@s/2 - \tqft@width} + \tqft@xb=\tqft@xa + \advance\tqft@xb by \tqft@w +\tqft@c=\tqft@control\relax + \pgfmathsetlength{\tqft@h}{.5 * \tqft@height} +% \end{macrocode} +% This section draws the non-boundary part of the cobordism. +% \begin{macrocode} + { +% \end{macrocode} +% Initialise the TikZ path settings and read in the style options for the boundary +% \begin{macrocode} + \tikz@mode@fillfalse% + \tikz@mode@drawfalse% + \let\tikz@mode=\pgfutil@empty + \let\tikz@options=\pgfutil@empty + \tqftset{cobordism style contents} + \tikz@mode + \tikz@options +% Do we have any incoming boundary components at all? +% \begin{macrocode} + \ifnum\tqft@incoming>0 +% \end{macrocode} +% Do we have more than one? +% \begin{macrocode} + \ifnum\tqft@incoming>1 +% \end{macrocode} +% Yes, so iterate over the remaining incoming boundary components +% \begin{macrocode} + \foreach \tqft@k in {2,...,\tqft@incoming} { + \advance\tqft@xa by \tqft@k\tqft@s + \advance\tqft@xb by \tqft@k\tqft@s + \advance\tqft@xb by -2\tqft@s + \advance\tqft@xa by -\tqft@s + \pgfpathmoveto{\pgfqpoint{\tqft@xb}{\tqft@h}} + \pgfpathcurveto{\pgfqpoint{\tqft@xb}{\tqft@c}}{\pgfqpoint{\tqft@xa}{\tqft@c}}{\pgfqpoint{\tqft@xa}{\tqft@h}} + } + \fi +% \end{macrocode} +% If we don't have any outgoing boundary components, may as well close up now. +% \begin{macrocode} + \ifnum\tqft@outgoing=0 + \advance\tqft@xb by \tqft@incoming\tqft@s + \advance\tqft@xb by -\tqft@s + \pgfmathsetlength{\tqft@ch}{min(0,max(-\tqft@h,\tqft@h - (\tqft@h - \tqft@c) * ((abs(\tqft@xb - \tqft@xa) - \tqft@w)/\tqft@s + 1)))} + \pgfpathmoveto{\pgfqpoint{\tqft@xb}{\tqft@h}} + \pgfpathcurveto{\pgfqpoint{\tqft@xb}{\tqft@ch}}{\pgfqpoint{\tqft@xa}{\tqft@ch}}{\pgfqpoint{\tqft@xa}{\tqft@h}} + \fi + \fi +% \end{macrocode} +% Shift down to the outgoing components, if we have any +% \begin{macrocode} + \ifnum\tqft@outgoing>0 + \advance\tqft@xb by \tqft@incoming\tqft@s + \advance\tqft@xb by -\tqft@s + \pgfmathsetlength{\tqft@xa}{\tqft@xa + (\tqft@outgoing - 1 + \tqft@offset) * \tqft@separation + 2*\tqft@width} +% \end{macrocode} +% If we had incoming boundaries, this is a curveto, otherwise it's a moveto +% \begin{macrocode} + \ifnum\tqft@incoming>0 + \pgfmathsetlength{\tqft@ch}{min(0,max(-\tqft@h,\tqft@h - (\tqft@h - \tqft@c) * ((abs(\tqft@xb - \tqft@xa) - \tqft@w)/\tqft@s + 1)))} + \pgfpathmoveto{\pgfqpoint{\tqft@xb}{\tqft@h}} + \pgfpathcurveto{\pgfqpoint{\tqft@xb}{\tqft@ch}}{\pgfqpoint{\tqft@xa}{-\tqft@ch}}{\pgfqpoint{\tqft@xa}{-\tqft@h}} + \else + \pgfpathmoveto{\pgfqpoint{\tqft@xa}{-\tqft@h}} + \fi + \tqft@xb=\tqft@xa + \advance\tqft@xb by -\tqft@w +% \end{macrocode} +% Now draw the lower components +% \begin{macrocode} + \pgfpathmoveto{\pgfqpoint{\tqft@xb}{-\tqft@h}} +% \end{macrocode} +% Now iterate over the remaining outgoing boundary components +% \begin{macrocode} + \ifnum\tqft@outgoing>1 + \foreach \tqft@k in {2,...,\tqft@outgoing} { + \advance\tqft@xa by -\tqft@k\tqft@s + \advance\tqft@xb by -\tqft@k\tqft@s + \advance\tqft@xb by 2\tqft@s + \advance\tqft@xa by \tqft@s + \pgfpathcurveto{\pgfqpoint{\tqft@xb}{-\tqft@c}}{\pgfqpoint{\tqft@xa}{-\tqft@c}}{\pgfqpoint{\tqft@xa}{-\tqft@h}} + \advance\tqft@xa by -\tqft@w + \pgfpathmoveto{\pgfqpoint{\tqft@xa}{-\tqft@h}} + } + \fi +% \end{macrocode} +% Shift back up to the incoming components, if we had any, otherwise arc back to our starting point +% \begin{macrocode} + \advance\tqft@xb by -\tqft@outgoing\tqft@s + \advance\tqft@xb by \tqft@s + \ifnum\tqft@incoming>0 + \pgfmathsetlength{\tqft@xa}{\tqft@xa - (\tqft@outgoing -1 + \tqft@offset) * \tqft@separation - 2*\tqft@width} + \pgfmathsetlength{\tqft@ch}{min(0,max(-\tqft@h,\tqft@h - (\tqft@h - \tqft@c) * ((abs(\tqft@xb - \tqft@xa) - \tqft@w)/\tqft@s + 1)))} + \pgfpathcurveto{\pgfqpoint{\tqft@xb}{-\tqft@ch}}{\pgfqpoint{\tqft@xa}{\tqft@ch}}{\pgfqpoint{\tqft@xa}{\tqft@h}} + \else + \pgfmathsetlength{\tqft@ch}{min(0,max(-\tqft@h,\tqft@h - (\tqft@h - \tqft@c) * ((abs(\tqft@xb - \tqft@xa) - \tqft@w)/\tqft@s + 1)))} + \pgfpathcurveto{\pgfqpoint{\tqft@xb}{-\tqft@ch}}{\pgfqpoint{\tqft@xa}{-\tqft@ch}}{\pgfqpoint{\tqft@xa}{-\tqft@h}} + \fi + \fi + \edef\tikz@temp{\noexpand\pgfusepath{% + \iftikz@mode@fill fill,\fi% + \iftikz@mode@draw draw\fi% + }}% + \tikz@temp +} +% \end{macrocode} +% This section draws the upper parts of the boundary circles +% \begin{macrocode} + { +% \end{macrocode} +% Initialise the TikZ path settings and read in the style options for the boundary +% \begin{macrocode} +\let\tqft@bdry@path=\pgfutil@empty +\let\tqft@bdry@node@path=\pgfutil@empty +\pgfsyssoftpath@setcurrentpath{\tqft@bdry@path} + \tikz@mode@fillfalse% + \tikz@mode@drawfalse% + \let\tikz@mode=\pgfutil@empty + \let\tikz@options=\pgfutil@empty + \tqftset{boundary upper style contents} + \tikz@mode + \tikz@options + \advance\tqft@xa by -\tqft@s + \advance\tqft@xa by \tqft@w +% \end{macrocode} +% Do we have any incoming boundary components at all? +% \begin{macrocode} + \ifnum\tqft@incoming>0 +% \end{macrocode} +% Yes, so iterate over them +% \begin{macrocode} + \foreach \tqft@k in {1,...,\tqft@incoming} { + \advance\tqft@xa by \tqft@k\tqft@s + \pgfpathmoveto{\pgfqpoint{\tqft@xa}{\tqft@h}} + \pgfpatharc{0}{\pgf@tqft@upper180}{\tqft@width and \tqft@depth} + \ifx\tikz@fig@name\pgfutil@empty + \else + { + \advance\tqft@xa by -\tqft@width + \pgftransformshift{\pgfqpoint{\tqft@xa}{\tqft@h}} + \tqft@within@nodetrue + \pgfsyssoftpath@getcurrentpath{\tqft@bdry@path} + \pgfsyssoftpath@setcurrentpath{\tqft@bdry@node@path} + \pgfnode{tqft boundary circle}{centre}{}{\tikz@fig@name\space incoming \tqft@k}{} + \pgfsyssoftpath@getcurrentpath{\tqft@bdry@node@path} + \pgfsyssoftpath@setcurrentpath{\tqft@bdry@path} + } + \fi + } + \fi +% \end{macrocode} +% Now iterate over the outgoing boundary components, if we have any +% \begin{macrocode} + \ifnum\tqft@outgoing>0 + \pgfmathsetlength{\tqft@xa}{\tqft@xa + (\tqft@outgoing + \tqft@offset + 1) * \tqft@separation} + \foreach \tqft@k in {1,...,\tqft@outgoing} { + \advance\tqft@xa by -\tqft@k\tqft@s +% \advance\tqft@xa by \tqft@s + \pgfpathmoveto{\pgfqpoint{\tqft@xa}{-\tqft@h}} + \pgfpatharc{0}{\pgf@tqft@upper180}{\tqft@width and \tqft@depth} + \ifx\tikz@fig@name\pgfutil@empty + \else + { + \pgfmathtruncatemacro{\tqft@l}{\tqft@outgoing + 1 - \tqft@k} + \advance\tqft@xa by -\tqft@width + \pgftransformshift{\pgfqpoint{\tqft@xa}{-\tqft@h}} + \tqft@within@nodetrue + \pgfsyssoftpath@getcurrentpath{\tqft@bdry@path} + \pgfsyssoftpath@setcurrentpath{\tqft@bdry@node@path} + \pgfnode{tqft boundary circle}{centre}{}{\tikz@fig@name\space outgoing \tqft@l}{} + \pgfsyssoftpath@getcurrentpath{\tqft@bdry@node@path} + \pgfsyssoftpath@setcurrentpath{\tqft@bdry@path} + } + \fi + } + \fi +% \end{macrocode} +% \begin{macrocode} + \edef\tikz@temp{\noexpand\pgfusepath{% + \iftikz@mode@fill fill,\fi% + \iftikz@mode@draw draw\fi% + }}% + \tikz@temp + } + } +} +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{boundary circle shape} +% This is a the shape of the boundary circles +% \begin{macrocode} +\pgfdeclareshape{tqft boundary circle}{ +% \end{macrocode} +% Now we save our dimensions: height, separation, and the radii of the boundary circles +% \begin{macrocode} + \saveddimen{\tqft@height}{\pgf@x=\pgfkeysvalueof{/pgf/tqft/cobordism height}} + \saveddimen{\tqft@separation}{\pgf@x=\pgfkeysvalueof{/pgf/tqft/boundary separation}} + \saveddimen{\tqft@width}{\pgf@x=\pgfkeysvalueof{/pgf/tqft/circle width}} + \saveddimen{\tqft@depth}{\pgf@x=\pgfkeysvalueof{/pgf/tqft/circle depth}} +% \end{macrocode} +% +% For the externally available anchors, we need to save the declared transformation; we save the actual transformation, not the macro that points to it. +% If we're called within the main cobordism shape, the transformation is already applied so we ignore it. +% \begin{macrocode} + \savedmacro{\tqft@transformation}{% + \iftqft@within@node + \let\tqft@transformation=\pgfutil@empty + \else + \pgfkeysgetvalue{/pgf/tqft/flow transformation}{\tqft@transformation} + \fi +} +% \end{macrocode} +% \begin{macrocode} + \savedanchor{\tqft@centre}{% + \pgfpointorigin} +% \end{macrocode} +% For completeness, we record the size of the text box (not that we expect any text, but you never know) +% \begin{macrocode} +\savedanchor{\tqft@textsize}{% + \pgf@y=-.5\ht\pgfnodeparttextbox% + \pgf@x=-.5\wd\pgfnodeparttextbox% +} +% \end{macrocode} +% These are our externally available anchors +% \begin{macrocode} + \anchor{centre}{\tqft@centre} + \anchor{center}{\tqft@centre} +\anchor{text}{ + \tqft@textsize +} + \anchor{next}{% + \tqft@process{\tqft@separation}{0pt}}% +% \end{macrocode} +% \begin{macrocode} + \anchor{prior}{% + \tqft@process{-\tqft@separation}{0pt}}% +% \end{macrocode} +% \begin{macrocode} + \anchor{above}{% + \tqft@process{0pt}{\tqft@height}}% +% \end{macrocode} +% \begin{macrocode} + \anchor{below}{% + \tqft@process{0pt}{-\tqft@height}}% +% \end{macrocode} +% The anchor border is the ellipse, but we need to take into account the possible transformation. +% (This isn't right if the origin is shifted.) +% At the moment, '0 degrees' is interpreted in the transformed coordinate system. +% Should provide a system whereby that can be intepreted in the main coordinate system. +% \begin{macrocode} + \anchorborder{ +% \end{macrocode} +% This next \Verb+\pgf@process+ makes the angles absolute. +% Comment it out to make the angles relative. +% \begin{macrocode} + \tqft@process{\the\pgf@x}{\the\pgf@y} + \edef\tqft@marshal{% + \noexpand\pgfpointborderellipse + {\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}} + {\noexpand\pgfqpoint{\tqft@width}{\tqft@depth}} + }% + \tqft@marshal + \tqft@process{\the\pgf@x}{\the\pgf@y} +} +% \end{macrocode} +% Now we define the background path. +% This is the upper part of the cobordism. +% \begin{macrocode} + \backgroundpath{ +% \end{macrocode} +% Apply the internal transformation if we're not within a node +% \begin{macrocode} + \let\tikz@transform=\pgfutil@empty + \expandafter\tikzset\expandafter{\tqft@transformation} + \tikz@transform +% \end{macrocode} +% Draw the boundary circle +% \begin{macrocode} + \pgfpathellipse{\pgfqpoint{0pt}{0pt}}{\pgfqpoint{\tqft@width}{0pt}}{\pgfqpoint{0pt}{\tqft@depth}} + } +% \end{macrocode} +% We draw the upper and lower arcs again with the appropriate styles +% \begin{macrocode} + \beforebackgroundpath{ + \iftqft@within@node + \else + \tikz@mode@fillfalse% + \tikz@mode@drawfalse% + \let\tikz@mode=\pgfutil@empty + \let\tikz@options=\pgfutil@empty + { + \pgfsys@beginscope + \tqftset{boundary lower style contents} + \tikz@mode + \tikz@options + \pgfpathmoveto{\pgfqpoint{\tqft@width}{0pt}} + \pgfpatharc{0}{\pgf@tqft@lower180}{\tqft@width and \tqft@depth} + \edef\tikz@temp{\noexpand\pgfusepath{% + \iftikz@mode@fill fill,\fi% + \iftikz@mode@draw draw\fi% + }}% + \tikz@temp + \pgfsys@endscope + } + { + \pgfsys@beginscope + \tqftset{boundary upper style contents} + \tikz@mode + \tikz@options + \pgfpathmoveto{\pgfqpoint{\tqft@width}{0pt}} + \pgfpatharc{0}{\pgf@tqft@upper180}{\tqft@width and \tqft@depth} + \edef\tikz@temp{\noexpand\pgfusepath{% + \iftikz@mode@fill fill,\fi% + \iftikz@mode@draw draw\fi% + }}% + \tikz@temp + \pgfsys@endscope + } + \fi + } + } +% \end{macrocode} +% \end{macro} +% \iffalse +%</package> +% \fi +% +% \Finale + +\endinput diff --git a/Master/texmf-dist/source/latex/tqft/tqft.ins b/Master/texmf-dist/source/latex/tqft/tqft.ins new file mode 100644 index 00000000000..f44edf4799c --- /dev/null +++ b/Master/texmf-dist/source/latex/tqft/tqft.ins @@ -0,0 +1,72 @@ +%% +%% This is file `tqft.ins', +%% generated with the docstrip utility. +%% +%% The original source files were: +%% +%% tqft.dtx (with options: `install') +%% ---------------------------------------------------------------- +%% tqft --- a style file for drawing TQFT diagrams with TikZ/PGF +%% E-mail: stacey@math.ntnu.no +%% Released under the LaTeX Project Public License v1.3c or later +%% See http://www.latex-project.org/lppl.txt +%% ---------------------------------------------------------------- +%% +\input docstrip.tex +\keepsilent +\askforoverwritefalse +\preamble +---------------------------------------------------------------- +tqft --- a style file for drawing TQFT diagrams with TikZ/PGF +E-mail: stacey@math.ntnu.no +Released under the LaTeX Project Public License v1.3c or later +See http://www.latex-project.org/lppl.txt +---------------------------------------------------------------- + +\endpreamble +\postamble + +Copyright (C) 2011 by Andrew Stacey <stacey@math.ntnu.no> + +This work may be distributed and/or modified under the +conditions of the LaTeX Project Public License (LPPL), either +version 1.3c of this license or (at your option) any later +version. The latest version of this license is in the file: + +http://www.latex-project.org/lppl.txt + +This work is "maintained" (as per LPPL maintenance status) by +Andrew Stacey. + +This work consists of the file tqft.dtx +and the derived files tqft.ins, + tqft.pdf, and + tqft.sty. + +\endpostamble +\usedir{tex/latex/tqft} +\generate{ + \file{\jobname.sty}{\from{\jobname.dtx}{package}} +} +\endbatchfile + +%% +%% Copyright (C) 2011 by Andrew Stacey <stacey@math.ntnu.no> +%% +%% This work may be distributed and/or modified under the +%% conditions of the LaTeX Project Public License (LPPL), either +%% version 1.3c of this license or (at your option) any later +%% version. The latest version of this license is in the file: +%% +%% http://www.latex-project.org/lppl.txt +%% +%% This work is "maintained" (as per LPPL maintenance status) by +%% Andrew Stacey. +%% +%% This work consists of the file tqft.dtx +%% and the derived files tqft.ins, +%% tqft.pdf, and +%% tqft.sty. +%% +%% +%% End of file `tqft.ins'. diff --git a/Master/texmf-dist/tex/latex/tqft/tqft.sty b/Master/texmf-dist/tex/latex/tqft/tqft.sty new file mode 100644 index 00000000000..490c95867b2 --- /dev/null +++ b/Master/texmf-dist/tex/latex/tqft/tqft.sty @@ -0,0 +1,753 @@ +%% +%% This is file `tqft.sty', +%% generated with the docstrip utility. +%% +%% The original source files were: +%% +%% tqft.dtx (with options: `package') +%% ---------------------------------------------------------------- +%% tqft --- a style file for drawing TQFT diagrams with TikZ/PGF +%% E-mail: stacey@math.ntnu.no +%% Released under the LaTeX Project Public License v1.3c or later +%% See http://www.latex-project.org/lppl.txt +%% ---------------------------------------------------------------- +%% +\NeedsTeXFormat{LaTeX2e} +\ProvidesPackage{tqft}[2011/05/03 v1.0 Tikz/PGF commands for drawing TQFT diagrams] +\RequirePackage{pgfkeys} +\RequirePackage{pgf} +\def\pgf@tqft@minus{-} +\let\pgf@tqft@upper\@empty +\let\pgf@tqft@lower\pgf@tqft@minus +\def\tqftset#1{\pgfkeys{/pgf/tqft/.cd,#1}} +\def\tqft@process#1#2{% + \edef\tqft@px{#1} + \edef\tqft@py{#2} + \pgf@process{ + \pgftransformreset + \let\tikz@transform=\pgfutil@empty + \expandafter\tikzset\expandafter{\tqft@transformation} + \tikz@transform + \pgfpointtransformed{\pgfqpoint{\tqft@px}{\tqft@py}} + } +} +\newdimen\tqft@xa +\newdimen\tqft@xb +\newdimen\tqft@c +\newdimen\tqft@ch +\newdimen\tqft@h +\newdimen\tqft@s +\newdimen\tqft@w +\newif\iftqft@within@node +\pgfkeys{ + /tikz/tqft/.style={% + /tikz/shape=tqft cobordism, + /pgf/tqft, + /tikz/every tqft + }, + /pgf/tqft/.unknown/.code={% + \let\tqft@searchname=\pgfkeyscurrentname% + \pgfkeysalso{% + /tikz/\tqft@searchname=#1 + } + }, + /tikz/every tqft/.style={}, + /tikz/tqft/.unknown/.code={% + \let\tqft@searchname=\pgfkeyscurrentname% + \pgfkeysalso{% + /pgf/tqft/\tqft@searchname=#1 + } + }, + /pgf/tqft/.is family, + /pgf/tqft, + boundary circle/.style={ + /tikz/shape=tqft boundary circle + }, + incoming boundary components/.initial=5, + outgoing boundary components/.initial=4, + offset/.initial=0, + cobordism height/.initial=2cm, + boundary separation/.initial=2cm, + circle width/.initial=10pt, + circle depth/.initial=5pt, + outer xsep/.initial=0pt, + outer ysep/.initial=0pt, + outer sep/.style={ + outer xsep=#1, + outer ysep=#1 + }, + flow/.code={% + \pgfkeys{/pgf/tqft/flow transformation/.expand twice/.expand once=\pgfkeysvalueof{/pgf/tqft/flow transformation #1}} + }, + flow transformation south/.initial={}, + flow transformation north/.initial={% + xscale=-1,rotate=180 + }, + flow transformation east/.initial={% + rotate=90,xscale=-1 + }, + flow transformation west/.initial={% + rotate=270 + }, + flow transformation/.initial={}, + view from/.is choice, + view from/incoming/.code={% + \let\pgf@tqft@upper\pgf@tqft@minus + \let\pgf@tqft@lower\@empty + }, + view from/outgoing/.code={% + \let\pgf@tqft@lower\pgf@tqft@minus + \let\pgf@tqft@upper\@empty + }, + boundary lower style contents/.initial={}, + boundary lower style/.code={% + \pgfkeys{/pgf/tqft/boundary lower style contents/.style={% + /tikz/.cd,#1 + } + } + }, + boundary style contents/.initial={}, + boundary style/.code={% + \pgfkeys{/pgf/tqft/boundary style contents/.style={% + /tikz/.cd,#1 + } + } + }, + boundary upper style contents/.initial={}, + boundary upper style/.code={% + \pgfkeys{/pgf/tqft/boundary upper style contents/.style={% + /tikz/.cd,#1 + } + } + }, + cobordism style contents/.initial={}, + cobordism style/.code={% + \pgfkeys{/pgf/tqft/cobordism style contents/.style={% + /tikz/.cd,#1% + } + } + }, + pair of pants/.style={ + /tikz/tqft, + incoming boundary components=1, + outgoing boundary components=2, + offset=-.5 + }, + /tikz/tqft pair of pants/.style={ + /pgf/tqft/pair of pants, + }, + reverse pair of pants/.style={ + /tikz/tqft, + incoming boundary components=2, + outgoing boundary components=1, + offset=.5 + }, + /tikz/tqft reverse pair of pants/.style={ + /pgf/tqft/reverse pair of pants, + }, + cylinder to prior/.style={ + /tikz/tqft, + incoming boundary components=1, + outgoing boundary components=1, + offset=-.5 + }, + /tikz/tqft cylinder to prior/.style={ + /pgf/tqft/cylinder to prior, + }, + cylinder to next/.style={ + /tikz/tqft, + incoming boundary components=1, + outgoing boundary components=1, + offset=.5 + }, + /tikz/tqft cylinder to next/.style={ + /pgf/tqft/cylinder to next, + }, + cylinder/.style={ + /tikz/tqft, + incoming boundary components=1, + outgoing boundary components=1 + }, + /tikz/tqft cylinder/.style={ + /pgf/tqft/cylinder, + }, + cup/.style={ + /tikz/tqft, + incoming boundary components=1, + outgoing boundary components=0 + }, + /tikz/tqft cup/.style={ + /pgf/tqft/cup, + }, + cap/.style={ + /tikz/tqft, + incoming boundary components=0, + outgoing boundary components=1 + }, + /tikz/tqft cap/.style={ + /pgf/tqft/cap, + }, +} +\pgfdeclareshape{tqft cobordism}{ + \savedmacro{\tqft@incoming}{\edef\tqft@incoming{\pgfkeysvalueof{/pgf/tqft/incoming boundary components}}} + \savedmacro{\tqft@outgoing}{\edef\tqft@outgoing{\pgfkeysvalueof{/pgf/tqft/outgoing boundary components}}} + \savedmacro{\tqft@offset}{\edef\tqft@offset{\pgfkeysvalueof{/pgf/tqft/offset}}} + \saveddimen{\tqft@height}{\pgf@x=\pgfkeysvalueof{/pgf/tqft/cobordism height}} + \saveddimen{\tqft@separation}{\pgf@x=\pgfkeysvalueof{/pgf/tqft/boundary separation}} + \saveddimen{\tqft@width}{\pgf@x=\pgfkeysvalueof{/pgf/tqft/circle width}} + \saveddimen{\tqft@depth}{\pgf@x=\pgfkeysvalueof{/pgf/tqft/circle depth}} + \saveddimen{\tqft@outerxsep}{\pgf@x=\pgfkeysvalueof{/pgf/tqft/outer xsep}} + \saveddimen{\tqft@outerysep}{\pgf@x=\pgfkeysvalueof{/pgf/tqft/outer ysep}} + \saveddimen{\tqft@control}{ + \pgfkeysgetvalue{/pgf/tqft/cobordism height}{\tqft@tempa} + \pgfkeysgetvalue{/pgf/tqft/circle depth}{\tqft@tempb} + \pgfmathsetlength{\pgf@x}{.5 * \tqft@tempa - 4 * \tqft@tempb} +} + \savedmacro{\tqft@transformation}{% + \pgfkeysgetvalue{/pgf/tqft/flow transformation}{\tqft@transformation} +} + \savedanchor{\tqft@start@incoming}{% + \pgfmathsetlength{\pgf@x}{-(max(\pgfkeysvalueof{/pgf/tqft/incoming boundary components} - 1,\pgfkeysvalueof{/pgf/tqft/outgoing boundary components} - 1 + \pgfkeysvalueof{/pgf/tqft/offset}) + min(0,\pgfkeysvalueof{/pgf/tqft/offset}) )*\pgfkeysvalueof{/pgf/tqft/boundary separation}/2} + \pgfmathsetlength{\pgf@y}{.5 * \pgfkeysvalueof{/pgf/tqft/cobordism height}} +} + \savedanchor{\tqft@start@outgoing}{% + \pgfmathsetlength{\pgf@x}{-(max(\pgfkeysvalueof{/pgf/tqft/incoming boundary components} - 1,\pgfkeysvalueof{/pgf/tqft/outgoing boundary components} - 1 + \pgfkeysvalueof{/pgf/tqft/offset}) + min(0,\pgfkeysvalueof{/pgf/tqft/offset})- 2*\pgfkeysvalueof{/pgf/tqft/offset})*\pgfkeysvalueof{/pgf/tqft/boundary separation}/2} + \pgfmathsetlength{\pgf@y}{-.5 * \pgfkeysvalueof{/pgf/tqft/cobordism height}} +} +\savedanchor{\tqft@textsize}{% + \pgf@y=-.5\ht\pgfnodeparttextbox% + \pgf@x=-.5\wd\pgfnodeparttextbox% +} + \anchor{centre}{\pgfpointorigin} + \anchor{center}{\pgfpointorigin} +\anchor{text}{ + \tqft@textsize +} +\anchor{north}{% + \pgf@ya=\tqft@height\relax + \pgf@yb=.5\pgf@ya + \advance\pgf@yb by \tqft@outerysep\relax + \tqft@process{0pt}{\the\pgf@yb} +} +\anchor{south}{% + \pgf@yb=\tqft@height\relax + \pgf@ya=.5\pgf@yb + \advance\pgf@ya by \tqft@outerysep\relax + \pgf@yb=-\pgf@ya + \tqft@process{0pt}{\the\pgf@yb} +} +\anchor{west}{% + \tqft@start@incoming + \pgf@xa=\pgf@x + \advance\pgf@xa by -\tqft@width + \pgf@ya=\pgf@y + \tqft@start@outgoing + \pgf@xb=\pgf@x + \advance\pgf@xb by -\tqft@width + \pgf@yb=\pgf@y + \pgf@xc=.5\pgf@xa + \advance\pgf@xc by .5\pgf@xb + \pgf@yc=.5\pgf@ya + \advance\pgf@yc by .5\pgf@yb + \advance\pgf@xc by -\tqft@outerxsep\relax + \tqft@process{\the\pgf@xc}{\the\pgf@yc} +} +\anchor{east}{% + \tqft@start@incoming + \pgf@xa=\pgf@x + \pgfmathsetlength{\pgf@xa}{\pgf@xa + (\tqft@incoming - 1) * \tqft@separation} + \advance\pgf@xa by \tqft@width\relax + \pgf@ya=\pgf@y + \tqft@start@outgoing + \pgf@xb=\pgf@x + \pgfmathsetlength{\pgf@xb}{\pgf@xb + (\tqft@outgoing - 1) * \tqft@separation} + \advance\pgf@xb by \tqft@width\relax + \pgf@yb=\pgf@y + \pgf@xc=.5\pgf@xa + \advance\pgf@xc by .5\pgf@xb + \pgf@yc=.5\pgf@ya + \advance\pgf@yc by .5\pgf@yb + \advance\pgf@xc by \tqft@outerxsep\relax + \tqft@process{\the\pgf@xc}{\the\pgf@yc} +} +\anchor{north west}{ + \tqft@start@incoming + \pgf@xc=\pgf@x + \pgf@yc=\pgf@y + \advance\pgf@xc by -\tqft@width\relax + \advance\pgf@yc by \tqft@outerysep\relax + \advance\pgf@xc by -\tqft@outerxsep\relax + \tqft@process{\the\pgf@xc}{\the\pgf@yc} +} +\anchor{south west}{ + \tqft@start@outgoing + \pgf@xc=\pgf@x + \pgf@yc=\pgf@y + \advance\pgf@xc by -\tqft@width\relax + \advance\pgf@yc by -\tqft@outerysep\relax + \advance\pgf@xc by -\tqft@outerxsep\relax + \tqft@process{\the\pgf@xc}{\the\pgf@yc} +} +\anchor{north east}{ + \tqft@start@incoming + \pgf@xc=\pgf@x + \pgfmathsetlength{\pgf@xc}{\pgf@xc + (\tqft@incoming - 1)*\tqft@separation} + \pgf@yc=\pgf@y + \advance\pgf@xc by \tqft@width\relax + \advance\pgf@yc by \tqft@outerysep\relax + \advance\pgf@xc by \tqft@outerxsep\relax + \tqft@process{\the\pgf@xc}{\the\pgf@yc} +} +\anchor{south east}{ + \tqft@start@outgoing + \pgf@xc=\pgf@x + \pgfmathsetlength{\pgf@xc}{\pgf@xc + (\tqft@outgoing - 1)*\tqft@separation} + \pgf@yc=\pgf@y + \advance\pgf@xc by \tqft@width\relax + \advance\pgf@yc by -\tqft@outerysep\relax + \advance\pgf@xc by \tqft@outerxsep\relax + \tqft@process{\the\pgf@xc}{\the\pgf@yc} +} +\expandafter\pgfutil@g@addto@macro\csname pgf@sh@s@tqft cobordism\endcsname{% + \c@pgf@counta\tqft@incoming\relax% + \pgfmathloop% + \ifnum\c@pgf@counta>0\relax% + \pgfutil@ifundefined{pgf@anchor@tqft cobordism@incoming boundary\space\the\c@pgf@counta}{% + \expandafter\xdef\csname pgf@anchor@tqft cobordism@incoming boundary\space\the\c@pgf@counta\endcsname{% + \noexpand\tqft@start@incoming + \noexpand\pgfmathsetlength{\noexpand\pgf@y}{\noexpand\pgf@y + \noexpand\tqft@outerysep} + \noexpand\pgfmathsetlength{\noexpand\pgf@x}{\noexpand\pgf@x + (\the\c@pgf@counta - 1) * \noexpand\tqft@separation} + \noexpand\tqft@process{\noexpand\the\noexpand\pgf@x}{\noexpand\the\noexpand\pgf@y} + } + }{\c@pgf@counta0\relax}% + \advance\c@pgf@counta-1\relax% + \repeatpgfmathloop% +} +\expandafter\pgfutil@g@addto@macro\csname pgf@sh@s@tqft cobordism\endcsname{% + \c@pgf@counta\tqft@outgoing\relax% + \pgfmathloop% + \ifnum\c@pgf@counta>0\relax% + \pgfutil@ifundefined{pgf@anchor@tqft cobordism@outgoing boundary\space\the\c@pgf@counta}{% + \expandafter\xdef\csname pgf@anchor@tqft cobordism@outgoing boundary\space\the\c@pgf@counta\endcsname{% + \noexpand\tqft@start@outgoing + \noexpand\pgfmathsetlength{\noexpand\pgf@y}{\noexpand\pgf@y - \noexpand\tqft@outerysep} + \noexpand\pgfmathsetlength{\noexpand\pgf@x}{\noexpand\pgf@x + (\the\c@pgf@counta - 1) * \noexpand\tqft@separation} + \noexpand\tqft@process{\noexpand\the\noexpand\pgf@x}{\noexpand\the\noexpand\pgf@y} + } + }{\c@pgf@counta0\relax}% + \advance\c@pgf@counta-1\relax% + \repeatpgfmathloop% +} +\expandafter\pgfutil@g@addto@macro\csname pgf@sh@s@tqft cobordism\endcsname{% + \c@pgf@counta\tqft@incoming\relax% + \advance\c@pgf@counta-1\relax + \pgfmathloop% + \ifnum\c@pgf@counta>0\relax% + \pgfutil@ifundefined{pgf@anchor@tqft cobordism@after incoming boundary\space\the\c@pgf@counta}{% + \expandafter\xdef\csname pgf@anchor@tqft cobordism@after incoming boundary\space\the\c@pgf@counta\endcsname{% + \noexpand\tqft@start@incoming + \noexpand\pgfmathsetlength{\noexpand\pgf@y}{.25 * \noexpand\pgf@y +.75 * \noexpand\tqft@control + \noexpand\tqft@outerysep} + \noexpand\pgfmathsetlength{\noexpand\pgf@x}{\noexpand\pgf@x + (\the\c@pgf@counta - .5) * \noexpand\tqft@separation} + \noexpand\tqft@process{\noexpand\the\noexpand\pgf@x}{\noexpand\the\noexpand\pgf@y} + } + }{\c@pgf@counta0\relax}% + \advance\c@pgf@counta-1\relax% + \repeatpgfmathloop% +} +\expandafter\pgfutil@g@addto@macro\csname pgf@sh@s@tqft cobordism\endcsname{% + \c@pgf@counta\tqft@outgoing\relax% + \advance\c@pgf@counta-1\relax + \pgfmathloop% + \ifnum\c@pgf@counta>0\relax% + \pgfutil@ifundefined{pgf@anchor@tqft cobordism@after outgoing boundary\space\the\c@pgf@counta}{% + \expandafter\xdef\csname pgf@anchor@tqft cobordism@after outgoing boundary\space\the\c@pgf@counta\endcsname{% + \noexpand\tqft@start@outgoing + \noexpand\pgfmathsetlength{\noexpand\pgf@y}{.25 * \noexpand\pgf@y -.75 * \noexpand\tqft@control - \noexpand\tqft@outerysep} + \noexpand\pgfmathsetlength{\noexpand\pgf@x}{\noexpand\pgf@x + (\the\c@pgf@counta - .5) * \noexpand\tqft@separation} + \noexpand\tqft@process{\noexpand\the\noexpand\pgf@x}{\noexpand\the\noexpand\pgf@y} + } + }{\c@pgf@counta0\relax}% + \advance\c@pgf@counta-1\relax% + \repeatpgfmathloop% +} + \backgroundpath{ + \let\tikz@transform=\pgfutil@empty + \expandafter\tikzset\expandafter{\tqft@transformation} + \tikz@transform + \pgfmathsetlength{\tqft@s}{\tqft@separation} + \pgfmathsetlength{\tqft@w}{2*\tqft@width} +\tqft@start@incoming +\tqft@xa=\pgf@x + \advance\tqft@xa by -.5\tqft@w\relax +\tqft@h=\pgf@y + \tqft@xb=\tqft@xa + \advance\tqft@xb by \tqft@w\relax +\tqft@c=\tqft@control\relax + \ifnum\tqft@incoming>0 + \pgfpathmoveto{\pgfqpoint{\tqft@xa}{\tqft@h}} + \pgfpatharc{\pgf@tqft@upper180}{0}{\tqft@width and \tqft@depth} + \ifnum\tqft@incoming>1 + \foreach \tqft@k in {2,...,\tqft@incoming} { + \advance\tqft@xa by \tqft@k\tqft@s + \advance\tqft@xb by \tqft@k\tqft@s + \advance\tqft@xb by -2\tqft@s + \advance\tqft@xa by -\tqft@s + \pgfpathcurveto{\pgfqpoint{\tqft@xb}{\tqft@c}}{\pgfqpoint{\tqft@xa}{\tqft@c}}{\pgfqpoint{\tqft@xa}{\tqft@h}} + \pgfpatharc{\pgf@tqft@upper180}{0}{\tqft@width and \tqft@depth} + } + \fi + \ifnum\tqft@outgoing=0 + \advance\tqft@xb by \tqft@incoming\tqft@s + \advance\tqft@xb by -\tqft@s + \pgfmathsetlength{\tqft@ch}{min(0,max(-\tqft@h,\tqft@h - (\tqft@h - \tqft@c) * ((abs(\tqft@xb - \tqft@xa) - \tqft@w)/\tqft@s + 1)))} + \pgfpathcurveto{\pgfqpoint{\tqft@xb}{\tqft@ch}}{\pgfqpoint{\tqft@xa}{\tqft@ch}}{\pgfqpoint{\tqft@xa}{\tqft@h}} + \fi + \fi + \ifnum\tqft@outgoing>0 + \advance\tqft@xb by \tqft@incoming\tqft@s + \advance\tqft@xb by -\tqft@s + \pgfmathsetlength{\tqft@xa}{\tqft@xa + (\tqft@outgoing - 1 + \tqft@offset) * \tqft@separation + 2*\tqft@width} + \ifnum\tqft@incoming>0 + \pgfmathsetlength{\tqft@ch}{min(0,max(-\tqft@h,\tqft@h - (\tqft@h - \tqft@c) * ((abs(\tqft@xb - \tqft@xa) - \tqft@w)/\tqft@s + 1)))} + \pgfpathcurveto{\pgfqpoint{\tqft@xb}{\tqft@ch}}{\pgfqpoint{\tqft@xa}{-\tqft@ch}}{\pgfqpoint{\tqft@xa}{-\tqft@h}} + \else + \pgfpathmoveto{\pgfqpoint{\tqft@xa}{-\tqft@h}} + \fi + \tqft@xb=\tqft@xa + \advance\tqft@xb by -\tqft@w + \pgfpatharc{0}{\pgf@tqft@upper180}{\tqft@width and \tqft@depth} + \ifnum\tqft@outgoing>1 + \foreach \tqft@k in {2,...,\tqft@outgoing} { + \advance\tqft@xa by -\tqft@k\tqft@s + \advance\tqft@xb by -\tqft@k\tqft@s + \advance\tqft@xb by 2\tqft@s + \advance\tqft@xa by \tqft@s + \pgfpathcurveto{\pgfqpoint{\tqft@xb}{-\tqft@c}}{\pgfqpoint{\tqft@xa}{-\tqft@c}}{\pgfqpoint{\tqft@xa}{-\tqft@h}} + \pgfpatharc{0}{\pgf@tqft@upper180}{\tqft@width and \tqft@depth} + } + \fi + \advance\tqft@xb by -\tqft@outgoing\tqft@s + \advance\tqft@xb by \tqft@s + \ifnum\tqft@incoming>0 + \pgfmathsetlength{\tqft@xa}{\tqft@xa - (\tqft@outgoing -1 + \tqft@offset) * \tqft@separation - 2*\tqft@width} + \pgfmathsetlength{\tqft@ch}{min(0,max(-\tqft@h,\tqft@h - (\tqft@h - \tqft@c) * ((abs(\tqft@xb - \tqft@xa) - \tqft@w)/\tqft@s + 1)))} + \pgfpathcurveto{\pgfqpoint{\tqft@xb}{-\tqft@ch}}{\pgfqpoint{\tqft@xa}{\tqft@ch}}{\pgfqpoint{\tqft@xa}{\tqft@h}} + \else + \pgfmathsetlength{\tqft@ch}{min(0,max(-\tqft@h,\tqft@h - (\tqft@h - \tqft@c) * ((abs(\tqft@xb - \tqft@xa) - \tqft@w)/\tqft@s + 1)))} + \pgfpathcurveto{\pgfqpoint{\tqft@xb}{-\tqft@ch}}{\pgfqpoint{\tqft@xa}{-\tqft@ch}}{\pgfqpoint{\tqft@xa}{-\tqft@h}} + \fi + \fi + \pgfpathclose + } + \behindbackgroundpath{ + \let\tikz@transform=\pgfutil@empty + \expandafter\tikzset\expandafter{\tqft@transformation} + \tikz@transform + \pgfmathsetlength{\tqft@s}{\tqft@separation} + \pgfmathsetlength{\tqft@w}{2*\tqft@width} + \pgfmathsetlength{\tqft@xa}{-(max(\tqft@incoming - 1,\tqft@outgoing - 1 + \tqft@offset) + min(0,\tqft@offset) + 2)*\tqft@separation/2} + \pgfmathsetlength{\tqft@h}{.5 * \tqft@height} + { + \tikz@mode@fillfalse% + \tikz@mode@drawfalse% + \let\tikz@mode=\pgfutil@empty + \let\tikz@options=\pgfutil@empty + \tqftset{boundary style contents} + \tikz@mode + \tikz@options + \ifnum\tqft@incoming>0 + \foreach \tqft@k in {1,...,\tqft@incoming} { + \advance\tqft@xa by \tqft@k\tqft@s + \pgfpathellipse{\pgfqpoint{\tqft@xa}{\tqft@h}}{\pgfqpoint{\tqft@width}{0pt}}{\pgfqpoint{0pt}{\tqft@depth}} + } + \fi + \ifnum\tqft@outgoing>0 + \pgfmathsetlength{\tqft@xa}{\tqft@xa + (\tqft@outgoing + \tqft@offset + 1) * \tqft@separation} + \foreach \tqft@k in {1,...,\tqft@outgoing} { + \advance\tqft@xa by -\tqft@k\tqft@s + \pgfpathellipse{\pgfqpoint{\tqft@xa}{-\tqft@h}}{\pgfqpoint{\tqft@width}{0pt}}{\pgfqpoint{0pt}{\tqft@depth}} + } + \fi + \edef\tikz@temp{\noexpand\pgfusepath{% + \iftikz@mode@fill fill,\fi% + \iftikz@mode@draw draw\fi% + }}% + \tikz@temp + } + { + \tikz@mode@fillfalse% + \tikz@mode@drawfalse% + \let\tikz@mode=\pgfutil@empty + \let\tikz@options=\pgfutil@empty + \tqftset{boundary lower style contents} + \tikz@mode + \tikz@options + \advance\tqft@xa by .5\tqft@w + \ifnum\tqft@incoming>0 + \foreach \tqft@k in {1,...,\tqft@incoming} { + \advance\tqft@xa by \tqft@k\tqft@s + \pgfpathmoveto{\pgfqpoint{\tqft@xa}{\tqft@h}} + \pgfpatharc{0}{\pgf@tqft@lower180}{\tqft@width and \tqft@depth} + } + \fi + \ifnum\tqft@outgoing>0 + \pgfmathsetlength{\tqft@xa}{\tqft@xa + (\tqft@outgoing + \tqft@offset + 1) * \tqft@separation} + \foreach \tqft@k in {1,...,\tqft@outgoing} { + \advance\tqft@xa by -\tqft@k\tqft@s + \pgfpathmoveto{\pgfqpoint{\tqft@xa}{-\tqft@h}} + \pgfpatharc{0}{\pgf@tqft@lower180}{\tqft@width and \tqft@depth} + } + \fi + \edef\tikz@temp{\noexpand\pgfusepath{% + \iftikz@mode@fill fill,\fi% + \iftikz@mode@draw draw\fi% + }}% + \tikz@temp + } + } + \beforebackgroundpath{ + \pgfmathsetlength{\tqft@s}{\tqft@separation} + \pgfmathsetlength{\tqft@w}{2*\tqft@width} + \pgfmathsetlength{\tqft@xa}{-(max(\tqft@incoming - 1,\tqft@outgoing - 1 + \tqft@offset) + min(0,\tqft@offset))*\tqft@s/2 - \tqft@width} + \tqft@xb=\tqft@xa + \advance\tqft@xb by \tqft@w +\tqft@c=\tqft@control\relax + \pgfmathsetlength{\tqft@h}{.5 * \tqft@height} + { + \tikz@mode@fillfalse% + \tikz@mode@drawfalse% + \let\tikz@mode=\pgfutil@empty + \let\tikz@options=\pgfutil@empty + \tqftset{cobordism style contents} + \tikz@mode + \tikz@options + \ifnum\tqft@incoming>0 + \ifnum\tqft@incoming>1 + \foreach \tqft@k in {2,...,\tqft@incoming} { + \advance\tqft@xa by \tqft@k\tqft@s + \advance\tqft@xb by \tqft@k\tqft@s + \advance\tqft@xb by -2\tqft@s + \advance\tqft@xa by -\tqft@s + \pgfpathmoveto{\pgfqpoint{\tqft@xb}{\tqft@h}} + \pgfpathcurveto{\pgfqpoint{\tqft@xb}{\tqft@c}}{\pgfqpoint{\tqft@xa}{\tqft@c}}{\pgfqpoint{\tqft@xa}{\tqft@h}} + } + \fi + \ifnum\tqft@outgoing=0 + \advance\tqft@xb by \tqft@incoming\tqft@s + \advance\tqft@xb by -\tqft@s + \pgfmathsetlength{\tqft@ch}{min(0,max(-\tqft@h,\tqft@h - (\tqft@h - \tqft@c) * ((abs(\tqft@xb - \tqft@xa) - \tqft@w)/\tqft@s + 1)))} + \pgfpathmoveto{\pgfqpoint{\tqft@xb}{\tqft@h}} + \pgfpathcurveto{\pgfqpoint{\tqft@xb}{\tqft@ch}}{\pgfqpoint{\tqft@xa}{\tqft@ch}}{\pgfqpoint{\tqft@xa}{\tqft@h}} + \fi + \fi + \ifnum\tqft@outgoing>0 + \advance\tqft@xb by \tqft@incoming\tqft@s + \advance\tqft@xb by -\tqft@s + \pgfmathsetlength{\tqft@xa}{\tqft@xa + (\tqft@outgoing - 1 + \tqft@offset) * \tqft@separation + 2*\tqft@width} + \ifnum\tqft@incoming>0 + \pgfmathsetlength{\tqft@ch}{min(0,max(-\tqft@h,\tqft@h - (\tqft@h - \tqft@c) * ((abs(\tqft@xb - \tqft@xa) - \tqft@w)/\tqft@s + 1)))} + \pgfpathmoveto{\pgfqpoint{\tqft@xb}{\tqft@h}} + \pgfpathcurveto{\pgfqpoint{\tqft@xb}{\tqft@ch}}{\pgfqpoint{\tqft@xa}{-\tqft@ch}}{\pgfqpoint{\tqft@xa}{-\tqft@h}} + \else + \pgfpathmoveto{\pgfqpoint{\tqft@xa}{-\tqft@h}} + \fi + \tqft@xb=\tqft@xa + \advance\tqft@xb by -\tqft@w + \pgfpathmoveto{\pgfqpoint{\tqft@xb}{-\tqft@h}} + \ifnum\tqft@outgoing>1 + \foreach \tqft@k in {2,...,\tqft@outgoing} { + \advance\tqft@xa by -\tqft@k\tqft@s + \advance\tqft@xb by -\tqft@k\tqft@s + \advance\tqft@xb by 2\tqft@s + \advance\tqft@xa by \tqft@s + \pgfpathcurveto{\pgfqpoint{\tqft@xb}{-\tqft@c}}{\pgfqpoint{\tqft@xa}{-\tqft@c}}{\pgfqpoint{\tqft@xa}{-\tqft@h}} + \advance\tqft@xa by -\tqft@w + \pgfpathmoveto{\pgfqpoint{\tqft@xa}{-\tqft@h}} + } + \fi + \advance\tqft@xb by -\tqft@outgoing\tqft@s + \advance\tqft@xb by \tqft@s + \ifnum\tqft@incoming>0 + \pgfmathsetlength{\tqft@xa}{\tqft@xa - (\tqft@outgoing -1 + \tqft@offset) * \tqft@separation - 2*\tqft@width} + \pgfmathsetlength{\tqft@ch}{min(0,max(-\tqft@h,\tqft@h - (\tqft@h - \tqft@c) * ((abs(\tqft@xb - \tqft@xa) - \tqft@w)/\tqft@s + 1)))} + \pgfpathcurveto{\pgfqpoint{\tqft@xb}{-\tqft@ch}}{\pgfqpoint{\tqft@xa}{\tqft@ch}}{\pgfqpoint{\tqft@xa}{\tqft@h}} + \else + \pgfmathsetlength{\tqft@ch}{min(0,max(-\tqft@h,\tqft@h - (\tqft@h - \tqft@c) * ((abs(\tqft@xb - \tqft@xa) - \tqft@w)/\tqft@s + 1)))} + \pgfpathcurveto{\pgfqpoint{\tqft@xb}{-\tqft@ch}}{\pgfqpoint{\tqft@xa}{-\tqft@ch}}{\pgfqpoint{\tqft@xa}{-\tqft@h}} + \fi + \fi + \edef\tikz@temp{\noexpand\pgfusepath{% + \iftikz@mode@fill fill,\fi% + \iftikz@mode@draw draw\fi% + }}% + \tikz@temp +} + { +\let\tqft@bdry@path=\pgfutil@empty +\let\tqft@bdry@node@path=\pgfutil@empty +\pgfsyssoftpath@setcurrentpath{\tqft@bdry@path} + \tikz@mode@fillfalse% + \tikz@mode@drawfalse% + \let\tikz@mode=\pgfutil@empty + \let\tikz@options=\pgfutil@empty + \tqftset{boundary upper style contents} + \tikz@mode + \tikz@options + \advance\tqft@xa by -\tqft@s + \advance\tqft@xa by \tqft@w + \ifnum\tqft@incoming>0 + \foreach \tqft@k in {1,...,\tqft@incoming} { + \advance\tqft@xa by \tqft@k\tqft@s + \pgfpathmoveto{\pgfqpoint{\tqft@xa}{\tqft@h}} + \pgfpatharc{0}{\pgf@tqft@upper180}{\tqft@width and \tqft@depth} + \ifx\tikz@fig@name\pgfutil@empty + \else + { + \advance\tqft@xa by -\tqft@width + \pgftransformshift{\pgfqpoint{\tqft@xa}{\tqft@h}} + \tqft@within@nodetrue + \pgfsyssoftpath@getcurrentpath{\tqft@bdry@path} + \pgfsyssoftpath@setcurrentpath{\tqft@bdry@node@path} + \pgfnode{tqft boundary circle}{centre}{}{\tikz@fig@name\space incoming \tqft@k}{} + \pgfsyssoftpath@getcurrentpath{\tqft@bdry@node@path} + \pgfsyssoftpath@setcurrentpath{\tqft@bdry@path} + } + \fi + } + \fi + \ifnum\tqft@outgoing>0 + \pgfmathsetlength{\tqft@xa}{\tqft@xa + (\tqft@outgoing + \tqft@offset + 1) * \tqft@separation} + \foreach \tqft@k in {1,...,\tqft@outgoing} { + \advance\tqft@xa by -\tqft@k\tqft@s + \pgfpathmoveto{\pgfqpoint{\tqft@xa}{-\tqft@h}} + \pgfpatharc{0}{\pgf@tqft@upper180}{\tqft@width and \tqft@depth} + \ifx\tikz@fig@name\pgfutil@empty + \else + { + \pgfmathtruncatemacro{\tqft@l}{\tqft@outgoing + 1 - \tqft@k} + \advance\tqft@xa by -\tqft@width + \pgftransformshift{\pgfqpoint{\tqft@xa}{-\tqft@h}} + \tqft@within@nodetrue + \pgfsyssoftpath@getcurrentpath{\tqft@bdry@path} + \pgfsyssoftpath@setcurrentpath{\tqft@bdry@node@path} + \pgfnode{tqft boundary circle}{centre}{}{\tikz@fig@name\space outgoing \tqft@l}{} + \pgfsyssoftpath@getcurrentpath{\tqft@bdry@node@path} + \pgfsyssoftpath@setcurrentpath{\tqft@bdry@path} + } + \fi + } + \fi + \edef\tikz@temp{\noexpand\pgfusepath{% + \iftikz@mode@fill fill,\fi% + \iftikz@mode@draw draw\fi% + }}% + \tikz@temp + } + } +} +\pgfdeclareshape{tqft boundary circle}{ + \saveddimen{\tqft@height}{\pgf@x=\pgfkeysvalueof{/pgf/tqft/cobordism height}} + \saveddimen{\tqft@separation}{\pgf@x=\pgfkeysvalueof{/pgf/tqft/boundary separation}} + \saveddimen{\tqft@width}{\pgf@x=\pgfkeysvalueof{/pgf/tqft/circle width}} + \saveddimen{\tqft@depth}{\pgf@x=\pgfkeysvalueof{/pgf/tqft/circle depth}} + \savedmacro{\tqft@transformation}{% + \iftqft@within@node + \let\tqft@transformation=\pgfutil@empty + \else + \pgfkeysgetvalue{/pgf/tqft/flow transformation}{\tqft@transformation} + \fi +} + \savedanchor{\tqft@centre}{% + \pgfpointorigin} +\savedanchor{\tqft@textsize}{% + \pgf@y=-.5\ht\pgfnodeparttextbox% + \pgf@x=-.5\wd\pgfnodeparttextbox% +} + \anchor{centre}{\tqft@centre} + \anchor{center}{\tqft@centre} +\anchor{text}{ + \tqft@textsize +} + \anchor{next}{% + \tqft@process{\tqft@separation}{0pt}}% + \anchor{prior}{% + \tqft@process{-\tqft@separation}{0pt}}% + \anchor{above}{% + \tqft@process{0pt}{\tqft@height}}% + \anchor{below}{% + \tqft@process{0pt}{-\tqft@height}}% + \anchorborder{ + \tqft@process{\the\pgf@x}{\the\pgf@y} + \edef\tqft@marshal{% + \noexpand\pgfpointborderellipse + {\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}} + {\noexpand\pgfqpoint{\tqft@width}{\tqft@depth}} + }% + \tqft@marshal + \tqft@process{\the\pgf@x}{\the\pgf@y} +} + \backgroundpath{ + \let\tikz@transform=\pgfutil@empty + \expandafter\tikzset\expandafter{\tqft@transformation} + \tikz@transform + \pgfpathellipse{\pgfqpoint{0pt}{0pt}}{\pgfqpoint{\tqft@width}{0pt}}{\pgfqpoint{0pt}{\tqft@depth}} + } + \beforebackgroundpath{ + \iftqft@within@node + \else + \tikz@mode@fillfalse% + \tikz@mode@drawfalse% + \let\tikz@mode=\pgfutil@empty + \let\tikz@options=\pgfutil@empty + { + \pgfsys@beginscope + \tqftset{boundary lower style contents} + \tikz@mode + \tikz@options + \pgfpathmoveto{\pgfqpoint{\tqft@width}{0pt}} + \pgfpatharc{0}{\pgf@tqft@lower180}{\tqft@width and \tqft@depth} + \edef\tikz@temp{\noexpand\pgfusepath{% + \iftikz@mode@fill fill,\fi% + \iftikz@mode@draw draw\fi% + }}% + \tikz@temp + \pgfsys@endscope + } + { + \pgfsys@beginscope + \tqftset{boundary upper style contents} + \tikz@mode + \tikz@options + \pgfpathmoveto{\pgfqpoint{\tqft@width}{0pt}} + \pgfpatharc{0}{\pgf@tqft@upper180}{\tqft@width and \tqft@depth} + \edef\tikz@temp{\noexpand\pgfusepath{% + \iftikz@mode@fill fill,\fi% + \iftikz@mode@draw draw\fi% + }}% + \tikz@temp + \pgfsys@endscope + } + \fi + } + } + +%% +%% Copyright (C) 2011 by Andrew Stacey <stacey@math.ntnu.no> +%% +%% This work may be distributed and/or modified under the +%% conditions of the LaTeX Project Public License (LPPL), either +%% version 1.3c of this license or (at your option) any later +%% version. The latest version of this license is in the file: +%% +%% http://www.latex-project.org/lppl.txt +%% +%% This work is "maintained" (as per LPPL maintenance status) by +%% Andrew Stacey. +%% +%% This work consists of the file tqft.dtx +%% and the derived files tqft.ins, +%% tqft.pdf, and +%% tqft.sty. +%% +%% +%% End of file `tqft.sty'. |