What is current status of using tikz with tex4ht?

I am completely confused now about how to use tikz with tex4ht, since there seems to be some latest changes and not able to figure what is the way to make it work.

Here is a MWE, which I'd like to compile with make4ht in mathjax mode. But the output does not look correct compared to the PDF

\documentclass[11pt]{article}
\usepackage{tikz}
\usepackage{amsmath}
\begin{document}

\begin{tikzpicture}
\coordinate[label =above:$0$,   label =below:{$u=0$}] (A) at (0,0);
\coordinate[label =above:$\pi$, label =below:{$u_x=0$}] (B) at (4,0);

\draw (A) -- node[above] {$u_t = k u_{xx}$}  node[below] {$f(x)$} ++ (B);

\node at (A)[circle,fill,inner sep=1pt]{};
\node at (B)[circle,fill,inner sep=1pt]{};

\end{tikzpicture}
\end{document}


Now lualatex produces this

And make4ht foo.tex "mathjax" or make4ht foo.tex produces this

The math does not look as good as the PDF. And if I do this make4ht -ulm foo.tex "mathjax" it produces this

Changing the MWE to have this

\documentclass[11pt]{article}
\usepackage{tikz,graphicx,tikz-dependency}
\def\pgfsysdriver{pgfsys-tex4ht.def}
\usepackage{amsmath}
\begin{document}
%as before
\end{document}


Produces same output which is

\ifdefined\HCode
\def\pgfsysdriver{pgfsys-tex4ht.def}
\fi


I looked at using-htlatex-with-tikz-dependency but answers given are way too complicated and could not follow it. It needs external tools to make them work. inkscape and so on. Which I do not want to use.

What is the simplest way to make tikz work with make4ht these days? I am using TL 2018.

Will things change in TL 2019 for tex4ht?

• It's worth mentioning that there are multiple issues with the tex4ht driver at the moment. See github.com/pgf-tikz/pgf/issues/651. The dvisvgm4ht(used in the answer below) is not without problems either and I gather is slower. – David Purton May 2 '19 at 10:12
• @DavidPurton Oh no :( well. Will try it once 2019 is installed. If all is lost and it is still not working, I could always generate the PDF's of the pictures using tikz standalone, then use \includegraphics to load the output pdf image with tex4ht. – Nasser May 2 '19 at 10:17
• Don't despair :) The dvisvgm4ht driver definitely does a better job. I think it's still a work in progress though. – David Purton May 2 '19 at 10:19
• @DavidPurton I think the dvisvgm4ht works in most cases, I don't recall any open issues. but maybe I just forgot about something. The compilation time can be saved using the dvisvgm_hashes extension for make4ht. It compiles only changed images and support multiple CPU cores. – michal.h21 May 2 '19 at 11:19
• @michal.h21, I found an issue while working on shadings. I'll put in a bug report for you. – David Purton May 2 '19 at 11:28

If you compile this file "correctly" with tex4ht then it produces the expected HTML file:

Here "correctly" means that you need to tell pgf the "correct" driver to use by adding the line:

 \def\pgfsysdriver{pgfsys-dvisvgm4ht.def}


to the top of the tex file. If you are using TeXLive 2019 then you will have this file as it is included as part of the webquiz package, but this driver file is actually written by Michal Hoftich, who is one of the tex4ht maintainers. You can download the latest version of this driver from https://github.com/michal-h21/dvisvgm4ht.

Here is the modified MWE:

\documentclass[11pt]{article}
\ifdefined\HCode
\def\pgfsysdriver{pgfsys-dvisvgm4ht.def}
\fi

\usepackage{tikz}
\usepackage{amsmath}
\begin{document}

\begin{tikzpicture}
\coordinate[label =above:$0$,   label =below:{$u=0$}] (A) at (0,0);
\coordinate[label =above:$\pi$, label =below:{$u_x=0$}] (B) at (4,0);

\draw (A) -- node[above] {$u_t = k u_{xx}$}  node[below] {$f(x)$} ++ (B);

\node at (A)[circle,fill,inner sep=1pt]{};
\node at (B)[circle,fill,inner sep=1pt]{};

\end{tikzpicture}
\end{document}


The easiest way to compile this file with tex4ht is to use Michal Hoftich's make4ht:

make4ht filename

• Thanks. I am installing TL 2019 at this moment. It will take 2-3 hrs to finish. Will try with \def\pgfsysdriver{pgfsys-dvisvgm4ht.def} then. I prefer not to download individual files so installing 2019 would be better option. – Nasser May 2 '19 at 10:08
• I've send mail to Henri Menke to use the alternative driver as a default one for TikZ and tex4ht. – michal.h21 May 2 '19 at 10:36
• @michal.h21 Thanks. When it hits texlive I'll have to update my package so that it no longer uses it. – Andrew May 2 '19 at 11:18
• Great, it works! Thanks to to your help and ofcourse thanks to Michal.h21 for all his great work on this. – Nasser May 2 '19 at 18:56
• @Andrew I've fixed some bugs in the dvisvgm4ht driver, it can can compile most tikz pictures without compilation errors. The output is sometimes wrong for some more complex images, but it is OK in most cases – michal.h21 May 6 '19 at 16:20