Low Dimensional Topology

November 22, 2010

Labeling figures in LaTeX

Filed under: Uncategorized — Nathan Dunfield @ 12:30 pm

It’s been pretty quiet here on this modest blog, so I’m taking that as an excuse to blog about TeX. One of the fun things about being a low-dimensional topologist is that our papers have many pictures. This leads to the problem of how to add labels to these figures. The right way to do this, I’m convinced, is to do so within the TeX file itself so that the fonts match the body text and it’s easy to move/change the labels without access to the program that originally generated the image files. Colin Rourke’s pinlabel.sty is a good way to do this and is used by the MSP journals such as G&T. The hard part is figuring out the coordinates for the labels without a lot of guesswork. Pete Storm wrote pinlabeler which makes this trivially easy, but unfortunately it doesn’t work naturally with Mac OS X. Therefore I wrote labelpin which is less sophisticated than pinlaber, but works on both OS X and Linux (and probably within Cygwin or MSYS on Windows). It’s just a simple Python script, so there’s no need to compile anything, and on OS X all you should need to do is put it in your path and make it executable (“chmod +x labelpin”).

Alternatives to pinlabel.sty include overpic, WARMReader, and the import environment of xypic. It’s easy to modify the labelpin script to handle any of these, though generally pinlabel is the best package out there. (The only negative of pinlabel is that it requires you have an EPS version of the image file even if you’re using PDFLaTeX, and it can’t handle bitmapped files like PNG or JPG even though PDFLaTeX can. In contrast, I have some macros that work with xypic which can deal with such things, see my script labelxy for details).



  1. I use psfrag to replace text in an eps figure (usually generated with inkscape). This works pretty well, but I usually have to move the text around a bit so that the latex comes out looking ok. Unfortunately, the latest version of Inkscape seems to not embed the fonts anymore in eps output, so I have to use an older version.

    Comment by Ian Agol — November 22, 2010 @ 12:36 pm | Reply

    • Yeah, I should have mentioned psfrag as well. Unfortunately, it doesn’t work with PDFLaTeX, though, and I’ve switched over to using only PDF for both input and output when TeXing…

      Comment by Nathan Dunfield — November 22, 2010 @ 12:41 pm | Reply

  2. I haven’t used it myself, but Ipe seems to be a popular alternative in computational geometry research.

    Comment by D. Eppstein — November 22, 2010 @ 1:32 pm | Reply

    • IPE allows you to use arbitrary TeX commands to write your labels, but the resulting labels (including the fonts) are hard-coded into the resulting EPS/PDF file. You can change IPE’s LaTeX preamble to match your document, but you can’t change the labels from within TeX after the fact.

      Comment by Nathan Dunfield — November 22, 2010 @ 1:49 pm | Reply

  3. I tend to use the “low tech” method of adding text within my graphics program (I use Adobe Illustrator). I find that I am often adding many labels in quite tight spaces, to the extent that positioning and font size need a fair amount of tweaking, and having to enter those tweaks “manually” would take a long time.

    The trick is to have the correct fonts accessible by your graphics program. I use TrueType fonts, which I believe should be possible to install on any machine. The main ones I use are:

    “umr10.tty”, which is the standard font used outside of mathmode by Latex, available from http://www.truetex.com/um.zip
    “cmmi10.tty”, “cmex10.tty”, “cmsy10.tty”, which cover much of mathmode, available from ftp://ctan.org/tex-archive/fonts/cm/ps-type1/bakoma/ttf/

    There are many more fonts in the second directory to cover other needs (“msbm10.tty” seems to have the \mathbb fonts for instance).

    The disadvantage of course is that you have to do much of the positioning within an expression yourself. Illustrator will do subscripts and superscripts, but more complicated arrangements need to be done by hand.

    Comment by Henry Segerman — November 22, 2010 @ 6:13 pm | Reply

    • Yeah, the tweaking can be a bit of a pain, but the tools I mentioned simplify this a great deal, to the point were it no longer bothers me. With more work, one could write a program that lets you move the positions the of the labels dynamically, but I figure the personal time savings isn’t worth doing so, though it might be a fun project.

      While you can certainly get Illustrator (or Inkscape or…) to use Computer Modern (the default TeX font) only some journals actually use this font in production. For instance, the AMS journals do, as does NYJM, but G&T, AG&T, AJM, Annals, Inventiones and PJM use other fonts (I think some version of Times in all cases).

      Also, I really, really hate Computer Modern which I feel is some kind of karmic retribution for the good that Knuth has done for the world…

      Comment by Nathan Dunfield — November 22, 2010 @ 6:37 pm | Reply

  4. I should try this out sometime: the change of font depending on the journal is a good point.

    Comment by Henry Segerman — November 22, 2010 @ 7:25 pm | Reply

  5. I’m curious as to what people do when writing a paper with figures. I write all my drafts in LaTex and often want to include figures from the beginning, but as they might change don’t want to do anything too labor intensive. What I do is this: I draw my figure in xFig and include the labels in the figure. I export it as an eps file that includes the LaTex. When I get to the final draft, I then need to go through and edit the labels to keep notation consistent and to prettify the figure. Sometimes, I remove all the labels and put them in the LaTex document using pinlabel. I’m not happy with this process since I end up spending lots of time simply managing the files associated to the figures. Any suggestions? For those who use Tikz — do you use it from the beginning of the writing process or do you redraw all your figures in Tikz when you are at the final draft?

    Comment by Scott Taylor — November 23, 2010 @ 9:44 am | Reply

    • In early drafts, sometimes I just sketch the figures on a piece of paper and scan them in at a pretty low resolution. PDFLaTeX is happy with PNG and JPG images, and if you don’t specify the file ending in the “\includegraphics” you can later replace file.png with file.pdf and it you don’t even have to change the TeX file. (If you still use DVI and dvips, you need to convert the bitmap formats to .eps files, which can be done, but adds an extra step).

      On the Mac, I can’t over-recommend Skitch for throwing together a quick sketch. It’s really quite limited, which turns out to be the point — you can’t endless fiddle with things, so you don’t. I’ve been making a lot of pictures this semester as I’m teaching vector calculus, and Skitch has been invaluable for this. I use it with an inexpensive tablet (the oddly-named Bamboo Fun Pen & Touch) though I’m not yet convinced this is better than just using the mouse.

      Comment by Nathan Dunfield — November 23, 2010 @ 10:53 am | Reply

      • Thanks, I’ll have to try Skitch (once I upgrade my computer — currently I have 10.3.9).

        Comment by Scott Taylor — December 5, 2010 @ 8:52 pm

  6. @Nathan — Very nice. I ran this from inside of the shell inside of emacs. Still worked and made cut-and-pasting \epsilon–easier.

    Comment by Saul Schleimer — November 23, 2010 @ 10:29 am | Reply

    • Cool, I hadn’t thought of doing that. I suspect an emacs cognescenti could quickly whip up a macro which invoked “lablepin” in place within the TeX file itself, eliminating the cut-and-paste all together, but I’m pretty ignorant about such things (even if I do use emacs).

      Comment by Nathan Dunfield — November 23, 2010 @ 10:59 am | Reply

  7. If your figures are “relatively nice”, you can produce them in the LaTeX document itself via something like TikZ. I think Inkscape even gives you a TikZ output of your figure so that you can make small adjustments from within the LaTeX document without having to go back to the drawing program. This is especially useful for producing many layered versions of the same object highlighting different components. Here it is easy to move around any labels, even if they are in math mode. Another plus is that you don’t have to worry about additional files — everything is self-contained.

    Comment by Moshe Cohen — December 21, 2010 @ 8:20 am | Reply

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: