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?
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?
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:

and html:

you can also see the html page in action.