[Tex/LaTex] svg package failing to find svg files

graphicsmacsvg

I am trying to get the svg package working on an OSX system. If I use inkscape to save the *.svg files as *.pdf and *.pdf_tex, then the sample file from this question works fine:

\documentclass{article}
\usepackage{svg}
\usepackage{amsmath}
\begin{document}

\begin{figure}[htbp]
  \centering
  \includesvg{example}
  \caption{svg image}
\end{figure}

\end{document}

But no matter what I try, the package will not create the pdf and pdf_tex files automatically. Instead I get an error:

! LaTeX Error: File `./example' not found.

I have added inkscape to the PATH. I've added the --shell-escape option to the latex command… I'm at a loss.

Best Answer

This is a macOS-specific issue.

The inkscape shell script which invokes the main inkscape binary has to change directory to the inkscape installation directory, which is why it fails finding the SVG files in the current working directory.

See this explanatory comment on line 30 of the inkscape script, /usr/local/bin/inkscape on my macOS:

# Due to changes after 0.48, we have to change working directory in the script named 'inkscape':
# recursive calls to inkscape from python-based extensions otherwise cause the app to hang or
# fail (for python-based extensions, inkscape changes the working directory to the 
# script's directory, and inkscape launched by python script thus can't find resources
# like the now essential 'units.xml' in INKSCAPE_UIDIR relative to the working directory).
cd "$BASE" || exit 1

That's a smoking gun if I've ever seen one. :)

You can try commenting out the cd "$BASE" || exit 1 line, and the conversion should still work for simple SVGs. This is what I am currently doing.

Alternatively, one would have to modify svg LaTeX package to invoke inkscape with full input and output pathnames instead of relative. Another option would be to modify the inkscape shell script to expand relative paths to absolute.