2

I am using tex4ht to convert a LaTeX document to HTML. I would like to know how to obtain a full display of equations either in the eqnarray, align and array environments. The following snippet illustrates my problem.

\documentclass[12pt,a4paper,twoside,english]{book}

\usepackage{amsmath}

\begin{document}

\begin{eqnarray*}
  \displaystyle
  \omega = \sqrt{\displaystyle\frac{\displaystyle k}{\displaystyle m}} 
  & \displaystyle\mbox{ and } 
  & \displaystyle\gamma = \frac{\displaystyle b}{\displaystyle m}
\end{eqnarray*}

\begin{align*}
  \displaystyle
  \omega = \sqrt{\displaystyle\frac{\displaystyle k}{\displaystyle m}} 
  & \displaystyle\mbox{ and } 
  & \displaystyle\gamma = \frac{\displaystyle b}{\displaystyle m}
\end{align*}

\begin{equation*}
  \left\{
  \begin{array}{rcl}
  \displaystyle
  \omega & = & \sqrt{\displaystyle\frac{\displaystyle k}{\displaystyle m}} \\
  \displaystyle
  \gamma & = & \frac{\displaystyle b}{\displaystyle m}
  \end{array}
  \right.
\end{equation*}

\begin{equation*}
  \omega = \sqrt{\frac{k}{m}}
\end{equation*}

\end{document}

If I compile it with pdflatex, the rendering is good. However, with tex4ht (make4ht --utf8 test.tex "mathml,mathjax"), the fractions are squished. The HTML looks like that:

enter image description here

I tried to put as much \displaystyle as I could. Notice that when the equation is in a regular equation environment (fourth line), it looks good. Is there a way to give more space to these fractions in the first three lines?

2
  • 3
    \displaystyle is doing nothing here, both evironments are display by default. Commented Oct 4, 2022 at 14:14
  • 1
    eqnarray is one of an older format tag, please use align as always...
    – MadyYuvi
    Commented Oct 4, 2022 at 14:28

1 Answer 1

1

We need to use the displaystyle="true" attribute to get the correct size of fractions etc. I will fix it in TeX4ht sources. In the meantime, you can use the following configuration file, which uses the original TeX4ht configuration with this attribute added:

\Preamble{xhtml}
\begin{document}
\catcode`\:=11
\makeatletter
\Configure{eqnarray}
   {\HCode{<\a:mathml mtable\Hnewline \a:mathml displaystyle="true" \mml:class="eqnarray\ifx
       \@seqncr\@eqncr\else-star\fi"
       \a:mathml columnalign="right center left" >}}%
   {\HCode{</\a:mathml mtable>}}
   {\HCode{<\a:mathml mtr>}}  {\HCode{</\a:mathml mtr>}}
   {\Tg<\a:mathml mtd\Hnewline \mml:class="eqnarray-\HCol">
      \ifnum \HCol=4
        \Tg<\a:mathml mtext
             \mml:class="eqnarray">\ht:special{t4ht@,&\#x00A0;}%
\PauseMathClass
        \mtexttrue
        \Configure{$}%
  {\EndPauseMathClass \mtextfalse
      \ht:special{t4ht@,}%
\HCode{</\a:mathml mtext><\a:mathml
                                mstyle\Hnewline \mml:class="math">}}%
  {\HCode{</\a:mathml mstyle><\a:mathml
       mtext \a:@mtext>}\ht:special{t4ht@,&\#x00A0;}%
\PauseMathClass
   \mtexttrue}%
  {}%
\Configure{()}%
  {\EndPauseMathClass \mtextfalse
      \ht:special{t4ht@,}%
\HCode{</\a:mathml mtext><\a:mathml
                                mstyle\Hnewline \mml:class="math">}$}%
  {$\HCode{</\a:mathml mstyle><\a:mathml
       mtext \a:@mtext>}\ht:special{t4ht@,&\#x00A0;}%
\PauseMathClass
   \mtexttrue}%
  {}%
%
      \fi}
   {\ifnum \HCol=4 \mtextfalse
      \EndPauseMathClass\ht:special{t4ht@,}%
\Tg</\a:mathml mtext>\fi
      \Tg</\a:mathml mtd>}

\def\:tempc#1#2{%
   \ConfigureEnv{#1}
     {\def\end:al:env{}\ifmmode\else
       \ifvmode\else \def\end:al:env{\par\ShowPar\IgnoreIndent}\fi\fi}
     {\end:al:env }
     {}{}%
   \Configure{#1}
   {\IgnorePar
    \ifvmode \EndP  \else \EndP  \HCode{<!--tex4ht:inline-->}\fi
    \ifmathml
       \Tg<\a:mathml mrow>\def\end:mathalign{\Tg</\a:mathml mrow>}%
    \else
       \Configure{@math}{%\a:mathml
 display="block"
}\DviMath
       \def\end:mathalign{\EndDviMath \DisplayMathfalse}%
       \DisplayMathtrue
    \fi
    \HCode{<\a:mathml mtable\Hnewline
                \a:mathml columnalign="left" \a:mathml displaystyle="true" \mml:class="#2">}}
   {\HCode{</\a:mathml mtable>}\end:mathalign }
   {\HCode{<\a:mathml mtr>}}    {\HCode{</\a:mathml mtr>}}
   {\HCode{<\a:mathml mtd\Hnewline
      \ifodd\HCol \a:mathml  columnalign="right" \fi
%
      \mml:class="align-\ifnum \HCol>\maxfields@ label\else
         \ifodd\HCol\space  odd\else     even\fi
       \fi">}}
   {\HCode{\ifodd\HCol\space\else
       <\a:mathml mspace width="2em"/>\fi
</\a:mathml mtd>}}}
\:tempc{align}{align}
\:tempc{alignat}{alignat}
\:tempc{xalignat}{xalignat}
\:tempc{xxalignat}{xxalignat}
\:tempc{flalign}{flalign}
\:tempc{align*}{align-star}
\:tempc{alignat*}{alignat-star}
\:tempc{xalignat*}{xalignat-star}
\:tempc{flalign*}{flalign-star}

\Configure{halignTB<>}{array}{\HCode{\Hnewline
   \a:mathml equalrows="false"
   \ifx\columnlines\empty\else\a:mathml columnlines="\columnlines" \fi
   \a:mathml equalcolumns="false" \a:mathml class="array" \a:mathml displaystyle="true" }<>\HAlign}


\makeatother
\catcode`\:=12
\EndPreamble

This is the result:

enter image description here

3
  • Great! It works for eqnarray and align. I however noticed that I also have this problem within the array environment in a few equations. Can this configuration be adapted to also cover array? In any case, thank you for your help. Commented Oct 4, 2022 at 16:03
  • 1
    @FrédéricGalliano hopefully yes. can you update your question with an array example, so I have something for testing?
    – michal.h21
    Commented Oct 4, 2022 at 18:06
  • Thank you for the update. Now it looks perfect. Commented Oct 6, 2022 at 9:09

You must log in to answer this question.

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