Comment 16 for bug 1417470

Revision history for this message
Biber (c-woltmann) wrote :

I just updated to Inkscape 0.91 and ran into the same trouble.
I call inkscape from inside LaTeX as I think many of you do as well.

Here is a solution that works fine for me (and because it uses some standard commands ... only for Linux). It essentially goes through the inkscape generated TEX files (on-the-fly) and removes bad stuff from them (like strings containing '\\' or these nasty wrong page numbers...). Some of the code is not my work, but recycled from different sources I can't recall (sorry for not citing them properly).

%######## Put all this code _before_ the '\begin{document}' statement. ###########

%Tell LaTeX where to look for graphics (the './.tmp /' folder will be used by the '\includesvg' command for the inkscape PDF+TEX output, './Figures/' is where all my SVGs are stored.)

\graphicspath{ {./Figures/} {./.tmp/} }

%We'll never call this manually, it's just used by the '\includesvg' command to avoid unnecessary rebuilding of PDFs

\newcommand{\executeiffilenewer}[3]{\ifnum\pdfstrcmp{\pdffilemoddate{#1}}{\pdffilemoddate{#2}}>0{\immediate\write18{ [ -d ./.tmp/ ] || mkdir ./.tmp; #3}}\fi}

%Here it comes... It is necessary that _all_ our SVG files are collected (e.g. by symlinking) in only one folder (here it is called './Figures/'. If you want a different one, make sure to change the path in this command as well.

\newcommand{\includesvg}[2][\textwidth]{\def\svgwidth{#1}\executeiffilenewer{./Figures/#2.svg}{./.tmp/#2.pdf}{\unexpanded{PDF_FILE="./.tmp/#2.pdf"; inkscape -z --file=./Figures/#2.svg --export-pdf=$PDF_FILE --export-latex; sed -i 's/\\\\/\n/g' ${PDF_FILE}_tex; MAXPAGE=$(pdfinfo $PDF_FILE | grep -oP "(?<=Pages:)\s*[0-9]+" | tr -d " ") ; sed -i "/page=$(($MAXPAGE+1))/,\${/page=/d}" ${PDF_FILE}_tex; } } \input{./.tmp/#2.pdf_tex}}

%##############################################################

You can then use the '\includesvg' command similarly (though not so advanced) to '\includegraphics', e.g.

\begin{figure}
     \centering
     \includesvg[0.5\textwidth]{My_Nice_SVG_File} %Where the file is located/linked at: ./Figures/My_Nice_SVG_File.svg
     \caption{My_Caption]
     \label{My_Label}
\end{figure}

Hope that is helpful for some of you,

Greetings, Bb