1

I want to convert the following (minimized) TeX file to HTML:

\documentclass{article}
\begin{document}
We have $a = a$, \(a = a\) and also
\[c = c\] and even
\begin{equation*}
  E = mc^2.
\end{equation*}
All seems to work, except for
$$F = ma.$$
\end{document}

My config file is

\RequirePackage{amsmath,amsfonts,amssymb,amsthm,enumitem,booktabs,float,graphicx,hyperref}

\Preamble{xhtml}

\Configure{MathJaxConfig}{{
tex: {
      tags: "ams",
      \detokenize{%
      inlineMath: [ [’$’,’$’], ["\\\(","\\\)"] ],
      displayMath: [ [’$$’,’$$’], ["\\[","\\]"] ],}
      processEscapes: true,
      processEnvironments: true,
      packages: [’base’, ’color’, ’ams’, ’boldsymbol’, ’newcommand’, ’verb’]
  }
}}
\Configure{MathjaxSource}{https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml-full.js}


\def\eqref#1{$\mathrm{(\ref{#1})}$}

\begin{document}

\EndPreamble

and the command I run is

make4ht -c /CONF/sample.cfg markup.tex "mathjax"

Unfortunately, this produces images for every formula that is wrapped between two dollar signs $$. How can I fix this? I have tried to mimic the solutions to this and this answers by Michal by detokenizing everything between two dollar signs but it did not work.

Also, I do not want to use MathML as it does not parse my formulas as good as TeX-to-MathJax.

7
  • 1
    someone may provide a make4ht config, but the input latex files should not have $$ which is not supported latex syntax. Oct 10, 2022 at 18:51
  • I don't quite understand what you mean by that. Are you saying make4ht cannot deal with $$?
    – qarabala
    Oct 10, 2022 at 18:56
  • See tex.stackexchange.com/q/503/107497
    – Teepeemm
    Oct 10, 2022 at 19:02
  • No I am saying $$ is not latex, if make4ht supports it that is because it is supporting some non-latex primitive tex constructs. Oct 10, 2022 at 19:02
  • 2
    as @DG' said, if you have up-to-date TeX Live installation, your code should work (except for the error message caused by equation* not defined, you need to use amsmath). I've added code to support $$ few weeks ago.
    – michal.h21
    Oct 10, 2022 at 19:59

1 Answer 1

3

It should work with the up-to-date TeX Live distribution, but you can add the support also using the following configuration file:

\Preamble{xhtml}
\catcode`\:=11
\Configure{$$}{\:HandleMathjaxCatcodes}{\:RestoreMathjaxCatcodes}{\expandafter\AltlDisplayDollars}
\long\def\AltlDisplayDollars#1$${\alteqtoks{\[#1\]}$$}
\catcode`\:=12
\begin{document}
\EndPreamble

It converts $$ in your source to \[ in the output, so you don't even need to provide any configuration to MathJax. This is the resulting HTML code:

<!-- l. 4 --><p class='noindent'>We have \(a = a\), \(a = a\) and also \[c = c\] and even \begin {equation*}  E = mc^2.  \end {equation*} All seems to work, except for
                                 \[F = ma.\]
</p>

enter image description here

1
  • I confirm that the problem was caused by the old version of texlive. As always, thanks a lot michal!
    – qarabala
    Oct 11, 2022 at 15:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .