[Tex/LaTex] Topological Quantum Field Theory diagrams with pstricks or tikz

pstrickstikz-pgf

This question led to a new package:
tqft — Blog: The TQFT Package

I'm going to write a brief note about topological quantum field theories, so I need to draw some copies of the "pair of pants"… I'm wondering if there's a simple way to obtain such an object with tikz or PStricks; the challenge is that I would like to create a "modular" set of objects to assembly in a second moment: drawn the pair of pants, and another object, I don't want to recreate everything to obtain the juxtaposition of the two.

Edit: this is what I want to obtain.

enter image description here

Best Answer

Update (2011-05-06): A reworked version of this code is available for download at: http://bazaar.launchpad.net/~tex-sx/tex-sx/development/files as the file tqft.dtx. To generate the package file and the documentation, run pdflatex tqft.dtx. This file is part of the package proposed at What are your favourite TikZ/PGF answers? which will be released on CTAN in due course.


What follows is an example, based on a previous version of this answer. I hope that I've edited it correctly to reflect the current methodology of the package, but if there's a conflict, refer to the package documentation.

Right, here's a more comprehensive solution. The main hassle was setting things up so that one can change the direction of the "flow" of the cobordisms. That's done by a key tqft/flow which, at the moment, can take one of the directions north, south, east, and west (default is south). This rotates stuff so that the incoming to outgoing directions are in the right direction. It also reflects things so that the boundary numbering is always from top to bottom or from left to right.

The node types are, with the anchors that they define (all define centre and center so I haven't listed them) (update the anchors have been reworked a little so that all now define incoming boundary n and outgoing boundary n for n a reasonable integer (less than 10 by default)):

  • tqft/pair of pants: incoming boundary 1, outgoing boundary 1, outgoing boundary 2
  • tqft/reverse pair of pants: incoming boundary 1, incoming boundary 2, outgoing boundary 1
  • tqft/cylinder to prior: incoming boundary 1, outgoing boundary 1; this is a cylinder that is skewed in so that the outgoing boundary is shifted towards the lower numbered boundary components by just the right amount to fit with a tqft/pair of pants
  • tqft/cylinder to next: incoming boundary 1, outgoing boundary 1; this is a cylinder that is skewed in so that the outgoing boundary is shifted towards the higher numbered boundary components by just the right amount to fit with a tqft/pair of pants
  • tqft/cylinder: incoming boundary 1, outgoing boundary 1; this is a straight cylinder
  • tqft/cap: this "caps off" a boundary component
  • tqft/cup: this starts a boundary component

Global keys:

  • tqft/flow: see above
  • tqft/cobordism height: this is the separation between the levels in the cobordism (aka the height of the pair of pants, etc)
  • tqft/boundary separation: this is the separation between the centres of the boundary components (aka the width of the pair of pants, etc)
  • tqft/circle width: the boundary components are ellipses, this sets the horizontal axis (relative to the cobordism)
  • tqft/circle depth: this sets the vertical axis of the boundary ellipses

And here's the code:

\documentclass{article}
\usepackage{tikz}
\usepackage{tqft}
\begin{document}
\begin{tikzpicture}[tqft/flow=east]
\node[tqft/pair of pants,draw] (a) {};
\node[tqft/reverse pair of pants,draw,anchor=incoming boundary 1] (b) at (a.outgoing boundary 2) {};
\node[tqft/cylinder to next,draw,anchor=incoming boundary 1] (c) at (a.outgoing boundary 1) {};
\node[tqft/cylinder to next,draw,anchor=outgoing boundary 1] (e) at (b.incoming boundary 2) {};
\path (b.outgoing boundary 1) ++(1.5,1) node[font=\Huge] {\(=\)};
\path (b.outgoing boundary 1) ++(3,0) node[tqft/reverse pair of pants,draw,anchor=incoming boundary 2] (e) {};
\node[tqft/pair of pants,draw,anchor=incoming boundary 1] (f) at (e.outgoing boundary 1) {};
\end{tikzpicture}
\end{document}

And here's the result:

tqft with tikz