55

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?

  • 3
    You might wish to take a look at TikZiT, tikzit.sourceforge.net. – bishopcranmer Dec 24 '13 at 23:12
  • 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
  • 6
    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. – user11232 Dec 25 '13 at 1:31
  • 1
    @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 7:15
45

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.

  • 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
  • so you can't directly make a pdf with equations from inkscape in MAC? – Charlie Parker Oct 19 '16 at 22:22
  • @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
  • 1
    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 8 '18 at 2:47
21

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
%%
  • Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. – Martin Schröder Sep 19 '16 at 11:09
  • Rather than code snippets it's better to give a compilable minimal working example. – Andrew Sep 19 '16 at 12:04
  • thanks for the links/suggestions. I tried to post it as comment to the answer above, but I do not have enough karma. – R D Sep 19 '16 at 14:01
  • When I do this all my text looks out of place + incorrect size. Any tips? – Juan Leni Oct 15 '18 at 11:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.