SVG drawn in Inkscape is not usable in overleaf with svg package

inkscapeoverleafsvg

I created an SVG drawing using Inkscape locally.
I then uploaded the created file to overleaf and wanted to include it.
I validated the correct setup with an svg file I had used before.

Not working svg

\begin{figure}[htpb]
    \centering
    \includesvg{figures/Zeichnung.svg}
    \caption{Borken svg}
    \label{fig:Broken}
\end{figure}

correct working svg

\begin{figure}[htpb]
\centering
\includesvg[width=0.55\textwidth]{figures/Definition_Viskositaet.svg}
\caption{working svg file}
\label{fig:Viskosität}
\end{figure}

Result

enter image description here

Overleaf gives me this error msg:

See the svg package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              
                                                  
l.5     \includesvg{figures/Zeichnung.svg}
                                          
Did you run the export with Inkscape? There's no file
`./svg-inkscape/Zeichnung_svg-tex.pdf_tex'
although `figures/Zeichnung.svg' was found.

I cannot find the specified file, but it's clearly working with the other svg file which gives me no error.

I assume that the file generated I generated with Inkscape is somehow not usable with the SVG package. However, I don't know how to fix this or how to create my own SVG which I can use in overleaf.
For clarification, the SVG I used to test the setup is from an online source and therefore not created by my self.

Best Answer

This was a known bug in the Inkscape pdf export (which is used by the svg package), see https://gitlab.com/inkscape/inkscape/-/issues/1984. The issue has been fixed in Inkscape itself (see https://gitlab.com/marcjeanmougin/inkscape/-/commit/9b5de7815fcd93c2801c7fb8703491125ef906b5) so at some point this will probably be picked up by Overleaf and the svg will render correctly.

In the meantime the bug report also provided a workaround: replace all instances of context-stroke in the SVG source by a fixed color, for example #000000 (black). In your SVG there were eight instances. I replaced them below:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
 
<svg
   width="125.33871mm"
   height="17.948942mm"
   viewBox="0 0 125.33871 17.948942"
   version="1.1"
   id="SVGRoot"
   sodipodi:docname="Zeichnung.svg"
   inkscape:version="1.1.2 (b8e25be833, 2022-02-05)"
   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
   xmlns:xlink="http://www.w3.org/1999/xlink"
   xmlns="http://www.w3.org/2000/svg"
   xmlns:svg="http://www.w3.org/2000/svg">
  <sodipodi:namedview
     id="namedview108087"
     pagecolor="#ffffff"
     bordercolor="#666666"
     borderopacity="1.0"
     inkscape:pageshadow="2"
     inkscape:pageopacity="0.0"
     inkscape:pagecheckerboard="0"
     inkscape:document-units="mm"
     showgrid="false"
     inkscape:zoom="0.64052329"
     inkscape:cx="239.6478"
     inkscape:cy="81.964233"
     inkscape:window-width="1264"
     inkscape:window-height="664"
     inkscape:window-x="1993"
     inkscape:window-y="260"
     inkscape:window-maximized="0"
     inkscape:current-layer="layer1" />
  <defs
     id="defs108082">
    <linearGradient
       inkscape:collect="always"
       xlink:href="#linearGradient41534"
       id="linearGradient104483"
       x1="326.86093"
       y1="76.218559"
       x2="369.78787"
       y2="76.218559"
       gradientUnits="userSpaceOnUse" />
    <linearGradient
       inkscape:collect="always"
       id="linearGradient41534">
      <stop
         style="stop-color:#0b30f6;stop-opacity:0.69999999"
         offset="0"
         id="stop41530" />
      <stop
         style="stop-color:#ff001c;stop-opacity:0.70194983"
         offset="1"
         id="stop41532" />
    </linearGradient>
    <linearGradient
       inkscape:collect="always"
       xlink:href="#linearGradient38240"
       id="linearGradient38242"
       x1="270.06329"
       y1="108.74166"
       x2="368.96173"
       y2="108.74166"
       gradientUnits="userSpaceOnUse"
       gradientTransform="matrix(0.43405083,0,0,0.43405083,209.63973,29.019152)" />
    <linearGradient
       id="linearGradient38240"
       inkscape:swatch="solid">
      <stop
         style="stop-color:#002bff;stop-opacity:1;"
         offset="0"
         id="stop38238" />
    </linearGradient>
    <marker
       style="overflow:visible"
       id="Arrow1Sstart-8"
       refX="0"
       refY="0"
       orient="auto"
       inkscape:stockid="Arrow1Sstart"
       inkscape:isstock="true">
      <path
         transform="matrix(0.2,0,0,0.2,1.2,0)"
         style="fill:#000000;fill-rule:evenodd;stroke:#000000;stroke-width:1pt"
         d="M 0,0 5,-5 -12.5,0 5,5 Z"
         id="path68676-4" />
    </marker>
    <marker
       style="overflow:visible"
       id="Arrow2Send"
       refX="0"
       refY="0"
       orient="auto"
       inkscape:stockid="Arrow2Send"
       inkscape:isstock="true">
      <path
         transform="matrix(-0.3,0,0,-0.3,0.69,0)"
         d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z"
         style="fill:#000000;fill-rule:evenodd;stroke:#000000;stroke-width:0.625;stroke-linejoin:round"
         id="path68697" />
    </marker>
    <marker
       style="overflow:visible"
       id="Arrow1Sstart-8-0"
       refX="0"
       refY="0"
       orient="auto"
       inkscape:stockid="Arrow1Sstart"
       inkscape:isstock="true">
      <path
         transform="matrix(0.2,0,0,0.2,1.2,0)"
         style="fill:#000000;fill-rule:evenodd;stroke:#000000;stroke-width:1pt"
         d="M 0,0 5,-5 -12.5,0 5,5 Z"
         id="path68676-4-4" />
    </marker>
    <marker
       style="overflow:visible"
       id="Arrow2Send-3"
       refX="0"
       refY="0"
       orient="auto"
       inkscape:stockid="Arrow2Send"
       inkscape:isstock="true">
      <path
         transform="matrix(-0.3,0,0,-0.3,0.69,0)"
         d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z"
         style="fill:#000000;fill-rule:evenodd;stroke:#000000;stroke-width:0.625;stroke-linejoin:round"
         id="path68697-0" />
    </marker>
  </defs>
  <g
     inkscape:label="Ebene 1"
     inkscape:groupmode="layer"
     id="layer1"
     transform="translate(-41.537344,-60.215376)">
    <g
       id="g69839"
       transform="matrix(0.37262531,0,0,0.37262531,-6.1711126,31.925465)"
       style="fill-rule:evenodd;stroke:#108000;stroke-opacity:1">
      <g
         id="g69827"
         style="fill-rule:evenodd;stroke:#108000;stroke-opacity:1">
        <rect
           style="opacity:0.971564;mix-blend-mode:normal;fill:#098000;fill-opacity:0.501393;fill-rule:evenodd;stroke:#108000;stroke-width:1;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
           id="rect86-9"
           width="97.898438"
           height="67.95063"
           x="270.56329"
           y="74.766342"
           ry="17.762169"
           transform="matrix(0.4220691,0,0,0.4220691,147.68606,52.931391)" />
      </g>
      <text
         xml:space="preserve"
         style="font-style:normal;font-weight:normal;font-size:2.68014px;line-height:1.25;font-family:sans-serif;fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:0.111672;stroke-opacity:1"
         x="276.55472"
         y="90.539818"
         id="text16494-8"><tspan
           id="tspan16492-9"
           style="font-size:2.68014px;fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:0.111672;stroke-opacity:1"
           x="276.55472"
           y="90.539818"
           sodipodi:role="line">Ardunino</tspan></text>
    </g>
    <g
       id="g106990"
       style="stroke:#66de03;stroke-opacity:1"
       transform="matrix(0.61676117,0,0,0.61676117,-72.465685,11.82445)">
      <g
         id="g69827-0"
         style="fill:#a2ff00;fill-opacity:0.504178;fill-rule:evenodd;stroke:#66de03;stroke-opacity:1"
         transform="matrix(0.60416467,0,0,0.60416467,26.748816,32.591246)">
        <rect
           style="opacity:0.971564;mix-blend-mode:normal;fill:#a2ff00;fill-opacity:0.504178;fill-rule:evenodd;stroke:#66de03;stroke-width:1;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
           id="rect86-9-2"
           width="97.898438"
           height="67.95063"
           x="270.56329"
           y="74.766342"
           ry="17.762169"
           transform="matrix(0.4220691,0,0,0.4220691,147.68606,52.931391)" />
      </g>
      <text
         xml:space="preserve"
         style="font-style:normal;font-weight:normal;font-size:1.61925px;line-height:1.25;font-family:sans-serif;fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:0.0674683;stroke-opacity:1"
         x="192.59203"
         y="87.000122"
         id="text16494-8-7"><tspan
           id="tspan16492-9-6"
           style="font-size:1.61925px;fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:0.0674683;stroke-opacity:1"
           x="192.59203"
           y="87.000122"
           sodipodi:role="line">Messrechner</tspan></text>
    </g>
    <g
       id="g53215"
       transform="matrix(0.59973583,0,0,0.59973583,-54.898976,23.478845)">
      <g
         id="g104514">
        <rect
           style="opacity:0.971564;mix-blend-mode:normal;fill:url(#linearGradient104483);fill-opacity:1;fill-rule:evenodd;stroke:url(#linearGradient38242);stroke-width:0.434051;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
           id="rect86"
           width="42.492897"
           height="29.494028"
           x="327.07794"
           y="61.471546"
           ry="7.7096844" />
        <text
           xml:space="preserve"
           style="font-style:normal;font-weight:normal;font-size:2.75622px;line-height:1.25;font-family:sans-serif;fill:#000000;fill-opacity:1;stroke:#020f00;stroke-width:0.114842;stroke-opacity:1"
           x="338.23734"
           y="67.376602"
           id="text16494"><tspan
             id="tspan16492"
             style="font-size:2.75622px;fill:#000000;fill-opacity:1;stroke:#020f00;stroke-width:0.114842;stroke-opacity:1"
             x="338.23734"
             y="67.376602"
             sodipodi:role="line">Klimakammer</tspan></text>
      </g>
    </g>
    <path
       style="display:inline;fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:0.308381;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;marker-start:url(#Arrow1Sstart-8);marker-end:url(#Arrow2Send)"
       d="m 107.43897,69.239103 33.24637,-0.08734"
       id="path69424"
       inkscape:connector-type="polyline"
       inkscape:connector-curvature="0" />
    <path
       style="display:inline;fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:0.308381;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;marker-start:url(#Arrow1Sstart-8-0);marker-end:url(#Arrow2Send-3)"
       d="m 57.642018,69.239103 33.246379,-0.08734"
       id="path69424-2"
       inkscape:connector-type="polyline"
       inkscape:connector-curvature="0" />
  </g>
</svg>

Then the conversion process does not crash anymore.

To make the LaTeX output a bit nicer I suggest to make the font small and sans serif:

\documentclass{article}
\usepackage{svg}
\begin{document}
\begin{figure}[htpb]
    \centering
    \includesvg[pretex=\tiny\sffamily]{Zeichnung.svg}
    \caption{Broken svg}
    \label{fig:Broken}
\end{figure}
\end{document}

Result:

enter image description here

To improve it further you can edit the SVG in Inkscape to center the labels, or even to export to a PDF directly from Inkscape and include the PDF with \includegraphics instead of the conversion with the svg package, then you have more control over the result.

Note: I think the second node should be labeled Arduino and not Ardunino.