Convert DVI to SVG with dvisvgm issue

3.1k views Asked by At

I try to use below steps to get a SVG file but it seems the output SVG file not displayed correctly.

  • Use latex to compile latex code test.tex to dvi file.

    \documentclass{standalone}
    \usepackage{tikz}
    
    \begin{document}
    \begin{tikzpicture}
      \def\r{2cm}
      \node (O) at (0,0) {$O$};
      \draw (0,0) circle (\r);
      \draw[->] (-\r,0)--(\r,0);
      \draw[->] (0,-\r)--(0,\r);
    \end{tikzpicture}
    \end{document}
    

    Compile to dvi (test.dvi) with below command line:

    # latex test.tex
    
  • use dvisvgm tool to convert dvi file to SVG (test.svg).

    # dvisvgm --no-fonts test.dvi 
    

The SVG file seems created successfully but it only display a O character in Chrome Browser or Firefox. So I guess the SVG file maybe something wrong. The SVG file content as below:

<?xml version='1.0' encoding='ISO-8859-1'?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<!-- This file was generated by dvisvgm 1.2.2 (x86_64-apple-darwin10.8.0) -->
<!-- Sat Nov 30 21:38:15 2013 -->
<svg height='6.8078pt' version='1.1' viewBox='-15.1079 -21.9156 7.87601 6.8078' width='7.87601pt' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink'>
<defs>
<path d='M7.4 -4.36C7.4 -5.97 6.34 -7.05 4.85 -7.05C2.69 -7.05 0.49 -4.78 0.49 -2.45C0.49 -0.79 1.61 0.22 3.05 0.22C5.17 0.22 7.4 -1.97 7.4 -4.36ZM3.11 -0.04C2.12 -0.04 1.42 -0.85 1.42 -2.17C1.42 -2.61 1.56 -4.07 2.33 -5.24C3.02 -6.28 4 -6.8 4.79 -6.8C5.61 -6.8 6.51 -6.24 6.51 -4.75C6.51 -4.03 6.24 -2.47 5.25 -1.24C4.77 -0.63 3.95 -0.04 3.11 -0.04Z' id='g0-79'/>
</defs>
<g id='page1' transform='matrix(0.996264 0 0 0.996264 0 0)'>
<use x='-15.1645' xlink:href='#g0-79' y='-15.1645'/>
</g>
</svg>

Anything wrong with dvisvgm command?

3

There are 3 answers

0
Martin On BEST ANSWER

You probably ran dvisvgm with deactivated PostScript support. You can find further information on how to check this on the dvisvgm FAQ page. With activated PS support, I get the correct result:

enter image description here

<?xml version='1.0'?>
<!-- This file was generated by dvisvgm 1.5.1 (x86_64-pc-win64) -->
<!-- Sun Dec 01 20:59:37 2013 -->
<svg height='113.785pt' version='1.1' viewBox='-72 -72 113.785 113.785' width='113.785pt' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink'>
<defs>
<path d='M7.4 -4.36C7.4 -5.97 6.34 -7.05 4.85 -7.05C2.69 -7.05 0.49 -4.78 0.49 -2.45C0.49 -0.79 1.61 0.22 3.05 0.22C5.17 0.22 7.4 -1.97 7.4 -4.36ZM3.11 -0.04C2.12 -0.04 1.42 -0.85 1.42 -2.17C1.42 -2.61 1.56 -4.07 2.33 -5.24C3.02 -6.28 4 -6.8 4.79 -6.8C5.61 -6.8 6.51 -6.24 6.51 -4.75C6.51 -4.03 6.24 -2.47 5.25 -1.24C4.77 -0.63 3.95 -0.04 3.11 -0.04Z' id='g0-79'/>
</defs>
<g id='page1' transform='matrix(0.996264 0 0 0.996264 0 0)'>
<g transform='matrix(1 0 0 1 -3.938 3.4039)'>
<use x='-15.1645' xlink:href='#g0-79' y='-15.1645'/>
</g>
<path d='M41.7418 -15.166C41.7418 -46.5921 16.2639 -72.0701 -15.166 -72.0701C-46.5921 -72.0701 -72.0701 -46.5921 -72.0701 -15.166C-72.0701 16.2639 -46.5921 41.7418 -15.166 41.7418C16.2639 41.7418 41.7418 16.2639 41.7418 -15.166ZM-15.166 -15.166' fill='none' stroke='#000000' stroke-miterlimit='10.0375' stroke-width='0.399994'/>
<path d='M-72.0701 -15.166H41.2831' fill='none' stroke='#000000' stroke-miterlimit='10.0375' stroke-width='0.399994'/>
<path d='M40.0834 -16.7658C40.1814 -16.1659 41.2832 -15.2641 41.5812 -15.166C41.2832 -15.0641 40.1814 -14.1662 40.0834 -13.5663' fill='none' stroke='#000000' stroke-linecap='round' stroke-linejoin='round' stroke-miterlimit='10.0375' stroke-width='0.319985'/>
<path d='M-15.166 41.7418V-71.6113' fill='none' stroke='#000000' stroke-miterlimit='10.0375' stroke-width='0.399994'/>
<path d='M-16.7658 -70.4115C-16.1659 -70.5096 -15.2641 -71.6113 -15.166 -71.9093C-15.0641 -71.6113 -14.1662 -70.5096 -13.5663 -70.4115' fill='none' stroke='#000000' stroke-linecap='round' stroke-linejoin='round' stroke-miterlimit='10.0375' stroke-width='0.319985'/>
</g>
</svg>
1
Paul LeBeau On

The SVG looks fine. It has only one graphical element in it (the path) and it gets drawn correctly by the browser(s).

So that would suggest that there is something wrong with your latex file or the conversion tool. I don't know latex well enough, so I can't help with that.

0
lucky1928 On

Oh,that means I didn't install Ghostscript tool in my MAC.

  • I try to install ghostscript to MAC with below command:

    # sudo port install ghostscript
    

The install seems work fine but it seems only /usr/local/gs file created, no share library at all.

Then I try to check dvisvgm libgs settings:

    # dvisvgm -h |grep libgs
    --libgs=filename          set name of Ghostscript shared library
    # dvisvgm -l |grep gs
    Notes:Nothing output for this command.

That means I need to use a --libgs=filename option to specify the share library.

Does that means dvisvgm tool can not work in MAC?

  • I have tried to compile ghostscript from source on MAC but compile failure.

  • Then I try to use MAC version gs to convert pdf to SVG, it seems segment fault:

    # gs -dBATCH -dSAFER -dNOPAUSE -sDEVICE=svg -sOutputFile=test.Svg test.pdf
    ....
    Segmentation fault: 11
    
  • And inkscape seems works fine with below command:

    inkscape test.pdf --export-plain-svg=test.svg
    

inkscape really do good job on MAC bit a bit time consuming.