5.10 how to use tikz picture with math in htlatex?

Assuming the latex file is foo2.tex

\documentclass{article} 
\ifdefined\HCode 
\def\pgfsysdriver{pgfsys-tex4ht.def} 
\fi 
\usepackage{tikz,graphicx} 
% 
\usetikzlibrary{trees} 
\begin{document} 
\begin{tikzpicture} 
 \node {root} 
  child {node {$\frac{a}{b}$}}; 
\end{tikzpicture} 
\end{document}
 

The file is compiled as

htlatex foo2.tex "my.cfg,charset=utf-8" " -cunihtf -utf8"
 

where my.cfg is

\Preamble{xhtml,mathml} 
\Configure{VERSION}{} 
\Configure{DOCTYPE}{\HCode{<!DOCTYPE html>\Hnewline}} 
\Configure{HTML}{\HCode{<html>\Hnewline}}{\HCode{\Hnewline</html>}} 
\Configure{@HEAD}{} 
\Configure{@HEAD}{\HCode{<meta charset="UTF-8" />\Hnewline}} 
\Configure{@HEAD}{\HCode{<meta name="generator" content="TeX4ht 
(http://www.cse.ohio-state.edu/\string~gurari/TeX4ht/)" />\Hnewline}} 
\Configure{@HEAD}{\HCode{<link 
         rel="stylesheet" type="text/css" 
         href="\expandafter\csname aa:CssFile\endcsname" />\Hnewline}} 
\Configure{@HEAD}{\HCode{<script type="text/javascript"\Hnewline 
src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"\Hnewline 
></script>\Hnewline}} 
\Configure{@HEAD}{\HCode{<style type="text/css">\Hnewline 
  .MathJax_MathML {text-indent: 0;}\Hnewline 
</style>\Hnewline}} 
\begin{document} 
\EndPreamble
 

Now the file foo2.html will display in the browser as

notice: The math does not show up in the HTML. This is a known issue with using math+tickz+htlatex see http://tex.stackexchange.com/questions/124682/error-u sing-htlatex-with-tikz-forest-package-invalid-svg-generated

A better approach is this: Use separate latex file to make the diagram using tikz. Use standalone class. Then generate the pdf file using pdflatex.

Next convert the pdf to png, then using a separate latex file, include this image as png where it needs to go. This way htlatex and pdflatex will be able to process it ok. Here are the steps.

  1. make separate latex file for each diagram. For example diagram.tex

    \documentclass{standalone} 
    \usepackage{tikz 
    } 
    \usetikzlibrary{trees} 
    \begin{document} 
    \begin{tikzpicture} 
     \node {root} 
      child {node {$\frac{a}{b}$}}; 
    \end{tikzpicture} 
    \end{document}
     
    
  2. compile the above file to pdf

    pdflatex diagram.tex
     
    
  3. convert the pdf file to png

    pdftoppm -png diagram.pdf > diagram.png 
    or 
    convert -density 200 -limit memory 64MB -limit map 128MB -colorspace RGB diagram.pdf diagram.png 
    \begin{TEXTinline} 
    % 
    \item create the latex file which will use the above diagram, say \verb|main.tex| 
     
    \begin{TEXTinline} 
    \documentclass{article} 
    \usepackage{graphicx} 
     
    \begin{document} 
     
    The following diagram was generated using tikz+latex in 
    a separate file 
     
    \includegraphics{diagram.png} 
     
    and it is now in html 
    \end{document}
     
    
  4. now make pdf and html files from the above

    pdflatex main.tex 
    htlatex main.tex
     
    
  5. now the files main.pdf and main.html can be used.

added 020814Some examples with math do work in htlatex. Here is a nice picture in tikz with math on it, that htlatex was able to process with no error. This is using texlive 2013 version.

I did not have to use standalone as workaround as in the above example to make the math show up. I am using the code as shown in this post http://tex.stackexchange.com/questions/158668/nice-scientific-pictures-show-off by Paul Gessler. Here are the steps to convert this to HTML using htlatex and the result obtained

  1. make the foo.tex file using your editor (copy from the above link)

    \documentclass{standalone} 
    \usepackage{tikz}             % TikZ and PGF 
     
    % Vector Styles 
    \tikzstyle{load}   = [ultra thick,-latex] 
    \tikzstyle{stress} = [-latex] 
    \tikzstyle{dim}    = [latex-latex] 
    \tikzstyle{axis}   = [-latex,black!55] 
     
    % Drawing Views 
    \tikzstyle{isometric}=[x={(0.710cm,-0.410cm)},y={(0cm,0.820cm)},z={(-0.710cm,-0.410cm)}] 
    \tikzstyle{dimetric} =[x={(0.935cm,-0.118cm)},y={(0cm,0.943cm)},z={(-0.354cm,-0.312cm)}] 
    \tikzstyle{dimetric2}=[x={(0.935cm,-0.118cm)},z={(0cm,0.943cm)},y={(+0.354cm,+0.312cm)}] 
    \tikzstyle{trimetric}=[x={(0.926cm,-0.207cm)},y={(0cm,0.837cm)},z={(-0.378cm,-0.507cm)}] 
     
    \begin{document} 
      \begin{tikzpicture} 
        \node (origin) at (0,0) {}; % shift relative baseline 
        \coordinate (O) at (2,3); 
        \draw[fill=gray!10] (O) circle (1); 
        \draw[fill=white] (O) circle (0.75) node[below,yshift=-1.125cm] {Signpost Cross Section}; 
        \draw[dim] (O) ++(-0.75,0) -- ++(1.5,0) node[midway,above] {$d_i$}; 
        \draw[dim] (O) ++(-1,1.25) -- ++(2,0) node[midway,above] {$d_o$}; 
        \foreach \x in {-1,1} { 
          \draw (O) ++(\x,0.25) -- ++(0,1.25); 
        } 
      \end{tikzpicture} 
      \begin{tikzpicture}[dimetric2] 
            \coordinate (O) at (0,0,0); 
            \draw[axis] (O) -- ++(6,0,0) node[right] {$x$}; 
            \draw[axis] (O) -- ++(0,6,0) node[above right] {$y$}; 
            \draw[axis] (O) -- ++(0,0,6) node[above] {$z$}; 
            \draw[fill=gray!50] (0,0,-0.5) circle (0.5); 
            \fill[fill=gray!50] (-0.46,-0.2,-0.5) -- (0.46,0.2,-0.5) -- (0.46,0.2,0) -- (-0.46,-0.2,0) -- cycle; 
            \draw[fill=gray!20] (O) circle (0.5); 
        \draw (0.46,0.2,-0.5) -- ++(0,0,0.5) node[below right,pos=0.0] {Fixed Support}; 
        \draw (-0.46,-0.2,-0.5) -- ++(0,0,0.5); 
        \draw[fill=gray!10] (O) circle (0.2); 
        \fill[fill=gray!10] (-0.175,-0.1,0) -- (0.175,0.1,0) -- ++(0,0,4) -- (-0.175,-0.1,4) -- cycle; 
        \draw (-0.175,-0.1,0) -- ++(0,0,4); 
        \draw (0.175,0.1,0) -- ++(0,0,4) node[right,midway] {Steel Post}; 
        \draw (4,0,3.95) -- ++(0,0,-1); 
        \foreach \z in {0.5,0.75,...,5} { 
          \draw[-latex] (-2*\z/5-0.2,0,\z) -- (-0.2,0,\z); 
        } 
        \draw[load] (0,0,4) -- ++(0,0,-1.25) node[right,xshift=0.1cm] {$F_{z1}$}; 
        \draw[fill=gray!20] (-0.25,-0.25,5) -- (4,-0.25,5) -- (4,+0.25,5) -- (-0.25,+0.25,5) -- cycle; 
        \draw[fill=gray!50] (+4.00,-0.25,4) -- (4,+0.25,4) -- (4,+0.25,5) -- (+4.00,-0.25,5) -- cycle; 
        \draw[fill=gray!10] (-0.25,-0.25,4) -- (4,-0.25,4) -- (4,-0.25,5) -- (-0.25,-0.25,5) -- cycle; 
        \draw (4.05,0,4) -- ++(1,0,0); 
        \draw (4.05,0,5) -- ++(1,0,0); 
        \draw[dim] (4.5,0,0) -- ++(0,0,4) node[midway,right] {$h_1$}; 
        \draw[dim] (4.5,0,4) -- ++(0,0,1) node[midway,right] {$h_2$}; 
        \draw[dim] (0,0,3.4) -- ++(4,0,0) node[midway,below] {$b_2$}; 
        \coordinate (P) at (2,-0.25,4.5); 
        \draw (P) -- ++(0,0,0.25); 
        \draw (P) -- ++(0.25,0,0); 
        \draw[dim] (2.125,-0.25,4.5) -- ++(0,0,-0.5) node[midway,right] {$z_1$}; 
        \draw[dim] (2,-0.25,4.625) -- ++(-2,0,0) node[midway,below] {$x_1$}; 
        \draw[load] (2,-2.45,4.5) -- ++(0,2.2,0) node[pos=0.0,right,xshift=0.08cm] {$F_{y1}$}; 
        \draw[axis,dashed,-] (O) -- (0,0,5); 
        \draw (0,0,5.5) -- ++(4,0,0) node[midway,above] {$w_{z}$}; 
        \foreach \x in {0,0.25,...,4} { 
          \draw[-latex] (\x,0,5.5) -- ++(0,0,-0.5); 
        } 
        \draw (-0.2,0,0) -- ++(-2,0,5) node[above,xshift=0.5cm] {$w_{x}=\frac{z}{h_1+h_2} w_0$}; 
      \end{tikzpicture} % 
    \end{document}
     
    
  2. compile using this his command

    htlatex foo.tex "my.cfg,htm,charset=utf-8" " -cunihtf -utf8"
     
    

    it is important to use my.cfg because without it, you’ll get an error. The cfg file is the one shown above. Just copy that and put it in the same location as the tex file.

  3. here is the HTML generated by the above. HTML should display as