1

I have maintaining display equations as it is. But the equation cross-link is not converting. How do achive this? My Sample LaTeX file is:

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{equation}\label{eq1}
\alpha + \beta = \gamma
\end{equation}
This is the equation cross ref link Eq.~\ref{eq1}
\end{document}

My CFG is:

\usepackage{verbatim}
\usepackage[T1]{fontenc}
\Preamble{xhtml}
% Configure for mathjax
\Configure{VERSION}{}
\Configure{DOCTYPE}{\HCode{<!DOCTYPE html>\Hnewline}}
\Configure{HTML}{\HCode{<html>\Hnewline}}{\HCode{\Hnewline</html>}}
\Configure{@HEAD}{\HCode{
<script type="text/x-mathjax-config">                                           
  MathJax.Hub.Config({
    TeX: {           
      Macros: {     
        \unexpanded{La : "\\Lambda",
        B: "\\beta", 
        twosilt: "\\textrm{2-silt}",}
      }        
    },        
    extensions: ["tex2jax.js"], 
    tex2jax: {       
        \unexpanded{
      inlineMath: [ ['\$','\$'], ["\\\\(","\\\\)"] ],
      displayMath: [ ['$$','$$'], ["\\[","\\]"] ],}
      processEscapes: true
    }                   
  });                  
</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}}

\newtoks\eqtoks 
\def\AltMath#1${\eqtoks{$#1$}% 
   \HCode{\the\eqtoks}$}
\Configure{$}{}{}{\expandafter\AltMath}  
\def\AltlMathI#1\){\eqtoks{\(#1\)}% 
        \HCode{\the\eqtoks}}
\Configure{()}{\AltlMathI}{}
\def\AltlDisplay#1\]{\eqtoks{\[#1\]}%
        \HCode{\the\eqtoks}}
\Configure{[]}{\AltlDisplay}{}
\begin{document} 
\newcommand\VerbMath[1]{%
\renewenvironment{#1}{%
\NoFonts%
\string\begin\{#1\}%
\verbatim}{\endverbatim\string\end\{#1\}\EndNoFonts}%
}
\VerbMath{equation}
\VerbMath{cases}
\VerbMath{array}
\VerbMath{matrix}
\VerbMath{pmatrix}
\VerbMath{eqnarray}
\VerbMath{eqnarray*}
\EndPreamble
Balaji
  • 2,282

1 Answers1

3

You need to use mathjax also for process \ref commands pointing to equations (not for ones pointing to sections or figures, which are still handled by LaTeX). As everything in math is handled by mathjax, a easiest solution is to use $\ref{label}$:

This is the equation cross ref link Eq.~$\ref{eq1}$

The second problem is that equation is unnumbered by default, so you can't get the reference number:

enter image description here

this can be solved with following code inserted in TeX section in mathjax configuration:

equationNumbers: { autoNumber: "AMS" } 

full config file with updated mathjax configuration:

\usepackage{verbatim}
\usepackage[T1]{fontenc}
\Preamble{xhtml}
% Configure for mathjax
\Configure{VERSION}{}
\Configure{DOCTYPE}{\HCode{<!DOCTYPE html>\Hnewline}}
\Configure{HTML}{\HCode{<html>\Hnewline}}{\HCode{\Hnewline</html>}}
\Configure{@HEAD}{\HCode{
<script type="text/x-mathjax-config">                                           
  MathJax.Hub.Config({
    TeX: {           
      Macros: {     
        \unexpanded{La : "\\Lambda",
        B: "\\beta", 
        twosilt: "\\textrm{2-silt}",}
      },
      equationNumbers: { autoNumber: "AMS" } 
    },        
    extensions: ["tex2jax.js"], 
    tex2jax: {       
        \unexpanded{
      inlineMath: [ ['\$','\$'], ["\\\\(","\\\\)"] ],
      displayMath: [ ['$$','$$'], ["\\[","\\]"] ],}
      processEscapes: true
    }                   
  });                  
</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}}

\newtoks\eqtoks 
\def\AltMath#1${\eqtoks{$#1$}% 
   \HCode{\the\eqtoks}$}
\Configure{$}{}{}{\expandafter\AltMath}  
\def\AltlMathI#1\){\eqtoks{\(#1\)}% 
        \HCode{\the\eqtoks}}
\Configure{()}{\AltlMathI}{}
\def\AltlDisplay#1\]{\eqtoks{\[#1\]}%
        \HCode{\the\eqtoks}}
\Configure{[]}{\AltlDisplay}{}
\begin{document} 
\newcommand\VerbMath[1]{%
\renewenvironment{#1}{%
\NoFonts%
\string\begin\{#1\}%
\verbatim}{\endverbatim\string\end\{#1\}\EndNoFonts}%
}
\VerbMath{equation}
\VerbMath{cases}
\VerbMath{array}
\VerbMath{matrix}
\VerbMath{pmatrix}
\VerbMath{eqnarray}
\VerbMath{eqnarray*}
\EndPreamble

the result is now much better:

enter image description here

michal.h21
  • 50,697
  • I have added equationNumbers: { autoNumber: "AMS" } in my .cfg file and still getting ??. How do solve this. And also tried $\ref{label}$ but result is same (??). – Balaji Aug 14 '15 at 11:01
  • @Balaji I've added full config file – michal.h21 Aug 14 '15 at 11:16
  • Now it's working fine. But i would like to get Eq 1 result in the HTML file instead of 1$\ref{eq1}$. In Figure cross-linkhtlatex` is converting. But in the Equation only is not converting. – Balaji Aug 14 '15 at 11:25
  • @Balaji equation numbers are added by mathjax, it is not possible to get them from LaTeX. – michal.h21 Aug 14 '15 at 11:29
  • But when i have converting all the equaions to MathML citation equations numbers (like \ref{eq1}) it's generating auto number. This concept is not possible in LaTeX Equations? Please check and advise. – Balaji Nov 20 '15 at 09:56