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.

Drawing and photographing and importing to computer is overcomplicating it IMO. Just print the paper with the places for the diagrams left blank, draw the diagrams by hand on the paper, and photocopy it.
–
Zsbán AmbrusApr 15 '10 at 12:28

3

Putting the photograph in the digital file has the advantage that you don't have to keep a master physical copy on hand. So long as a substantial amount of the exam is being saved digitally anyway, there may as well be a digital master copy. (I suppose that this assumes that the exam, complete with diagrams, is likely to be reused...)
–
Niel de BeaudrapApr 15 '10 at 12:55

6

Here is the quick and dirty for writing the test. Go to a paper on the arxiv that you know has a diagram for the knot you want on the test. Download the source. Find the diagram as a pdf file or eps file. Use the graphicx package for embedding it in your exam.
–
Charlie FrohmanApr 15 '10 at 13:16

2

Aha! Precisely the problem I had with my knot theory course. Tried the honest approach first (xfig), opted for draw it by hand and scan it after the first homework/sols.
–
algoriJul 7 '10 at 5:26

Knotinfo has the advantage of using circle packings of the 2-sphere to construct its knot diagrams so they're fairly appealing diagrams. The disadvantage of knotinfo is the diagrams are efficient (maybe you want a complicated unknot, etc?), and the knots are prime. I use xfig, exported to .eps for most of the diagrams in my papers.
–
Ryan BudneyApr 15 '10 at 14:18

That's pretty good, but I want to draw a link as well, say sum of 2 Hopf links. I can't find links on the site, do you know some sources?
–
Hailong DaoApr 15 '10 at 14:20

I ended up using this method (-:, thanks.
–
Hailong DaoApr 18 '10 at 17:49

2

You can also create .eps files from the .png files by using the 'Trace' tool in programs like Illustrator, Inkscape or Corel Draw. This is a great thing if you want to adjust the knot, scale it or change colours.
–
JCollinsMar 25 '11 at 10:44

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.

I realize that some issues in paragraph 1 don't apply to writing a single exam for one-time printout, but I interpreted the question to ask about the more general challenge of drawing nice diagrams in latex.
–
David JordanApr 15 '10 at 11:16

3

Also you can scan a black and white sketch, and tell Inkscape to "trace" it for you, and then perform the simplifying step I mentioned (most paths need no more than 3 or 4 data points, even if they start with 100. The fewer they have the more curvy and regular they look.
–
David JordanApr 15 '10 at 11:18

7

yes, that is why it is useful. pdf's also use scalable vector graphics, and so we have a faithful functor svg--> pdf
–
David JordanApr 15 '10 at 12:38

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.

+1 for TikZ. Also, if you prefer to draw them but want them looking computer-generated (and want them to look integrated with the document), Inkscape has a plugin that can export to TikZ format.
–
Loop SpaceApr 15 '10 at 10:40

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.

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.

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.

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

But then you're making yourself dependent on the ps-workflow and miss out on all the nice typographical improvements of pdftex.
–
TilmanApr 15 '10 at 8:04

1

I draw lots of knots, and I do it this way. I think Xara is the best drawing programme for knots myself- I can draw a 15-crossing knot nicely and with everything where I want it in around 10 minutes. I also use psfrag. I include in minipages usually. e-mail me for code snippets if you are interested.
–
Daniel MoskovichApr 15 '10 at 8:33

1

Xfig can produce PDF and can use LaTeX internally for labels (not WYSIWYG, though) so this method can be used properly with pdflatex. However, I don't recommend it due to the presence of TikZ
–
Loop SpaceApr 15 '10 at 10:39

1

This brings up an algorithmic question: are there nice algorithms for producing (numerically) "nice" (whatever that might mean) 3d embeddings of knots. Then use graphics programs with hidden surface elimination.
–
Victor MillerApr 15 '10 at 15:02

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 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.