7

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.

7
  • If the conversion is not successful, the necessary files won't be found. Try the manual conversion inkscape -z -C -f./example.svg -A./example.pdf --export-latex which may give some hints about what's going wrong.
    – egreg
    Dec 25, 2015 at 23:37
  • Did you install it via dmg? You can check the installation dir with which inkscape. If this returns no answers, the problem is, that LaTeX can't find inkscape at all.
    – Rico
    Dec 26, 2015 at 0:00
  • @egreg The command line does not work. ** (inkscape-bin:821): WARNING **: Can't open file: example.svg (doesn't exist). This looks to be related to a Mac python issue with directories. However, I've tried every combination on that webpage and nothing works.
    – weymouth
    Dec 26, 2015 at 9:11
  • @Rico I installed via dmg, which I got from the website a few days ago. which inkscape gives /usr/local/bin/inkscape. Even if I run the command using the full path - I have the same issue.
    – weymouth
    Dec 26, 2015 at 9:13
  • Maybe you could provide a screenshot of your folder structure. Could make it easier to figure out what is going wrong
    – Rico
    Dec 26, 2015 at 10:37

5 Answers 5

5

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.

1
  • I'll try this out and hopefully give you a (long overdue) checkmark.
    – weymouth
    Feb 4, 2019 at 13:51
3

Check that inkscape is in your PATH environment variable.

Test this by opening up your command terminal window and typing inkscape --version (do not do this in the directory you installed inkscape; we want to see if your environment can find the program from an arbitrary location, like your home directory)

If it returns with a version, then this is not your problem (sorry).

However, If it responds with any form of error, then the svg package won't be able to call inkscape to convert the file. For directions on adding inkscape to your PATH, see here (here for Windows).

Good luck!

3
  • 1
    The poster already states the program is the PATH and shows an error message from the Inkscape saying it can't find the svg file. Jan 12, 2017 at 7:17
  • 1
    Besides, the OP is on Mac OS X.
    – egreg
    Jan 12, 2017 at 7:22
  • I've had similar errors on Linux and windows where the error shown was "cannot find file" when it was actually a path issue. So just suggesting this as a troubleshooting step to double check that it was added to PATH properly by running from console. (I've messed that up before). I'll amend the answer to add in editing path for Mac, missed that in the Q. Txs. Jan 12, 2017 at 8:23
2

Try changing your command-line call to put --shell-escape first:

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

After having the \includesvg work and not work in Windows and Linux (ubuntu), and having this exact problem sometimes, but not others (however, after it stopped working, it seemed really hard to get it to compile again), I found that putting the --shell-escape option FIRST in the command line seems to make the pdflatex call work every time.

I hope this helps other people, I've been caught by this over and over again with no real rhyme or reason for why the pdflatex call starts failing.

Good luck! Let me know if this works for anyone else out there.

2

Linux & Snap problem

If you're on Linux and installed inkscape via snap store the svg file cannot be opened due to permission issues with snaps sandbox.

You can confirm this by right clicking on a file -> open with -> inkscape. Nothing will happen.

How to fix

Open your terminal and type:
which inkscape
This should return /snap/bin/inkscape
type to uninstall inkscape from snap:sudo snap remove inkscape
Type to install via ppa:

sudo apt update
sudo apt install inkscape

type to confirm inkscape was installed: which inkscape
This should return /usr/bin/inkscape

This is the currently opened issue: https://gitlab.com/inkscape/inkscape/-/issues/3649
Maybe someone can find a solution by modifying the snap permissions?

1

My problem was the --clean option. I figured this out by selected pdflatex in TeXWorks and it suddenly built. Taking out options one by one helped me get to the bottom of this. Hope this helps someone (probably future me in six months).

1
  • 1
    maybe you should mention that you are using latexmk, otherwise this answer might not make sense
    – user190633
    Jun 11, 2019 at 11:56

You must log in to answer this question.

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