I found this today:


Author interactive math equations and diagrams online using LATEX and PSTricks

It looks nice, but I'm more familiar with TikZ. Is anybody aware of something equivalent which is not based on PSTricks but TikZ?

  • 1
    you can use tex4ht for this job - tex.stackexchange.com/q/35145/2891 for tex4ht + tikz, albany.edu/~hammond/demos/Html5/arXiv for tex4ht + mathjax + html5
    – michal.h21
    Nov 18, 2013 at 10:03
  • 3
    You need to know that not all PSTricks constructs are currently supported. The author probably chose PSTricks because it is much less verbose compared to TikZ. Parsing TikZ is much more complicated. Nov 18, 2013 at 14:29
  • @michal.h21 Do you mind cooking up the simplest example with tex4ht?
    – percusse
    Mar 14, 2014 at 19:03
  • @percusse not really the simples example, because I added also other features, but I added something :)
    – michal.h21
    Mar 17, 2014 at 15:08

1 Answer 1


There is simple example which shows usage of tikz-to-svg, mathjax and webfonts with tex4ht.

First some sample document:

\usepackage{tikz, myexternalize, myfontspec, mathtools}
\setmathfont{XITS Math}

First, show me some inline math: 
\(\forall x \in X, \quad \exists y \leq \epsilon\)

Now some display math:

    \frac{n!}{k!(n-k)!} = \binom{n}{k}

And finally, some tikz picture, source is some answer on TeX.sx:

    % Time axis
    \draw (0,0) -- node[below=1cm] {Time $\to$} (6,0);
    % Emotional axis
    \draw (0,0) -- node[left] {\parbox{2cm}{\centering $\uparrow$ \\ Emotional \\ intensity}} (0,4);
    % Time ticks
    \foreach \x [count=\j] in {0.2,3,4.5,6} {
        \draw (\x,0) coordinate (t\j) -- (\x,-0.1cm) node[below] (tt\j) {Time \j};
    \node[below] at (tt1.south) {(Emotional event)};
    % Curves
    \draw (t1) .. controls +(1,2) .. node[above right] {Experienced} (t2);
    \draw[dashed] (t1) .. controls +(1,4) .. node[above right] {Predicted} (t4);

Some samples \textit{of font} \textbf{changes} and diacritics: Příliš žluťoučký kůň úpěl ďábelské ódy.

Two custom packages are used, myexternalize and myfontspec. These packages tries to resolve issues of fontspec and tikz-externalize with tex4ht.

Now we should show these packages. myexternalize.sty:

    tex4ht inc/.style={
        /pgf/images/include external/.code={%


    \tikzexternalize[mode=only graphics]
        \tikzset{tex4ht inc}
    \tikzset{external/system call={lualatex \tikzexternalcheckshellescape -halt-on-error -interaction=batchmode -jobname "\image" "\texsource"}}
 external/system call/.add={}                                                
      {; inkscape -z -f "\image.pdf" -l "\image.svg"

this package uses lualatex to convert tikz pictures to pdf and inkscape to convert these pdf to svg. Some details can be found here and here. You also need file myexternalize.4ht, which configures tex4ht to include svg images:

          {\Configure{Needs}{File: \[email protected]}\Needs{}}
          \Picture[\csname a:GraphicsAlt\endcsname]{\csname Gin@base\endcsname.svg \csname a:Gin-dim\endcsname}%  

Now we need to handle fonts, with package myfontspec.sty:


This file only loads inputenc and fontenc packages and defines some dummy commands when compiled with tex4ht, fontspec is used otherwise. Now you can compile your document to get svg images:

lualatex -shell-escape filename

Now we need to provide some configurations for mathjax and webfonts for tex4ht. File myconfig.cfg:

\Preamble{xhtml, mathml}
% Configure for mathjax
\Configure{DOCTYPE}{\HCode{<!DOCTYPE html>\Hnewline}}
\Configure{@HEAD}{\HCode{<script type="text/javascript"\Hnewline
\Css{@font-face {
    font-family: #1;
    src: local("#2"),
\special{t4ht+@File: #3}
\newcommand\NormalFont[2]{\AddFontFace{\CurrentFontFamily}{#1}{#2}{font-weight: normal;font-style: normal;}}

\newcommand\BoldFont[2]{\AddFontFace{\CurrentFontFamily}{#1}{#2}{font-weight: bold;font-style: normal;}}
\newcommand\ItalicFont[2]{\AddFontFace{\CurrentFontFamily}{#1}{#2}{font-weight: normal;font-style: italic;}}
\newcommand\BoldItalicFont[2]{\AddFontFace{\CurrentFontFamily}{#1}{#2}{font-weight: bold;font-style: italic;}}

\Css{body{font-family:rmfamily, "STIXDefault", sans-serif;}}

There are definitions for mathjax before \begin{document}, after that, definitions for fonts follow. I created new command \AddFontFace which add font definition to the css file, and number of commands for including files for different font weights and styles. Stix fonts are used, because these fonts are used by mathjax, so it looks good when they are used also for text. You need to copy used .woff files from zip file provided on Sourceforge.

Now we can compile the document with:

htlatex filename "myconfig, mathml, charset=utf-8" " -cunihtf -utf8"

Resulting pdf:

enter image description here

and html:

enter image description here

you can also see the html page in action.

You must log in to answer this question.

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