1

I am trying to build upon this previous question.

I can successfully specify node and edge SVG classes with dvisvgm specials when drawing a regular graph.

With this MWE:

\documentclass[tikz,dvisvgm]{standalone}

\usepackage{tikz}

\usetikzlibrary{graphs}

\begin{document}
\begin{tikzpicture}[]
  \special{dvisvgm:raw <g class="mainnode">}
    \node (1) at (0, 0) {one};
  \special{dvisvgm:raw </g>}
\end{tikzpicture}

\end{document}

I can run

$ latexmk -latex='dvilualatex'  -dvi nolayout.tex 
$ dvisvgm --zoom=-1  --optimize --font-format=woff2,autohint nolayout.dvi

The special is properly wrapping the created node.

<g class="mainnode">
  <g transform="translate(-7.5 -2.185)matrix(1.00375 0 0 -1.00375 61.437027 -66.642029)" stroke="none" fill="#000">
    <text class="f0" x="-61.207499" y="-66.393055">one</text>
  </g>
</g>

However if I use graph drawing instead of manually specifying coordinates in this example:

\documentclass[tikz,dvisvgm]{standalone}

\usepackage{tikz}

\usetikzlibrary{graphs, graphdrawing}
\usegdlibrary{layered}

\begin{document}
\begin{tikzpicture}[layered layout]

  \special{dvisvgm:raw <g class="mainnode">}
    \node (1) at (0, 0) {one};
  \special{dvisvgm:raw </g>}

\end{tikzpicture}

\end{document}

The specials do not actually wrap the generated node in the SVG but instead have no content.

<g class="mainnode"> </g>

<g stroke="none" transform="matrix(1.00375 0 0 -1.00375 61.437027 -66.642029)matrix(.996264 0 0 -.996264 -61.207499 -66.393055)translate(-7.5 -2.185)matrix(1.00375 0 0 -1.00375 61.437027 -66.642029)" stroke-miterlimit="10" fill="#000">
  <text class="f0" x="-61.207499" y="-66.393055">one</text>
</g>

With graph automatic graph drawing, how do I wrap the generated nodes with specials?

2
  • 1
    Tests show the output svg is ok If layered layout option is passed to a \graph command, not the whole tikzpicture env. Aug 27, 2021 at 8:03
  • @muzimuzhiZ that works for me too, do you mind creating an answer with this information? Aug 27, 2021 at 16:10

1 Answer 1

3

If I move the layered layout option from the optional arg of tikzpicture environment to an actual \graph command, the output SVG is OK.

\begin{tikzpicture}%[layered layout]

  \special{dvisvgm:raw <g class="mainnode">}
    \graph[layered layout] {<group specification>};
  \special{dvisvgm:raw </g>}

\end{tikzpicture}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .