# include svg images with the svg package

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}

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

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
• 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! Aug 24, 2013 at 6:56
• 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. Aug 24, 2013 at 10:54
• @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. Aug 24, 2013 at 16:34
• 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. Jun 30, 2015 at 18:15
• @JosephWright what is meant by this You need Inkscape on your path. Path that we give while installing inkspacke, should be of .tex file? Dec 6, 2017 at 11:56

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:

• 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}

• Welcome to TeX.SX! This is not really an answer as you do not include the svg (that's what's asked for). Oct 30, 2017 at 7:51
• @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. Oct 30, 2017 at 9:16
• 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 Sep 23, 2020 at 8:53

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. ;)

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
+-- ...
`
• Welcome to TeX.SE! Can you explain, why the second folder structure works? Nov 18, 2021 at 16:36