# Includesvg with % sign

I am using \usepackage{svg} to include an svg file using \includesvg{filename.svg} and compiling using pdflatex --shell-escape file.tex

This generally works like a charm. However I encountered a problem when the svg file (created by inkscape) includes the percent character (%).

During compilation pdflatex gives the following error message:

Runaway argument?

{\color [rgb]{0,0,0}\makebox (0,0)[lt]{\lineheight {1.25}\smash {\begin \ETC.

! File ended while scanning use of \put. \par l.29
\includesvg{filename.svg}

As a quick and dirty fix I can convert the font in the svg into a path and everything works, but how can I include an svg that contains a proper % character into LaTeX?

Sample code:

\documentclass{scrartcl}
\usepackage{svg}
\begin{document}
\includesvg{filename.svg}
\end{document}


This uses the svg-image at filename.svg, which is a simple svg file with only a %-sign as text.

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="210mm"
height="297mm"
viewBox="0 0 210 297"
version="1.1"
id="svg8"
inkscape:version="0.92.3 (2405546, 2018-03-11)"
sodipodi:docname="filename.svg">
<defs
id="defs2" />
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:zoom="0.35"
inkscape:cx="400"
inkscape:cy="560"
inkscape:document-units="mm"
inkscape:current-layer="layer1"
showgrid="false"
inkscape:window-width="1022"
inkscape:window-height="746"
inkscape:window-x="0"
inkscape:window-y="20"
inkscape:window-maximized="1" />
<rdf:RDF>
<cc:Work
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title />
</cc:Work>
</rdf:RDF>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1">
<text
xml:space="preserve"
style="font-style:italic;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:6.61458302px;line-height:125%;font-family:Sans;-inkscape-font-specification:'Sans Italic';letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.26458332px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
x="43.089287"
y="111.79166"
id="text10"><tspan
sodipodi:role="line"
id="tspan8"
x="43.089287"
y="111.79166"
style="stroke-width:0.26458332px">%</tspan></text>
</g>
</svg>

• @DavidCarlisle Sample code added. Nov 23, 2018 at 15:13
• inkscape rejects the SVG file as invalid Nov 23, 2018 at 15:49
• @egreg My inkscape (ver 0.92.3) does not complain. In fact I created the file with inkscape, so it would be strange if it rejected the SVG. Can you see the file in the browser or in some other viewer? Nov 23, 2018 at 15:56
• Firefox doesn't balk, but inkscape 0.92.2 does. But the graphic interface of inkscape opens it. Weird. Nov 23, 2018 at 21:06

The error appears to be in inkscapes combined tex/pdf export as it fails to quote the % in text. It is also hard to use \catcode to make % a normal chanacter that does not need quoting as it inserts a % at the end of almost every line.

the simplest fix it to edit svg-inkscape/filename_svg-tex.pdf_tex (which is generated after the first run)

\put(-0.11824539,0.01843611){\color[rgb]{0,0,0}\makebox(0,0)[lt]{\lineheight{1.25}\smash{\begin{tabular}[t]{l}\textit{%}\end{tabular}}}}%


changing % to \% to get

   \put(-0.11824539,0.01843611){\color[rgb]{0,0,0}\makebox(0,0)[lt]{\lineheight{1.25}\smash{\begin{tabular}[t]{l}\textit{\%}\end{tabular}}}}%


the package does not over-write the file on later runs so it will be included without error if you re-run latex on the main file.

By design, the svg package renders text in the SVG file as latex. There are two straightforward solutions:

1. If you want text in the SVG rendered as latex, use proper latex syntax (i.e. escape the % with a \).
2. If you don't want text in the SVG rendered with latex, provide the option inkscapelatex=false when you load the svg package or when you invoke the includesvg command.

If you want to split the difference — e.g. you want text to render with the document font, but you don't want % to be interpreted as a comment — then David Carlisle's answer has you covered.

This helped me a lot when I encountered a lot of error messages for a simple figure even though other figures that I implemented the same way hadn't given any problems compiling.

@David Carlisle's fix definitely works, however, it was more obvious (and maybe even easier) for me to just change the "%" in the picture itself (meaning in the Inkscape-Window, editing the file) to an "\%", as you would in any .tex file.

Just leaving this here in case this might help someone.