1

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:

Screenshot of the above described html.

I have tried this on multiple computers with brand new installations of MacTeX.

6
  • I'm having no problem if the first two \ce uses in the paragraph placed in inline math mode (i.e., surrounded by \( and \)) and simply typesetting using make4ht mytestfile.tex "mathjax". Commented Oct 11, 2022 at 20:14
  • I think there must be some wrong files in MacTeX, which is strange, as I believe that it is based on TeX Live. In this gist, there are two files that carry the MathJax configuration directly from TeX4ht sources. I hope they will fix this issue for you, as I cannot reproduce it on my system: gist.github.com/michal-h21/48cb1f8027ece60444e26f270512403a
    – michal.h21
    Commented Oct 11, 2022 at 20:54
  • @michal.h21 - thank you for all your help. The file you linked didn't fix it, but I used the docker container for Overleaf and it worked fine. I have no idea what is all wrong with MacTeX that this happens. Commented Oct 20, 2022 at 1:11
  • @JustinShorb that's really strange, as I always thought that MacTeX is just a variant of TeX Live. I knew that there are issues with MikTeX, but not with MaxTeX.
    – michal.h21
    Commented Oct 20, 2022 at 7:45
  • @michal.h21 - Sorry to pop back into this thread but I thought it might be the easiest way to give you context and keep the answer where it might be helpful to others who stumble across this. Have you heard or seen whether the newest MacTeX update in March 2023 fixed this? Or if it was even known/reported? I didn't - and am thinking I should have. The documentation doesn't mention anything. Commented May 30, 2023 at 18:26

0

You must log in to answer this question.

Browse other questions tagged .