79

I know only the very basics of TikZ, having only used it to produce a pretty flow chart for one of my documents. I recently learned that you can use Inkscape and export to TikZ.

What are the limitations of the Inkscape->TikZ workflow? Is there some compelling reason to take the time to learn TikZ (which I'm told has a fairly steep learning curve) rather than simply exporting to TikZ from Inkscape?

Ethan Bolker
  • 9,333
  • 3
  • 42
  • 69
Dennis
  • 3,855
  • 9
    I'd guess that the TikZ code produced by Inkscape is 'messier' than hand written code, relying mostly/only on absolute positioning, perhaps making adjustments more difficult. But I've never really used that route a lot, so I'm not that familiar with it. – Torbjørn T. Dec 24 '13 at 23:35
  • @TorbjørnT. From what I've seen of the code produced by Inkscape this definitely seems correct. I'd be curious to know (though don't expect you to have an answer since you say you haven't used Inkscape->TikZ much) if this is an issue if you're content to modify your graphics within Inkscape. – Dennis Dec 24 '13 at 23:54
  • 7
    tikz isn't that difficult (not like PSTricks) IMO. You have an excellent manual too. In inkscape you have to draw using mouse and accuracy of putting some thing here will be lost. –  Dec 25 '13 at 01:31
  • I'm curious. Why not go directly from inkscape to TeX? – Ethan Bolker Dec 25 '13 at 01:52
  • 1
    @EthanBolker Is that an option? I'm very new to using graphics in LaTeX--- I've almost exclusively used it to typeset text. Is the suggestion to simply generate an image with Inkscape and then directly include that image in your .tex (as opposed to exporting to TikZ first)? – Dennis Dec 25 '13 at 07:09
  • 2
    @HarishKumar What makes me hesitant to spend the time learning it is how little need I have for graphics in my documents. I'd need to generate maybe 5-6 diagrams per year and don't necessarily want to spend a lot of time generating them. Your second point is something I'd be worried about, though. What sort of accuracy do you lose? Is the accuracy within Inkscape the issue (e.g., if there was no way to pull up a grid and use a combo of the mouse and coordinates to ensure accurate placement of items)? Or is the issue with accuracy once you export to TikZ and include the code in your .tex? – Dennis Dec 25 '13 at 07:15
  • 4
    You might wish to take a look at TikZiT, http://tikzit.sourceforge.net. – bishopcranmer Dec 24 '13 at 23:12
  • UPDATE 2020: The TikZiT project is now hosted on GitHub: https://tikzit.github.io/ – Ashton Wiersdorf Jun 03 '20 at 03:01

3 Answers3

64

Edit: @XiaodongQi comments below that

The same options are no longer available in the newer version of Inkscape. But there are similar options when saving the PDF.

You can save your inkscape figures as pdfs and put them in your document with \includegraphics. If you have text in your figures you can select the PDF+LaTeX option from the inkscape save-as pdf menu. That will create a pdf_tex file instead. You \input that file and TeX does the typesetting.

In inkscape:

enter image description here

Saving from inkscape after selecting save-as pdf. Inkscape writes file topview.pdf_tex:

enter image description here

In the document:

\begin{figure}[h]
\centering{
\resizebox{75mm}{!}{\input{images/topview.pdf_tex}}
\caption{Top view.}
\label{fig:topView}
}
\end{figure}

Output:

enter image description here

This is clearly a picture that could be drawn with tikz, but I chose not to, for reasons you spelled out in your response to @HarishKumar - the longer tikz learning curve and a preference for wysiwyg for occasional use. If you did need precise placement (lines really meeting at corners) you might be able to do that with the snap-to features of inkscape. I haven't tried those yet.

Ethan Bolker
  • 9,333
  • 3
  • 42
  • 69
  • 2
    When you expand it, if you could note whether this approach would have shortcomings compared to a pure TikZ approach that would be greatly appreciated. – Dennis Dec 25 '13 at 15:50
  • 1
    so you can't directly make a pdf with equations from inkscape in MAC? – Charlie Parker Oct 19 '16 at 22:22
  • 1
    @CharlieParker You may be able to write equations in inkscape (I don't know). The point of the PDF+LaTeX option is to have TeX typeset the text in the figure (whether or not it's mathematical) so that the fonts and typography match those in the surrounding document. – Ethan Bolker Oct 19 '16 at 23:46
  • 4
    The same options are no longer available in the newer version of Inkscape. But there are similar options when saving the PDF. – Xiaodong Qi Mar 08 '18 at 02:47
  • I needed to add \usepackage{graphicx} to make this work (it fails if you use graphics) – Scott Seidman Jul 22 '20 at 19:33
  • While the export in itself works, all my text is misaligned. It seems Inkscape and Latex position the boxes differently, with Latex not being able to center the text as intended. – YPOC Nov 18 '21 at 18:25
  • Instead of opening Inkscape, one can also use the command line. – winkmal Aug 24 '22 at 14:05
29

After exporting (described by Ethan Bolker) use the following snippet to embed the image generated by Inscape:

\begin{figure}
\def\svgwidth{\linewidth}
\input{img/filename.pdf_tex}
\caption{}
\end{figure}

Using \def\svgwidth{desired width} instead of \resizebox will preserve the font size. This is the recommended way described in the head of the generated file:

%% Creator: Inkscape 0.91_64bit, www.inkscape.org
%% PDF/EPS/PS + LaTeX output extension by Johan Engelen, 2010
%% Accompanies image file '_masks.pdf' (pdf, eps, ps)
%%
%% To include the image in your LaTeX document, write
%%   \input{<filename>.pdf_tex}
%%  instead of
%%   \includegraphics{<filename>.pdf}
%% To scale the image, write
%%   \def\svgwidth{<desired width>}
%%   \input{<filename>.pdf_tex}
%%  instead of
%%   \includegraphics[width=<desired width>]{<filename>.pdf}
%%
%% Images with a different path to the parent latex file can
%% be accessed with the `import' package (which may need to be
%% installed) using
%%   \usepackage{import}
%% in the preamble, and then including the image with
%%   \import{<path to file>}{<filename>.pdf_tex}
%% Alternatively, one can specify
%%   \graphicspath{{<path to file>/}}
%% 
%% For more information, please see info/svg-inkscape on CTAN:
%%   http://tug.ctan.org/tex-archive/info/svg-inkscape
%%
R D
  • 391
0

As another alternative, there is a tool SVG2TikZ (used to be Inkscape2TikZ), which can be used to generate TikZ code.

If you install the Python package from the GitHub repository, you can convert a SVG (which may be exported from Inkscape) to TeX source code using TikZ as follows:

svg2tikz a.svg > a.tex

It can also be installed as a Inkscape extension.

user202729
  • 7,143