NOTE: I am in the process of completely rewriting this script in order to add better transform support, including rotation.  It should be done within a few days.

I frequently use Latex for my academic writing, and I like to use Inkscape to create images for my documents.  In the past I used to export my Inkscape drawings to PNG so that I could insert them into my latex docs, but this was unsatisfactory as it meant any text in the images would not be typeset by Latex, therefore its style could be inconsistent and it wouldn’t be searchable.  With Inkscape 0.48 it became possible to export the image as a pdf with a latex wrapper that  typesets the image text using latex. However, I found this had several downsides:  the pdf images generated were generally much larger and took longer to display than the PNGs I had been previously generating, the font sizes came out wrong, and several other issues.

To overcome these problems I hacked up a python script (originally started writing it as an XSLT, then realised XSLT sucks).  The script generates an image (in user’s choice of format, I prefer PNG), and a tex file containing the latex commands to generate the type for the image.

Advantages

My script has several advantages over Inkscape 0.48′s native export (as far as I can tell):

  • Respects font size as set in Inkscape.
  • Handles formatting changes within a text element.
  • Supports multiline text elements.
  • Supports coloured text (I think Inkscape supports this too).
  • Ignores off-page text.

Known Issues

This script is undergoing active development and testing as I write my thesis.  At the moment it works for me, bar the known issues listed here:

  • Lack of support for rotated text.
  • No escaping of reserved characters.

Download

The script and an example can be downloaded here: