1

I am trying to include SVG into my document using the SVG package. On OSX Yosemite, I use Sublime Text 3 with the LatexTools Package, BasicTex 2015 and Inkscape installed via Homebrew Cask. Additional missing Tex packages as the SVG package are installed using tlmgr. The inkscape command is available, as a symlink /usr/local/bin/inkscape has been created automatically by homebrew.

Here is my minimal example, taken and even simplified from here:

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

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

\end{document}

test.svg is a very simple graphic and the file is in the same directory as test.tex. As proposed here I added the following lines to the builder_settings:

"program": "pdflatex",
"command": ["latexmk", "-cd", "-e", "$pdflatex = '%E -shell-escape -interaction=nonstopmode -synctex=1 %S %O'", "-f", "-pdf"],  

I even tried to mess around with the path definitions in svg.sty from as proposed here but still, the build engine obviously is not able to use Inkscape to generate the pdf and tex files. This is the ST console output:

[Compiling /Users/mcnesium/Desktop/ma/tex/test.tex]
SimpleBuilder: pdflatex run 1; done.
Errors:
./test.tex:7: LaTeX Error: File `./test' not found. [      \includesvg{test}]
./test.tex:7: LaTeX Error: File `./test' not found. [      \includesvg{test}]
./test.tex:7: LaTeX Error: File `test.pdf_tex' not found. [      \includesvg{test}]
[Done!]

Who has a similar setup and can point me to whats wrong with mine?

mcnesium
  • 203

2 Answers2

0

I don't really know anything about the svg package, but I do know a few things about LaTeXTools.

First, from your console output, you have set your builder setting to simple in LaTeXTools.sublime-settings which means that the command setting you set is ignored. Since the simple builder does not support changing the options passed to pdflatex and you need to pass --shell-escape, you should set this back to default.

Second, the PATH for graphical programs on OSX is... annoying to say the least. The work-around supplied by LaTeXTools is the texpath setting in the Platform settings section of LaTeXTools.sublime-settings. You need to ensure that the texpath includes the path to wherever you installed Inkscape is this is necessary for the svg package. I think it should be, but its best to check. (Note that you will see the default setting includes $PATH but this is usually not the same as the $PATH on your shell. To see what this $PATH will expand to, on the Sublime console run: import os; os.environ['PATH'].)

ig0774
  • 1,970
  • Thank you for answering. Unfortunately, this does not make things much different. With builder set to default it just says TraditionalBuilder: Invoking latexmk... done. followed by the same errors. When setting it to script there is no output at all in the ST3 console. – mcnesium Sep 15 '15 at 15:03
  • The script builder actually doesn't do anything, so that's pretty much expected. Did you verify the PATH as well? If the PATH isn't correct, pdflatex won't be able to launch inkscape. – ig0774 Sep 16 '15 at 09:06
  • From trying this out, it looks like you should have a line in your log like this: runsystem(inkscape -z -C -f./test.svg -A./test.pdf --export-latex)...executed. Can you verify that you have that too? – ig0774 Sep 16 '15 at 09:07
  • the line says "texpath" : "$PATH:/usr/texbin:/usr/local/bin:/opt/local/bin" which includes the path to the inkscape symlink mentioned above. Having set "display_log" : true, here is the log for {test} and here for {test.svg} – mcnesium Sep 16 '15 at 14:26
  • Can I provide any other information? – mcnesium Oct 06 '15 at 09:49
  • The only other thing I can think of is that it must be somehow related to your Inkscape install. What happens if you try to run the following two commands from a terminal shell: first, PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/texbin:/opt/local/bin followed by inkscape -z -C -f./test.svg -A./test.pdf --export-latex in the directory in which your svg file is stored. The order is important: I'm trying to simulate the $PATH as LaTeXTools sees it. – ig0774 Oct 07 '15 at 15:56
  • Inkscape on OS X I think depends on having a version of X11 installed. Wherever your X11 is installed is probably not on the PATH that LaTeXTools sets. I think this can be fixed by adding /opt/X11 to the end of the "texpath" setting, but I'm not entirely sure... I don't have XQuartz or Inkscape installed on my Mac to test with. – ig0774 Oct 07 '15 at 16:02
  • I just figured out that the inkscape command you provided on my system only works with absolute paths to both the input and the output file. – mcnesium Oct 16 '15 at 12:26
0

I figured out that at least in my setup the inkscape command only works when using absolute paths to both the input and the output file (see this bug). This propably screws up the functionality of the SVG Package.

So I worte this bash script that I fire up just after hitting save on testsvg.svg in Inkscape:

#!/usr/local/bin/bash

dirname=$(dirname "$1");
fullpath=$(cd "$dirname" && pwd -P)/;
inputfile=$(basename "$1");
filename=${inputfile%.*}

svg="$fullpath$inputfile";
pdf="$fullpath$filename".pdf;

$(which inkscape) -z -C -f $svg -A $pdf --export-latex;

The following part is optional. I use it because my svg files reside in a sub-directory of my main tex file. So on build the references in the *.pdf_tex files to the *.pdf file need to have the sub-directory appended, which the following does:

$(which sed) -i 's/'"$filename.pdf"'/'"$dirname\/$filename.pdf"'/g' "$pdf"_tex;

In the TeX-file I reference it using

\begin{figure}
    \begin{center}
        \def\svgwidth{\columnwidth}
        \input{figures/testsvg.pdf_tex}
    \end{center}
\end{figure}

Make sure that the SVG file has a different name than the TeX file, otherwise the output PDF will be mixed up with the Inkscape helper PDF.

This is not as cool as just having the ST Build System do it, but better than always saving as PDF and SVG back and forth in Inkscape.

mcnesium
  • 203