How to draw knots with Latex? - MathOverflow most recent 30 from http://mathoverflow.net2013-05-23T06:29:27Zhttp://mathoverflow.net/feeds/question/21424http://www.creativecommons.org/licenses/by-nc/2.5/rdfhttp://mathoverflow.net/questions/21424/how-to-draw-knots-with-latexHow to draw knots with Latex? Hailong Dao2010-04-15T06:33:05Z2013-04-22T19:47:11Z
<p>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. </p>
<p>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. </p>
http://mathoverflow.net/questions/21424/how-to-draw-knots-with-latex/21428#21428Answer by Sam Nead for How to draw knots with Latex? Sam Nead2010-04-15T07:41:50Z2011-02-22T13:42:56Z<p>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.</p>
<p>Old answer - </p>
<p>I draw knots in a different program (xfig), save them as eps files, and then include them via </p>
<pre><code>\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}
</code></pre>
<p>Then latex, dvips -o, ps2pdf produces the pdf file. This technique allows one to use psfrag to add labels inside of figures. </p>
http://mathoverflow.net/questions/21424/how-to-draw-knots-with-latex/21430#21430Answer by Niel de Beaudrap for How to draw knots with Latex? Niel de Beaudrap2010-04-15T07:56:49Z2011-02-22T19:54:41Z<ol>
<li><p>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.<sup>†</sup> Multiple 2½-dimension diagrams, without tons of regularity, are not fun to draw on a computer --- unless perhaps you have access to touch-screens.</p></li>
<li><p>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 <a href="http://www.ctan.org/tex-archive/graphics/pgf/base/doc/generic/pgf/pgfmanual.pdf" rel="nofollow">fairly comprehensive and reasonably readable manual</a>. 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.<p>
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.</p></li>
</ol>
<p>Good luck with your exam!
<br><br>
<sub>
<sup>†</sup>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.</sub></p>
http://mathoverflow.net/questions/21424/how-to-draw-knots-with-latex/21431#21431Answer by Sammy Black for How to draw knots with Latex? Sammy Black2010-04-15T07:58:00Z2010-04-15T07:58:00Z<p>Aaron Lauda has a nice description using the package XY-pic <a href="http://www.math.columbia.edu/~lauda/xy/" rel="nofollow">here</a>. 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.</p>
http://mathoverflow.net/questions/21424/how-to-draw-knots-with-latex/21433#21433Answer by David Lehavi for How to draw knots with Latex? David Lehavi2010-04-15T08:48:26Z2010-04-15T08:48:26Z<p>The knot atlas gang have a <a href="http://katlas.math.toronto.edu/wiki/Printable_Manual" rel="nofollow">mathematica package</a> for this - you paste the pictures it produces.</p>
http://mathoverflow.net/questions/21424/how-to-draw-knots-with-latex/21442#21442Answer by Andrew Stacey for How to draw knots with Latex? Andrew Stacey2010-04-15T10:41:54Z2010-04-15T10:41:54Z<p>Here's a, perhaps silly, suggestion that perhaps isn't quite what you're looking for:</p>
<p>Draw them <strong>properly</strong> in 3D using something like Blender, and then render it to a 2D picture.</p>
<p>The second animation on <a href="http://www.math.ntnu.no/~stacey/Seminars/komin.html" rel="nofollow">this page</a> is of a variant on the borromean rings.</p>
http://mathoverflow.net/questions/21424/how-to-draw-knots-with-latex/21443#21443Answer by David Jordan for How to draw knots with Latex? David Jordan2010-04-15T11:15:30Z2010-04-15T11:15:30Z<p>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).</p>
<p>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.</p>
<p>Since they only have much fancier screenshots on their homepage, here is a paper with diagrams done in Inkscape.</p>
<p><a href="http://arxiv.org/pdf/0908.3013" rel="nofollow">http://arxiv.org/pdf/0908.3013</a></p>
http://mathoverflow.net/questions/21424/how-to-draw-knots-with-latex/21456#21456Answer by Paul for How to draw knots with Latex? Paul2010-04-15T13:11:22Z2010-04-15T13:11:22Z<p>Knotinfo has .png files of all knots of 12 crossings or less.<br>
<a href="http://www.indiana.edu/~knotinfo" rel="nofollow">http://www.indiana.edu/~knotinfo</a></p>
http://mathoverflow.net/questions/21424/how-to-draw-knots-with-latex/23172#23172Answer by Pádraig Ó Conbhuí for How to draw knots with Latex? Pádraig Ó Conbhuí2010-05-01T11:47:22Z2010-05-01T12:21:43Z<p>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.</p>
<p>There's a good xy-pic tutorial for creating knots at <a href="http://lf.starlogik.de/res/XYPic-Knot-Intro.pdf" rel="nofollow">http://lf.starlogik.de/res/XYPic-Knot-Intro.pdf</a></p>
<p>There's a great xymatrix tutorial at <a href="http://www.ctan.org/tex-archive/macros/generic/diagrams/xypic/xy/doc/xyguide.pdf" rel="nofollow">http://www.ctan.org/tex-archive/macros/generic/diagrams/xypic/xy/doc/xyguide.pdf</a></p>
<p>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.</p>
http://mathoverflow.net/questions/21424/how-to-draw-knots-with-latex/30863#30863Answer by Nikos Apostolakis for How to draw knots with Latex? Nikos Apostolakis2010-07-07T06:46:43Z2010-07-07T06:46:43Z<p>Have a look at the knot program by Kodama:</p>
<p><a href="http://www.math.kobe-u.ac.jp/~kodama/knot.html" rel="nofollow">http://www.math.kobe-u.ac.jp/~kodama/knot.html</a></p>
<p>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.</p>
http://mathoverflow.net/questions/21424/how-to-draw-knots-with-latex/30883#30883Answer by Kevin O'Bryant for How to draw knots with Latex? Kevin O'Bryant2010-07-07T12:58:02Z2010-07-07T12:58:02Z<p><a href="http://www.wolframalpha.com/input/?i=8_3+knot" rel="nofollow">Wolfram|Alpha</a> 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".</p>
<p>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.</p>
http://mathoverflow.net/questions/21424/how-to-draw-knots-with-latex/30887#30887Answer by Henry Segerman for How to draw knots with Latex? Henry Segerman2010-07-07T13:24:06Z2010-07-07T13:24:06Z<p>I gave a talk on the subject of drawing knots using computers (without much detail, but I cover both 2D and 3D methods), the <a href="http://math.utexas.edu/users/henrys/talks/drawing_knots.pdf" rel="nofollow">slides</a> might be of interest.</p>
http://mathoverflow.net/questions/21424/how-to-draw-knots-with-latex/56278#56278Answer by Andrew Stacey for How to draw knots with Latex? Andrew Stacey2011-02-22T13:01:37Z2013-04-22T19:32:14Z<p><em>Update 2013-04-22</em>: 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 <code>spath3</code> library. Here's the <a href="http://www.ctan.org/pkg/spath3" rel="nofollow">link to CTAN</a>. The <a href="http://www.ctan.org/pkg/hobby" rel="nofollow"><code>hobby</code></a> package also contains some useful code for drawing knots. For drawing braids, there's the <a href="http://www.ctan.org/pkg/braids" rel="nofollow"><code>braids</code></a> package. And <a href="http://tex.blogoverflow.com/2013/04/how-can-i-draw-a-knot-in-tex-let-me-count-the-ways/" rel="nofollow">here's</a> a short blog post I wrote explaining the variety of methods.</p>
<hr>
<p>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 <a href="http://tex.stackexchange.com" rel="nofollow">http://tex.stackexchange.com</a> if you want). Using it, I can produce SVGs (as evidenced by some nLab pages: <a href="http://ncatlab.org/nlab/show/Borromean+link" rel="nofollow">http://ncatlab.org/nlab/show/Borromean+link</a>, <a href="http://ncatlab.org/nlab/show/Whitehead+link" rel="nofollow">http://ncatlab.org/nlab/show/Whitehead+link</a>, and some others) as well as PDFs, PNGs, and so forth. As an example, here's the trefoil knot:</p>
<p><img src="http://www.math.ntnu.no/~stacey/Research/Preprints/TheEnchantedForest/png/brunnian035-1_large.png" alt="Trefoil knot"></p>
http://mathoverflow.net/questions/21424/how-to-draw-knots-with-latex/58170#58170Answer by Vafa Khalighi for How to draw knots with Latex? Vafa Khalighi2011-03-11T15:51:34Z2011-03-11T15:51:34Z<p>You can draw knots with metapost:</p>
<pre><code>\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}
</code></pre>
<p>or use <a href="http://tug.ctan.org/cgi-bin/ctanPackageInformation.py?id=pst-knot" rel="nofollow">pst-knot</a> package (using postscript).</p>