# conversion issues using htlatex and MathJax/mathML method

I am using the method shown in this answer below to convert my LaTeX file to HTML so that the resulting LaTeX file is processed by MathJax via MATHML:

Convert Latex to MathJax-HTML

  "... mathml which can be then displayed with mathjax...."


Everything works well, and using the above method, the math looks much better than the standard htlatex method. Except for things such as $\dot{x}$ which shows up really strange now and is not rendered well. I tried this on IE, Firefox, and Chrome, all with the same problem.

I'll show the small tex file, then the htlatex command I used, then the htlatex .cfg file (which is the same exact .cfg file show in the above answer), then show the HTML output.

LaTeX file:

\documentclass[12pt]{article}%
\begin{document}
$\dot{\alpha}$
$x \dot{x}$
\end{document}


Command used to generate HTML (which is also the same command given in the above answer):

 htlatex t.tex "t.cfg,charset=utf-8" " -cunihtf -utf8"


The t.cfg file used above is the same one shown in the answer above, so will not show it here again.

Screen shot of the HTML generated (notice how the x with the dot does not look right):

Compare that to the PDF output:

Here is the HTML file itself. I think the problem is the MATHML is not right? Is this a htlatex bug? or MATHML? Or MathJax? And how to correct it?

<!DOCTYPE html>
<html>
<meta charset="UTF-8" />
<meta name="generator" content="TeX4ht (http://www.cse.ohio-state.edu/~gurari/TeX4ht/)" />
<script type="text/javascript"
src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"
></script>
<style type="text/css">
.MathJax_MathML {text-indent: 0;}
</style>
>
<!--l. 4--><p class="noindent" ><!--l. 4--><math
xmlns="http://www.w3.org/1998/Math/MathML"
display="inline" ><mover
accent="true"><mrow
><mi
>α</mi></mrow><mo
class="MathClass-op">̇</mo></mover>[/itex]
<!--l. 5--><math
xmlns="http://www.w3.org/1998/Math/MathML"
display="inline" ><mi
>x</mi><mi
>ẋ</mi>[/itex]
</p>

</body>
</html>


Although over all the math looks better in this new method (mathml/mathjax which I have no idea how it actually works), but there are few spots where the math does not render well in HTML. Here is another case

\documentclass[12pt]{article}%
\begin{document}
$\dot{x}_{1}^{2}$
\end{document}


-

The main problem is that tex4ht has been configured to use a precomposed accented x for \dot{x} which is the wrong translation, and produces incorrect output as you show. The generated MathML should use the <mover> form as for the dotted x.

 <!DOCTYPE html>
<html>
<meta charset="UTF-8" />
<meta name="generator" content="TeX4ht (http://www.cse.ohio-state.edu/~gurari/TeX4ht/)" />
<script type="text/javascript"
src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"
></script>
<style type="text/css">
.MathJax_MathML {text-indent: 0;}
</style>
>
<!--l. 4--><p class="noindent" ><!--l. 4--><math
xmlns="http://www.w3.org/1998/Math/MathML"
display="inline" ><mover
accent="true"><mrow
><mi
>α</mi></mrow><mo
class="MathClass-op">̇</mo></mover>[/itex]
<!--l. 5--><math
xmlns="http://www.w3.org/1998/Math/MathML"
display="inline" ><mi
>x</mi><mi
>ẋ</mi>[/itex]
</p>

</body>
</html>


(2) is this fixed to use a real x, note you then get math italic x as intended.

 <!DOCTYPE html>
<html>
<meta charset="UTF-8" />
<meta name="generator" content="TeX4ht (http://www.cse.ohio-state.edu/~gurari/TeX4ht/)" />
<script type="text/javascript"
src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"
></script>
<style type="text/css">
.MathJax_MathML {text-indent: 0;}
</style>
>
<!--l. 4--><p class="noindent" ><!--l. 4--><math
xmlns="http://www.w3.org/1998/Math/MathML"
display="inline" ><mover
accent="true"><mrow
><mi
>α</mi></mrow><mo
class="MathClass-op">̇</mo></mover>[/itex]
<!--l. 5--><math
xmlns="http://www.w3.org/1998/Math/MathML"
display="inline" ><mi
>x</mi><mover
accent="true"><mrow
><mi
>x</mi></mrow><mo
class="MathClass-op">̇</mo></mover>[/itex]
</p>

</body>
</html>


However since you are using MathJax anyway, you could just give it the TeX fragments and let it translate them (3)

 <!DOCTYPE html>
<html>
<meta charset="UTF-8" />
<meta name="generator" content="TeX4ht (http://www.cse.ohio-state.edu/~gurari/TeX4ht/)" />
<script type="text/x-mathjax-config">
MathJax.Hub.Config({tex2jax: {inlineMath: [['$','$'], ['\$','\$']]}});
</script>
<script type="text/javascript"
src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"
></script>
<style type="text/css">
.MathJax_MathML {text-indent: 0;}
</style>
>
<!--l. 4--><p class="noindent" >
$\dot{\alpha}$
$x \dot{x}$
</p>

</body>
</html>


-
But how would this solution be incorporated in the workflow that I have? I simply have source .tex file and also configuration file .cfg that I can change, and htlatex ofcourse. I can't be editing HTML files by hand each time and fix things after each build? I do not use Mathjax directly myself. htlatex generated the mathml file itself such that it uses MathJax to render things somehow. So any fix I need to do, must be done during compiling the latex file by htlatex and not after that. It seems you think there is a bug in htlatex then? Should I report this as htlatex bug? thanks. –  Nasser Apr 20 '13 at 8:32
@Nasser Not so much a bug as a mis-configuration I suspect. It's a long time since I used tex4ht (last century sometime:-) so I can't directly point you to the configuration option but it can't be that hard to tell it not to mess with the mathematics at all and just pass it straight to the output html for mathjax to sort out. –  David Carlisle Apr 20 '13 at 8:49

Math accents are handled in complex way in tex4ht configurations for matml. I don't really understand this way, so I cannot provide clean solution.

Simple fix is to add this line after \begin{document} in your cfg file:

\def\dot#1{\Tg<mover accent="true">#1\HCode{<mo>&sdot;</mo></mover>}}


but this still faills in the case of

$\dot{x}_{1}^{2}$


Other method is to configure tex4ht to not convert math, whis is described in these two answers:

tex4ht leaving equations unchanged

tex4ht leaving equations unchanged - including $...$ and $...$

-
It also failes on $\dot{x}^2$ producing this !Mathematica graphics, after many hours trying many different combinations, I gave up on tex4ht+mathml+mathjax. It is not working. Back to using tex4ht+ png for math. At least png for math works. Also the suggestion to leave equations unchanged did not work for me. I give up :) –  Nasser Dec 31 '13 at 9:39
@Nasser maybe try $\dot{x}^{2}$, tex4ht has some issues with subscripts without brackets. see tug.org/applications/tex4ht/mml.html –  michal.h21 Dec 31 '13 at 9:45
Yes, adding the {} helped. But it still had the same issue with not using the correct \dot{x} rendering. I use this matjax nice page cdn.mathjax.org/mathjax/latest/test/sample-dynamic.html to test things on mathjax directly. And mathjax itself can handle $\dot{x}^2$, so it seems the mathml generated by htlatex has issue with it. thanks. –  Nasser Dec 31 '13 at 10:08