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)




 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}

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:

  \Configure{DOCTYPE}{\HCode{<!DOCTYPE html>\Hnewline}}
  \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}}
           rel="stylesheet" type="text/css"
           href="\expandafter\csname aa:CssFile\endcsname" />\Hnewline}}
  \Configure{@HEAD}{\HCode{<script type="text/javascript"\Hnewline
  \Configure{@HEAD}{\HCode{<style type="text/css">\Hnewline
    .MathJax_MathML {text-indent: 0;}\Hnewline


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


MathML code. Case (1)

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

case (2)

<p class="nopar" >
<div class="par-math-display"><!--l. 17--><math xmlns="http://www.w3.org/1998/Math/MathML"  display="block" >
<mi>k</mi> <mo class="MathClass-rel">=</mo><munderover accentunder="false" accent="false">
<mrow><mo mathsize="big"> &#x2211;</mo>
<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 
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">
<mo class="MathClass-bin">&#x25AA;</mo></mrow></mover></mrow><mrow><mn>2</mn></mrow></msub>

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.

  • Could you copy the actual MathML snippets instead of putting pictures of them? So that one can test them. Oct 27, 2013 at 8:15
  • @KhaledHosny fyi, added the MathML for the 3 cases.
    – Nasser
    Oct 27, 2013 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. Oct 27, 2013 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, 2013 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). Oct 27, 2013 at 10:10

2 Answers 2


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.


For the large size of summation issue, you have to modify the mathml.4ht file which is, at least with windows using miktex, in somewhere like C:\users\yourname\AppData\Roaming\MiKTeX\2.9\tex\generic\tex4ht (if you read the log file after the htlatex, path will be indicated) :

You will see (after a search in the file) that everything defined as \:tempd will have mathsize="big", included the number 50 "sum" as in \:tempd{sum}{50}.

The quickest way to solve the issue is to replace "big" with "large" or "normal" or "tiny".... and the longest way would be to define another environment only maybe for the "sum" command.

You must log in to answer this question.

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