1

Question: How can we convert multiple paths of following svg file into a single path?

I have been trying to convert multiple paths of the following svg file into a single path. I tried the following steps in InkSCape but the converted file still look almost the same with multiple paths:

  1. Path-->Object to Path
  2. Object-->Ungroup
  3. Path-->Combine

InkScape's Save as Optimized SVG (*.svg) also did not convert it into a single path.

I also tried many online tools (such as the following) for this task. But all of them have only been able to remove the empty paths, and they have converted all other non-empty paths (there are 5 of them) into 3 paths:

https://www.ofoct.com/image-converter/svg-optimizer.html
https://jakearchibald.github.io/svgomg/
http://petercollingridge.appspot.com/svg-optimiser
https://github.com/svg/svgo

Remark: I do not have any commercial software. I would be interested in open source or free online tool that can do the job. Or if someone can explain the correct steps to perform the task that would also be suffice.

MySVGFile.svg:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
   xmlns:ns7="http://www.iki.fi/pav/software/textext/"
   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="svg943"
   sodipodi:docname="Sqrt_test.svg"
   inkscape:version="1.0.1 (3bc2e813f5, 2020-09-07)">
  <defs
     id="defs937" />
  <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"
     inkscape:document-rotation="0"
     showgrid="false"
     inkscape:window-width="1267"
     inkscape:window-height="728"
     inkscape:window-x="52"
     inkscape:window-y="0"
     inkscape:window-maximized="0" />
  <metadata
     id="metadata940">
    <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></dc:title>
      </cc:Work>
    </rdf:RDF>
  </metadata>
  <g
     inkscape:label="Layer 1"
     inkscape:groupmode="layer"
     id="layer1">
    <g
       transform="matrix(0.352778 0 0 0.352778 103.494 146.408)"
       ns7:version="1.3.1"
       ns7:texconverter="pdflatex"
       ns7:pdfconverter="inkscape"
       ns7:text="\\[\\sqrt{x}\\]"
       ns7:preamble="C:\Users\RazLT3user\AppData\Roaming\inkscape\extensions\textext\default_packages.tex"
       ns7:scale="1.0"
       ns7:alignment="middle center"
       ns7:jacobian_sqrt="0.352778"
       id="g968">
      <defs
         id="id-fc1fb31e-80f7-41f7-944b-33a65b0c7953">
        <g
           id="id-c8abbc90-a208-4fd6-944d-b6b284bb753c">
          <symbol
             overflow="visible"
             id="id-5b127d2a-bd8a-484e-bd28-d12d0ac986e4">
            <path
               style="stroke:none;stroke-width:0"
               d=""
               id="id-8de2a455-f0b9-4396-9705-713697487c12" />
          </symbol>
          <symbol
             overflow="visible"
             id="id-8ebb50fe-7ed3-46fe-9755-38b6c641e90a">
            <path
               style="stroke:none;stroke-width:0"
               d="m 3.875,8.515625 -1.75,-3.875 C 2.046875,4.484375 2,4.484375 1.96875,4.484375 c 0,0 -0.0625,0 -0.171875,0.078125 l -0.9375,0.71875 c -0.125,0.109375 -0.125,0.125 -0.125,0.15625 0,0.0625 0.015625,0.109375 0.09375,0.109375 0.0625,0 0.234375,-0.140625 0.34375,-0.21875 C 1.21875,5.28125 1.375,5.171875 1.484375,5.09375 l 1.96875,4.3125 C 3.515625,9.5625 3.5625,9.5625 3.65625,9.5625 c 0.15625,0 0.1875,-0.046875 0.25,-0.1875 L 8.4375,0 C 8.5,-0.140625 8.5,-0.171875 8.5,-0.203125 8.5,-0.296875 8.421875,-0.40625 8.296875,-0.40625 c -0.078125,0 -0.140625,0.0625 -0.21875,0.21875 z m 0,0"
               id="id-591c447f-2911-49df-a851-2e3a6680e422" />
          </symbol>
          <symbol
             overflow="visible"
             id="id-bfdb2a50-dbf2-4c28-a53b-887de8101e98">
            <path
               style="stroke:none;stroke-width:0"
               d=""
               id="id-98253d78-2ab0-4e20-8805-4adad34a7607" />
          </symbol>
          <symbol
             overflow="visible"
             id="id-74c2ea4b-0fa0-400f-bcf3-77fa5a7ab16b">
            <path
               style="stroke:none;stroke-width:0"
               d="M 3.328125,-3.015625 C 3.390625,-3.265625 3.625,-4.1875 4.3125,-4.1875 c 0.046875,0 0.296875,0 0.5,0.125 C 4.53125,-4 4.34375,-3.765625 4.34375,-3.515625 c 0,0.15625 0.109375,0.34375 0.375,0.34375 0.21875,0 0.53125,-0.171875 0.53125,-0.578125 0,-0.515625 -0.578125,-0.65625 -0.921875,-0.65625 -0.578125,0 -0.921875,0.53125 -1.046875,0.75 -0.25,-0.65625 -0.78125,-0.75 -1.078125,-0.75 -1.03125,0 -1.609375,1.28125 -1.609375,1.53125 0,0.109375 0.109375,0.109375 0.125,0.109375 0.078125,0 0.109375,-0.03125 0.125,-0.109375 0.34375,-1.0625 1,-1.3125 1.34375,-1.3125 0.1875,0 0.53125,0.09375 0.53125,0.671875 0,0.3125 -0.171875,0.96875 -0.53125,2.375 -0.15625,0.609375 -0.515625,1.03125 -0.953125,1.03125 -0.0625,0 -0.28125,0 -0.5,-0.125 0.25,-0.0625 0.46875,-0.265625 0.46875,-0.546875 0,-0.265625 -0.21875,-0.34375 -0.359375,-0.34375 -0.3125,0 -0.546875,0.25 -0.546875,0.578125 0,0.453125 0.484375,0.65625 0.921875,0.65625 0.671875,0 1.03125,-0.703125 1.046875,-0.75 0.125,0.359375 0.484375,0.75 1.078125,0.75 1.03125,0 1.59375,-1.28125 1.59375,-1.53125 0,-0.109375 -0.078125,-0.109375 -0.109375,-0.109375 -0.09375,0 -0.109375,0.046875 -0.140625,0.109375 -0.328125,1.078125 -1,1.3125 -1.3125,1.3125 -0.390625,0 -0.546875,-0.3125 -0.546875,-0.65625 0,-0.21875 0.046875,-0.4375 0.15625,-0.875 z m 0,0"
               id="id-4da64eab-9ea5-47aa-8b15-87988bff3f4f" />
          </symbol>
        </g>
      </defs>
      <g
         id="id-92fb6d2b-2d4a-47c5-9c8e-04c4ede4b8ba"
         transform="translate(-299.36, -138.652)">
        <g
           style="fill:#000000;fill-opacity:1"
           id="id-09d1d91a-cd32-4274-8160-ae109a739c57">
          <g
             transform="translate(298.626, 139.058)"
             id="g959">
            <path
               style="stroke:none;stroke-width:0"
               d="m 3.875,8.515625 -1.75,-3.875 C 2.046875,4.484375 2,4.484375 1.96875,4.484375 c 0,0 -0.0625,0 -0.171875,0.078125 l -0.9375,0.71875 c -0.125,0.109375 -0.125,0.125 -0.125,0.15625 0,0.0625 0.015625,0.109375 0.09375,0.109375 0.0625,0 0.234375,-0.140625 0.34375,-0.21875 C 1.21875,5.28125 1.375,5.171875 1.484375,5.09375 l 1.96875,4.3125 C 3.515625,9.5625 3.5625,9.5625 3.65625,9.5625 c 0.15625,0 0.1875,-0.046875 0.25,-0.1875 L 8.4375,0 C 8.5,-0.140625 8.5,-0.171875 8.5,-0.203125 8.5,-0.296875 8.421875,-0.40625 8.296875,-0.40625 c -0.078125,0 -0.140625,0.0625 -0.21875,0.21875 z m 0,0"
               id="id-87e9bbd4-e59e-414c-bd10-a3ec5e2104f3" />
          </g>
        </g>
        <path
           style="fill:none;stroke:#000000;stroke-width:0.398;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:10;stroke-opacity:1"
           d="M 0.0016875,-0.001375 H 5.693094"
           transform="matrix(1 0 0 -1 306.928 138.858)"
           id="id-533ba1fa-39e6-4f95-b4db-9db22a7489a0" />
        <g
           style="fill:#000000;fill-opacity:1"
           id="id-3640a48e-8fc4-4219-a6f2-d729cf8ad007">
          <g
             transform="translate(306.928, 146.72)"
             id="g964">
            <path
               style="stroke:none;stroke-width:0"
               d="M 3.328125,-3.015625 C 3.390625,-3.265625 3.625,-4.1875 4.3125,-4.1875 c 0.046875,0 0.296875,0 0.5,0.125 C 4.53125,-4 4.34375,-3.765625 4.34375,-3.515625 c 0,0.15625 0.109375,0.34375 0.375,0.34375 0.21875,0 0.53125,-0.171875 0.53125,-0.578125 0,-0.515625 -0.578125,-0.65625 -0.921875,-0.65625 -0.578125,0 -0.921875,0.53125 -1.046875,0.75 -0.25,-0.65625 -0.78125,-0.75 -1.078125,-0.75 -1.03125,0 -1.609375,1.28125 -1.609375,1.53125 0,0.109375 0.109375,0.109375 0.125,0.109375 0.078125,0 0.109375,-0.03125 0.125,-0.109375 0.34375,-1.0625 1,-1.3125 1.34375,-1.3125 0.1875,0 0.53125,0.09375 0.53125,0.671875 0,0.3125 -0.171875,0.96875 -0.53125,2.375 -0.15625,0.609375 -0.515625,1.03125 -0.953125,1.03125 -0.0625,0 -0.28125,0 -0.5,-0.125 0.25,-0.0625 0.46875,-0.265625 0.46875,-0.546875 0,-0.265625 -0.21875,-0.34375 -0.359375,-0.34375 -0.3125,0 -0.546875,0.25 -0.546875,0.578125 0,0.453125 0.484375,0.65625 0.921875,0.65625 0.671875,0 1.03125,-0.703125 1.046875,-0.75 0.125,0.359375 0.484375,0.75 1.078125,0.75 1.03125,0 1.59375,-1.28125 1.59375,-1.53125 0,-0.109375 -0.078125,-0.109375 -0.109375,-0.109375 -0.09375,0 -0.109375,0.046875 -0.140625,0.109375 -0.328125,1.078125 -1,1.3125 -1.3125,1.3125 -0.390625,0 -0.546875,-0.3125 -0.546875,-0.65625 0,-0.21875 0.046875,-0.4375 0.15625,-0.875 z m 0,0"
               id="id-8f1254a8-794d-440e-b4cc-a4fbf35e97bd" />
          </g>
        </g>
      </g>
    </g>
  </g>
</svg>
0
2
  1. Select everything, and do Ungroup Shift+Ctrl+G 5 times to remove all those unnecessary nested groups.

  2. Do Path > Stroke to Path to turn the horizontal stroke into a path.

  3. Now you can do Path > Combine, or alternatively do Path > Union if you want to get rid of any overlaps.

  4. Do File > Cleanup document

  5. To export as optimised SVG, do File > Save as, then select "Optimised SVG" from the file type dropdown.

  6. In the Optimsed SVG Output dialog set up the items you want to keep and which you want to remove. Here are my settings

enter image description here

Here's the output

<?xml version="1.0" encoding="UTF-8"?>
<svg width="210mm" height="297mm" version="1.1" viewBox="0 0 210 297" xmlns="http://www.w3.org/2000/svg">
<path id="id-8f1254a8-794d-440e-b4cc-a4fbf35e97bd" transform="scale(.265)" d="m401 553c-.104 0-.187.0828-.291.291l-5.61 11.6-2.33-5.17c-.104-.208-.167-.209-.209-.209 0 0-.083.001-.229.105l-1.25.957c-.167.146-.168.167-.168.209 0 .0835.0245.146.127.146.0835 0 .311-.189.457-.293.0624-.0624.272-.208.418-.312l2.62 5.75c.0835.208.144.209.27.209.208 0 .25-.0625.334-.25l6.04-12.5c.00055-.001-.00054-.00073 0-.002h7.41v-.531h-7.56c-.0128-.002-.0234-.008-.0371-.008zm2.95 4.88c-1.37 0-2.15 1.71-2.15 2.04 0 .146.145.146.166.146.104 0 .147-.0422.168-.146.458-1.42 1.33-1.75 1.79-1.75.25 0 .709.126.709.896 0 .417-.23 1.29-.709 3.17-.208.813-.688 1.38-1.27 1.38-.0831 0-.374.00067-.666-.166.333-.0831.625-.355.625-.73 0-.354-.291-.459-.479-.459-.417 0-.73.334-.73.771 0 .604.647.875 1.23.875.896 0 1.37-.937 1.39-1 .167.479.646 1 1.44 1 1.37 0 2.12-1.71 2.12-2.04 0-.146-.103-.146-.145-.146-.125 0-.146.063-.188.146-.438 1.44-1.33 1.75-1.75 1.75-.521 0-.73-.417-.73-.875 0-.292.0631-.585.209-1.17l.459-1.83c.0835-.333.396-1.56 1.31-1.56.0624 0 .395-.00066.666.166-.375.0832-.625.397-.625.73 0 .208.146.457.5.457.292 0 .709-.228.709-.77 0-.688-.772-.875-1.23-.875-.771 0-1.23.708-1.39 1-.333-.875-1.04-1-1.44-1z"/>
</svg>
1
  • That's what I was looking for. Your step-by-step explanation was important - since I need it for other expressions that are more complex. Thank you for explaining the steps and including the Optimsed SVG Output dialog set up, as well.
    – nam
    May 6 at 15:41

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.