4

This MWE

\documentclass{article}
\usepackage{amsmath}
\begin{document}    

   \[
    W = \begin{vmatrix}
\sqrt {x} & {x}^{{\frac{3}{2}}} \\ 
{\frac {1}{2}{\frac {1}{\sqrt {x}}}} & {\frac {3}{2}\sqrt {x}}
\end{vmatrix}
\]          
\end{document}

when compiled using make4ht foo3.tex "mathjax" gives

enter image description here

The raw HTML is

<html lang='en-US' xml:lang='en-US'> 
<head><title></title> 
<meta charset='utf-8' /> 
<meta content='TeX4ht (https://tug.org/tex4ht/)' name='generator' /> 
<meta content='width=device-width,initial-scale=1' name='viewport' /> 
<link rel='stylesheet' href='foo3.css' type='text/css' /> 
<meta content='foo3.tex' name='src' /> 
 <script> window.MathJax = { tex: { tags: "ams", inlineMath: [ ["\\\(","\\\)"] ], displayMath: [ ['$$','$$'], ["\\[","\\]"] ], processEscapes: true, processEnvironments: true, packages: ['base', 'color', 'ams'] }, loader: { load: ['[tex]/color', '[tex]/ams'] } }; </script> 
 <script async='async' src='https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml-full.js' id='MathJax-script' type='text/javascript'></script>  
</head><body>
<!-- l. 25 --><p class='noindent'>\[ W = \begin{vmatrix} \sqrt{x} &amp;{x}^{{\frac{3}{2}}} \\:{\frac{1}{2}{\frac{1}{\sqrt{x}}}} &amp;{\frac{3}{2}\sqrt{x}} \end{vmatrix} \]
</p>
    
</body> 
</html>

Where did the extra ":" come from and how to get rid of it?

>make4ht --version
make4ht version v0.3e

Using TL 2020 on Linux

FYI, the code above was auto-generated by Maple latex, which seems to add extra {} automatically as follows

Example 1

 latex(x^(3/2))
                    {x}^{{\frac{3}{2}}}

Example 2

   latex(diff(x^(3/2),x))
                       {\frac {3}{2}\sqrt {x}}

This has no effect when compiling to PDF. The PDF output of the above from lualatex foo3.tex is OK

enter image description here

Updated

FYI, link to bug report to mathjax added

https://github.com/mathjax/MathJax/issues/2487

5

TeX4ht passes LaTeX math verbatim to the HTML file. The problem is that the process it uses introduces lot of unwanted spaces to the output. This can cause issues in MathJax rendering. To fix this, it uses several regular expressions. One of them replaces \ { with \:{, in order to fix this issue. The problem is that it also replaces \\ { with \\:{, which causes the spurious colon. So we need to catch this case with another regular expression.

Here is updated mathjax-latex-4ht.4ht:

% mathjax-latex-4ht.sty (2020-07-27-14:09), generated from tex4ht-mathjax.tex
% Copyright 2018-2019 TeX Users Group
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either
% version 1.3c of this license or (at your option) any
% later version. The latest version of this license is in
%   http://www.latex-project.org/lppl.txt
% and version 1.3c or later is part of all distributions
% of LaTeX version 2005/12/01 or later.
%
% This work has the LPPL maintenance status "maintained".
%
% The Current Maintainer of this work
% is the TeX4ht Project <http://tug.org/tex4ht>.
%
% If you modify this program, changing the
% version identification would be appreciated.
\immediate\write-1{version 2020-07-27-14:09}

\RequirePackage{etoolbox,expl3,environ}

\ExplSyntaxOn
\cs_new_protected:Npn \alteqtoks #1
{
  \tl_set:Nx \l_tmpa_tl {\detokenize{#1}}
  % convert \ { to \:{  
  \regex_replace_all:nnN { \x{5C} \x{20} \x{7B} } { \x{5C} \x{3A} \x{7B} } \l_tmpa_tl
  \regex_replace_all:nnN { \x{5C} \x{5C}  \x{3A} \x{7B} } { \x{5C} \x{5C} \x{20} \x{7B} } \l_tmpa_tl
  % delete spaces before left brackets
  \regex_replace_all:nnN { \x{20} \x{7B} } { \x{7B} } \l_tmpa_tl
  % convert \\:{ back to \\ { 
  \regex_replace_all:nnN { \x{5C} \x{5C}  \x{3A} \x{7B} } { \x{5C} \x{5C} \x{20} \x{7B} } \l_tmpa_tl
  % replace < > and & with xml entities
  \regex_replace_all:nnN { \x{26} } { &amp; } \l_tmpa_tl
  \regex_replace_all:nnN { \x{3C} } { &lt; } \l_tmpa_tl
  \regex_replace_all:nnN { \x{3E} } { &gt; } \l_tmpa_tl
  \tl_set:Nx \l_tmpb_tl{ \l_tmpa_tl }
  \HCode{\l_tmpb_tl}
}
\ExplSyntaxOff

\NewConfigure{MathJaxConfig}{1}

\long\def\AltlMath#1\){\expandafter\alteqtoks{\(#1\)}\)}
\long\def\AltlDisplay#1\]{\alteqtoks{\[#1\]}\]}
\long\def\AltMathOne#1${\alteqtoks{\(#1\)}$}
% this seems a bit hacky -- we need to skip some code inserted at the
% beginning of each display math
\long\def\AltlDisplayDollars\fi#1$${\alteqtoks{\[#1\]}$$}

\newcommand\VerbMathToks[2]{%
  \alteqtoks{\begin{#2}
    #1
  \end{#2}}%
}
\newcommand\VerbMath[1]{%
\ifcsdef{#1}{%
  \RenewEnviron{#1}{%
  \NoFonts\expandafter\VerbMathToks\expandafter{\BODY}{#1}\EndNoFonts%
  }
}{}%
}
\def\fixmathjaxtoc#1{\Configure{writetoc}{\def#1{\detokenize{#1}}}}
\def\fixmathjaxsec#1{\def#1{\detokenize{#1}}}

\AtBeginDocument{%
\VerbMath{subarray}
\VerbMath{smallmatrix}
\VerbMath{matrix}
\VerbMath{pmatrix}
\VerbMath{bmatrix}
\VerbMath{Bmatrix}
\VerbMath{vmatrix}
\VerbMath{Vmatrix}
\VerbMath{cases}
\VerbMath{subequations}
\VerbMath{aligned}
\VerbMath{alignedat}
\VerbMath{gathered}
\VerbMath{gather}
\VerbMath{gather*}
\VerbMath{alignat}
\VerbMath{alignat*}
\VerbMath{xalignat}
\VerbMath{xalignat*}
\VerbMath{xxalignat}
\VerbMath{align}
\VerbMath{align*}
\VerbMath{flalign}
\VerbMath{flalign*}
\VerbMath{split}
\VerbMath{multline}
\VerbMath{multline*}
\VerbMath{equation}
\VerbMath{equation*}
\VerbMath{math}
\VerbMath{displaymath}
\VerbMath{eqnarray}
\VerbMath{eqnarray*}
\ConfigureEnv{multline}{}{}{}{}
\ConfigureEnv{multline*}{}{}{}{}
\fixmathjaxsec\left
\fixmathjaxsec\right
\fixmathjaxtoc\int
\fixmathjaxtoc\,
\fixmathjaxtoc\sin
\fixmathjaxtoc\cos
\fixmathjaxtoc\tan
\fixmathjaxtoc\arcsin
\fixmathjaxtoc\arccos
\fixmathjaxtoc\arctan
\fixmathjaxtoc\csc
\fixmathjaxtoc\sec
\fixmathjaxtoc\cot
\fixmathjaxtoc\sinh
\fixmathjaxtoc\cosh
\fixmathjaxtoc\tanh
\fixmathjaxtoc\coth
\fixmathjaxtoc\log
\fixmathjaxtoc\ln
\fixmathjaxtoc\sum

}
\endinput

The important code is this:

\cs_new_protected:Npn \alteqtoks #1
{
  \tl_set:Nx \l_tmpa_tl {\detokenize{#1}}
  % convert \ { to \:{  
  \regex_replace_all:nnN { \x{5C} \x{20} \x{7B} } { \x{5C} \x{3A} \x{7B} } \l_tmpa_tl
  \regex_replace_all:nnN { \x{5C} \x{5C}  \x{3A} \x{7B} } { \x{5C} \x{5C} \x{20} \x{7B} } \l_tmpa_tl
  % delete spaces before left brackets
  \regex_replace_all:nnN { \x{20} \x{7B} } { \x{7B} } \l_tmpa_tl
  % convert \\:{ back to \\ { 
  \regex_replace_all:nnN { \x{5C} \x{5C}  \x{3A} \x{7B} } { \x{5C} \x{5C} \x{20} \x{7B} } \l_tmpa_tl
  % replace < > and & with xml entities
  \regex_replace_all:nnN { \x{26} } { &amp; } \l_tmpa_tl
  \regex_replace_all:nnN { \x{3C} } { &lt; } \l_tmpa_tl
  \regex_replace_all:nnN { \x{3E} } { &gt; } \l_tmpa_tl
  \tl_set:Nx \l_tmpb_tl{ \l_tmpa_tl }
  \HCode{\l_tmpb_tl}
}

This is the result:

enter image description here

| improve this answer | |
7

I find that that the issue you've encountered goes away if I get rid of the specious pairs of curly braces in your code.

Here's a screenshot of the displayed html file obtained by running make4ht main.tex "mathjax". (The tex file is called main.tex. My TeX distribution is MacTeX2020.)

enter image description here

\documentclass{article}
\usepackage{amsmath} 
\begin{document}    
\[
W = \begin{vmatrix}
\sqrt {x} & {x}^{\frac{3}{2}} \\ 
\frac {1}{2}\frac {1}{\sqrt {x}} & \frac {3}{2} \sqrt {x}
\end{vmatrix}
\]          
\end{document}
| improve this answer | |
  • Thanks for finding out the cause. The output is OK in pdf, so I would expect the output to be also OK from tex4ht. the extra {} are automatically generated as this is auto-generated latex from Maple and I would have no way to tell Maple not to do this. – Nasser Jul 30 at 2:06
  • 1
    @Nasser your math is rendered by MathJax, TeX4ht doesn't do anything with it, as it passes it verbatim to the generated HTML. – michal.h21 Jul 30 at 6:53
  • @michal.h21 but in raw HTML I see \\: added, Who added this? mathjax did not yet process the HTML yet. What Am I missing here? any way, based on what you said, I entered a bug against mathjax. But I do not understand why tex4ht added \\: when it is not in latex. – Nasser Jul 30 at 17:16
  • I will wait to accept this answer once I confirm this is mathjax issue and not tex4ht, – Nasser Jul 30 at 17:22
  • 1
    @Nasser ah I see it now. it is bug in TeX4ht, I will post answer with fix – michal.h21 Jul 30 at 18:39

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.