91

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}
6
  • 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. Commented Jul 7, 2013 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
    Commented Jul 7, 2013 at 10:11
  • May be useful: How to include SVG diagrams in LaTeX?
    – user11232
    Commented Jul 7, 2013 at 13:10
  • 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
    Commented May 23, 2017 at 10:30
  • 1
    @pushpen.paul I'd rather convert it to a pdf to keep the vector graphics.
    – andreee
    Commented Jan 10, 2019 at 15:31

4 Answers 4

82

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} % you need amsmath as the demo includes a use of \eqref
\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.

Note that for this to work:

  • You need Inkscape on your path (why?) (schtandard pointed to this step-by-step of the setup)
  • You need to compile your .tex file to PDF with the --shell-escape option enabled
17
  • 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
    Commented Aug 24, 2013 at 6:56
  • 4
    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
    Commented Aug 24, 2013 at 10:54
  • 1
    Somehow it does not work for me, when I remove the .svg extension, I got the error File not found.
    – LWZ
    Commented Aug 24, 2013 at 15:59
  • 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
    Commented Aug 24, 2013 at 16:34
  • 2
    @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
    Commented Dec 6, 2017 at 11:56
16

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}
3
  • 8
    Welcome to TeX.SX! This is not really an answer as you do not include the svg (that's what's asked for).
    – TeXnician
    Commented Oct 30, 2017 at 7:51
  • 9
    @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. Commented Oct 30, 2017 at 9:16
  • 1
    It's a relevant answer since using the svg package is using inkscape and will create a .pdf in the root directory anyway. BTW inkscape can do this in one command if someone wish to integrate it in a script or whatever
    – Welgriv
    Commented Sep 23, 2020 at 8:53
1

While this may not be a valuable option for some users, it may be worth it for some:

Online SVG to PDF converters.

Here you may find Google search results.

After this one may follow the usual strategies for embedding PDF files into LaTeX,
(as described for example in the answer above).

Hope this helps some users. ;)

0

I had the same issue and just wanted to share the trivial solution which worked for me. I am using overleaf by the way.

I had to remove one layer from my folder structure.


This did not work:

+-- data
|   +-- img
|       +-- file.svg
+--TeX
|  +-- Sections
|  |   +-- 01_Section.tex
|  +-- main.tex
|  +-- ...

Removing "TeX" layer solved the porblem:

+-- data
|   +-- img
|       +-- file.svg
+-- Sections
|   +-- 01_Section.tex
+-- main.tex
+-- ...
2
  • 1
    Welcome to TeX.SE! Can you explain, why the second folder structure works?
    – Mensch
    Commented Nov 18, 2021 at 16:36
  • I think, it's about forgetting "../" in the file path. With the first folder structure, it is ../data/img/file.svg, where as in the second, it is data/img/file.svg.
    – koppor
    Commented Oct 25, 2023 at 11:17

You must log in to answer this question.

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