0

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?

  • have you tried with \includesvg{test.svg}? – Bordaigorl Oct 15 '15 at 16:58
  • yes, the output then is: LaTeX Error: Unknown graphics extension: .svg. [ \includesvg{test.svg}] – mcnesium Oct 16 '15 at 9:20
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'].)

  • 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 9: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 9: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 6 '15 at 9:49
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.