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.

updated: Added the MathML code in source form at the bottom of this, as requested.

I am now configuring tex4ht to generate MathML instead of .png for the math. Then MathJax is loaded for final display. I found 3 problems (so far) with the MathML code generated by tex4ht.

The first one, \pm (plus or minus sign) generates wrong mathml code, the workaround I just found is to use \mp (minus or plus) instead (but I prefer to use \pm as it is more common). For some reason \mp works while \pm does not.

The third problem (dot) also have a good work around in Latex which I can use. The second problem does not have work around in Latex code so far. (The extra large size of the summation sign)

So I need some help in what to do configure tex4ht or Mathml to avoid this problem, at least for case (2), as the others I have a work around for now. But I prefer to use \pm for case (1).

I am on Linux, using TL 2013. Please assume I am a newbie when giving any instructions on what to do.

Below I show screen shot of the math generated by MathML with the pdflatex output next to it, and the latex code.

Below that is the MathML code for each case. These cases are numbered 1 to 3. Case (2) (the big summation) has a MathML workaround, which is to remove <mo mathsize="big">, however, I do not know how to tell htlatex about this, or where to configure this change, or where to change things in TL installation to do this change. I can't ofcourse edit the HTML file each time I build it to fix mathml by hand. I have hundreds or thousands of small html files that I build from Latex.

enter image description here

The MWE follows (collection_of_problems.tex)

\documentclass[12pt]{report}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}

\begin{document}

%(1)
\[
y=\pm\sqrt{x}
\]

\[
 y=\mp\sqrt{x}  %work around, but I prefer (1) not this one.
\]

% (2)
\[
k= \sum_{i}^{2} m_{i}(x)
\]

%bad dot (3)

\[
\overset{\rightarrow}{a} = \overset{\centerdot}{\omega}_{2}
\]

\[
\overset{\rightarrow}{a} = \overset{\cdot}{\omega}_{2}
\]

\[
\overset{\rightarrow}{a} = \overset{\bullet}{\omega}_{2}
\]
\end{document}

The command to use to build the htm file

 htlatex  collection_of_problems.tex "my,htm"

Where my.cfg file, in the same folder, is the following:

\Preamble{mathml,ext=htm}
\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/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 the .htm is created, simply double click on it and assuming you are connected to the internet, MathJax will be loaded in your browser and you'll see the problem as shown in the screen shots above. To build the pdf file, pdflatex file.tex ofcourse.

ps. strange why \mp works but not \pm. Here is the code for \pm

enter image description here

Updated:

MathML code. Case (1)

<div class="par-math-display"><!--l. 12--><math xmlns="http://www.w3.org/1998/Math/MathML"  
display="block" >
<mrow>
<mi>y</mi> <mo 
class="MathClass-rel">=</mo> <mo 
class="MathClass-bin">±</mo><msqrt><mrow><mi>x</mi></mrow></msqrt>
</mrow></math>

case (2)

<p class="nopar" >
<div class="par-math-display"><!--l. 17--><math xmlns="http://www.w3.org/1998/Math/MathML"  display="block" >
<mrow>
<mi>k</mi> <mo class="MathClass-rel">=</mo><munderover accentunder="false" accent="false">
<mrow><mo mathsize="big"> &#x2211;</mo>
</mrow><mrow><mi>i</mi></mrow><mrow><mn>2</mn></mrow></munderover><msub><mrow>
<mi>m</mi></mrow><mrow><mi>i</mi></mrow></msub><mrow >
<mo class="MathClass-open">(</mo><mrow><mi>x</mi></mrow>
<mo class="MathClass-close">)</mo></mrow></mrow></math>

case (3)

<div class="par-math-display"><!--l. 23--><math 
xmlns="http://www.w3.org/1998/Math/MathML"  
display="block" ><mrow>
<mover class="overset"><mrow><mi>a</mi></mrow><mrow> 
<mo class="MathClass-rel">&#x2192;</mo></mrow></mover> 
<mo class="MathClass-rel">=</mo><msub><mrow> <mover class="overset">
<mrow><mi>&#x03C9;</mi></mrow><mrow> 
<mo class="MathClass-bin">&#x25AA;</mo></mrow></mover></mrow><mrow><mn>2</mn></mrow></msub>
</mrow></math>
</div>

update 2:

A workaround is found, thanks to @Khaled Hosny in the comments below, which is to use UTF-8. Changing the tex4ht command to change the default, fixed the problem with \pm. This is the new command to use.

htlatex foo.tex "my,htm,charset=utf-8" " -cunihtf -utf8"

Only problem left, is the large size of summation. Case (2) above. Changing the default renderer to MathML from the default HTML-CSS fixed this as well. But I am not sure now if this is something I can control and change from my end using MathJax setting, or if this is something on the client browser side only, so I can let it go.

share|improve this question
    
Could you copy the actual MathML snippets instead of putting pictures of them? So that one can test them. –  Khaled Hosny Oct 27 '13 at 8:15
    
@KhaledHosny fyi, added the MathML for the 3 cases. –  Nasser Oct 27 '13 at 8:38
    
Your MathML example look fine here (in Firefox, with default setup); the \pm is shown in (1), the \sum in (2) is what I’d expect from display size equation, and the \centerdot in (3) is a bit big but smaller than your example. So I think the problem is in the MathML renderer side not the conversion itself. –  Khaled Hosny Oct 27 '13 at 9:33
    
@KhaledHosny thanks, but what does this mean in plain English please? the bit about MathML renderer side? Are you saying then it is MathJax that is at fault? I am also using FF 24.0 on windows 7. You can also see the MathML generated yourself if you just run the command shown above (the htlatex command). If you are connected to the net, then MathJax will load from the server and you can see the result. If you open the html file generated by tex4ht, you should see the same mathML code. I am using TL 2013. –  Nasser Oct 27 '13 at 9:45
    
You can see the native Firefox MathML rendering by right clicking an equation Math Settings → Math Renderer → MathML. I can replicate the \pm issue here running htlatex, it seems to be generating an invalid UTF-8 sequence (which got “cleaned” up when you copied it here). –  Khaled Hosny Oct 27 '13 at 10:10
show 5 more comments

1 Answer 1

up vote 1 down vote accepted

Thanks to the hints given in the comments, the fix is to use UTF when building the HTML page with htlatex.

The command to use is

htlatex foo.tex "my,htm,charset=utf-8" " -cunihtf -utf8"

The large size of summation issue is not a big problem. So there is no need to keep this open.

share|improve this answer
add comment

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.