[pgf-tikz] converting tikz to the corresponding svg elements

Henri Menke henrimenke at gmail.com
Mon Jul 27 05:34:12 CEST 2020


Dear Gil,

Before answering your questions, I'd like to note that it is very
important to provide a reproducible example.  This is not specific to
PGF/TikZ but applies to *any* technical problem you will ever report to
anyone.  Without clear steps to reproduce it can become impossible to
diagnose the problem.  In this case, a proper example would have been

    \documentclass[dvisvgm]{article}
    \usepackage{tikz}
    \begin{document}
    \begin{tikzpicture}
        \draw (0,0) rectangle (4,4);
    \end{tikzpicture}
    \end{document}

together with the compilation info (that you provided)

    lualatex --output-format=dvi exmaple.tex
    dvisvgm example.dvi

Now to your question.  Originally PGF has had no SVG support, so
everything was implemented with PDF output in mind, where no such shapes
exist and everything has to be implemented as a sequence of moveto,
lineto, and curveto operations.  Take for example a look at how the
`rectangle' operation is implemented at [1].  In principle it is
possible to output SVG shapes instead of paths, but that is not how it
is currently implemented and I think it will be very tricky to adapt all
of the low-level code to do this.

Also, in my view this looks like a lot of work for diminishing return.
I doubt that there a lot of users of the SVG backend and the usefulness
of having shapes instead of path is unclear to me.  I guess shapes are
useful if you want to apply CSS stylesheets, but then again you can also
easily achieve the same styling at the TikZ end, although maybe not as
dynamic.

Kind regards,
Henri

[1] https://github.com/pgf-tikz/pgf/blob/bbe2b56fa0d7c0a514663ac578e019c0f6775739/tex/generic/pgf/frontendlayer/tikz/tikz.code.tex#L3337-L3343

On 27/07/20, 01:33, Gil Cohen wrote:
> I have read the very well written *pgfmanual* and followed the steps on to
> convert tikx into svg:
> 
> lualatex --output-format=dvi example
> dvisvgm example
> 
> But I found out *all elements are getting converted to svg paths*,
> although some are circles, rectangles, Ellipsis.
> So I was wondering how to accomplish this?
> 
> for example, for the following tikz lines:
> 
> 
> 
> *\begin{tikzpicture}\ draw (0,0) rectangle (4,4);\end{tikzpicture}*
> 
> I would like to convert into the corresponding SVG shape:
> 
>  <rect x="0" y="0" width="4" height="4" />
> 
> I guess I need to hook into one of the compiling stages of tikz/tex files,
> 
> can someone give me some suggestions how to accomplish it?
> 
> Thank you very much


More information about the pgf-tikz mailing list.