SVG in LaTeX: how to include an SVG image
LaTeX's \includegraphics cannot read SVG. Three ways to include one: convert it to PDF, use the svg package with Inkscape, or let LaTeX typeset its text.
Published
LaTeX cannot place an SVG file directly. Give one to \includegraphics and the run stops with ! LaTeX Error: Unknown graphics extension: .svg. The picture has to reach LaTeX as a PDF, which is also a vector format, so nothing is lost. There are three ways to get there: convert the SVG to PDF yourself, let the svg package call Inkscape to do it during the run, or have Inkscape split the drawing so that LaTeX sets the text in the document’s own fonts.
Which image formats LaTeX reads
Overleaf’s documentation sums up what each compiler accepts:
| Compiler | Image formats |
|---|---|
latex (DVI output) | EPS only |
pdflatex | JPG, PNG and PDF, and EPS by way of the epstopdf package |
SVG is in neither list. The same page gives the rule of thumb: “If you have an image in vector format, you should go for PDF or EPS.”
Way one: convert the SVG to PDF first
This works with every LaTeX installation and on every online editor, because by the time LaTeX runs there is only a PDF.
With Inkscape, from a terminal:
inkscape --export-type=pdf drawing.svg
Inkscape’s manual for the command line says the exported area of a PDF is the page by default, and that with --export-area-drawing it is “the bounding box of all objects of the document”. Add that option if the picture should be trimmed to the artwork and not to the page.
In a browser, with nothing installed: SVG to PDF writes a one-page vector PDF whose page is exactly the size of the drawing. We checked the output for a 60 mm square test drawing: the page came out 170.079 points square, which is 60 mm at 72 points to the inch, and the file was 890 bytes of plain path commands. It carries shapes, fills, strokes and clip paths. It leaves out text, pictures and filters, and flattens a gradient to one colour, and it lists whatever it left out. So use it for logos, icons, diagrams and line art, and convert any text to paths first. For a drawing with live text or gradients, use Inkscape.
Then include the PDF like any other figure:
\usepackage{graphicx}
...
\begin{figure}
\centering
\includegraphics[width=0.6\linewidth]{drawing}
\caption{A drawing that began as an SVG.}
\end{figure}
Leaving off the extension lets LaTeX find drawing.pdf for itself.
The PDF’s page is the SVG’s page. If the SVG has wide empty margins, the figure will too. Trim them first with Crop SVG, which fits the viewBox to the artwork, or use Inkscape’s --export-area-drawing.
Way two: the svg package
The svg package, by Philip Ilten and Falk Hanisch, adds a command that takes the SVG file itself. CTAN lists version 2.02k, dated 26 November 2020, as the current release.
\usepackage{svg}
...
\includesvg[width=0.6\linewidth]{drawing}
Its manual describes \includesvg as “quite similar to the \includegraphics command”. Behind the scenes the package runs Inkscape to export the SVG, then includes the result. That gives it two requirements, and both are stated plainly in the manual:
- Inkscape must be installed and its “installation path must be known to the operating system”. The manual’s test is to type
inkscape -Vin a terminal. If that prints a version, the package can find it. If Inkscape lives somewhere unusual, set\svgsetup{inkscapeexe=...}in the preamble. - LaTeX must be allowed to run programs. “Passing flag
--shell-escapeto the LaTeX engine is utterly essential when using package svg.”
pdflatex --shell-escape report.tex
Without that flag the package warns that “it wasn’t possible to launch the Inkscape export”, and there is no exported picture to include. Shell escape lets a document run any command on your computer, so switch it on only for documents you trust.
Useful options, all from the manual:
| Option | What it does |
|---|---|
width, height, scale | Size of the figure, as with \includegraphics. With both width and height, the picture is scaled so that neither is exceeded |
inkscapelatex=false | Keep the text exactly as drawn in the SVG. See way three for the default |
inkscapearea=page | Export the SVG’s page. The default, drawing, exports the bounding box of the objects |
inkscapeformat=png | Export a PNG instead of a PDF, at 300 dpi unless inkscapedpi says otherwise |
pretex=\tiny | Run a LaTeX command before the picture, for example to change the size of its text |
\svgpath{{svg/}} | Tell the package which folder holds the SVG files, like \graphicspath |
The export is repeated only when the SVG file is newer than the exported one, so later runs are quick.
For a document that must compile without shell escape, the same package has \includeinkscape, which “includes files already exported by Inkscape”. You run Inkscape once by hand and commit the exported files.
Way three: let LaTeX set the text
Lettering inside a figure usually looks best when it matches the document: same font, same size, real mathematics. Inkscape can export a drawing in two parts for exactly this. Its manual describes the --export-latex option as “used for creating images for LaTeX documents, where the image’s text is typeset by LaTeX”: it “splits the output into a PDF/PS/EPS file” and “a LaTeX file”. The text goes into the LaTeX file, and that file pulls in the PDF.
inkscape --export-type=pdf --export-latex drawing.svg
In the document, input the LaTeX file that Inkscape wrote instead of including the PDF. The svg package’s manual gives its extension as .pdf_tex, so for drawing.pdf look for a file of this name beside it:
\input{drawing.pdf_tex}
Because LaTeX typesets the text, a label in the SVG such as $\alpha_1$ comes out as mathematics.
This is also what the svg package does by default. Its inkscapelatex option is on unless you turn it off, so with \includesvg the text in your drawing is set by LaTeX. That explains two surprises: text that changes font or shifts, and labels holding characters such as _, % or &, which LaTeX reads as commands and which can stop the run. If you want the text left as drawn, use inkscapelatex=false.
Overleaf
Upload a PDF and Overleaf treats it like any other figure, and its documentation recommends PDF for vector images. That is the dependable route.
Whether \includesvg works there is another matter. Overleaf’s documentation, as we read it in October 2026, does not say whether its hosted compiler allows shell escape or has Inkscape installed, so we cannot promise it. For people who run Overleaf Community Edition on their own server, the documentation does say that \write18, the mechanism behind shell escape, “is disabled by default”, and that it can be enabled for a project with a latexmkrc file containing $pdflatex = 'pdflatex --shell-escape';.
If \includesvg fails on Overleaf, convert the SVG to PDF, upload the PDF and use \includegraphics.
Errors and what they mean
| Message or symptom | Cause | Fix |
|---|---|---|
Unknown graphics extension: .svg | \includegraphics was given an SVG | Convert to PDF, or use \includesvg |
The picture is missing after a run without --shell-escape | The run was not allowed to call Inkscape | Add --shell-escape, or convert the file yourself |
| Inkscape is not found | It is not installed, or not on the system path | Check with inkscape -V, or set inkscapeexe |
| Text in the figure changed font or moved | The text is being typeset by LaTeX | Use inkscapelatex=false, or convert the text to paths in the SVG |
| The run stops inside the figure | A label may hold a character LaTeX treats as a command | Escape it, or use inkscapelatex=false |
| Wide empty space round the figure | The SVG’s page is larger than the artwork | Crop the SVG, or export the drawing area only |
| The figure looks soft when zoomed | It was converted to PNG on the way | Convert to PDF instead, which stays vector |
Before you convert
A tidy SVG converts cleanly. Open it in the SVG viewer to see its size and whether it holds text or embedded pictures. A photograph inside an SVG stays a photograph inside the PDF, and for that a JPG or PNG included directly is simpler. For going the other way, from a LaTeX document or equation to an SVG file, see LaTeX to SVG.