# [tex4ht] how to prevent mathjax from processing latex code inside Verbatim in the HTML generated by tex4ht?

Nasser M. Abbasi nma at 12000.org
Fri Jan 10 10:56:30 CET 2014

I hit a big problem and not able to find a solution.

My Latex cheat sheet uses verbatim to illustrate latex
commands and the result of the command.

So I show the actual latex command inside verbatim, and then
outside the verbatim show the result.

This all works well when using tex4ht to generate HTML using
png for math and ofcourse works with pdflatex.

But when I use mathml and load mathjax also, then mathjax
ends up processing all the latex which is inside the verbatim
as well the latex outside !

The Latex inside the Verbatim is meant to remain as is ofcourse
and not to be processed.

I was hoping someone will have a trick to handle this situation.
Here is a MWE.

-----------------------------------
\documentclass{article}
\usepackage{fancyvrb}
\begin{document}

This is an example of Latex command

\begin{Verbatim}
$\sin{\frac{a}{b}}$
\end{Verbatim}

which will display as $\sin{\frac{a}{b}}$ when compiled
\end{document}
---------------------------------

Compiled with

htlatex foo.tex "nma"

where nma.cfg is below.

Now looking at the generated HTML file, and assuming one
is connected to the internet, then mathjax javascript will read
the math inside the HTML, and one can see that the verbatim
was also processed. This makes the whole HTML not useful at all.

So I need a way to protect this verbatim from mathjax hands.

I really do not want to end up writing things like

\begin{Verbatim}
\verb|$\sin{\frac{a}{b}}$|
\end{Verbatim}

Since the pdf file now will show up with \verb in there.

Here is the nma.cfg, it is standard cfg file to load mathjax

---------------
\Preamble{mathml}
\Configure{VERSION}{}
\Configure{DOCTYPE}{\HCode{<!DOCTYPE html>\Hnewline}}
\Configure{HTML}{\HCode{<html>\Hnewline}}{\HCode{\Hnewline</html>}}
(http://www.cse.ohio-state.edu/\string~gurari/TeX4ht/)" />\Hnewline}}
rel="stylesheet" type="text/css"
href="\expandafter\csname aa:CssFile\endcsname" />\Hnewline}}

<script type="text/x-mathjax-config">\Hnewline
MathJax.Hub.Config({\Hnewline
extensions: ["tex2jax.js"],
jax: ["input/TeX", "output/HTML-CSS"],
tex2jax: {
\unexpanded{inlineMath: [ ['$','$'], ["\$$","\$$"] ],}\Hnewline
\unexpanded{displayMath: [ ['$$','$$'], ["\$","\$"] ],}\Hnewline
processEscapes: true
},
"HTML-CSS": { availableFonts: ["TeX"] }
});\Hnewline
</script>
}}

src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"\Hnewline
></script>\Hnewline}}
.MathJax_MathML {text-indent: 0;}\Hnewline
</style>\Hnewline}}

\begin{document}
\EndPreamble
---------------------------

Here is the actual HTML generated:

--------------------------------------
<body >
<!--l. 5--><p class="noindent" >This is an example of Latex command
<div class="fancyvrb" id="fancyvrb1"><a
id="x1-3r1"></a><span
class="cmtt-10">&#x00A0;</span><span
class="cmtt-10">&#x00A0;$\sin{\frac{a}{b}}$</span></div>
<!--l. 9--><p class="noindent" >which will display as <!--l. 9--><math
xmlns="http://www.w3.org/1998/Math/MathML"
display="inline" ><mo
class="MathClass-op">sin</mo><!--nolimits--> <mfrac><mrow
><mi
>a</mi></mrow>
<mrow
><mi
>b</mi></mrow></mfrac>[/itex]
when compiled
</body>
-------------------------------------

I will also post this question at the mathjax stackoverflow site, just
in case this is more of a mathjax issue than tex4ht, as I am not sure.

thank you,
--Nasser