为什么 make4ht 在这个数学表达式中生成一个额外的:?

为什么 make4ht 在这个数学表达式中生成一个额外的:?

此 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}

当使用编译时make4ht foo3.tex "mathjax" 给出

在此处输入图片描述

原始 HTML 是

<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>

多余的“:”从何而来,如何消除它?

>make4ht --version
make4ht version v0.3e

在 Linux 上使用 TL 2020

仅供参考,上面的代码是由 Maple latex 自动生成的,它似乎会{}自动添加额外的内容,如下所示

示例 1

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

示例 2

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

编译为 PDF 时,这不会产生任何影响。上面的 PDF 输出lualatex foo3.tex正常

在此处输入图片描述

更新

仅供参考,已添加 mathjax 错误报告链接

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

答案1

TeX4ht 将 LaTeX 数学逐字传递到 HTML 文件。问题是它使用的过程会在输出中引入大量不必要的空格。这可能会导致 MathJax 渲染出现问题。为了解决这个问题,它使用了几个正则表达式。其中一个用 替换\ {\:{以修复这个问题。问题是它也\\ {用替换\\:{,这会导致错误的冒号。所以我们需要用另一个正则表达式来捕捉这种情况。

更新内容如下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

重要的代码是这样的:

\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}
}

结果如下:

在此处输入图片描述

答案2

我发现,如果我删除代码中似是而非的花括号,您遇到的问题就会消失。

下面是运行后显示的 html 文件的截图make4ht main.tex "mathjax"。(该 tex 文件名为main.tex。我的 TeX 发行版是 MacTeX2020。)

在此处输入图片描述

\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}

相关内容