# [Tex/LaTex] How to export svg to tikz

svgtikz-pgf

I was wondering if anyone had managed exporting .svg files to TikZ code. I do not mean include an .svg file into a latex document, but rather to obtain the code of an image so you can then edit it with TikZ.

I know that this has been done here: http://www.texample.net/tikz/examples/india-map/ using inkscape and the svg converter svg2tikz (https://github.com/kjellmf/svg2tikz) but I cannot reproduce it after installing inkscape.

When I run inkscape, I get the following message on the console (I run it from the console):

(inkscape:8700): Gtk-CRITICAL **: gtk_misc_set_alignment: assertion GTK_IS_MISC (misc)' failed

I can still import an image and export to TikZ path but I get the following error message in a pop-up window:

Inkscape encountered an internal error and will close now.
Automatic backups of unsaved documents were done to the following locations:
/home/squeeze/New document 1.2012_06_19_18_10_24.0.svg

and the exported .tex file shows the following code which does not reproduce the image and compiles to a blank page:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}[y=0.80pt,x=0.80pt,yscale=-1, inner sep=0pt, outer sep=0pt]
\begin{scope}[cm={{2.4087301,0.0,0.0,3.1036527,(-508.27381,-1163.9469)}}]
\begin{scope}[cm={{1.25,0.0,0.0,-1.25,(213.2835,636.20725)}}]
\begin{scope}[scale=0.100]
\begin{scope}[cm={{2304.0,0.0,0.0,1195.2,(141.732,141.732)}}]
\end{scope}
\end{scope}
\end{scope}
\end{scope}

\end{tikzpicture}
\end{document}


Has anyone done it?

I run Debian Squeeze; Inkscape is 0.47 and the forum on the inkscape-svg converter is not really active so I thought someone may have done it here.

I do not wish to specifically use .svg; I use GIMP usually, so if there is such a way to do it in GIMP, I am happy to do it (even better).

Here is an example of an .svg image that fails the above procedure:

The problem is that your source image is a bitmap (raster image), while TikZ is a vector graphics format. In order to export your bitmap image to TikZ you have to convert it to a vector format first. This process is called "tracing" or "vectorization".

Tracing can be done in numerous ways:

1. Insert the image into an Inkscape document. Select the image. Press Shift+Alt+B` to open the tracing dialogue. Twiddle with the knobs or just press "Ok". Then delete the bitmap.
• You can also adjust the result manually using the path editing tools provided by inkscape.
2. While the Inkscape tracing algorithm is free and relatively easy to use, the results are only mediocre, most of the time. Try feeding your favourite search engine terms like "bitmap to vector converter" and try one of the results. Some are quite good.
3. If you found the image file online, try searching for a vector version of the same image. If you found it via Google image search, you can just append "filetype:svg" to your search query to find only vector images. For example in case of the Debian logo, the Debian website also has an svg version.
4. Trace the image manually. Place the bitmap in Inkscape, lock the object (as to not accidentally move it) and start painting a path over it, that follows the contours of the bitmap image. This is really tedious.

Once you have a vectorized version of your image, converting it to TikZ with any svg-to-TikZ converter (like svg2tikz) should be possible.