# Including and updating of pdf_tex files from svg with inkscape in directory of choice

I'm working on a way to have my .svg exported with inkscape to .pdf_tex if the .svg file was changed. That allows me to change the figure, hit Ctrl+S and then just compile my tex file.

I adapted some commands which I found here so that I can access my figures anywhere (previously it was only working with the working directory).

Now to make it easier to use, I'd like to just declare \graphicspath and then have my commands use it.

Right now I'm doing the following:

\newcommand{\figurepath}[1]{D:/figures/#1}


which I can then use in my own command like

\newcommand{\includesvg}[1]{
\input{\figurepath{#1.pdf_tex}}
}


Now how do I get my \figurepath to use \graphicspath? Is there something like get(grahicspath)?

Edit:

Okay, so here is what I'm working with at the moment:

\usepackage{graphicx,import,xcolor,transparent}

\newcommand{\figurepath}[1]{path/to/svgs/#1}

\ifnum\pdfstrcmp{\pdffilemoddate{#1}}
{\pdffilemoddate{#2}}>0
{\immediate\write18{#3}}\fi
}

\newcommand{\includesvg}[1]{%
{inkscape -z -D --file=\figurepath{#1.svg}
--export-pdf=\figurepath{#1.pdf} --export-latex}
\input{\figurepath{#1.pdf_tex}}%
}


It runs and is quite useful. What it does is check if the svg file has been edited and if yes it exports a new pdf_tex with inkscape. There are some other examples around which do the same, but they all worked only for svgs in the working directory. I couldn't find one where it is possible to use svgs from any location on your computer.

In order for this to work, it is necessary to add -shell-escape to pdflatex, e. g. I'm using Texstudio and under Options->Commands I edited the line PdfLaTex to look like

pdflatex -synctex=1 -interaction=nonstopmode -shell-escape %.tex


Under Windows it is also required to add the location of inkscape.exe to PATH. To do this type System in the search panel and then go to advanced system settings. Under advanced click Environment Variables... and a window will pop up, find PATH in system variables, click edit and add the directory of inkscape.

There is a known bug with the 0.48 versions of inkscape, which will print

 RegistryTool: Could not set the value 'Path/to/inkscape'


nevertheless it works and this bug has been fixed in the 0.91 version.

The original LaTeX code found on page 3 of this document, on which your question seems to be based on, requires the packages graphicx.sty and color.sty (or xcolor.sty) to work.

A slightly different approach is to make additional use of the package import.sty:

\usepackage{graphicx,import,xcolor}

\ifnum\pdfstrcmp%
{\pdffilemoddate{#1}}%
{\pdffilemoddate{#2}}%
>0%
{\immediate\write18{#3}}%
\fi%
}
\newcommand{\includesvg}[2][]{%
{inkscape -z -D --file=#1#2.svg --export-pdf=#1#2.pdf --export-latex}%
\subimport{#1}{#2.pdf_tex}%
}


Now \includesvg has an optional argument which accepts the relative path to the files (note that all three files, i.e. .PDF, .PDF_TEX, and .SVG, must have the same name and be present in the same directory).

Examples of usage:

\includesvg[figures/]{mydwg}
\includesvg{mydwg} % working directory
\includesvg[../figures/aero/]{mydwg}


Actually it's the other way round:-) the path mechanism is implemented for \input and \includegraphics locally sets it to the value given in \graphicspath .

So most efficient is don't use \graphicspath just set

TEXINPUTS="D:/work/figures;"


before you run latex which will add that folder to the start of the search path.

Or, if you want to use the \graphicspath notation but have \input see it, use

\makeatletter
\def\input@path{{D:/work/figures/}}
\makeatother