1

This file

\documentclass{article}
\usepackage{siunitx}
\begin{document}
 \SI{10}{\square\meter}

 $\SI{10}{\square\meter}$
\end{document}

Builds fine in padlatex, but fails in the HTML generated by tex4ht when using mathml. The HTML page displays an error parsing mathml message. The problem is when using the square meter in the math mode. In non-math mode it works.

Below is the command used, the htlatex configuration file used, and the error message and the HTML generated.

Is this a configuration issue, or a mathml bug in code generated by tex4ht? I spent many hours changing all my code to use the \usepackage{siunitx} and have lots of such code now changed and only noticed this problem now.

The command used

htlatex foo.tex "my,htm,pic-align,charset=utf-8,notoc*" " -cunihtf -utf8"

where my.cfg is the configuration file. Please see it below. It has to be in the same folder (or in $HOME)

This is the error

Mathematica graphics

Here is the HTML code generated

<!DOCTYPE html> 
<html> 
<head> <title></title> 
<meta charset="UTF-8" /> 
<meta name="generator" content="TeX4ht (http://www.cse.ohio-state.edu/~gurari/TeX4ht/)" /> 
<link rel="stylesheet" type="text/css" href="foo.css" /> 
<script type="text/x-mathjax-config"> 
MathJax.Hub.Config({ 
extensions: ["tex2jax.js"], jax: ["input/TeX", "output/HTML-CSS"], tex2jax: { inlineMath: [ ['$','$'], ["\\(","\\)"] ], 
displayMath: [ ['$$','$$'], ["\\[","\\]"] ], 
ignoreClass: "fancyvrb|verbatim", 
processEscapes: true }, "HTML-CSS": { availableFonts: ["TeX"] } }); 
</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> 
</head><body 
>
<!--l. 4--><p class="noindent" >10 m<sup class="textsuperscript"><span 
class="cmr-9">2</span></sup>
<!--l. 6--><p class="indent" >   <!--l. 6--><math 
 xmlns="http://www.w3.org/1998/Math/MathML"  
display="inline" ><mstyle 
class="text"><mtext  >10</mtext></mstyle><mspace width="0em" class="thinspace"/><mstyle 
class="text"><mtext  >m<sup class="textsuperscript">2</sup></mtext></mstyle></math>

</body> 
</html>

This is my .cfg that I use with mathml mode

\Preamble{mathml}
\Configure{VERSION}{}
  \Configure{DOCTYPE}{\HCode{<!DOCTYPE html>\Hnewline}}
  \Configure{HTML}{\HCode{<html>\Hnewline}}{\HCode{\Hnewline</html>}}
  \Configure{@HEAD}{}
  \Configure{@HEAD}{\HCode{<meta charset="UTF-8" />\Hnewline}}
  \Configure{@HEAD}{\HCode{<meta name="generator" content="TeX4ht
  (http://www.cse.ohio-state.edu/\string~gurari/TeX4ht/)" />\Hnewline}}
  \Configure{@HEAD}{\HCode{<link
           rel="stylesheet" type="text/css"
           href="\expandafter\csname aa:CssFile\endcsname" />\Hnewline}}

  \Configure{@HEAD}{\HCode{%
     <script type="text/x-mathjax-config">\Hnewline
       MathJax.Hub.Config({\Hnewline
         extensions: ["tex2jax.js"],
         jax: ["input/TeX", "output/HTML-CSS"],
         tex2jax: {
           \unexpanded{inlineMath: [ ['$','$'], ["\\(","\\)"] ],}\Hnewline
           \unexpanded{displayMath: [ ['$$','$$'], ["\\[","\\]"] ],}\Hnewline
           ignoreClass: "fancyvrb|verbatim",\Hnewline
           processEscapes: true
         },
         "HTML-CSS": { availableFonts: ["TeX"] }
       });\Hnewline
     </script>
  }}

  \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}}
  \Configure{@HEAD}{\HCode{<style type="text/css">\Hnewline
    .MathJax_MathML {text-indent: 0;}\Hnewline
  </style>\Hnewline}}

\begin{document}
\EndPreamble

When not using mathml then the error goes away (notice, not using my.cfg)

htlatex foo.tex "htm,pic-align,charset=utf-8,notoc*" " -cunihtf -utf8"

Mathematica graphics

But I have to use mathml, since I use mathjax to render everything and I do not want to go back to using .png images for math.

I am using texlive 2013 on Linux mint 16

3
  • from siunitx documentation: "siunitx will detect when tex4ht is in use, and makes some changes to the way output is printed. Text mode printing is automatically selected, and certain items (such as spaces) are printed in text mode rather than as math. This is designed to reduce the likelihood of spurious formulae appearing in, for example, output converted to OpenOffice format."
    – michal.h21
    Feb 23, 2014 at 9:50
  • so I think you shouldn't use siunitx in math mode. The error is caused by <sup> element appearing in math, and this is because units are printed in text mode. maybe you can ask @JosephWright for some consultation
    – michal.h21
    Feb 23, 2014 at 9:52
  • 1
    I can't comment on whether siunitx is supposed to generate this, but the MathJax error is due to a current limitation of MathJax. The output is valid HTML5 but it contains MathML mixed with HTML (the <sup></sup> elements). MathJax does not support this kind of mixed HTML content (yet), only semantics/annotation-xml embedding of HTML is supported right now. Feb 23, 2014 at 21:57

1 Answer 1

2

It seems that this issue was fixed in the meantime, the result looks like this:

enter image description here

The MathML code seems OK too:

<!-- l. 4 --><p class='noindent'><!-- l. 4 --><math display='inline' xmlns='http://www.w3.org/1998/Math/MathML'><mrow><mn>10</mn></mrow></math> <!-- l. 4 --><math display='inline' xmlns='http://www.w3.org/1998/Math/MathML'><msup><mrow><mstyle mathvariant='normal'><mi>m</mi></mstyle></mrow><mrow><mn>2</mn></mrow></msup></math>
</p><!-- l. 6 --><p class='indent'>   <!-- l. 6 --><math display='inline' xmlns='http://www.w3.org/1998/Math/MathML'><mrow><mn>10</mn><mspace class='thinspace' width='0.17em'></mspace><msup><mrow><mstyle mathvariant='normal'><mi>m</mi></mstyle></mrow><mrow><mn>2</mn></mrow></msup></mrow></math>
</p>

You must log in to answer this question.

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