# Inkscape images with LaTeX fonts

With the release of Inkscape 0.48, it is now possible to match the font of the text in your images with the font used in your LaTeX document. This includes math environments and references. Hence that this is a very powerful tool that will make your LaTeX documents even prettier! Previously, this integration was also possible, but it was a bit of a pain. In this post I’ll show you how to get LaTeX typesetting in your Inkscape pictures.

## Creating the image

For this example, I’m going to create a double pendulum. I’m not going to show you how to draw this, because it isn’t that hard and not in the scope of this blog. The result can be viewed here (Note: the .pdf image can be downloaded below).

## Inserting text

This is the easy part, where it was before rather difficult. To insert text you don’t have to bother about the fonts you’re using. In my pendulum example, I want text next to the rods and the masses. I also want to indicate two angles. What I do is just pick the text tool in Inkscape and insert $m_1$ next to the first mass. The same is done for the second mass and in Inkscape it looks like this. This doesn’t look okay at all! But remember what I said before, don’t worry about the font.

After I put the rest of the text in my image, I’d like to export it as a .pdf file. To do so, go to File > Save As… > Choose Portable Document Format (*.pdf). Now, a small window pops up. Choose the settings as shown here. After you save, Inkscape had created to files: the .pdf image and an .pdf_tex file. The last one contains the text information.

Open your LaTeX editor and create a document as. I used:

\documentclass[]{article} \usepackage{graphicx} \usepackage{color} \usepackage{transparent} \begin{document} \begin{figure}[htb] \centering \def\svgwidth{200pt} \input{drawing.pdf_tex} \caption{Double pendulum} \end{figure} \end{document}

Let’s explain this a bit. The graphicx package is needed because we’re inserting an image. The color package and transparant package are needed if you use colors and/or transparency in you image. I’ve used grey once, which is treated as a color.
Inside the figure environment you see the svgwidth line. This line defines the width of your image, since this is not yet done in the .pdf_tex file created by Inkscape. The next line inputs the image with the text.

Done! Render your document and you’ll see that the text in your images perfectly fits the font you use in your document.

## Making adjustments to the picture

In my example, I used a rather large font in Inkscape. This way, it’s pretty hard to place the text on the exact right spot (as can be seen in the compiled PDF, downloadable below). It’s wise to use a small font, for instance Arial size 6. Using a smaller font will make it a lot easier to place the text in the right place, especially if you have a lot of text to insert.

If you find the result compiled by LaTeX not satisfying and you want to adjust the position of some text elements, there are a few ways to do this. The first, of course, would be to adjust the whole image in Inkscape. But another way is to open the .pdf_tex file in your LaTeX editor. Scroll down to see the picture environment and notice the \put commands. These can be interpreted as follows:

\put(x,y)

There is more code following this command, but by changing the x and/or y components of the command you can shift the picture horizontally and/or vertically. This is a nice solutions to make small adjustments.

You can download the content of this post in a zip file. In here, the image files are included. Also I used the blindtext package to create dummy text. In the .tex file, the used commands are commented.

1. jose says:

Nice Post!
Thanks.
It would be perfect for me y i could locate the images in a subfolder. I dont know why but i only can success if i put them in the root path (the same as the tex file)

• Frits says:

Hi Jose,
That is possible by adding  \input{myfigs/drawing.pdf_tex} to the preamble, where ‘myfigs’ is the name of the subfolder containing drawing.pdf_tex and drawing.pdf. If that doesn’t do the trick try to add \graphicspath{{figs/}} to the preamble as well.

2. Jordan says:

Hi, do you know how I get text on multiple lines? If I write “text *enter* text” to get it on two lines, it works well in inkscape but LaTeX just keeps it all in one long line.

• Frits says:

I think you should try the ‘LaTeX syntax’: “text \\ text” instead of “text *enter* text”

3. Tweety600 says:

Hi, I am experiencing difficulties with the method.

My source code looks like the one on this page (difference: included packages are inputenc and babel) but I do not get ouptut as expected. Text is there (Title, caption and stuff) but the picture is missing.

MacTeX2012, Inkscape 0.48.2, Mountain Lion.

When I compile my .tex file, I do not even get an error message.

When I open the drawing.pdf_tex, I see some code, looking reasonable to me.

Any ideas?

• Frits says:

Does it work when you use exactly the same source code?

Also, have you tried different PDF viewers? I recall that I once had a similar problem of a graphic not showing in Skim, but in Adobe or Preview.app it did.

• Ash says:

it’s a path problem
\graphicspath{{./the_graphics_folder/}}

4. Núria says:

Thank you for this nice trick and explanation – since psfrag stopped working well I was having real trouble. This is wonderful.

I have a problem though. In pdf everything seems to work fine. Instead, when using eps figures, all labels appear misplaced if the tex commands surpass the drawing area.

I believe the reason is that the bounding box of the figure seems to include the tex commands in the svg file, while the coordinates are calculated with respect to the naked drawing.

Does anyone know how to fix this? Restricting the tex labels not to exceed the drawing is not a good option if you have many complicated tex commands.

Thanks!

• Frits says:

Sorry for the (very) late reply. If you’re still having this problem, email me with a minimal working example. Then I’ll try to figure out what’s going on!

5. Bee says:

Hello,
Thanks for this useful article! How do I use the \put(x,y) correctly? Do I have to write it in inkscape or latex? And where do I know the exact coordinates for x and y from?

Bee

• Frits says:

Hi Bee,
The idea is that you create a figure, including some text and/or formulas, in Inkscape. Then you export the figure to .pdf_tex format, as described in my post. If you’re not satisfied with the placement of the text/formulas in your figure when you compile your LaTeX document, then you can open the .pdf_tex file in your LaTeX editor and there you will see command that look like: \put(x,y). Where x and y are values.

So, Inkscape automatically generates the \put(x,y) commands for you and if you’re not happy with that afterwards, you can manually change them. This is unfortunately trial-and-error: change the command, compile your LaTeX document, check if the result is better, etc.

6. Carlos says:

It’s good, I didn’t know about of latex text on version 0.48, every time I had to typing on a editor latex online then download the file with extension .svg and add it to inkscape like a out file haha. By the way on linux is so easy to do it, but in OS X was hard try to do latex text, on the web there are some tips but I didn’t like it. Thanks so much!

7. mas says:

Frits, I checked again on a clean \$HOME dir. Same result. Yes, the settings are exactly the same.

I will check on a couple of other machines and then file a bug report.

8. Frits says:

MAS, that’s strange. Did you use the same settings as in the screenshot here?
I’ve tested it once more on both OS X and W7 and it works fine, so you might want to search for help at the Inkscape Forums.

9. MAS says:

Nice tip. But, when I tried saving a drawing, inkscape is saving the whole page and the result is not as expected. Maybe it is an inkscape bug. I am using inkscape 0.48.1-2 (debian testing).

10. Frits says:

Daniele, I have heard about inkscape2tikz. It’s indeed a great package.

The result of inkscape2tikz is basically the same as the result of the method described in this post (note the last but one paragraph of the post, about making adjustments). If you’re not familiar with TikZ, my solution is probably more straight-forward if you want to edit the text in your image later on. If you want to edit the image itself later on, the inkscape2tikz package is indeed very powerfull.

11. Daniele says:

Hello! Have you tried inkscape2tikz?