3

How do I configure htlatex so that equations are not rendered as an image in a separate file, but within the document as in $x$? I still would like the ability to assign \label

5

I think that it is best to convert math to MathML and use MathJax to render it. Native LaTeX labels work with no problems this way.

All we need to do is to use simple config file, which will provide some JavaScript to load MathJax:

\Preamble{xhtml,mathml}
\Configure{@HEAD}{%
\HCode{<script type="text/javascript"
   src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=MML_CHTML">
 </script>\Hnewline}}
\begin{document}
\EndPreamble

All what this does is that it selects MathML output in the \Preamble command and then include external script to load MathJax. Important piece is MathJax.js?config=MML_CHTML, which configures MathJax to parse only MathML and to select common html as the rendered format. MathJax by default also parse LaTeX math in the document, but we really don't need that, it would only slow down the processing.

Some sample document:

\documentclass{article}

\usepackage{amsmath}
\begin{document}

hello world

\begin{equation}
\label{eq:hello}
a = \sqrt{b^2 + c^2}
\end{equation} 

See equation~\ref{eq:hello}

Now some multiline

\begin{multline*}
  p(x) = 3x^6 + 14x^5y + 590x^4y^2 + 19x^3y^3\\ 
  - 12x^2y^4 - 12xy^5 + 2y^6 - a^3b^3
\end{multline*}


Align:

\begin{align*} 
  2x - 5y &=  8 \\ 
  3x + 9y &=  -12
\end{align*}


Align*:

\begin{align*}
  x&=y           &  w &=z              &  a&=b+c\\
  2x&=-y         &  3w&=\frac{1}{2}z   &  a&=b\\
  -4 + 5x&=2+y   &  w+2&=-1+w          &  ab&=cb
\end{align*}

\end{document}

We can compile it using

make4ht -uc configfilename.cfg filename.tex

and the result looks this way:

enter image description here

  • I upvoted and I'll play around with this, thanks, but right now I was just looking to reproduce the same behavior as $...$ (which does not use mathjax). I don't want to use javascript here. – Manu Oct 16 '16 at 23:22
  • @EmanueleViola it works with $...$ as well. If you don't want to use JavaScript, then it is possible to install command line version of MathJax using node.js and convert the HTML file with MathML to simplified version. I can update the answer with an example. – michal.h21 Oct 17 '16 at 6:30
  • I am trying to produce a very minimalistic html here that can be pasted into wordpress. Wordpress doesn't like javascript (as far as I can tell). The way $...$ is converted is just plain HTML, which Wordpress understands, but for some reason \begin{equation} is rendered as an image, which wordpress does not like. – Manu Oct 17 '16 at 12:43
  • @EmanueleViola ah I see. This might be useful then. – michal.h21 Oct 17 '16 at 12:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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