mgieseki / dvisvgm

A fast DVI, EPS, and PDF to SVG converter
https://dvisvgm.de
GNU General Public License v3.0
306 stars 33 forks source link

TikZ picture incorrectly translated #192

Closed nschloe closed 2 years ago

nschloe commented 2 years ago

I have a fairly complex TikZ plot that I'd like to convert to an SVG using dvisvgm.

\documentclass{standalone}

\usepackage{tikz}
\usetikzlibrary{arrows,shapes}
\usetikzlibrary{decorations.pathmorphing}
\usetikzlibrary{decorations.pathreplacing}
\usetikzlibrary{decorations.shapes}
\usetikzlibrary{decorations.text}
\usetikzlibrary{decorations.markings}
\usetikzlibrary{decorations.fractals}
\usetikzlibrary{decorations.footprints}
\usetikzlibrary{snakes}

\pagenumbering{gobble}
\thispagestyle{empty}

\begin{document}

\tikzstyle{decision} = [rectangle, draw, fill=gray!05, 
    text width=7em, text badly centered, node distance=2cm, inner sep=2pt]

\tikzstyle{spatial} = [scale=0.3,regular polygon,regular polygon sides = 4
, draw, fill=gray!05, 
    text width=3.5em, text badly centered, node distance=2cm, inner sep=0pt,fill = gray!30]   

    \tikzstyle{interaction} = [scale=0.2,regular polygon,regular polygon sides = 3
, draw, fill=gray!05, 
    text width=3.5em, text badly centered, node distance=2cm, inner sep=0pt,fill = gray!30]   

    \tikzstyle{product} = [scale=0.3,regular polygon,regular polygon sides = 6
, draw, fill=gray!05, 
    text width=3.5em, text badly centered, node distance=2cm, inner sep=0pt,fill = gray!30]    

\tikzstyle{block} = [rectangle, text=white, draw, fill=black, 
    text width=8em, text centered, rounded corners, minimum height=4em,font=\bfseries]

    \tikzstyle{sub} = [rectangle, text=white, draw, fill=black, 
    text width=8em, text centered, rounded corners, minimum height=2em,font=\bfseries]

\tikzstyle{line} = [draw, -latex']
\tikzstyle{edgebis}=[snake=expanding waves,segment length=1mm,segment angle=20,draw]

\tikzstyle{cloud} = [draw, ellipse,fill=gray!20, node distance=3cm,
    minimum height=2em,text width=4em]

\tikzstyle{colo} = [draw, rectangle,fill=gray!20,double = black, node distance=3cm,
    minimum height=1.5em,text width=5.2em,
rounded corners,inner sep=2pt,text centered]

\tikzstyle{exti} = [draw, rectangle,fill=gray!20,double = black, node distance=3cm,
    minimum height=1.5em,text width=5.2em,
rounded corners,text centered]

\begin{tikzpicture}[node distance = 2cm, auto]
    % Place nodes
    \node [block]  at (0,0) (DBN) {DBN formalism};
    \node [spatial,label={below:\small spatial network}] at (2,2) (spatial) {};
    \node [interaction,label={\small interaction network}] at (2,-2) (interaction) {};
    \node [product,label={\small product network}] at (6.5,0) (product) {};
    \node [block] at (3.5,0) (metacom) {metacommunity models};
    \node [block] at (-2,2) (metapop) {metapopulation models};
    \node [block] at (-2,-2) (mainland-island) {mainland-island models};
    \node [decision] at (10,3) (lev) {Levins type submodel};
    \node [spatial] at (10,2.3) (spatial_lev) {};
    \node [interaction] at (10,1.65) (inter_lev) {};

    \node [decision] at (10,1) (comb) {Combined effect model};
    \node [spatial] at (10,0.3) (spatial_comb) {};
    \node [interaction] at (10,-0.35) (inter_comb) {};

    \node [decision] at (10,-1) (sep) {Separated effect submodel};
    \node [spatial] at (10,-1.7) (spatial_sep) {};
    \node [interaction] at (10,-2.35) (inter_sep) {};

    \node [decision] at (10,-3) (resc) {Rescue effect submodel};
    \node [spatial] at (10,-3.7) (spatial_resc) {};
    \node [interaction] at (10,-4.35) (inter_resc) {};

    \node [colo] at (2,3.5) (colo) {colonisation};
    \node [exti] at (2,-3.5) (exti) {extinction};

    \node [colo] at (14,1.5) (colo_bis) {colonisation};
    \node [exti] at (14,-1.5) (exti_bis) {extinction};
    \node at (16,-1.5) (detour) {};
    \node [sub] at (10,4) (submodels) {submodels}; 

    % Draw edges
    \path [edgebis] (DBN) -- (mainland-island);
    \path [edgebis] (DBN) -- (metacom);
    \path [edgebis] (DBN) -- (metapop);
    \path [line,dashed,thick] (metapop) --  (spatial) ;
    \path [line,dashed,thick] (mainland-island) --  (interaction) ;
    \path [line,dashed,thick] (metacom) --  (product) ;
    \path [line,dashed,thick] (spatial) edge[bend left] node [left] {} (product);
     \path [line,dashed,thick] (interaction) edge[bend right] node [left] {} (product);
     \path [line,dotted,thick] (product) edge[bend left] node [left] {} (lev);
    \path [line,dotted,thick] (product) edge node [left] {} (comb);
    \path [line,dotted,thick] (product) edge node [left] {} (sep);
    \path [line,dotted,thick] (product) edge[bend right] node [left] {} (resc);
    \draw[line]  (spatial) -- node[sloped,pos=0.5,text width=2em] {acts on} (colo); 
    \draw[line]  (interaction) -- node[sloped,pos=0.5,text width=2em] {acts on} (exti);  

    \draw[line]  (spatial_lev) edge[bend left= 10] (colo_bis); 
    \draw[line]  (inter_lev) edge[bend left=10] (colo_bis);

    \draw[line]  (spatial_comb) edge[bend right= 10] (colo_bis); 
    \draw[line]  (inter_comb) edge[bend right= 10] (colo_bis);
    \draw[line]  (inter_comb) edge[bend left= 20] (exti_bis);

     \draw[line]  (spatial_sep) edge[bend right= 35] (colo_bis); 
    \draw[line]  (inter_sep) edge[bend right= 10] (exti_bis);

    \draw[line]  (spatial_resc) to[out=0,in=-90] (detour) to[out=90,in=0] (colo_bis); 
    \draw[line]  (inter_resc) edge[bend right= 30] (exti_bis);
    \draw[line]  (spatial_resc) edge[bend right= 30] (exti_bis);
\end{tikzpicture}

\end{document}

Compiled with tectonic,

tectonic t.tex

I'm getting this PDF:

screenshot

When using the XDV route,

tectonic t.tex --outfmt xdv
dvisvgm t.xdv --no-fonts -o t.svg

the output SVG looks like

screenshot

Any idea what might be going wrong?

mgieseki commented 2 years ago

That's because TikZ creates PDF specials by default when used with XeLaTeX. dvisvgm doesn't support these. You can either use LaTeX instead or add \def\pgfsysdriver{pgfsys-dvips.def} before \usepackage{tikz}.

muzimuzhi commented 1 year ago

tikz/pgf has a specific dvisvgm driver, so \def\pgfsysdriver{pgfsys-dvisvgm.def} should also work and supports tikz svg animations additionally (compared to dvips driver).