The svg package

Includes SVG files with \includesvg by calling Inkscape during the LaTeX run to convert them to PDF.

This package runs an external program and needs -shell-escape. The editor compiles without shell escape, so the package does not work there.

Loading the package

\usepackage{svg}

pdfLaTeX cannot read SVG files. The svg package does not change that; it starts the program Inkscape for every SVG file, lets it export a PDF into the folder svg-inkscape, and includes the result. Two conditions follow: Inkscape has to be installed, and LaTeX has to run with -shell-escape, which allows it to start other programs.

Where shell escape is switched off, which is the safe default, \includesvg stops with the error that the file ..._svg-tex.pdf is missing. Convert the SVG to PDF yourself in that case and include it with \includegraphics from graphicx.

By default the text of the drawing is not part of the exported PDF. LaTeX sets it on top in the document font, so formulas in the SVG text are typeset by LaTeX. inkscapelatex=false keeps the text as it was drawn.

Main commands

\includesvg{diagram}Includes diagram.svg; the extension can be left out.
\includesvg[width=0.6\textwidth]{diagram}Sets the width; height and scale work as well.
\includesvg[inkscapelatex=false]{diagram}Leaves the text inside the drawing, in the font of the SVG.
\svgpath{{figures/}}Folder in which the package looks for SVG files.
\svgsetup{inkscapelatex=false}Sets options for all following \includesvg commands.

Complete example

\documentclass{article}
\usepackage{svg}
\begin{document}
% Needs Inkscape and a run with -shell-escape.
\begin{figure}[ht]
  \centering
  \includesvg[width=0.6\textwidth]{diagram}
  \caption{A drawing included from the file diagram.svg.}
\end{figure}
\end{document}

File diagram.svg:

<svg xmlns="http://www.w3.org/2000/svg" width="200" height="100" viewBox="0 0 200 100">
  <rect x="10" y="10" width="180" height="80" fill="#cfe8ff" stroke="#1f77b4" stroke-width="2"/>
  <text x="100" y="58" font-size="20" text-anchor="middle">Diagram</text>
</svg>

This example needs shell escape and was not compiled for this page.

Pitfalls

Related pages