To include an SVG in LaTeX, you have two common routes. The svg package runs Inkscape while LaTeX compiles and inserts the drawing with \includesvg. The other route exports a PDF from Inkscape and includes it with \includegraphics. The PDF route doesn’t need shell escape, and it can keep the labels in LaTeX. The overview of inserting images in LaTeX covers the general image commands.
Why LaTeX can’t read SVG directly
LaTeX engines read PDF, PNG and JPG files directly. EPS needs extra steps. SVG is an XML-based format that these engines don’t handle. If you write \includegraphics{picture.svg} with pdfLaTeX, you get an Unknown graphics extension error. You need to convert the drawing first, or let a package do it during compilation.
Option 1: the svg package
The svg package calls Inkscape during compilation. To use it:
- Install a current Inkscape release (1.x). Make sure the
inkscapecommand runs from a terminal. - Compile with shell escape turned on, so LaTeX can run Inkscape:
pdflatex --shell-escape main.tex
- Load the package in the preamble:
\usepackage{svg}
- Insert the drawing in the body:
\begin{figure}[htbp]
\centering
\includesvg[width=0.8\textwidth]{diagram}
\caption{Workflow diagram drawn in Inkscape.}
\label{fig:workflow}
\end{figure}
The .svg extension can usually be left out. If your SVG files are in a subfolder, set the path once:
\svgpath{{images/}}
By default, the package has Inkscape split the text out of the drawing, so LaTeX typesets the labels with your document’s fonts and any math. If that causes problems, turn the feature off with \usepackage[inkscapelatex=false]{svg}. Inkscape then renders the text itself, and its fonts may not match the rest of the document.
On Overleaf, the svg package can run in the project’s compile environment. If a compile fails with an error about Inkscape, use option 2 or 3 instead.
Option 2: export PDF with LaTeX text from Inkscape
This route doesn’t need shell escape, and the labels are typeset by LaTeX.
- Open the SVG in Inkscape and choose File, then Save As. Pick the PDF format.
- In the PDF options, turn on the option that omits text from the PDF and creates a LaTeX file. The exact wording depends on your Inkscape version.
- Inkscape writes two files:
diagram.pdfanddiagram.pdf_tex. Keep them in the same folder. - Include the drawing in LaTeX:
\usepackage{graphicx}
...
\begin{figure}[htbp]
\centering
\def\svgwidth{0.8\textwidth}
\input{diagram.pdf_tex}
\caption{Workflow diagram.}
\label{fig:workflow}
\end{figure}
The \svgwidth macro sets the width, and \input reads the file that places the PDF and its text. LaTeX typesets the labels, so simple math in a label can work. Test one label first, because the result depends on how the text was entered in Inkscape.
Option 3: export a plain PDF
This is the simplest route. You export the drawing as a PDF and include it like any other image:
inkscape diagram.svg --export-filename=diagram.pdf
\includegraphics[width=0.8\textwidth]{diagram}
The labels stay as text in the PDF, drawn with the fonts Inkscape uses. LaTeX doesn’t typeset them, so labels won’t pick up your document’s font or math. For the classic latex and dvips route, export an EPS file instead. The guide to EPS images covers that workflow.
Which option to choose
| Option | Shell escape needed | LaTeX typesets labels | Setup |
|---|---|---|---|
| svg package | Yes | Yes, by default | Install Inkscape and enable shell escape |
| PDF with LaTeX text | No | Yes | Keep two files together |
| Plain PDF | No | No | Simplest, but no LaTeX math in labels |
If you edit the drawing often and want LaTeX math in its labels, the svg package is the most convenient, provided shell escape is available. If you share the project with others or submit it to a journal, the PDF routes avoid shell escape. For simple diagrams, you can also draw them in LaTeX itself, as the guide to block diagrams and flowcharts shows.
Common problems and fixes
Unknown graphics extension: .svg. You used\includegraphicswith an SVG file. Use one of the three options above.- The svg package doesn’t produce the image. Check that Inkscape runs from a terminal, and that you compiled with
--shell-escape. \inputcan’t find the file. The.pdf_texfile and its.pdfmust be in the same folder as the.texfile, or the path must include the folder name.- The text uses the wrong font. With the svg package, set
inkscapelatex=falseonly if the LaTeX text causes trouble. Otherwise, check the labels in Inkscape. - The drawing is too large or too small. Set
widthon\includesvgor\includegraphics, or set\svgwidthbefore\input.
Summary
For the most control over labels, use the svg package with Inkscape and shell escape. For a build that doesn’t need shell escape, export a PDF with LaTeX text and use \input. For the simplest setup, export a plain PDF and include it with \includegraphics.