inkscapelatexextension

inkscapeLaTEXextension

as subject.

A script with the same name is available at :http://www.electricrock.co.nz/tools/inkscape-to-latex-script/

Inkscape 0.48 has been released that has the functionality this script provides built in. You should upgrade and ignore this page if 0.48 works for you! One feature that I believe is missing from Inkscape pdf-latex export is font size support. This is basic font size support in the script described on this page.

I've decoupled this code from inkscape, it is a stand alone python script which converts a svg file into a latex 'mask' and a pdf. It uses Inkscape to generate the pdf file. These documentation pages have been updated to reflect this.

The idea

Save the text of an inkscape drawing as a latex image.

I use gnuplot for generating plots. This has a nice 'epslatex' terminal type. Output from this terminal type has two files: the graphics of the plot (an eps file), the text of the plot (an over-laid tex file). This is nice because I can use all the latex I want in my figures to generate math, symbols etc. In addition, if I change the font of the whole document, the font used in my figures change as well.

Occasionally, I also need to draw arbitrary figures. It would be nice if these were in the same format: a (vector) image with latex text in a separate file. This extension provides an initial first attempt at providing such functionality for Inkscape (which I'm a great fan of).

Screenshots

First a drawing, with text (and some latex) in inkscape.

Now, the equivalent PDF generated by pdflatex.

Demo of color and rotation:

In inkscape:

After latex:

note: The lack of transparency in the purple circle is probably related pdf export from inkscape.

The inkscape image is 'A5' in size, it is unscaled in latex so it overflows the right hand margin.

Features

    • Text extraction and figure alignment works for Latex versions I have tried.

    • Text box positions are supported.

    • Text box rotations are supported.

    • Text color is supported.

    • Text alignment is supported.

    • Text line breaks are supported.

    • Font size is supported.

    • FlowRoot (a 'text area') and Text (text without an area) are supported.

    • Decoupled from Inkscape.

Known Issues

    • Bold or italic text are not supported currently.

    • Font type is not supported currently; scaling a font box will cause problems. The WORK AROUND is to add the text after you've decided on the basic dimensions of your image.

    • The alignment does not work for rotated text nodes.

Availability

In initial announcement: http://permalink.gmane.org/gmane.comp.graphics.inkscape.devel/24700

The code is available under GPL 2 or later.

The most recent version is no-longer a plugin and has the name 'svg2latex', 0.5.0 is available from a new page called 'svg2latex'.

This version is recommended for users of Inkscape 0.46+

HISTORY

0.1 has a bug, it /appends/ to the output latex picture file. this will be fixed shortly.

0.2 fixes bug from 0.1

includes support for rotated text boxes.

includes support for color text.

0.2.1 fixed bug:

BUG: The code is not expecting floating point values with a mantissa, and breaks if one is given.

0.2.2 added name space to .inx file. This change seems to cause problems when using with the older <.46 versions of Inkscape. You can use 0.2.1 for these occasions.

0.3.0 Name spaces seem to have changed. This is a pain to try and keep up with 0.3.0 supports Inkscape on Ubuntu 8.04. I haven't had any other reports of it working on other distros.

One feature enhancement: font sizes are now supported for sizes described on http://web.image.ufl.edu/help/latex/fonts.shtml

0.3.1 Fixed bug with multi-line text boxes and a bug which got the doc width and height mixed up.

0.4.0 Robert W reported a bug; The problem was that I only expect 'flowRoot' text elements in the Inkscape SVG, but you can also get 'text' elements within Inkscape SVG! I've now added support for 'text' elements.

0.5.0 has a new name 'svg2latex'. I started a new page with such a name.

Documentation

Workflow

Requirements:

    • Inkscape installed

    • A Inkscape illustration, saved as 'Inkscape SVG'.

    • A sensible name to give the illustration.

Steps:

    1. Create a drawing in Inkscape, with text which you would like to be rendered by latex.

    2. Save the illustration as type 'Inkscape SVG'

    3. Run the extension (svg2latex.py) calling the saved file with a destination filename.

    4. This saves the text of the illustration as a latex file (.tex) and the drawing elements as a pdf file with the same name.

    5. Include the latex file in your latex document and the figure is automatically included with the text correctly positioned (see 'using with latex' below).

deployment

Put the file 'svg2latex.py' somewhere on your path.

using with latex

once you have generated a tex and corresponding pdf or eps file, I include this in my document with:

\documentclass[11pt,a4paper,twoside]{report} %% LaTeX2e document.

\usepackage{graphicx} %% Preamble.

\usepackage{color}

\begin{document}

\begin{figure}

\begin{center}

\scalebox{1.0}{\input{./somelatexfile.tex}}

\caption{a test of inkscape latex export extension.}

\label{fig:latexexport}

\end{center}

\end{figure}

\end{document}

Where './somelatexfile.tex' is the file generated by the extension.

Alternatives

    • inkscape has a pstricks output. However, this converts the fonts to paths. Adding the functionality to not convert fonts to paths would be very nice, rendering this extension of less use (although this extension does not use latex pstricks package which can be a problem in some circumstances).

    • I believe XFIG will do exactly what this extension does - and has done for ages.

    • You should check out Oni's work which looks well maintained and well documented: http://github.com/Oni/svg2tex/tree/master

    • It is a similar plugin which some nice extra features: it automatically disables text layer (I think). It integrates into the 'save' options of inkscape.

    • Johan Engelen has modified the Inkscape source to produce a native file saving option. This is available from his page on launchpad. It appears to have excellent accuracy (compared to my code anyway!).

  • Inkscape 0.48 has been released that has the functionality this script provides built in. You should upgrade and ignore this page if 0.48 works for you!

contact, rjhenwood a_t yahoo.co.uk