The following are my notes (mostly for my benefit) about how I got Inkscape and LaTeX to properly work together, so that I can have LaTeX text in my images.
Before anything, check that you have Inkscape v0.48 or higher installed. Also, I’ve tried this using PDFLaTeX (not the dvi+ps LaTeX compilation path).
Whenever I’m working on a LaTeX project, I usually keep all my images in a separate images directory, so all the paths reflect that. Adjust to your needs.
The definitive guide is the InkscapePDFLaTeX.pdf document of the svg-inkscape CTAN page.
To keep things simple with when it comes to the size of figures with respect to the size of text, draw your SVG image using the same font size as your working LaTeX project. In my case, it was 10pt.
Save your image, eg as “~/images/myTestImage.svg”. In addition, in Inkscape go to the option File -> Save a Copy and chose PDF as your output format in the same folder as the SVG. In the PDF options popup that comes right after select the options:
- PDF+LaTeX: Omit text in PDF and create LaTeX file
- Export area is drawing
Save and go to your LaTeX document.
The preamble of your LaTeX document should contain this command:
\newcommand{\includesvg}[1]{
\immediate\write18{inkscape -z -D –file=images/#1.svg
–export-pdf=images/#1.pdf –export-latex}
\input{images/#1.pdf_tex}
}
Also, make sure you add to the preamble the images path:
\graphicspath{{images/}}
Now go at the point in your document where you want your image to appear and add:
\begin{figure}
\centering
% \def\svgwidth{\columnwidth}
\includesvg{myTestImage}
\end{figure}
Note the commented out line. If you uncomment it, you can adjust the size of the shapes of your image. However, the size of the text remains the same. Without it, the image is imported with its own size and since you’ve used font size 10pt it should appear normal.
Finally, you need to enable the “write18” feature of LaTeX, which enables it to run external programs (in our case, the headless inkscape). You do this by adding
-enable-write18
to the TeX command-line. You can either add it to your makefile or invoke it everytime. I prefer to use Kile as my LaTeX IDE and there you need to go to Settings -> Configure Kile -> Tools -> Build -> PDFLaTeX -> General -> Options and add it there. I found solace in adding it as the first of the arguments.
Compile and gaze at the awesomeness.
From now on, if you want to change your image, you do so in Inkscape, save the SVG normally (ctrl+S) and recompile the LaTeX document. That saves you the annoying extra step of exporting.
Note1: It so happens that as of April 12, 2011, the version of Inkscape on the CSLab servers is v0.47. So you’ll have to work on a local copy on your machine. In the case of my co-authoring team, that’s no problem, because I’m in charge of the paper’s pictures! Moreover, the invocation of Inkscape whenever they try to compile the LaTeX document doesn’t cause them any problems, as Inkscape merely complains for the extra –export-latex command.
Note2: A more elegant solution would be to move the invocation of Inkscape to the makefile. I’ll do that sometime.
Hello,
Thanks for the tutorial. I was having trouble using includesvg since write18 was not activated. If anyone uses linux, you have to:
– locate the texmf.cnf file thanks to the command “kpsewhich texmf.cnf”
– in this file change the line “shell_escape = f” by “shell_escape = t”.
I would just like to add that by modifying the includesvg function it is possible to compute the pdf / pdf_tex files only if the svg file has been modified:
\newcommand{\executeiffilenewer}[3]{%
\ifnum\pdfstrcmp{\pdffilemoddate{#1}}%
{\pdffilemoddate{#2}}>0%
{\immediate\write18{#3}}\fi%
}
\newcommand{\includesvg}[1]{%
\executeiffilenewer{#1.svg}{#1.pdf}%
{inkscape -z -D –file=#1.svg %
–export-pdf=#1.pdf –export-latex}%
\input{#1.pdf_tex}%
}
Hi,
works like a charme. The only thing which is really annoying is that the text in an image is place somewhat randomly in the resulting compiled pdf document. For instance, if you make a circle and want to center text within that circle, how do you know where to place it in the .svg image? In my cases, I have to manually adjust each line of text serveral times till it is at the right place. Any suggestions for that?
Thanks.