1

I can convert tex to html keeping equations as latex (to be rendered by MathJax) but using multiple dollar signs in a paragraph poses a problem. If there's only one dollar sign in a paragraph, using \$ works fine for pdflatex and tex4ht. But if there are two dollar signs in a paragraph, they get "paired up" and all text in between gets interpreted as MathJax. Is there a way around this?

Tex mwe:

\documentclass{article}

\usepackage[]{amsmath,amsthm}
\usepackage[T1]{fontenc}

\begin{document}

One price in a paragraph works fine: \$30. 

But if I need to use two prices in a paragraph, the dollar signs get ``paired up'' and rendered as mathjax: \$20 to \$30.

\end{document}

Config file: \usepackage{verbatim} \Preamble{html}

\Configure{VERSION}{}
\Configure{DOCTYPE}{\HCode{<!DOCTYPE html>\Hnewline}}
\Configure{HTML}{\HCode{<html>\Hnewline}}{\HCode{\Hnewline</html>}}
%\Configure{@HEAD}{\HCode{<link href="basic.css" rel="stylesheet" type="text/css" />\Hnewline}} 
\Configure{@HEAD}{\HCode{
  <script type="text/x-mathjax-config">                                           
  MathJax.Hub.Config({
    TeX: {           
      extensions: ["color.js"], 
      equationNumbers: { autoNumber: "AMS" }         
    },        
    extensions: ["tex2jax.js"], 
    tex2jax: {       
      \unexpanded{
      inlineMath: [ ['\$','\$'], ["\\\(","\\\)"] ],
      displayMath: [ ['$$','$$'], ["\\[","\\]"] ],}
      processEscapes: true,
      processEnvironments: true
    }                   
  });                  
  </script>\Hnewline
}}
\Configure{@HEAD}{\HCode{ <script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script> \Hnewline}}

\newtoks\eqtoks
\def\AltMathOne#1${\HCode{\detokenize{$#1$}}$}
%\def\AltMathOne#1${\eqtoks{$#1$}% 
%\HCode{\the\eqtoks}$}
\Configure{$}{}{}{\expandafter\AltMathOne} 
\def\AltlMath#1\){\HCode{\detokenize{\(#1\)}}\)}
%\def\AltlMath#1\){\eqtoks{\(#1\)}% 
%\HCode{\the\eqtoks}}
\Configure{()}{\AltlMath}{}
\def\AltlDisplay#1\]{\HCode{\detokenize{\[#1\]}}\]}
%\def\AltlDisplay#1\]{\eqtoks{\[#1\]}%
%\HCode{\the\eqtoks}}
\Configure{[]}{\AltlDisplay}{}

\begin{document}

\newcommand\VerbMath[1]{%
  \renewenvironment{#1}{%
%\ifvmode \IgnorePar\fi \EndP
    \NoFonts%
    \string\begin\{#1\}%
  \verbatim}{\endverbatim\string\end\{#1\}\EndNoFonts}%
}

\VerbMath{align}
\VerbMath{equation}
\VerbMath{equation*}

\EndPreamble

1 Answer 1

4

It seems that Mathjax interprets these dollar signs as math delimiters. Solution is to configure tex4ht to save inline math in rounded bracket form and to disable dollar processing in mathjax:

\Preamble{xhtml,mathml}
\Configure{VERSION}{}
\Configure{DOCTYPE}{\HCode{<!DOCTYPE html>\Hnewline}}
\Configure{HTML}{\HCode{<html>\Hnewline}}{\HCode{\Hnewline</html>}}
%\Configure{@HEAD}{\HCode{<link href="basic.css" rel="stylesheet" type="text/css" />\Hnewline}} 
\Configure{@HEAD}{\HCode{
  <script type="text/x-mathjax-config">                                           
  MathJax.Hub.Config({
    TeX: {           
      extensions: ["color.js"], 
      equationNumbers: { autoNumber: "AMS" }         
    },        
    extensions: ["tex2jax.js"], 
    tex2jax: {       
      \unexpanded{
      inlineMath: [ ["\\\(","\\\)"] ],
      displayMath: [ ['$$','$$'], ["\\[","\\]"] ],}
      processEscapes: true,
      processEnvironments: true
    }                   
  });                  
  </script>\Hnewline
}}
\Configure{@HEAD}{\HCode{ <script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script> \Hnewline}}

\newtoks\eqtoks
\def\AltMathOne#1${\HCode{\detokenize{\(#1\)}}$}
%\def\AltMathOne#1${\eqtoks{$#1$}% 
%\HCode{\the\eqtoks}$}
\Configure{$}{}{}{\expandafter\AltMathOne} 
\def\AltlMath#1\){\HCode{\detokenize{\(#1\)}}\)}
%\def\AltlMath#1\){\eqtoks{\(#1\)}% 
%\HCode{\the\eqtoks}}
\Configure{()}{\AltlMath}{}
\def\AltlDisplay#1\]{\HCode{\detokenize{\[#1\]}}\]}
%\def\AltlDisplay#1\]{\eqtoks{\[#1\]}%
%\HCode{\the\eqtoks}}
\Configure{[]}{\AltlDisplay}{}

\begin{document}

\newcommand\VerbMath[1]{%
  \renewenvironment{#1}{%
%\ifvmode \IgnorePar\fi \EndP
    \NoFonts%
    \string\begin\{#1\}%
  \verbatim}{\endverbatim\string\end\{#1\}\EndNoFonts}%
}

\VerbMath{align}
\VerbMath{equation}
\VerbMath{equation*}

\EndPreamble

Important changes are:

inlineMath: [ ["\\\(","\\\)"] ],

and

\def\AltMathOne#1${\HCode{\detokenize{\(#1\)}}$}

this will translate $a = b^2$ as \(a = b^2\)

1
  • Your help has been invaluable.
    – user59959
    Jan 14, 2016 at 19:49

You must log in to answer this question.

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