[Tex/LaTex] How to make LaTeX automatically call Inkscape to export figure to *.pdf_tex

inkscapepdftexsvgworkflow

I'm working with Inkscape to update all the figures of a book, using the PDF+LaTeX option to export the figures. Right now, every time I modify a figure I "save as…" both with Inkscape's *.svg and *.pdf (with the PDF+LaTeX option enabled). In the document the figure is included using:

\begin{figure}
\centering
\def\svgwidth{0.5\textwidth}
\input{my_figure.pdf_tex}
\end{figure}

This works fine, but having to save in both formats quickly gets annoying. I've read on the svg-inkscape documentation that "whenever the SVG file is updated, it is possible to have LATEX automatically call Inkscape to export the image to PDF and LATEX again. This simplifies the workflow (…)".

The documentation says its possible, but I have not been able to implement it. ¿Is there a way to do it on OS X? I'm working with OSX 10.9.4, MacTeX 2014 and Inkscape 0.48, compiling with PDFLaTeX on both TexMaker or TexPad.

Best Answer

You could use the svg package, which does exactly what the svg-inkscape documentation describes.

\documentclass[12pt]{article}
\usepackage{svg}
\setsvg{inkscape=inkscape -z -D,svgpath=fig/}

\begin{document}

\begin{figure}
  \centering
  \includesvg[width=0.5\textwidth]{my-figure}
\end{figure}

\end{document}

Now all you need to do is save your images as svg files and pdflatex does the rest for you.

Important: Compile this with the --shell-escape flag, e.g. pdflatex --shell-escape my-book.tex. Have a look at this answer which may help you add this option. (TeXstudio is/was a Texmaker fork.)

A couple of points:

  • inkscape=inkscape -z -D makes inkscape export the the svg drawing, not the whole page. Change it to inkscape=inkscape -z -C if you want to export the whole page (or just remove it - it's the default behaviour).
  • svgpath=fig/ is the directory containing your figures. Change this as appropriate, but do not remove the trailing /.