How to draw knots with Latex?  I am writing an exam for my students, and the topic is intro knots theory. I have no idea how to put knots into the file, but I know many MO users who can draw amazing diagrams in their papers. 
Can someone please provide some hints on what can be used, preferably with some example codes? I do not need complicated diagrams, just some simple knots and links with few crossings. Thanks in advance. 
 A: *

*I would seriously consider the photographic technology suggested by Kevin Buzzard in the comments, if you happen to have a decent digital camera handy (and if you trust your drawing skills). Or, as Peter Shor suggests in the comments, you can use a scanner if you have one handy.† Multiple 2½-dimension diagrams, without tons of regularity, are not fun to draw on a computer --- unless perhaps you have access to touch-screens.

*If you want special effects or other benefits of computer-aided graphics badly enough, you can do it directly in LaTeX with TiKZ. I recommend their fairly comprehensive and reasonably readable manual. For sufficiently complicated diagrams, I find that drawing diagrams with TiKZ is relatively painless, and more robust to changes (e.g. in how you want lines to curve, or the positions of nodes if you have them) than ones drawn in xfig. 
The over/under relationships can be achieved by drawing the "over" curve-segments twice: once with a thicker white line (or a line matching the background color), and once with a thinner line corresponding to the color of the knot. If you use the PGF extensions (technology which accompanies the TiKZ package), you can quite probably do colorful things such as gradients along the knot curve, if this serves to emphasize features of your knot diagrams.
Good luck with your exam!


†Added after Peter's comment — my workplace at the time of my original post has the odd feature that it is more likely to have convenient cameras than convenient scanners.
A: Aaron Lauda has a nice description using the package XY-pic here.  There are commands that generate pieces of knots (such as crossings in various orientations), although I prefer just using the \crv "curve" command to make splines.
A: The knot atlas gang have a mathematica package for this - you paste the pictures it produces.
A: Here's a, perhaps silly, suggestion that perhaps isn't quite what you're looking for:
Draw them properly in 3D using something like Blender, and then render it to a 2D picture.
The second animation on this page is of a variant on the borromean rings.
A: Have a look at the knot program by Kodama:
http://www.math.kobe-u.ac.jp/HOME/kodama/knot.html
You can draw and manipulate knot diagrams using the mouse and there is an option to export the figures to pstricks.  It also comes with all the prime knots of up to 10 crossings.
A: Knotinfo has .png files of all knots of 12 crossings or less.
http://www.indiana.edu/~knotinfo
A: EDIT - Following the suggestions of several people I have, somewhat painfully, switched from what is described below to using just pdflatex and pinlabel.  I still use xfig for figures, exporting them to both eps and pdf to make pinlabel happy.
Old answer - 
I draw knots in a different program (xfig), save them as eps files, and then include them via 
\begin{figure}[htbp]
    $$\begin{array}{c}
    \epsfig{file=Figures/foo.eps, width = 10 cm} \\
    \epsfig{file=Figures/bar.eps, width = 10 cm}
    \end{array}$$
    \caption{Top: A picture of a foo. Bottom: a bar.}
    \label{Fig:FooBar}
    \end{figure}

Then latex, dvips -o, ps2pdf produces the pdf file. This technique allows one to use psfrag to add labels inside of figures. 
A: I didn't really like Simon's link. The tutorial there seems to be based solely on drawing the curves by specifying coordinates. I find that a more, say, tabular or rigidly based approach is much easier to work with.
There's a good xy-pic tutorial for creating knots at http://lf.starlogik.de/res/XYPic-Knot-Intro.pdf
There's a great xymatrix tutorial at http://www.ctan.org/tex-archive/macros/generic/diagrams/xypic/xy/doc/xyguide.pdf
There are only 10 pages to read in each manual and you'll have mastered them both. You could get away without reading the xymatrix tutorial, but I'd reccommend reading it because it goes more in-depth into some of the parameter modifiers that aren't actually explained in the knot manual.
A: 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}



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)
A: You can draw knots with metapost:
\documentclass{article}
\usepackage{mpgraphics}
\begin{document}
    \begin{mpdisplay}
      for i=0 step 1 until 360:
        pair P;
        P = 2cm* (sind(2*i), cosd(3*i));
        fill fullcircle scaled 4mm shifted P withcolor white;
        draw fullcircle scaled 4mm shifted P;
      endfor;
      picture p;
      p:=nullpicture;
      for i=-180 step 1 until 180:
        pair P;
        P = 2cm* (sind(2*i), cosd(3*i));
        addto p contour fullcircle scaled 4mm shifted P withcolor white;
        addto p doublepath fullcircle scaled 4mm shifted P
          withpen pencircle scaled .5bp;
      endfor;
      clip p to (.5cm,2.5cm) -- (.5cm,1.5cm)--
                (-.5cm,1.5cm) -- (-.5cm,2.5cm)--cycle;
      draw p;
    \end{mpdisplay}
    \end{document}

or use pst-knot package (using postscript).
A: 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
A: I gave a talk on the subject of drawing knots using computers (without much detail, but I cover both 2D and 3D methods), the slides might be of interest.
A: Wolfram|Alpha will draw knots with Alexander-Briggs input. Mathematica will do it with almost any sort of input, including Dowker notation and Conway notation, and most any named knot. The command to look up in the help files is "KnotData".
From Wolfram|Alpha, I'm sure there's some way to grab the picture into a file. Mathematica itself will export to JPG, PNG, PDF, EPS, GIF, etc.
