[cairo] Inkscape eps export for Latex

Bernd Bandemer bandemer at gmail.com
Sat Aug 29 18:12:18 PDT 2009


Hi Cairo developers,

For a while now, I have been using the following tool chain to include
nice-looking figures in latex documents (scientific papers, mostly):

- make figure in inkscape, use placeholders for labels (for example,
"xrecursion")
- export as eps file
- in latex, include the eps file (\includegraphics)
- use the latex package psfrag to replace the placeholder with an
arbitrary latex expression (for example,
\psfrag{xrecursion}{$x_i=x_{i-1}^2-1$})

psfrag relies on the fact that in postscript (and eps), text can be
rendered using "(xrecursion) show" (after proper cursor placement,
font selection, etc). So all psfrag does is to find occurrences of
"show", compare with its replacement rules, and if they match invoke
latex-internal rendering instead of postscript rendering.

This has worked really well for a long time. Since Inkscape has become
so powerful, I think many scientific authors have moved to the same
tool chain (many coming from xfig). It's a great example of open
source software being superior to any commercial solution.

So far, so good. With version 0.47pre, inkscape has migrated to cairo
as eps output filter. That's great, many things that didn't work
previously now do work (gradients, for example).

However, cairo is too smart for psfrag: it uses font subsetting. Only
those glyphs that are actually being used are included in the eps
file. Unfortunately, this also means that the letters are resequenced.
For example, if the eps file contains only 9 distinct letters (as in
the "xrecursion" example), those would be labeled 1,2,...,9. These
glyphs would be embedded and instead of the conventional "() show",
the text is printed using "<01020304050206070809> Tj". Tj is a
cairo-defined macro in the eps file. Of course, psfrag doesn't
understand any of this, so no replacements work anymore. This really
bothers me, and I am sure many other scientific authors.

It would be great if we can fix this and make the tool chain work
again. It would be great if cairo had an option that turns off font
subsetting (or uses a default font subset) and revert to plain "show",
plus proper hooks in inkscape to activate the option. [In my opinion,
making psfrag smart enough to understand font subsetting seems a very
hard thing to do.]

I talked to Behdad and he was so kind as to make a quick hack that
makes cairo use "() show" instead of "<> Tj" everywhere if
CAIRO_PSFRAG_HACK is set in the environment. Using a so-patched cairo
with inkscape produces psfrag-compatible eps files. It's not a final
solution (the patch will revert all text in the file to a standard
font), but it works for now.

Any ideas on a robust solution for this? I also noticed that the
roadmap for Cairo has enabling/disabling certain subsetters scheduled
for 2.12, but this is very far in the future... It would be great if a
solution can be found sooner.

(See also the bug report for inkscape:
https://bugs.launchpad.net/inkscape/+bug/375323 -- At the end of the
page, a quick&dirty after-the-fact eps conversion hack is suggested.)


Cheers,
Bernd


More information about the cairo mailing list