michal-h21 / make4ht

Build system for tex4ht
131 stars 15 forks source link

'mathml'-option produces large division sign #101

Closed yalguzaq closed 12 months ago

yalguzaq commented 1 year ago

LaTeX:

\begin{gather*}
  \left|y_n-x_n\right| = \left[\left|y_n-x_n\right|^2\right]^{1/2} \leq \left[\sum_{i=1}^\infty (y_i-x_i)^2\right]^{1/2} < e/2 \,.
\end{gather*}

Compilation command: make4ht markup.tex 'mathml,mathjax'

Correct output: image

Erroneous output: image

Problem summary: Division sign is too big when other large objects appear in the equation.

michal-h21 commented 1 year ago

It seems that math table requires it's contents to be displayed in the inline style, it needs explicit displaystyle="true" parameter to prevent it.

Try this configuration file:

\Preamble{xhtml}

\catcode`\:=11
\Configure{gather*}
   {\HCode{<\a:mathml mtable\Hnewline \a:mathml displaystyle="true" \mml:class="gather-star">}}
   {\HCode{</\a:mathml mtable>}}
   {\HCode{<\a:mathml mtr>}}    {\HCode{</\a:mathml mtr>}}
   {\HCode{\Hnewline<\a:mathml mtd>}}   {\HCode{</\a:mathml mtd>}}
\catcode`\:=12
\begin{document}
\EndPreamble
yalguzaq commented 1 year ago

Did not work, strange. Did it work on your machine? I ran it with

make4ht -c $HOME/conf.cfg markup.tex 'mathml,mathjax'

Here is my configuration file:

\Preamble{xhtml,mathml,mathjax}

% Table fix last row (in the meantime)
\Css{.hline + .vspace:last-child{display:none;}}
\Css{.hline:first-child, .array-hline:first-child{border-bottom:1px solid black;border-top:none;}}

% \includegraphics relative width (will be included as an option in compile command)
\makeatletter
\ExplSyntaxOn
\Configure{Gin-dim}{style="width:\fp_eval:n{round(\Gin@req@width/\textwidth*100,2)}\char_generate:nn { `\% } { 12 }"}
\ExplSyntaxOff
\makeatother

% \implies, \impliedby, \iff (in the meantime)
\MathSymbol\mathrel{Longleftarrow}
\Configure{Longrightarrow}        {\expandafter\csname x:unicode\endcsname{27F9}}
\Configure{Longleftarrow}         {\expandafter\csname x:unicode\endcsname{27F8}}

%% \boxed command (in the meantime)
\catcode`\:=11
\Configure{boxed}
   {\ifmathml \Tg<\a:mathml menclose \a:mathml notation="box">\Tg<\a:mathml mrow>%
    \else     \HCode{<span class="boxed">}\IgnorePar\fi}
   {\ifmathml \Tg</\a:mathml mrow>\Tg</\a:mathml menclose>%
    \else \HCode{</span>}\fi}
\catcode`\:=12

%% Font: \mathcal characters
\catcode`\:=11
\renewcommand\mathcal[1]{\bgroup\HCode{<\a:mathml mi\Hnewline  data-mjx-variant="-tex-calligraphic" mathvariant="script">}#1\HCode{</\a:mathml mi>}\egroup}
\catcode`\:=12

%% Font change: {\bf E} (in the meantime)
\catcode`\:=11
\makeatletter
\def\:closemi{\HCode{</\a:mathml mi>}\EndPauseMathClass}
\def\bf{\ifmmode\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi{\PauseMathClass\HCode{<\a:mathml mi mathvariant="bold">}\aftergroup\:closemi}{\bfseries}}
\makeatother
\catcode`\:=12

%% Long division sign
\catcode`\:=11
\Configure{gather*}
   {\HCode{<\a:mathml mtable\Hnewline \a:mathml displaystyle="true" \mml:class="gather-star">}}
   {\HCode{</\a:mathml mtable>}}
   {\HCode{<\a:mathml mtr>}}    {\HCode{</\a:mathml mtr>}}
   {\HCode{\Hnewline<\a:mathml mtd>}}   {\HCode{</\a:mathml mtd>}}
\catcode`\:=12

\begin{document}
\EndPreamble
michal-h21 commented 1 year ago

You are right, I missed that. It seems to be again caused by the missing stretchy parameter on the <mo> element. This should fix that:


\Preamble{xhtml}
\Configure{MathClass}{2}{*}{<mo class="MathClass-bin" stretchy="false">}{</mo>}{}
\Configure{MathClass}{3}{*}{<mo class="MathClass-rel" stretchy="false">}{</mo>}{}
\begin{document}
\EndPreamble

There was still an error in the configuration for gather*, but the fix is already included in TeX Live.

yalguzaq commented 12 months ago

Yes, this worked. Hope to see this solution as default in the next update.

michal-h21 commented 12 months ago

It should be already included in TeX Live, I've added it when I wrote my previous comment.