1

I am trying include an Inkscape generated pdf image, with text to be interpreted by LaTeX, into a LaTeX document.

When I keep the image files in the same folder as the tex file it works, but I would like to have my images in a subfolder img.

I've seen multiple instructions on how to accomplish this, but the mostly accepted way to do this seems to be to use the svg package by \includepackage{svg}, tel LaTeX where to look for files/images using \svgpath{{img/}} and insert the image into the document using \input{example.pdf_tex}.

MWE:

\documentclass{standalone}
\usepackage{svg}
\svgpath{{img/}}

\begin{document}
    \input{example.pdf_tex}
\end{document}

This is also the way as described in the documentation of the svg package

However, when I do so, latex is not able to find the file and I get the error

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

Now, there are alternative ways to accomplish what I want to do. For instance to include \graphicspath{{img/}} or to use the import package with the command \import{<path to file>}{<filename>.pdf_tex}. I've also tried these commands using an absolute path.

Would anyone have an idea what is wrong?

  • 1
    What happens if you drop the \svgpath... part and use \input{img/example.pdf_tex} ? – Rasmus Feb 8 at 21:01
  • 1
    @Rasmus thank you for your suggestion, it didn't solve it completely but did get me a step closer to the solution. Using your suggestion latex knows to find the pdf_tex file. It turned out, that it couldn't find the corresponding pdf file. This then could be solved by including \graphicspath{{img/}} to the preamble. Strange, but it now works. – Alwin Feb 8 at 22:28
1

Actually, the way to include svg files using the package of the same name is using the command \includesvg (as a pendant to \includegraphics for normal graphic inclusion). The argument of this command should point to the svg file (not the pdf_tex file) and you can tell LaTeX where to look for this file using the \svgpath macro (as a pentant to \graphicspath). LaTeX will then automatically call Inkscape to create the pdf and pdf_tex file (provided they are outdated or don't exist) and include them.

So, your MWE should read

\documentclass{article}

\usepackage[inkscapearea=page]{svg}
\svgpath{{img/}}

\begin{document}

\includesvg{example}

\end{document}

where example.svg is located in the img/ subfolder. (I included the inkscapearea=page option because I think that is what most people want.)


In order for this to work, you need to run LaTeX with shell escape enabled and have Inkscape in the system path variable. See this answer for a more detailed explanation.

|improve this answer|||||
0

I solved the problem using the suggestion Rasmus made in the comment to my original question. As it needed one additional step, I give the full solution here.

The problem is solved by telling LaTeX the location of the pdf_tex file at the moment it is included in the document by \input{img/example.pdf_tex}. Telling LaTeX where the corresponding pdf file can be found can be done by adding \graphicspath{{img/}} to the preamble. This tells LaTeX to search this folder for images.

Note that adding \svgpath{{img/}} in the preamble instead of \graphicspath{{img/}} doesn't work, it will raise the compiling error/ warning LaTeX Warning: File `example.pdf' not found. This is true for me and I'm using the TeX Live 2019 distribution.

The following thus works:

\documentclass{standalone}

\usepackage{svg}
\graphicspath{{img/}}

\begin{document}
    \input{img/example.pdf_tex}
\end{document}

Hope this will be useful for someone else as well.

|improve this answer|||||
  • You aren't actually using the svg package at all. If you remove the \usepackage{svg}, your document will show the same behavior. See my answer for how to properly use the package. – schtandard Feb 10 at 8:43
  • When I comment out the \usepackage{svg} I get an error ! Undefined control sequence. l.4 \graphicspath {{img/}} ? So it seems that LaTeX needs the svg package for something at least. But thank you very much for your answer as well, I haven't looked into calling Inkscape at LaTeX compile time. It looks like a better way to go. – Alwin Feb 10 at 21:40
  • 1
    You need to load graphicx (which is one of the packages svg loads in the background). – schtandard Feb 14 at 20:24

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.