Here is a very simple mwe that does not render on any machines without giving an extra \protect. Without the % sign after the \begin{equation} this renders fine for both pdf (using lualatex) and make4ht. With the % sign, an extraneous \protect shows up. This happens with an extra \label{} inside, or just this % sign (which I discovered in debugging the \label problem).
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}
This is compiled using:
make4ht -c config.cfg mwe.tex
and this config.cfg:
\Preamble{xhtml,mathjax}
\def\ce#1{\texttt{\detokenize{\(\ce{#1}\)}}}
\begin{document}
\EndPreamble
The generated HTML is:
<!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>
With the random \protect showing up:
I have tried this on multiple computers with brand new installations of MacTeX.
\ce
uses in the paragraph placed in inline math mode (i.e., surrounded by\(
and\)
) and simply typesetting usingmake4ht mytestfile.tex "mathjax"
.