Great solution Michal!
It worked very well.
thank you,
--Nasser
On 1/10/2014 6:30 AM, Michal Hoftich wrote:
Hello Nasser,
mathjax can be configured to ignore certain classes, so you only have
to figure out what classes does have elements generated by Verbatim,
verbatim, etc. In your example it is `fancyvrb`.
Just add `ignoreClass: "fancyvrb|verbatim",` to `tex2jax` section of
mathjax config. This will ignore `fancyvrb` and `verbatim` classes.
Complete config file:
\Preamble{mathml}
\Configure{VERSION}{}
\Configure{DOCTYPE}{\HCode{<!DOCTYPE html>\Hnewline}}
\Configure{HTML}{\HCode{<html>\Hnewline}}{\HCode{\Hnewline</html>}}
\Configure{@HEAD}{}
\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}}
\Configure{@HEAD}{\HCode{<link
rel="stylesheet" type="text/css"
href="\expandafter\csname aa:CssFile\endcsname" />\Hnewline}}
\Configure{@HEAD}{\HCode{%
<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
ignoreClass: "fancyvrb|verbatim",\Hnewline
processEscapes: true
},
"HTML-CSS": { availableFonts: ["TeX"] }
});\Hnewline
</script>
}}
\Configure{@HEAD}{\HCode{<script type="text/javascript"\Hnewline
src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"\Hnewline
></script>\Hnewline}}
\Configure{@HEAD}{\HCode{<style type="text/css">\Hnewline
.MathJax_MathML {text-indent: 0;}\Hnewline
</style>\Hnewline}}
\begin{document}
\EndPreamble
Regards,
Michal
2014/1/10 Nasser M. Abbasi <[email protected]>:
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>}}
\Configure{@HEAD}{}
\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}}
\Configure{@HEAD}{\HCode{<link
rel="stylesheet" type="text/css"
href="\expandafter\csname aa:CssFile\endcsname" />\Hnewline}}
\Configure{@HEAD}{\HCode{%
<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>
}}
\Configure{@HEAD}{\HCode{<script
type="text/javascript"\Hnewline
src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"\Hnewline
></script>\Hnewline}}
\Configure{@HEAD}{\HCode{<style type="text/css">\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"> </span><span
class="cmtt-10"> $\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></math>
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