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?

9
  • 4
    You might wish to take a look at TikZiT, tikzit.sourceforge.net. Dec 24, 2013 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. Dec 24, 2013 at 23:35
  • 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.
    – user11232
    Dec 25, 2013 at 1:31
  • 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, 2013 at 7: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, 2013 at 7:15

3 Answers 3

63

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.

7
  • 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, 2013 at 15:50
  • 1
    so you can't directly make a pdf with equations from inkscape in MAC? Oct 19, 2016 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. Oct 19, 2016 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. Mar 8, 2018 at 2:47
  • I needed to add \usepackage{graphicx} to make this work (it fails if you use graphics) Jul 22, 2020 at 19:33
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
%%
6
  • Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. Sep 19, 2016 at 11:09
  • Rather than code snippets it's better to give a compilable minimal working example.
    – user30471
    Sep 19, 2016 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, 2016 at 14:01
  • 2
    When I do this all my text looks out of place + incorrect size. Any tips?
    – Juan Leni
    Oct 15, 2018 at 11:48
  • I needed to add \usepackage{graphicx} to make this work (it fails if you use graphics) Jul 22, 2020 at 19:34
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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .