## 1. Introduction

In this tutorial, we’ll show how to embed SVG (Scalable Vector Graphics) files in a LaTex document. SVG files have the useful property of being scalable and zoomable. When we view them in a web browser, they don’t change resolution upon resizing the window. This makes them ideal for use in documents that we wish to publish on the web.

## 2. Inkscape

We’ll need to install the Inkscape drawing program on our machine before proceeding further. It’s free and open source software, available for Linux, Windows and macOS. We need Inkscape to convert from svg to pdf, png, ps & eps files (pdf is the default), but all this is done automatically by the \includesvg command described below. We don’t need Inkscape for other types of image files.

## 3. The \includesvg COMMAND

The \includesvg command is part of the svg package. We use it to insert SVG figures into our LaTeX documents. This command is typically used as follows:

\includesvg[options]{imagefilename}

The options control features such as width, height, scale etc. We can omit the filename extension most of the time, since the svg package can take care of it automatically in most modern LaTeX engines. We can also use options to control what kind of conversion we want Inkscape to perform. For instance, we can set conversion to png:

\usepackage[inkscapeformat=png]{svg}

We could also choose ps, eps, or leave the default option pdf.

### 3.1. Including .svg FILES

If we had an svg file figSVG that we wished to include, our code would be as follows:

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

Here is an .svg file.

\includesvg{figSVG}
\end{document}


The output would look like this:

### 3.2. Compilation

We’ll use PDFLaTeX:

pdflatex --shell-escape svg.tex

The —shell-escape option allows the running program to invoke an external program, in this case, Inkscape. In addition to pdflatex, we can also use the xelatex and lualatex engines. In the case of lualatex, the –shell-escape option is not required.

Let’s assume we are working with a LaTeX file called myFile.tex. When inkscape is called from within LaTeX, it will create a sub-directory under the current directory. The new directory’s name will be myFile-inkscape, and it will contain the converted files (figSVG.png, for example).

## 4. Various Outputs

We now show how different arguments to the \includesvg command impact the output of the program,

### 4.1. Specifying Width

We can specify width. For instance, if we set it to 1 inch:

\includesvg[width=1.0in]{figSVG}

we’ll get the following:

### 4.2. Specifying Height

If, on the other hand, we specify the height:

\includesvg[height=2.75in]{figSVG}


we’ll get:

### 4.3. Width, Height, and Distortion

When we specify both width and height and allow distortion. For example:

\includesvg[width=1.25in,height=2.75in,distort=true]{figSVG}

We obtain a distorted figure that obeys both width and height options:

### 4.4. Specifying Scale

We can also specify the scale and get a proportionately scaled figure:

\includesvg[scale=1.25]{figSVG}
 

## 5. Conclusion

In this article, we showed how to include svg image files in a LaTeX document using \includesvg. We found this to be relatively easy in an environment running a modern LaTeX system, such as pdflatex, xelatex and lualatex.

It is essential to have the Inkscape program on our computer. We can also use the material in this article to include figures exported by other LaTeX programs.