[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.


This is an example of Latex command


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

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


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

   \Configure{DOCTYPE}{\HCode{<!DOCTYPE html>\Hnewline}}
   \Configure{@HEAD}{\HCode{<meta charset="UTF-8" />\Hnewline}}
   \Configure{@HEAD}{\HCode{<meta name="generator" content="TeX4ht
   (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
          extensions: ["tex2jax.js"],
          jax: ["input/TeX", "output/HTML-CSS"],
          tex2jax: {
            \unexpanded{inlineMath: [ ['$','$'], ["\\(","\\)"] ],}\Hnewline
            \unexpanded{displayMath: [ ['$$','$$'], ["\\[","\\]"] ],}\Hnewline
            processEscapes: true
          "HTML-CSS": { availableFonts: ["TeX"] }
   \Configure{@HEAD}{\HCode{<script type="text/javascript"\Hnewline
   \Configure{@HEAD}{\HCode{<style type="text/css">\Hnewline
     .MathJax_MathML {text-indent: 0;}\Hnewline


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
<!--l. 9--><p class="noindent" >which will display as <!--l. 9--><math
display="inline" ><mo
class="MathClass-op">sin</mo><!--nolimits--> <mfrac><mrow
when compiled

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,

More information about the tex4ht mailing list