3

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:pageshadow="2"
     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" />
  <metadata
     id="metadata5">
    <rdf:RDF>
      <cc:Work
         rdf:about="">
        <dc:format>image/svg+xml</dc:format>
        <dc:type
           rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
        <dc:title />
      </cc:Work>
    </rdf:RDF>
  </metadata>
  <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. – user1583209 Nov 23 '18 at 15:13
  • inkscape rejects the SVG file as invalid – egreg Nov 23 '18 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? – user1583209 Nov 23 '18 at 15:56
  • Firefox doesn't balk, but inkscape 0.92.2 does. But the graphic interface of inkscape opens it. Weird. – egreg Nov 23 '18 at 21:06
3

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.