[tex4ht] MathML errors using TeX4ht

Michal Hoftich michal.h21 at gmail.com
Sat Apr 3 21:18:11 CEST 2021


Dear Francis, 

these are the common issues that I mentioned in one of my previous 
e-mails. TeX4ht doesn't support \mathbf{xxx}^x. Valid input is 
{\mathbf{xxx}}^x. The {}_x issue is something different, this is really 
known bug that I don't know how to fix. 

Here are some other known issues: https://tug.org/tex4ht/doc/mml.html

Anyway, as these issues are really common and it isn't realistic to fix 
them in already existing documents, here is a workaround. We can use Lua 
script to preprocess the TeX file and fix these issues.

Here it is, filter.lua:

--------------
for line in io.lines() do
   -- fix primes
   line = line:gsub([[%'%^(.-)%_]], [[^{\prime %1}_]])
   -- fix \mathrm{hello}^2
   line = line:gsub([[(\[a-zA-Z]-)(%b{})([%^%_])]], [[{%1%2}%3]])
   -- fix x_\mathrm{hello}
   line = line:gsub([[([%_%^])(\[a-zA-Z]-)(%b{})]], "%1{%2%3}")
   -- fix 10^2
   line = line:gsub("([%d])([%_%^])", "{%1}%2")
   -- fix {}_x
   line = line:gsub("{}([%_%^])", "{\\HCode{}}%1")
   print(line)
end
-------------

It can be executed in this way:

$ texlua filter.lua < MathML-bugs.tex | make4ht -f html5+mjcli -j MathML-bugs -

It seems to work on your sample. I plan to include support for TeX file 
preprocessing in a future make4ht version. It should be easier to run 
such code then.

Best regards,
Michal

>Attached is a MWE illustrating the MathML generation errors that I 
>detected originally when using make4ht with mjcli. They appear to fall 
>into two classes: text in a different font with a super- or sub-script; 
>use of {} with a super- or sub-script. Please see also the comments at 
>the end of the attached file.
>
>Francis




More information about the tex4ht mailing list.