Charles Basenga Kiyanda

Kludging your way to nice figures with ubuntu+kile+inkscape+cairo+eps+psfrag

Several inkscape+latex+psfrag users have been complaining for quite a while now about the changes in cairo. I periodically forget how to kludge my way through while I wait for the situation to stabilize and I have to search the tubes for a couple hours before I remember all the details, so here it is for all to enjoy (and for me to find much more quickly the next time). I use linux (ubuntu), kile, tetex, inkscape and psfrag. If you’re on windows, well, I can probably not help.

The problem: The later versions of inkscape use cairo to generate eps files. The new version of cairo doesn’t have explicit strings for the words in the eps files. Instead of having the string “(hello)Tj” somewhere in your eps file, you have the string “<0102030304>Tj”. Psfrag looks for hello somewhere, can’t find it and hence is utterly confused. As a result, so are you. (Un)fortunately, inkscape is a really good FOSS program and I’m unwilling to change my ways at this point.

The solution: Here’s my workflow.

  1. Make a file in inkscape as usual. Use short labels (which will later be replaced by psfrag) if you want to make it quicker later on. I just go through the alphabet in sequence.
  2. Replace all the <##>Tj strings with (CC)Tj. Make sure to change the numbers to the right letters. (If you write the letters in order in inkscape, then 01 corresponds to a, 02 corresponds to b, etc.) To be a bit quicker, I make a script, which does it for me once I’ve figured it out. This way, I can modify the figure later on and not go completely mad. A sample script is shown at the bottom for 2 labels, a and b.
  3. run
  4. produce dvi using kile (I use kile, you might not)
  5. produce ps from dvi using kile (or whatever it is you use)
  6. ps2pdf text.pdf (because using kile and dvi2pdf(?), the pdf doesn’t have the psfrag substitutions in)

As an extra (which I always forget also): to get text on multiple lines using psfrag, use a shortstack: “\psfrag{label}{\shortstack[l]{some more\\text}}”.

Not simple and not pretty. There are probably more succint and elegant scripts for You might be able to get the pdf generation to work from withing kile. Personally, I’ve given up and just keep a terminal window open for that operation.

Sample script with 2 labels, a and b:

#! /bin/sh
cp fig.eps fig.eps.backup ##(for your sanity the first time you run the script)
mv temp.eps fig.eps
sed ‘s/<01>/(a)/’ fig.eps | sed ‘s/<02>/(b)/’ > temp.eps
rm fig.eps
mv temp.eps fig.eps

Leave a Reply




You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>