46
$\begingroup$

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.

$\endgroup$
8
  • 4
    $\begingroup$ To be honest, I would actually seriously consider drawing them on paper, taking a photo of them using my phone, tidying it up with a picture-editing program like the gimp, and then importing it into the LaTeX file! $\endgroup$ Commented Apr 15, 2010 at 7:38
  • 2
    $\begingroup$ Plus, my phone does not take nice pictures (-: $\endgroup$ Commented Apr 15, 2010 at 7:53
  • 9
    $\begingroup$ 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. $\endgroup$ Commented Apr 15, 2010 at 12:28
  • 3
    $\begingroup$ 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...) $\endgroup$ Commented Apr 15, 2010 at 12:55
  • 8
    $\begingroup$ 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. $\endgroup$ Commented Apr 15, 2010 at 13:16

13 Answers 13

54
$\begingroup$

Knotinfo has .png files of all knots of 12 crossings or less.
https://knotinfo.math.indiana.edu/

$\endgroup$
7
  • 2
    $\begingroup$ 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. $\endgroup$ Commented Apr 15, 2010 at 14:18
  • 2
    $\begingroup$ I ended up using this method (-:, thanks. $\endgroup$ Commented Apr 18, 2010 at 17:49
  • 3
    $\begingroup$ 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. $\endgroup$
    – JCollins
    Commented Mar 25, 2011 at 10:44
  • 1
    $\begingroup$ It seems the link is dead now. $\endgroup$ Commented May 15, 2023 at 7:14
  • 1
    $\begingroup$ I have just checked the link - works for me! $\endgroup$
    – Sam Nead
    Commented Aug 29 at 4:40
32
$\begingroup$

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)

$\endgroup$
1
  • $\begingroup$ Look great, thank you! I will email you someday. $\endgroup$ Commented Feb 22, 2011 at 19:36
22
$\begingroup$

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.

https://arxiv.org/pdf/0908.3013

$\endgroup$
9
  • 2
    $\begingroup$ 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. $\endgroup$ Commented Apr 15, 2010 at 11:16
  • 4
    $\begingroup$ 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. $\endgroup$ Commented Apr 15, 2010 at 11:18
  • 8
    $\begingroup$ yes, that is why it is useful. pdf's also use scalable vector graphics, and so we have a faithful functor svg--> pdf $\endgroup$ Commented Apr 15, 2010 at 12:38
  • 1
    $\begingroup$ +1 for the faithful functor! $\endgroup$ Commented Apr 15, 2010 at 13:13
  • 5
    $\begingroup$ Version 0.47 of Inkscape has a routine for drawing knots: tavmjong.free.fr/INKSCAPE/MANUAL/html/… $\endgroup$
    – Ian Agol
    Commented Aug 5, 2010 at 1:19
15
$\begingroup$

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.

$\endgroup$
12
$\begingroup$

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.

$\endgroup$
0
9
$\begingroup$
  1. 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.

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

$\endgroup$
6
  • 4
    $\begingroup$ +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. $\endgroup$ Commented Apr 15, 2010 at 10:40
  • $\begingroup$ Ooh, I wasn't aware that Inkscape can export to TikZ. Are you referring to this ( code.google.com/p/inkscape2tikz ) or something else? $\endgroup$ Commented Apr 15, 2010 at 13:43
  • $\begingroup$ TiKZ even has code to do the double drawing Niel talks about automatically: you want to do something like \draw [double] ... $\endgroup$ Commented Apr 15, 2010 at 14:54
  • $\begingroup$ Both comments 1-2 are what I would have posted. $\endgroup$ Commented Apr 15, 2010 at 16:01
  • $\begingroup$ You don't need a camera. There should be a scanner you can use somewhere. $\endgroup$
    – Peter Shor
    Commented Feb 22, 2011 at 14:06
7
$\begingroup$

Aaron Lauda has a nice description using the package XY-pic here (Wayback Machine). 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.

$\endgroup$
2
  • 3
    $\begingroup$ Of course, to call the code hard to read would be an understatement... $\endgroup$
    – Tilman
    Commented Apr 15, 2010 at 8:07
  • 6
    $\begingroup$ Friends don't let friends use XY-pic! $\endgroup$
    – Ben Webster
    Commented May 1, 2010 at 14:30
6
$\begingroup$

The knot atlas gang have a mathematica package for this - you paste the pictures it produces.

$\endgroup$
5
$\begingroup$

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.

$\endgroup$
1
  • $\begingroup$ The link seems to be broken. $\endgroup$
    – Ben McKay
    Commented 8 hours ago
5
$\begingroup$

Have a look at the knot program by Kodama:

https://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.

$\endgroup$
4
$\begingroup$

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.

$\endgroup$
4
  • $\begingroup$ But then you're making yourself dependent on the ps-workflow and miss out on all the nice typographical improvements of pdftex. $\endgroup$
    – Tilman
    Commented Apr 15, 2010 at 8:04
  • 1
    $\begingroup$ 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. $\endgroup$ Commented Apr 15, 2010 at 8:33
  • 1
    $\begingroup$ 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 $\endgroup$ Commented Apr 15, 2010 at 10:39
  • 1
    $\begingroup$ 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. $\endgroup$ Commented Apr 15, 2010 at 15:02
3
$\begingroup$

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

$\endgroup$
1
  • 3
    $\begingroup$ Finding explicit parametrizations of knots seems to be awfully time consuming for the purposes of answering Hailong's original question! $\endgroup$ Commented Mar 24, 2011 at 17:47
3
$\begingroup$

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 (Lars Fischer: Drawing knot pictures using LATEX with XY-pic - An introduction and tutorial) - available at https://web.archive.org/web/20060305165509/http://lf.starlogik.de/res/XYPic-Knot-Intro.pdf http://larsfischer.bplaced.net/XYPic-Knot-Intro/index.html (Wayback Machine)

There's a great xymatrix tutorial at https://mirror.easyname.at/ctan/macros/generic/diagrams/xypic/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 recommend reading it because it goes more in-depth into some of the parameter modifiers that aren't actually explained in the knot manual.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .