2

Take the following simple latex file

\documentclass{article}
\usepackage{amsfonts,amsmath}
\newcommand\R{\mathbb{R}}

\begin{document}

  $\overrightarrow{AB}$

  $|\mathbf{v}|$

  $e^{x^2+y^2}$

  $\{ x\in\R | x<0 \}$

  \begin{align*}
      f & = 1+2+3+4+\dots+n\\
        & = \binom{n+1}2
  \end{align*}

\end{document}

and run it through tex4ht/make4ht using the configuration file from TeX4ht issue with chrome

\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

(for example, use make4ht -u -c file.cfg file.tex). On firefox, safari and chrome this produces a web page with errors that look something like

enter image description here

The problem is with the mathjax settings. If, instead, I change the configuration file to use

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

then this page displays correctly on firefox but superscripts and subscripts, for example, do not display correctly on chrome and everything is pear-shaped on safari:

enter image description here

This shows how this web page produced by tex4ht displays on firefox, chrome and safari, respectively.

I have tried all of the mathjax settings given on http://docs.mathjax.org/en/latest/config-files.html, as well as trying to configure mathjax directly using MathJax.Hub.Config, but I cannot find a way to get these examples to work. Firefox displays this page well with several of the mathjax configurations, chrome does OK with some and safari is not happy at all.

I have also tried using Michal's mathjax-latex-4ht package, described in Converting latex to html using exsheets, and keeping equations as latex. This is almost perfect except that it doesn't cope with the \R macro in my MWE:

enter image description here

Is there a way to configure tex4ht and mathjax to play well with this example on all browsers? Annoyingly, pandoc seems to produce sensible output here but in my real application I have some significant post-processing to do, which is possible using tex4ht and I am not sure if this can be done starting with pandoc.

  • Why the down vote? ... – Andrew Jun 26 '17 at 10:03
2

This is caused by bug in configuration for \mathbf command:

\Configure{mathbf}%
 {\bgroup \Tg<\a:mathml mi mathvariant="bold">\PauseMathClass}%
  {\Tg</\a:mathml mi>\egroup }%

tex4ht automatically add markup around math variables and operators, but this is disabled by \PauseMathClass command in this configuration, because the markup is added explicitly in this case. The automatic markup must be turned on after end of \mathbf, otherwise it will result in invalid markup. Because your second math example contains \mathbf, all following examples contain invalid markup. We need to use \EndPauseMathClass command to turn markup on again.

I will fix this issue in tex4ht sources, but it will take some time before the fix goes to TeXLive, so you can use the following configuration in the meantime.

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

\Configure{@HEAD}{\HCode{\Hnewline<script type="text/javascript"
   src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=MML_CHTML">
   </script>\Hnewline}}
\begin{document}

\EndPreamble

The result:

enter image description here

  • Thanks very much Michal! I am amazed how quickly you find these things and fix them. Once again I am in your debt. I'll be in Praha for a few months towards the end of the year. More than happy to buy you a beer. – Andrew Apr 5 '17 at 9:24
  • @Andrew it wasn't so hard to localize the bug, I introduced it to the sources not so long ago :D It would be nice to see you, there are not so many TeXies around me (much more in Brno than in Prague) – michal.h21 Apr 5 '17 at 10:29

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.