1

I am trying to produce equations as it is while converting from LaTex to html by using tex4ht. If I place the environments inside of minipage then it is giving error.

File is

\documentclass{article}

\usepackage{amsmath}

\begin{document}

After a time $t$, the ground state $\ket{g}$ and the excited state $\ket{e}$ will each have accumulated a phase that is proportional to their energies:

\medskip
\noindent
\fbox{\begin{minipage}{0.98\textwidth}
\begin{align}
\ket{\psi(0)} \to \ket{\psi(t)} = \frac{e^{-iE_1 t/\hbar}}{\sqrt{2}} \ket{g} + \frac{e^{-iE_2 t/\hbar}}{\sqrt{2}} \ket{e}\, .
\end{align}
\end{minipage}}

We can take out the factor $e^{-iE_1 t/\hbar}$ as a global unobservable phase, and obtain

\begin{align}\label{eq:atomequator}
                \ket{\psi(t)} = \frac{1}{\sqrt{2}} \ket{g} + \frac{e^{-i(E_2 - E_1)t/\hbar}}{\sqrt{2}} \ket{e}\, .
\end{align}

\end{document}

when I compile above file using the command htlatex test.tex myconfig.cfg it gives following error meesage

! Argument of \verbatim@ has an extra }.
<inserted text> 
                \par 
l.13 \end{minipage}}

myconfig.cfg contains following lines of code

\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{ ket: ['{\\left|\#1\\right\\rangle}',1]}
      },
      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}{}
\def\AltlDisplayI#1$${\eqtoks{$$#1$$}%
  \HCode{\the\eqtoks}$$}           
\Configure{$$}{}{}{\expandafter\AltlDisplayI}  
\begin{document} 
\newcommand\VerbMath[1]{%
\renewenvironment{#1}{%
%\ifvmode \IgnorePar\fi \EndP
\NoFonts%
\char`\\begin\{#1\}%
\verbatim}{\endverbatim\string\end\{#1\}\EndNoFonts}%
}

\VerbMath{equation*}
\VerbMath{align}
% add all used math environments here with \VerbMath
\EndPreamble

If I enter multiline equations inside of minigpage then it is giving same type of error messages

Please guide

1 Answer 1

1

The problem is that \verbatim is used inside command argument (\begin{align} is expanded to \verbatim). I would instead use custom environment for framed math, which can be configured in tex4ht.

The modified TeX file:

\documentclass{article}

\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{braket}
\usepackage{mdframed}
\newenvironment{framedmath}{\mdframed}{\endmdframed}

\begin{document}

After a time $t$, the ground state $\ket{g}$ and the excited state $\ket{e}$ will each have accumulated a phase that is proportional to their energies:

\medskip

\noindent
\begin{framedmath}
\begin{align}
  \ket{\psi(0)} \to \ket{\psi(t)} = \frac{{e}^{{-iE}_{1} t/\hbar}}{\sqrt{2}} \ket{g} + \frac{e^{-iE_2 t/\hbar}}{\sqrt{2}} \ket{e}\, .
\end{align}
\end{framedmath}


We can take out the factor $e^{-iE_1 t/\hbar}$ as a global unobservable phase, and obtain

\begin{align}\label{eq:atomequator}
                \ket{\psi(t)} = \frac{1}{\sqrt{2}} \ket{g} + \frac{e^{-i(E_2 - E_1)t/\hbar}}{\sqrt{2}} \ket{e}\, .
\end{align}

\end{document}

The mdframed environment is used as alternative to \fbox and minipage in the definition of framedmath environment.

The configuration file can be simplified if you require the mathjax-latex-4ht.sty from the helpers4ht bundle:

\RequirePackage{mathjax-latex-4ht}
\Preamble{xhtml,html5}
\Configure{@HEAD}{\HCode{
<script type="text/x-mathjax-config">                                           
  MathJax.Hub.Config({
    TeX: {           
      Macros: {     
        \unexpanded{ ket: ['{\\left|\#1\\right\\rangle}',1]}
      },
      equationNumbers: { autoNumber: "AMS" }         
    }             
  });                  
</script>   
}}
\begin{document}
\renewenvironment{framedmath}{\ifvmode\IgnorePar\fi\EndP\NoFonts\HCode{<div class="fbox">}\verbatim}{\endverbatim\HCode{</div>}\EndNoFonts\par}
\EndPreamble

The redefinition of framedmath environment uses the \verbatim command to print it's content unchanged. You can use just this definition with your original config file if you don't want to use the modified config file.

\renewenvironment{framedmath}{\ifvmode\IgnorePar\fi\EndP\NoFonts\HCode{<div class="fbox">}\verbatim}{\endverbatim\HCode{</div>}\EndNoFonts\par}

This is the result:

enter image description here

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.