Low-Performing InkScape Extension, for TikZ Export.

One of the facts which I’ve been writing about is, that the application ‘InkScape’ supports exporting its graphics to the ‘PSTricks’ flavour of .TEX-File. It does this out-of-the-box and without apparent error. But I have also written that A flavour of .TEX-File exists, which is the PGF/TikZ form. And Linux has few graphical, interactive editors, to be able to create this file-format, because again, the file that is being sought is a text file. It would be nice of InkScape could additionally output to this format, since InkScape is a powerful, GUI-based graphics application.

Well as it happens, It’s possible to add some meagre extensions to InkScape, in user-space, or with elevated privileges. One such extension is called ‘svg2tikz‘, and so at first glance it would seem that users can benefit fully. But as is often the case, there are caveats with using this one extension.

(Updated 3/10/2018, 7h30 … )

(As of 3/08/2019, 17h50 : )

The biggest problem with ‘svg2tikz’ is, that it will render SVG Paths as invisible, if those paths are only defined as paths, and not as being filled with a defined colour. In theory this might sound right because a Mathematical line is so narrow, that it should be invisible, if it could exist in the physical Universe. In principle, it would be because the space between lines is filled with substance, and therefore with colour, that anything is visible. But this behaviour will also make many, existing InkScape documents unfit for TikZ export because assumptions are made about how ‘naked paths’ should be filled with colour, assumptions which the extension fails to make.

(Update 3/09/2019, 14h20 : )

More precisely, when users create Paths with InkScape, this application sets the fill-colour between them, as well as the “Stroke Colour” to ‘Undefined’, while rendering the latter as being Black by default. But the ‘svg2tikz’ extension fails to render any colour, when that colour has been set to Undefined, unless that behaviour of the extension is patched.

(End of Update, 3/09/2019, 14h20.)

And so, one way in which this can be remedied, is that A specific patch can be applied to the extension, which the repository mentioned above has not merged, but which will set the default colour to black, thus making some existing arrows and boxes visible. And just because the repository has not merged this patch, this patch can only be ‘applied’ exclusively of all the other (3) suggested patches. Each of these (4) patches in total, would override the others.

The easiest way to apply this patch is, to open the file in its raw form in the browser, and to use the browser’s ‘Save As’ feature to save it to a folder, from which ‘tikz_export.py’ can be copied and then pasted over where the official version of this file exists, within the ‘/svg2tikz/svg2tikz/extensions’ source-folder of this project. This needs to be done before ‘python setup.py build’ and ‘python setup.py install’ are run in the root folder of this project, so that the changes will be incorporated both into the command-line program, and into the Python Packages. After that, the conventional instructions can be followed again, to copy the 3 required files to the folder ‘/usr/share/inkscape/extensions’…


There will still be 3 basic drawbacks to using this form of .TEX-File:

  1. Text cannot be resized, even if it was so within the original InkScape document,
  2. Fill colours other than black, and shades of grey, are not available,
  3. In certain cases InkScape documents have been built, that contain rectangles which are defined as completely transparent, and ‘behind’ which actual content should display. Specifically, such fill-colours seem to combine the Undefined colour, with an Alpha of Zero.  In such cases, the entire rectangle will be black instead (:1).

What this means is that an InkScape project practically needs to be built by the user, to be exported to TikZ format. If I use an existing project in this fashion, I will sometimes obtain output, for better or worse, that looks like this:



Yet, if I use the built-in ‘PSTricks’ Flavour of .TEX-File to export to, such errors do not occur.


Within ‘InkScape’ the setting under ‘File -> Document Properties -> Page’, that is known as ‘Scale’, must be set to 1.0 User Units per Pixel, in order for the output of ‘svg2tikz’ to be proportioned consistently, just because in some places this extension fails to perform a conversion:


(Update 3/09/2019, 16h50 : )


There is a practical application, in which such an ‘unwanted black rectangle’ can arise. The intention of creating the document could have been to define a frame around some other content, where the colour of the frame is defined. The problem with this is, the fact that the low-level representation of such a frame is, an outer path – rectangular – with an inside path that’s only slightly smaller, which is to be negated from the outside path.

The problem with the ‘svg2tikz’ extension, the way I patched it, now becomes, the fact that this inner rectangle has no defined fill colour. In the GUI of InkScape, it looks like this:


The rectangle in question has a Stroke Colour that’s defined, but a Fill Colour that was set to “x – No Paint”. Now, I’ve tried to remedy this, by setting a Fill Colour that has an RGBA value of 0x00000000, and a separate Opacity of 0%. But unfortunately, that Fill Colour is not supported by the ‘svg2tikz’ extension, and for that reason, I get identical final results.



And what that means is, If the user wants to be able to define a Frame around figures he has created with InkScape, he must use the unpatched version of  ‘svg2tikz’, and accept that some extra work must also be done, to define Fill-Colours for all the surfaces which, in standard InkScape-SVG Files, were undefined.


(Update 3/10/2019, 7h30 : )

The way I have solved this problem is, that I have first reverted the extension source code to the unpatched version, and rebuilt it. This way I have accepted that InkScape Documents need to be designed for TikZ export, or prepared for it. And then I applied a simple recipe, to set all the previously-undefined Stroke Colours to a defined ‘Black’. There exists an instruction manual, that shows users how to select all the objects with the Same Fill Colour as the presently-selected Object, but the method can also be used to select all the Objects, which have the same Stroke Colour.

Then, any one object can be selected in an InkScape document which is to be modified, that has an Undefined Stroke Colour. All the matching Objects can be selected, by choosing from the Menu, ‘Edit -> Select Same -> Stroke Colour’. All their Stroke Colours can next be set to Black with one operation. And the following is the result that derives from the TikZ Export, in my exercise:


I should also note, that this extension only works within Inkscape versions 0.48 through 0.91 . Because on one of my computers I have InkScape version 0.92, this extension additionally malfunctions on that computer, in that Text is never positioned correctly.

For that reason, where I have InkScape 0.92, I need to use this extension from the command-line, since it also installs the command ‘svg2tikz’.



Print Friendly, PDF & Email

One thought on “Low-Performing InkScape Extension, for TikZ Export.”

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>