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).
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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
@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 |
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 |
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 |
@Nathan – the fact that pinlabel does not work in XeTeX and LuaTeX is becoming a show stopper as time goes by … so solutions like OverPic, XY-Pic import and TikZ will gain some traction… but I would like also to mention that WARMreader should stop being recommended as an alternative for labeling. The reasons are many: it hasn’t been distributed in 20 years; it is extremely hard to obtain; it was designed for the Mac (specifically for TeXtures) and it does not work as-is on other more modern systems, lots of its functionality have been inherited or re-integrated into XY-Pic…
Comment by Paulo Ney de Souza — March 10, 2020 @ 9:30 am |
Thanks for the comment, I didn’t realize pinlabel didn’t work with XeTeX and LuaTeX. I myself now use TikZ exclusively for adding labels, and wrote a version of the labelpin script with that as the target (available at the link in the post).
Comment by Nathan Dunfield — March 10, 2020 @ 3:25 pm |
It is more than just not working, it will never work properly, specially from the preservation point of view. pinlabel redefines \includegraphics, a staple of modern TeX, in terms of \psfig which is an officially deprecated command. So it will never be a path-forward.
Comment by Paulo Ney de Souza — March 12, 2020 @ 9:52 am