Make4ht: \ce を含む式内のものは、mathjax にレンダリングされ、追加の \protect が追加されます

Make4ht: \ce を含む式内のものは、mathjax にレンダリングされ、追加の \protect が追加されます

これは、追加の \protect を与えないとどのマシンでもレンダリングされない非常に単純な mwe です。\begin{equation} の後の % 記号がなければ、pdf (lualatex を使用) と make4ht の両方で正常にレンダリングされます。% 記号があると、余分な \protect が表示されます。これは、内部に余分な \label{} がある場合、またはこの % 記号だけがある場合に発生します (これは、\label の問題のデバッグ中に発見しました)。

mwe.tex:

\documentclass{book} 
\usepackage[english]{babel}
\usepackage[version=4]{mhchem}
\begin{document}

Text with formula \ce{CuCl2} and \ce{Cu^{2+}}.


\begin{equation}%
        \frac{\ce{H2O}}{xyz} = 4
\end{equation}

\end{document}

これは以下を使用してコンパイルされます:

make4ht -c config.cfg mwe.tex

そしてこのconfig.cfg:

\Preamble{xhtml,mathjax}
\def\ce#1{\texttt{\detokenize{\(\ce{#1}\)}}}
\begin{document}
\EndPreamble

生成された HTML は次のとおりです。


<!DOCTYPE html> 
<html lang='en' xml:lang='en'> 
<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 href='mwe.css' rel='stylesheet' type='text/css' /> 
<meta content='mwe.tex' name='src' /> 
<script>window.MathJax = { tex: { tags: "ams", }, }; </script> 
 <script async='async' id='MathJax-script' src='https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml-full.js' type='text/javascript'></script>  
</head><body>
<!-- l. 6 --><p class='noindent'>Text with formula <span class='cmtt-10'>\(\ce {CuCl2}\) </span>and <span class='cmtt-10'>\(\ce {Cu^{2+}}\)</span>.
</p><!-- l. 11 --><p class='indent'>   \begin {equation} \protect \frac  {\ce {H2O}}{xyz} = 4  \end {equation}
</p>
    
</body> 
</html>

ランダムな \protect が表示されます:

上記の HTML のスクリーンショット。

私は、MacTeX を新規にインストールした複数のコンピューターでこれを試しました。

関連情報