47

I'm trying to use the svg package for inserting svg images in my latex file, as suggested in other questions. But now I ran into a problem:

For example I have a image figure1.svg, if I write

\includesvg{figure1}

it will give an error says

ERROR: LaTeX Error: File `figure1.pdf_tex' not found.

But if I write

\includesvg{figure1.svg}

it will give another error says

ERROR: LaTeX Error: Unknown graphics extension: .svg.

How can I fix this problem? I'll prefer not having to convert all my svg files to pdf_tex files with some external program.


Update

My LaTeX environment is latest the TeXLive 2013 on Windows 7. A MWE code would be

\documentclass{article}
\usepackage{svg}

\begin{document}

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

\end{document}
  • 1
    I just tried it using a simple SVG. I had all prerequisites: adding the --shell-escape option to pdflatex and installing ImageMagick. To me it seems as if the package is a bit buggy. – Uwe Ziegenhagen Jul 7 '13 at 6:40
  • 2
    I spite of your last sentence, I suggest change all \includesvg{..} by \includegraphics{...} without any extension and (1) import the latex document with Lyx to allow an automatic conversion with rsvg-convert or (2) work directly with pdf files that still can be edited with Inkscape. For many files is less painfull the command line (inkscape -f file.svg -A file.pdf). – Fran Jul 7 '13 at 10:11
  • May be useful: How to include SVG diagrams in LaTeX? – user11232 Jul 7 '13 at 13:10
  • Helpful tutorial on including svg file using includesvg: comp-phys.net/2014/03/22/… – Mukesh Chapagain Mar 25 '15 at 10:13
  • 1
    Had this same error using XeLaTeX with Texmaker on GNU/Linux where \includesvg{image} or \includesvg{image.svg} just wouldn't work. Had to do \includegraphics{image} and then it magically started working. – ZN13 May 23 '17 at 10:30
44

The problem is that you have given a file extension: you should not do this (indeed this seems clear in the svg manual. For me, the short demo

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

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

\end{document}

using the demonstration file used by the package works fine (you need amsmath as the demo includes a use of \eqref).

Note that for this to work:

  • You need Inkscape on your path
  • You need to run the file with the --shell-escape option enabled
  • 2
    Getting this to work on Windows is OK, but on my Mac seems tricky. That's likely an Inkscape/Mac issue, so not relevant here! – Joseph Wright Aug 24 '13 at 6:56
  • 2
    Calling svg as \usepackage[inkscape={/Applications/Inkscape.app/Contents/Resources/bin/inkscape -z -C}]{svg} seems to solve the issue on Mac OS X (assuming Inkscape has been installed with the .dmg file. – egreg Aug 24 '13 at 10:54
  • 1
    @LWZ No, what actually happens is that the svg package uses Inkscape to convert to PDF on-the-fly. You have to have Inkscape available for this to work. – Joseph Wright Aug 24 '13 at 16:34
  • 1
    I had problems when the image was located in different folder e.g. ../images/image2. The pdfs are created on the fly in this directory, but then tex tries to include the pdfs from the previous directory. – sauerburger Jun 30 '15 at 18:15
  • 1
    @JosephWright what is meant by this You need Inkscape on your path. Path that we give while installing inkspacke, should be of .tex file? – Infinity Dec 6 '17 at 11:56
7

I had the same problem.

I found a simple way to deal with it.

  • Just open the svg file by Inkscape.

  • Save as the .pdf format

  • On the next pop up window:

    • Embed Fonts

    • Use exported object's size

    • Margin 0.1

  • click ok

Next the generated pdf file will be imported by latex easily as same as png or eps.


But some times inkscape does not read the svg file properly and some mistakes are occurred. In this case the solution which works for me is:

  • generate a pdf version of figure by your used designer software

  • include the pdf file in latex

  • use trim for cropping the figure in latex

for example:

\includegraphics[width=0.8\textwidth, trim={1cm 3cm 1cm 8cm},clip]{Fig.pdf}
  • 2
    Welcome to TeX.SX! This is not really an answer as you do not include the svg (that's what's asked for). – TeXnician Oct 30 '17 at 7:51
  • 8
    @TeXnician You are very stringent. Generally I like this, but in this case … You are absolutely right: It's not an answer to the asked question but an alternative way to avoid the problem. – Schweinebacke Oct 30 '17 at 9:16

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.