1

I want to retain the equations unchanged (for later usage), i tried with the help of Tex4ht leaving equations unchanged, it is working for inline equations, I need to retain for display equations such as like $$...$$, \begin{equation}/\begin{align}.... how to configure these environment to unchanged.

my MWE is

\documentclass{book}
\usepackage{amsmath}
\begin{document}
  text $a+b$ and \(a+b\alpha\beta\)
  $$a+b$$
  Sample text
  \begin{equation}
  \alpha+\beta
  \end{equation}
  Sample text
  \begin{align}
   &&\alpha+\beta\\
   &&\gamma+\delta
  \end{align}
 Sample text
\end{document}

and my cfg file is

\Preamble{html}
\newtoks\eqtoks

\def\AltMath#1${\eqtoks{$#1$}% 
\HCode{\the\eqtoks}$}
\Configure{$}{}{}{\expandafter\AltMath}  

\def\AltlMath#1\){\eqtoks{\(#1\)}% 
        \HCode{\the\eqtoks}}
    \Configure{()}{\AltlMath}{}

\def\AltlDisplay#1\]{\eqtoks{\[#1\]}%
        \HCode{\the\eqtoks}}
    \Configure{[]}{\AltlDisplay}{}

\begin{document}
\EndPreamble

I compiled through the calling command htlatex filename "sample.cfg"

Note: When I am using the option xhtml in the htlatex filename "xhtml,sample.cfg" the equations are changed to htmlcoding, without using html/xhtml option the equations are unchanged. Why equations are changing to html code when i am using the option xhtml?

1

The following code is based on MathJax support package from the Helpers4ht bundle:

\RequirePackage{verbatim,etoolbox}

\Preamble{xhtml}
\def\AltMathOne#1${\HCode{\detokenize{\(#1\)}}$}
\Configure{$}{}{}{\expandafter\AltMathOne} 
\def\AltlMath#1\){\HCode{\detokenize{\(#1\)}}\)}
\Configure{()}{\AltlMath}{}
\def\AltlDisplay#1\]{\HCode{\detokenize{\[#1\]}}\]}
\Configure{[]}{\AltlDisplay}{}
\def\AltDisplayOne#1#2$${#1\HCode{\detokenize{$$#2$$}}$$}
\Configure{$$}{}{}{\AltDisplayOne}{}{}
\newcommand\VerbMath[1]{%
\ifcsdef{#1}{%
  \renewenvironment{#1}{%
    \NoFonts%
  \Configure{verbatim}{}{} % suppress <br /> tags
    \texttt{\string\begin\{#1\}}\HCode{\Hnewline}% we need to use \texttt to get all characters right
      \verbatim}{\endverbatim\texttt{\string\end\{#1\}}\EndNoFonts}%
}{}%
}
\VerbMath{align}
\VerbMath{equation}
\VerbMath{equation*}

\begin{document}

\EndPreamble

\detokenize is used for verbatim output of the basic math commands instead of \toks register. It seems to be easier to handle.

For math environments, \VerbMath command is introduced. It redefines the environment to print it's content in verbatim and to print \begin{env name} ... \end{...} around it. It uses verbatim package for that.

This is the result from your code:

<!--l. 4--><p class="noindent" >text \(a+b\) and \(a+b\alpha \beta \)
                                 $$a+b$$
 Sample text  \begin{equation} 

\alpha+\beta
\end{equation}
Sample text  \begin{align} 

&#x0026;&#x0026;\alpha+\beta\\
&#x0026;&#x0026;\gamma+\delta
\end{align}
Sample text </p> 
  • when i am using the option xhtml in the calling command the equations are converting to HTML format, how to retain this in the xhtml option – vctu Mar 25 '17 at 4:05
  • & alignment characters are changed to unicode characters in your output, but in my output it is changed to &amp; this will give wrong output – vctu Mar 25 '17 at 4:36
  • @VenkatesanRamachandiran I use make4ht with -u option, it requests Unicode output. @amp; is correct, isn't it? You can't have & character in a xml file. What do you mean by HTML format? – michal.h21 Mar 25 '17 at 9:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.