3

I am trying to generate an html file from a tex file using htlatex. The htlatex works well with simple tikz pictures, but it has problem with the pictures (trees) drawn with tikz-dependency package. Here is my code copied from tikz-dependency manual.

\documentclass{article}
\def\pgfsysdriver{pgfsys-tex4ht.def}

\usepackage{tikz,graphicx,tikz-dependency}
%\usetikzlibrary{external}
\begin{document}
\begin{dependency}
\begin{deptext}[column sep=.5cm, row sep=.1ex]
PRP\$ \& NN \& RB \&[.5cm] VBZ \& VBG \& NN \\
My \& dog \& also \& likes \& eating \& sausage \\
\end{deptext}
\deproot{4}{root}
\depedge{2}{1}{poss}
\depedge{4}{2}{nsubj}
\depedge{4}{3}{advmod}
\depedge{4}{5}{xcomp}
\depedge{5}{6}{dobj}
\wordgroup{2}{4}{4}{pred}
\wordgroup{2}{1}{2}{a0}
\wordgroup{2}{5}{6}{a1}
\groupedge[edge below]{pred}{a0}{ARG0}{4ex} % pred -> a0 (ARG0, 4ex)
\groupedge[edge below]{pred}{a1}{ARG1}{6ex} % pred -> a1 (ARG1, 6ex)
\end{dependency}

\begin{dependency}
\begin{deptext}[column sep=0.2cm]
My \&[.5cm] dog \& also \&[.7cm] likes \&[.4cm] eating \& sausage \\
\end{deptext}
\depedge{2}{1}{poss}
\depedge{4}{2}{nsubj}
\depedge{4}{3}{advmod}
\depedge{4}{5}{xcomp}
\depedge{5}{6}{dobj}
\end{dependency}
\end{document}

For second example, I get a nice tree, though without terminal-nodes (words). The first code throws an error in html. htlatex also doesn't work with qtree and xytree packages! Any help is highly appreciated. This thing is really getting on my nerves!

8

It is known problem that tex4ht pgfsysdriver does have some problems with text nodes. In such cases, it is better to use tikz externalization.

There are some problems you need to solve:

  1. dependendency environment doesn't support externalization. You can replace it with tikzpicture in your case
  2. there are several ways to convert externalized pictures to svg, I did some tests and it seems best is to use inkscape in the command line mode
  3. you need to configure tex4ht to include svg images.

So, you need to modify your file in such way:

\documentclass{article}

\usepackage{tikz,graphicx,tikz-dependency}

\usetikzlibrary{external}
\tikzset{
    tex4ht inc/.style={
        /pgf/images/include external/.code={%
            \includegraphics[]{##1.svg}%
        }

    }
}

\tikzset{
 external/system call/.add={}                                                
      {; inkscape -z -f "\image.pdf" -l "\image.svg" }    
}
\makeatletter
\@ifpackageloaded{tex4ht}{
    \tikzexternalize[mode=only graphics]
}{
    \tikzexternalize
}
\makeatother
\begin{document}
\begin{tikzpicture}
\begin{deptext}[column sep=.5cm, row sep=.1ex]
PRP\$ \& NN \& RB \&[.5cm] VBZ \& VBG \& NN \\
My \& dog \& also \& likes \& eating \& sausage \\
\end{deptext}
\deproot{4}{root}
\depedge{2}{1}{poss}
\depedge{4}{2}{nsubj}
\depedge{4}{3}{advmod}
\depedge{4}{5}{xcomp}
\depedge{5}{6}{dobj}
\wordgroup{2}{4}{4}{pred}
\wordgroup{2}{1}{2}{a0}
\wordgroup{2}{5}{6}{a1}
\groupedge[edge below]{pred}{a0}{ARG0}{4ex} % pred -> a0 (ARG0, 4ex)
\groupedge[edge below]{pred}{a1}{ARG1}{6ex} % pred -> a1 (ARG1, 6ex)
\end{tikzpicture}

\begin{tikzpicture}
\begin{deptext}[column sep=0.2cm]
My \&[.5cm] dog \& also \&[.7cm] likes \&[.4cm] eating \& sausage \\
\end{deptext}
\depedge{2}{1}{poss}
\depedge{4}{2}{nsubj}
\depedge{4}{3}{advmod}
\depedge{4}{5}{xcomp}
\depedge{5}{6}{dobj}
\end{tikzpicture}
\end{document}

There are several changes:

\tikzset{
        tex4ht inc/.style={
            /pgf/images/include external/.code={%
                \includegraphics[]{##1.svg}%
            }

        }
    }

This is a definition of new tikz style, used in tex4ht for svg inclusion.

\tikzset{
 external/system call/.add={}                                                
      {; inkscape -z -f "\image.pdf" -l "\image.svg"
            }    
}

this definition calls inkscape to convert pdf pictures to svg,

\makeatletter
\@ifpackageloaded{tex4ht}{
    \tikzexternalize[mode=only graphics]
}{
    \tikzexternalize
}
\makeatother

and we need to use this code for correct inclusion of images in tex4ht.

Now you can generate pictures with:

pdflatex -shell-escape filename

You also have to create configuration file for tex4ht, like myconfig.cfg

\Preamble{xhtml}
\makeatletter
\Configure{graphics*}  
         {svg}{  
          {\Configure{Needs}{File: \Gin@base.svg}\Needs{}}
          \Picture[\csname a:GraphicsAlt\endcsname]{\csname Gin@base\endcsname.svg \csname a:Gin-dim\endcsname}%  
         }  
\makeatother
\begin{document}
\tikzexternalize[mode=only graphics]  
\tikzset{tex4ht inc}
\EndPreamble

configuration for svg inclusion is provided here.

Now you can compile the document to html with

htlatex filename myconfig

Result:

enter image description here

  • Thanks for your reply. I copied and pasted your code as such and compiled it, unfortunately it didn't work. I only see PIC PIC in the ftml page generated not trees! I don't see any svg files generated. There are just pdf files. – Riyaz Feb 7 '14 at 10:39
  • @Riyaz do you have inkscape installed? maybe there are some error messages in the log file? – michal.h21 Feb 7 '14 at 10:52
  • Sorry sh: 1: inkscape: not found – Riyaz Feb 7 '14 at 10:54
  • I installed the inkscape but still I have the same output. I tried inkscape -z -f "\image.pdf" -l "\image.svg" outside the tex file it works, but not inside the tex – Riyaz Feb 7 '14 at 11:01
  • @Riyaz and do you compile your file with pdflatex -shell-escape filename? – michal.h21 Feb 7 '14 at 11:03
1

There are two things wrong with your code:

  1. Missing \begin{document}.
  2. The command \def\pgfsysdriver{...} should go after \usepackage{tikz,...}, as some of the macros defined in the pgf driver require lower level macros defined by tikz-pgf.

The following code compiles all right for me with pdflatex and htlatex, both with and without externalized graphics:

\documentclass{article}
\usepackage{tikz,graphicx,tikz-dependency}

\def\pgfsysdriver{pgfsys-tex4ht.def}
%\usetikzlibrary{external}

\begin{document}

\begin{dependency}
\begin{deptext}[column sep=.5cm, row sep=.1ex]
PRP\$ \& NN \& RB \&[.5cm] VBZ \& VBG \& NN \\
My \& dog \& also \& likes \& eating \& sausage \\
\end{deptext}
\deproot{4}{root}
\depedge{2}{1}{poss}
\depedge{4}{2}{nsubj}
\depedge{4}{3}{advmod}
\depedge{4}{5}{xcomp}
\depedge{5}{6}{dobj}
\wordgroup{2}{4}{4}{pred}
\wordgroup{2}{1}{2}{a0}
\wordgroup{2}{5}{6}{a1}
\groupedge[edge below]{pred}{a0}{ARG0}{4ex} % pred -> a0 (ARG0, 4ex)
\groupedge[edge below]{pred}{a1}{ARG1}{6ex} % pred -> a1 (ARG1, 6ex)
\end{dependency}

\begin{dependency}
\begin{deptext}[column sep=0.2cm]
My \&[.5cm] dog \& also \&[.7cm] likes \&[.4cm] eating \& sausage \\
\end{deptext}
\depedge{2}{1}{poss}
\depedge{4}{2}{nsubj}
\depedge{4}{3}{advmod}
\depedge{4}{5}{xcomp}
\depedge{5}{6}{dobj}
\end{dependency}
\end{document}

On the other hand, while the pdf renders fine in the html it's only possible to see the textual information of the trees, no edges or other graphical elements.

  • I need to generate an html page using htlatex which has some issues with tikz-dependency trees. pdflatex is working fine with me as well. – Riyaz Feb 5 '14 at 9:46
  • The example that you provided did not compile with pdflatex. The corrected version compiles both with pdflatex and htlatex, even though I see no trees (only the text). Could you paste the commands that you are running? – masterpiga Feb 5 '14 at 10:00
  • I am running the same commands that you are running pdflatex *.tex and htlatex *.tex. There are no compilation errors but no trees as well with htlatex which is the problem I want to fix. pdflatex is working fine! – Riyaz Feb 5 '14 at 10:20
  • Oh sorry. I appreciate your help. I am concerned about the html page with tree images which I am unable to produce with htlatex. Forget about the errors my original code has, I somehow missed the end{document} and order as you mentioned that’s not a real issue. I just want the images to be printed in html pages, which is not happening. – Riyaz Feb 5 '14 at 10:35
  • I see. In the output of htlatex I don't see anything suspicious. Maybe the pgf html driver does not support some of the tikz features used by tikz-dependency, such as matrices? I really don't know though, maybe someone with more expertise on htlatex can help (I never used it myself and tikz-dependency was not tested against it). – masterpiga Feb 5 '14 at 10:37

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.