Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I found this today:

http://latex2html5.com/

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?

share|improve this question
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 '13 at 10:03
2  
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. –  Please don't touch Nov 18 '13 at 14:29
    
@michal.h21 Do you mind cooking up the simplest example with tex4ht? –  percusse Mar 14 at 19:03
    
@percusse not really the simples example, because I added also other features, but I added something :) –  michal.h21 Mar 17 at 15:08
    
@michal.h21 Great! Thanks. –  percusse Mar 17 at 15:13

1 Answer 1

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

First some sample document:

\documentclass[]{article}
\usepackage{tikz, myexternalize, myfontspec, mathtools}
\setmainfont{STIXGeneral}
\setmathfont{XITS Math}
\begin{document}


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:

\begin{tikzpicture}
    % 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);
\end{tikzpicture}

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

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:

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

    }
}

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

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{graphics*}  
         {svg}{  
          {\Configure{Needs}{File: \Gin@base.svg}\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:

\@ifpackageloaded{tex4ht}{
    \usepackage[utf8]{inputenc}
    \usepackage[T1]{fontenc}
  \newcommand\setmainfont[1]{}
  \newcommand\setmathfont[1]{}  
}{
    \usepackage{fontspec}
    \usepackage{unicode-math}
}

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{VERSION}{}
\Configure{DOCTYPE}{\HCode{<!DOCTYPE html>\Hnewline}}
\Configure{HTML}{\HCode{<html>\Hnewline}}{\HCode{\Hnewline</html>}}
\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}}
\begin{document}
\newcommand\AddFontFace[4]{%
\Css{@font-face {
    font-family: #1;
    src: local("#2"),
        url('#3');
    #4
 }}
\special{t4ht+@File: #3}
}
\edef\CurrentFontFamily{rmfamily}
\newcommand\SetFontFamily[1]{
\edef\CurrentFontFamily{#1}
}
\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;}}

\NormalFont{STIXDefault}{STIXGeneral-Regular.woff}
\BoldFont{STIXDefault}{STIXGeneral-Bold.woff}
\ItalicFont{STIXDefault}{STIXGeneral-Italic.woff}
\BoldItalicFont{STIXDefault}{STIXGeneral-BoldItalic.woff}
\Css{body{font-family:rmfamily, "STIXDefault", sans-serif;}}
\EndPreamble

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.