tex4ht 在 minipage 中给出多行方程的错误信息

tex4ht 在 minipage 中给出多行方程的错误信息

我尝试在使用 tex4ht 将 LaTex 转换为 html 时生成方程式。如果我将环境放在 minipage 中,则会出现错误。

文件是

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

当我使用命令编译上述文件时,htlatex test.tex myconfig.cfg它给出以下错误消息

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

myconfig.cfg 包含以下代码行

\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

如果我在 minigpage 中输入多行方程式,它会给出相同类型的错误消息

请指导

答案1

问题是\verbatim在命令参数中使用了 (\begin{align}扩展为\verbatim)。我宁愿使用框架数学的自定义环境,它可以在 中进行配置tex4ht

修改后的 TeX 文件:

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

环境mdframed是作为环境的替代来使用的,\fbox并且用于环境minipage的定义中。framedmath

如果您需要mathjax-latex-4ht.sty来自helpers4ht捆:

\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

framedmath环境的重新定义使用\verbatim命令来打印其内容不变。如果您不想使用修改后的配置文件,则可以将此定义与原始配置文件一起使用。

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

结果如下:

在此处输入图片描述

相关内容