1

I would like to convert all the inline-math and display-math should be LaTeX format only and not for image. I had referred tex4ht leaving equations unchanged and tex4ht leaving equations unchanged - including \[...\] and \(...\). But author defined macros are not converted to HTML.

LaTeX MWO:

\documentclass{article}
\usepackage{amsmath,amssymb}
\newcommand{\La}{\Lambda}
\def\B{\beta}
\newcommand{\twosilt}{\mbox{\rm 2-silt}}
\begin{document}
In this section, we $\B$ recall some definitions and results. 
Throughout $\alpha+\B$ this section, let ${\La}$ be a finite dimensional algebra. 
\begin{equation*}
\Phi:\Lambda\longrightarrow\twosilt\Lambda,\ \ \ (X,P)\mapsto \Phi(X,P):=P_X\oplus P[1].
\end{equation*}
\end{document}

How do achieve this?

1 Answer 1

4

I am not really sure, what you are looking for, purpose of questions and answers you linked to is exactly not to convert macros to html, to be processed with some tool like mathjax. Try this configuration file, with definitions of your macros for mathjax:

\usepackage{verbatim}
\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*}
\EndPreamble

I combined definitions from "leave equations unchanged", added definitions of your macros for mathjax and created new command, \VerbMath. You need to use this command for every math environment, like equation* in your case. It will leave also math environments unchanged. Name this file myconfig.cfg.

I also slightly edited your sample file:

\documentclass{article}
\usepackage[T1]{fontenc}

\usepackage{amsmath,amssymb}
\newcommand{\La}{\Lambda}
\def\B{\beta}
\newcommand{\twosilt}{\mbox{\rm 2-silt}}
\begin{document}
In this section, we $\B$ recall some definitions and results. 
Throughout $\alpha+\B$ this section, let ${\La}$ be a finite dimensional algebra. 

\begin{equation*}
\Phi:\Lambda\longrightarrow\twosilt\Lambda,\; (X,P)\mapsto \Phi(X,P):=P_X\oplus P[1].
\end{equation*}

\end{document}

I added fontenc package in order to correctly convert all characters and replaced \ \ \ in your equation with \;. I suppose that you wanted bigger space, but \ seems to be not supported by mathjax.

Now you can compile your file with:

htlatex mwo myconfig

you can see the result here

11
  • Thanks for your help and i have many author defined macros and would like how to do in automatically conversion way instead of manual add in MathJax?
    – Balaji
    Commented Mar 13, 2014 at 5:12
  • it would be more difficult, you would need to redefine every macro you use to print its name. adding your macros to mathjax seems much easier. but I would suggest you to switch to mathml with mathjax: you would get best performance.
    – michal.h21
    Commented Mar 13, 2014 at 13:34
  • Equations is can convert to image and any possible all the inline and display equations should convert to alt attribute?
    – Balaji
    Commented Mar 21, 2014 at 6:45
  • The config file here sufffers some of the same typos as mentioned here in the comments, in case michal hasn't updated this answer. (And I'm waiting to see if michal agrees.) Additionally, this one has \AltlMathiI instead of \AltlMathI. Commented Oct 5, 2014 at 2:38
  • @alex.jordan yes, the errors are same, as I just copied the same file between different answers
    – michal.h21
    Commented Oct 5, 2014 at 8:57

This site is temporarily in read-only mode and not accepting new answers.

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