2

Consider the following very simple LaTeX file:

\documentclass{article}
\begin{document}
   \( z=e^{x^{2}+y^{2}} \)
\end{document}

Run it through TeX4ht using the command make4ht -c config.cfg where config.cfg is the configuration file

% We are generating HTML + MathML code
\Preamble{xhtml,mathml}

% Output HTML5 doctype instead of the default for HTML4
\Configure{DOCTYPE}{\HCode{<!doctype html>\Hnewline}}

% Custom page opening
\Configure{HTML}{\HCode{<html lang="en">\Hnewline}}{\HCode{\Hnewline</html>}}

\begin{document}
\EndPreamble

On firefox and safari this produces the expected output with a web page displaying

enter image description here

Unfortunately, on chrome this display incorrectly as:

enter image description here

That is, superscripts (and subscripts) are not displaying properly. I suspect that this is a mathml problem, but I don't know how to fix this.

2

You requests mathml conversion with

 \Preamble{xhtml,mathml}

It is generally a good thing, because tex4ht uses images for math otherwise and it doesn't look really great. The problem is that not all browsers support mathml correctly (in fact none of them), or, as is the Chrome's case, they don't support it all. Fortunately, we can use MathJax library to fix these browser issues.

Also note, that tex4ht has basic support for HTML5 now, so you can simplify your config file to look like this:

\Preamble{xhtml,mathml,html5}
\Configure{HTML}{\HCode{<html lang="en">\Hnewline}}{\HCode{\Hnewline</html>}}

\Configure{@HEAD}{\HCode{\Hnewline<script type="text/javascript"
   src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=MML_CHTML">
   </script>\Hnewline}}
\begin{document}

\EndPreamble

the html5 support doesn't support lang attribute in html element, so we still need to configure HTML hooks.

This is the result:

enter image description here

1

Sorry, I am being stupid: I identified mathml as being the problem, so all that needs to be done is to remove mathml from the config file:

% We are generating HTML + MathML code
\Preamble{xhtml}

% Output HTML5 doctype instead of the default for HTML4
\Configure{DOCTYPE}{\HCode{<!doctype html>\Hnewline}}

% Custom page opening
\Configure{HTML}{\HCode{<html lang="en">\Hnewline}}{\HCode{\Hnewline</html>}}

\begin{document}
\EndPreamble
  • you can also use MathJax to display mathml, see tex.stackexchange.com/a/359065/2891 for example – michal.h21 Mar 23 '17 at 9:46
  • @michal.h21 Thanks. This is a much better approach that mine. You should post and I"ll delete this. – Andrew Mar 23 '17 at 10:06
  • OK, I provided new answer – michal.h21 Mar 23 '17 at 11:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.