Make4ht:方程式內的任何內容與 \ce 渲染到 mathjax 都會增加額外的 \protect

Make4ht:方程式內的任何內容與 \ce 渲染到 mathjax 都會增加額外的 \protect

這是一個非常簡單的 mwe,如果不提供額外的 \protect 則不會在任何機器上渲染。如果 \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 的電腦上嘗試過此操作。

相關內容