转换为 html,将方程式保留为乳胶并使用美元符号

转换为 html,将方程式保留为乳胶并使用美元符号

我可以将 tex 转换为 html,同时将方程式保留为 latex(由 MathJax 呈现),但在一个段落中使用多个美元符号会带来问题。如果一个段落中只有一个美元符号,则使用 \$ 可以很好地用于 pdflatex 和 tex4ht。但如果一个段落中有两个美元符号,它们会“配对”,并且中间的所有文本都会被解释为 MathJax。有办法解决这个问题吗?

特克斯和凯利:

\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}

配置文件:\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

似乎Mathjax将这些美元符号解释为数学分隔符。解决方案是配置tex4ht为以圆括号形式保存内联数学,并禁用美元处理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

重要变化包括:

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

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

这将翻译$a = b^2$\(a = b^2\)

相关内容