How to draw knots with Latex?

Knotinfo has .png files of all knots of 12 crossings or less.
http://www.indiana.edu/~knotinfo


Update 2021-02-07: I've now uploaded an extension to my spath3 package which provides yet another way to draw knots and links using TikZ. (This isn't a replacement for the original knots package, that is still being maintained.)

Here's some example code and rendering, for more see the package documentation.

\documentclass{article}
%\url{https://tex.stackexchange.com/q/17181/86}

\usepackage{tikz}
\usetikzlibrary{spath3, intersections, hobby}
\begin{document}
\begin{tikzpicture}[
  use Hobby shortcut,
  every trefoil component/.style={ultra thick, draw, red},
  trefoil component 1/.style={blue},
]
\path[spath/save=trefoil] ([closed]90:2) foreach \k in {1,...,3} { .. (-30+\k*240:.5) .. (90+\k*240:2) } (90:2);
\tikzset{spath/knot={trefoil}{8pt}{1,3,5}}
\end{tikzpicture}
\end{document}

trefoil with one component blue


Update 2013-04-22: I've now uploaded a TikZ library to CTAN expressly for the purpose of drawing knots. It is already in MikTeX (according to CTAN), TeXLive might have to wait until TL2013 has been released. It is released as part of the spath3 library. Here's the link to CTAN. The hobby package also contains some useful code for drawing knots. For drawing braids, there's the braids package. And here's a short blog post I wrote explaining the variety of methods, and a slightly more detailed tutorial. The package was inspired by a question on TeX-SX and now has its own tag tikz-knots.


This is a follow-up to Niels' answer, namely to use TikZ. I've recently had occasion to draw a few knots and links using TikZ and have quite a workable system. I'll not post code here (ask by email or on http://tex.stackexchange.com if you want). Using it, I can produce SVGs (as evidenced by some nLab pages: http://ncatlab.org/nlab/show/Borromean+link, http://ncatlab.org/nlab/show/Whitehead+link, and some others) as well as PDFs, PNGs, and so forth. As an example, here's the trefoil knot:

(source: Wayback Machine)


I would discourage the method of drawing them by hand and importing them via scanner etc. as they won't be scalable. Many journals would be unhappy with such an image, and in any case it would look bad and make your pdf filesize huge. Instead, I am a big fan of the free program Inkscape, which you can get for unix/linux and also mac with the X server, and probably Windows, if you're into that kind of thing. It produces pdf files, in which one can zoom in on the curves and they look nice. Also they print quickly, whereas if you include an image file in a pdf it will take a long time to print on a laser printer (which prefers postscript).

Inkscape is similar to xy-pic, only it's very easy to use. You can start by drawing the knots free hand using the pen tool. Then you click a tool which highlights all the data points of a line segment, and you can start deleting them (alternatively, you can use the command "Path->Simplify"). It also has two extra compatibilities with latex: First, you can get a script to actually run snippets of latex in inkscape to make fonts and such for labels. Alternatively, you can just compile the font you want into a pdf and import it. It will import in a scalable way. Then when you're done you export to pdf, and you can include it back into a new pdf if you are using pdflatex to compile your .tex document. If you use ordinary latex, then you need to save it to .eps; I prefer the former.

Since they only have much fancier screenshots on their homepage, here is a paper with diagrams done in Inkscape.

http://arxiv.org/pdf/0908.3013