Black Friday 2025 – NPI EA (cat = Baeldung on CS)
announcement - icon

Yes, we're now running our Black Friday Sale. All Access and Pro are 33% off until 2nd December, 2025:

>> EXPLORE ACCESS NOW

1. Introduction

In this tutorial, we’ll show how to embed Scalable Vector Graphics (SVG) files in a LaTeX document. SVG files are 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 we wish to publish on the web.

2. Inkscape

LaTeX doesn’t natively support including SVG images. Because of this, we’ll need to first install two pieces of software: the LaTeX svg package and the Inkscape vector graphics editor. We can install svg using a TeX package manager like tlmgr – the native TeX Live Manager.

Inkscape, an open-source software for Linux, Windows, and macOS, can import and export various file formats, including SVG (default), EPS, PDF, PS, and PNG. The svg package automates the integration of SVG graphics into LaTeX documents. Inkscape’s command line tool is used to export the text within an SVG graphic to a separate file, which is then rendered by LaTeX.

To elaborate further, Inkscape can export the graphics to a PDF, PNG, PS, or another supported format, and the text to a separate LaTeX file. When the LaTeX file is input in a LaTeX document, the PDF, PNG, or PS image is included with overlaid text. Notably, Inkscape can be used independently of svg; however, we discuss it only in the context of svg.

3. The \includesvg Command

The \includesvg command, which is part of the svg package, is used to include standalone SVG graphics into a LaTeX document. We use it to insert SVG figures into our LaTeX documents. The \includesvg command depends on Inkscape to do all the heavy lifting. Typically, it performs three actions:

  1. Automated export of the SVG file with Inkscape to a PDF(EPS, PS, or PNG) file.
  2. Automated export with Inkscape to a correlating LaTeX file (.tex file) if the SVG file has embedded text.
  3. After the export is done, include the graphic file and maybe the LaTeX file in the LaTeX document.

This command is typically used as:

\includesvg[<options>]{<svg filename>}

The options control features such as width, height, and scale. 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 conversion we want Inkscape to perform. To pass options to package svg, use \usepackage. For instance, we can set the conversion format 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 have an SVG file named figSVG.svg, that we wish 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:

An svg file that is to be included in a LaTeX file.

3.2. Compilation

We can run the PDFTeX typesetter on a .tex file directly, usually creating PDF output. This is not something we need to run when we automate the complete conversion and inclusion with the \includesvg command. PDFTeX is an extension of TeX that can produce PDF directly from TeX source. Further, PDFLaTeX is a wrapper around PDFTeX. Let’s assume we are working with a TeX file called shapes.tex, a LaTeX source document. We can convert it into a PDF using PDFLaTeX:

pdflatex --shell-escape shapes.tex

The –shell-escape option allows the running program to invoke an external program, in this case, Inkscape. Further, we can enable this option to run other external commands from inside the .tex file. In addition to pdflatex, we can also use xelatex and lualatex to convert to PDF.

When Inkscape is called from within LaTeX, it will create a subdirectory under the current directory. The new directory’s name will be shapes-inkscape, and it will contain the converted files (figSVG.pdf, or figSVG.png, for example).

4. Various Outputs

The svg package supports several parameters for stretching and shrinking our SVGs. Let’s take a look at how different arguments to the \includesvg command impact the output of the program.

4.1. Specifying Width

When the width of a vector graphic is the only parameter of interest, specify the width, say, to 1 inch:

\includesvg[width=1.0in]{figSVG}

This modifies the given SVG file to:

A width restricted svg file

4.2. Specifying Height

Furthermore, we can change only the height using the height parameter:

\includesvg[height=2.75in]{figSVG}

Notice how the resulting image’s height and width are affected to maintain the aspect ratio:

A height restricted svg file

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:

A distorted svg file

4.4. Specifying Scale

Or, perhaps our document needs a smaller image. For this, includesvg provides a scale parameter:

\includesvg[scale=1.25]{figSVG}

A scaled svg file

5. Conclusion

In this article, we showed how to include SVG image files in a LaTeX document using \includesvg and the capabilities provided by Inkscape’s command-line tool. Furthermore, the option to run a modern LaTeX engine, such as pdflatex, xelatex, or lualatex, directly on a LaTeX file exists.

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.