michal-h21 / make4ht

Build system for tex4ht
132 stars 15 forks source link

underbrace: invalid markup with MATHML #76

Closed danielezambelli closed 1 year ago

danielezambelli commented 2 years ago

The underbrace command is not recognized in MATHML, it works fine in MATHJAX.

%--8<------------------------------------- \documentclass[10pt,a4paper]{memoir} \usepackage[T1]{fontenc} \usepackage{textcomp}
\usepackage[utf8]{inputenc} \usepackage[italian]{babel}

\RequirePackage{amsmath, amssymb, amsthm}% amsfonts è caricato da amssymb \RequirePackage[normalem]{ulem} % sottolineature \usepackage{lipsum}

\begin{document}

\verb|[m \times n = 0 + \underbrace{m + m + \dots + m}{\text{n times}}]|: [m \times n = 0 + \underbrace{m + m + \dots + m}{\text{n times}}]

\end{document} %--8<-------------------------------------

michal-h21 commented 2 years ago

I see some underbrace, but it doesn't look correctly. Apparently a wrong character for underbrace is used at the moment. You can try this configuration file with character that is used in the MathML examples:

\Preamble{xhtml}
\catcode`\:=11
\Configure{underbrace}
   {\Configure{mathop*}{*}
         {<\a:mathml munder
                 \a:mathml accentunder="false"><\a:mathml mrow>}
         {</\a:mathml mrow><\a:mathml mo>\string
               &\#x23DF;</\a:mathml mo></\a:mathml munder>}
         {\Configure{mathop}{}{}{}{}}%
   }
   {\let\o:underbrace:=\displaystyle}
   {}
\catcode`\:=12
\begin{document}
\EndPreamble
danielezambelli commented 2 years ago

I attach the config file, modified as suggested, but the compilation with:

make4ht underbrace.tex -c ml_make4ht -l -u -s -d dist "mathml"

always produces: "invalid-markup".

ml_make4ht.txt .

michal-h21 commented 2 years ago

I cannot reproduce that, your example code works for me with the updated configuration file.

danielezambelli commented 2 years ago

It's a mystery...

When I execute:

make4ht underbrace.tex -c ml_make4ht -l -u -s -d dist "mathml"

I don't get any errors, but the html produced has the words on a red background: "invalid markup".

Inspecting the html file I saw that the code produced by mathjax compilation, and working, is slightly different from the one produced by mathml compilation.

With: make4ht underbrace.tex -c ml_make4ht -l -u -s -d dist "mathjax"

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
  <mi>m</mi>
  <mo>&#xD7;</mo>
  <mi>n</mi>
  <mo>=</mo>
  <mn>0</mn>
  <mo>+</mo>
  <munder>
    <mrow data-mjx-texclass="OP">
      <munder>
        <mrow>
          <mi>m</mi>
          <mo>+</mo>
          <mi>m</mi>
          <mo>+</mo>
          <mo>&#x22EF;</mo>
          <mo>+</mo>
          <mi>m</mi>
        </mrow>
        <mo>&#x23DF;</mo>
      </munder>
    </mrow>
    <mrow data-mjx-texclass="ORD">
      <mtext>n times</mtext>
    </mrow>
  </munder>
</math>

With: make4ht underbrace.tex -c ml_make4ht -l -u -s -d dist "mathml"

<mi>m</mi> 
<mo class="MathClass-bin">×</mo> 
<mi>n</mi> 
<mo class="MathClass-rel">=</mo> 
<mn>0</mn> 
<mo class="MathClass-bin">+</mo>
<munder class="msub">
  <mrow>
    <munder accentunder="false">
      <mrow>
        <mrow> 
        <mi>m</mi> 
        <mo class="MathClass-bin">+</mo> 
        <mi>m</mi> 
        <mo class="MathClass-bin">+</mo> 
        <mo class="MathClass-rel">⋯</mo> 
        <mo class="MathClass-bin">+</mo> 
        <mi>m</mi>
        </mrow>
      <mo>⏟</mo>
      </mrow>
    </munder>
  </mrow>
  <mrow>
    <mstyle class="text">
      <mtext>n&nbsp;times</mtext>
    </mstyle>
  </mrow>
</munder>

Thanks.

michal-h21 commented 2 years ago

The second example seems strange, as there are some extra <mrow> elements. It is possible that they were added using some DOM filters. Could you try to disable them using make4ht -f html5-common_domfilters -c ml_make4ht -l -u -s -d dist underbrace.tex "mathml"?

danielezambelli commented 2 years ago

Magic Michal!!!

It works!

I don't understand where the problem lies. I use Debian maybe the problem is in the packaging of Texlive for Debian?

Thanks, you are always helpful.

michal-h21 commented 2 years ago

Ah, it is quite possible. I think that I fixed this bug in December, so if the distribution uses an older version, it can be broken.

danielezambelli commented 2 years ago

Also "\overrightarrow" is not translated into mathml and gives the error "invalid-markup".

%--8<------------------------------------- vector: \verb|(\overrightarrow{abc})| \quad (\overrightarrow{abc}) %--8<-------------------------------------

Thanks.

michal-h21 commented 2 years ago

You are right. I will loot at this later.

danielezambelli commented 2 years ago

I report that the cancel package also creates problems in mathml:

%--8<-------------------------------------
\documentclass[10pt,a4paper]{memoir}
\usepackage[T1]{fontenc} 
\usepackage{textcomp}   
\usepackage[utf8]{inputenc}
\usepackage[italian]{babel} 

\usepackage{amsmath, amssymb, amsthm}
\usepackage{cancel}
\usepackage[normalem]{ulem} % sottolineature

\begin{document}

vettore: \verb|\(\vec{a}\)| \quad \(\vec{a}\)

vettore: \verb|\(\vec{abc}\)| \quad \(\vec{abc}\)

vettore: \verb|\(\overrightarrow{a}\)| \quad \(\overrightarrow{a}\)

vettore: \verb|\(\overrightarrow{abc}\)| \quad \(\overrightarrow{abc}\)

overline: \verb|\(24 : 18 = 1,\overline{3}\)| \quad
\(24 : 18 = 1,\overline{3}\)

\[\cancel{5} + 3 - \cancel{5} = 3\]

\[8^1 = 8^{4-3} = 8^4 : 8^3 =
    \frac{8 \cdot 8 \cdot 8 \cdot 8}{8 \cdot 8 \cdot 8} = 
    \frac{\cancel{8} \cdot \cancel{8} \cdot \cancel{8} \cdot 8}
    {\cancel{8} \cdot \cancel{8} \cdot \cancel{8}} = 8
\]

\end{document}
%--8<-------------------------------------

Thanks.

michal-h21 commented 2 years ago

I hope that \overrightarrorw and \overleftarrow should be fixed using this configuration:

\Preamble{xhtml}
\catcode`\:=11
\Configure{underbrace}
   {\Configure{mathop*}{*}
         {<\a:mathml munder
                 \a:mathml accentunder="false"><\a:mathml mrow>}
         {</\a:mathml mrow><\a:mathml mo>\string
               &\#x23DF;</\a:mathml mo></\a:mathml munder>}
         {\Configure{mathop}{}{}{}{}}%
   }
   {\let\o:underbrace:=\displaystyle}
   {}
\Configure{overrightarrow}
  {\leavevmode\hbox\bgroup$\Tg<\a:mathml mover accent="true" class="overrightarrow">%
   \Tg<\a:mathml mrow\Hnewline>\:gobble}
  {\Tg</\a:mathml mrow>\HCode{<\a:mathml mo>&\#x2192;</\a:mathml mo>}%
   \Tg</\a:mathml mover>$\egroup}
\Configure{overleftarrow}
  {\leavevmode\hbox\bgroup$\Tg<\a:mathml mover accent="true" class="overleftarrow">%
   \Tg<\a:mathml mrow\Hnewline>\:gobble}
  {\Tg</\a:mathml mrow>\HCode{<\a:mathml mo>&\#x2190;</\a:mathml mo>}%
   \Tg</\a:mathml mover>$\egroup}

\catcode`\:=12
\begin{document}
\EndPreamble
danielezambelli commented 2 years ago

\overrightarrow and \overleftarrow works fine.

Is it complicated to realize support for the cancel package?

Thanks.

michal-h21 commented 2 years ago

Try this file, cancel.4ht:

\NewConfigure{cancel}{2}
\NewConfigure{cancelmath}{2}
\def\:tempa#1{\ifmmode\a:cancelmath#1\b:cancelmath\else\a:cancel#1\b:cancel\fi}
\HLet\cancel\:tempa

\NewConfigure{bcancel}{2}
\NewConfigure{bcancelmath}{2}
\def\:tempa#1{\ifmmode\a:bcancelmath#1\b:bcancelmath\else\a:bcancel#1\b:bcancel\fi}
\HLet\bcancel\:tempa

\NewConfigure{xcancel}{2}
\NewConfigure{xcancelmath}{2}
\def\:tempa#1{\ifmmode\a:xcancelmath#1\b:xcancelmath\else\a:xcancel#1\b:xcancel\fi}
\HLet\xcancel\:tempa

\NewConfigure{cancelto}{3}
\def\:tempa#1#2#3#4{\a:cancelto#2\b:cancelto#4\c:cancelto}
\HLet\@cancelto\:tempa

\Configure{cancelmath}{\HCode{<\a:mathml menclose notation="updiagonalstrike">}}{\HCode{</\a:mathml menclose>}}
\Configure{cancel}{\HCode{<span class="cancel">}}{\HCode{</span>}}
\Css{.cancel{background: linear-gradient(to left top, transparent 47.75\%, currentColor 49.5\%, currentColor 50.5\%, transparent 52.25\%);}}

\Configure{bcancelmath}{\HCode{<\a:mathml menclose notation="downdiagonalstrike">}}{\HCode{</\a:mathml menclose>}}
\Configure{bcancel}{\HCode{<span class="bcancel">}}{\HCode{</span>}}
\Css{.bcancel{background: linear-gradient(to bottom left, transparent 47.75\%, currentColor 49.5\%, currentColor 50.5\%, transparent 52.25\%);}}

\Configure{xcancelmath}{\HCode{<\a:mathml menclose notation="updiagonalstrike downdiagonalstrike">}}{\HCode{</\a:mathml menclose>}}
\Configure{xcancel}{\HCode{<span class="xcancel">}}{\HCode{</span>}}
\Css{.xcancel{background: linear-gradient(to bottom left, transparent 47.75\%, currentColor 49.5\%, currentColor 50.5\%, transparent 52.25\%), linear-gradient(to left top, transparent 47.75\%, currentColor 49.5\%, currentColor 50.5\%, transparent 52.25\%);}}

\Configure{cancelto}
{\HCode{<\a:mathml msup><\a:mathml menclose notation="updiagonalarrow"><\a:mathml mrow>}}
{\HCode{</\a:mathml mrow></\a:mathml menclose><\a:mathml mrow>}}
{\HCode{</\a:mathml mrow></\a:mathml msup>}}

\Hinput{cancel}
\endinput

It should support Cancel's commands both in text and math mode. It expects the MathML output. I will add it to TeX4ht sources too, so it should be available soon in TL.

danielezambelli commented 2 years ago

Thank you for your work, but in my system I do not get the desired result.

The compilation with:

make4ht underbrace.tex -f html5-common_domfilters -c ml_make4ht -l -u -s -d ./html/mathml "mathml"

produces:

[...]
<!--l. 35--><math 
 xmlns="http://www.w3.org/1998/Math/MathML"  
display="block" class="equation">
                          <img 
src="[underbrace0x.png](view-source:file:///dati/daniele/progetti/md2xhtml/tests/underbrace/html/mathml/underbrace0x.png)" alt="/5  "  class="oalign"  />
                            <mo 
class="MathClass-bin">+</mo> <mn>3</mn> <mo 
class="MathClass-bin">−</mo><img 
src="[underbrace4x.png](view-source:file:///dati/daniele/progetti/md2xhtml/tests/underbrace/html/mathml/underbrace4x.png)" alt="/5  "  class="oalign"  /> <mo 
class="MathClass-rel">=</mo> <mn>3</mn>
</math></td></tr></table>
<table class="equation-star"><tr><td>

<!--l. 37--><math 
 xmlns="http://www.w3.org/1998/Math/MathML"  
display="block" class="equation">
          <msup><mrow 
><mn>8</mn></mrow><mrow 
><mn>1</mn></mrow></msup 
> <mo 
class="MathClass-rel">=</mo> <msup><mrow 
><mn>8</mn></mrow><mrow 
><mn>4</mn><mo 
class="MathClass-bin">−</mo><mn>3</mn></mrow></msup 
> <mo 
class="MathClass-rel">=</mo> <msup><mrow 
><mn>8</mn></mrow><mrow 
><mn>4</mn></mrow></msup 
> <mo 
class="MathClass-punc">:</mo> <msup><mrow 
><mn>8</mn></mrow><mrow 
><mn>3</mn></mrow></msup 
> <mo 
class="MathClass-rel">=</mo> <mfrac><mrow 
><mn>8</mn> <mo 
class="MathClass-bin">⋅</mo> <mn>8</mn> <mo 
class="MathClass-bin">⋅</mo> <mn>8</mn> <mo 
class="MathClass-bin">⋅</mo> <mn>8</mn></mrow> 
<mrow 
>
<mn>8</mn> <mo 
class="MathClass-bin">⋅</mo> <mn>8</mn> <mo 
class="MathClass-bin">⋅</mo> <mn>8</mn></mrow></mfrac>   <mo 
class="MathClass-rel">=</mo> <mfrac><mrow 
><img 
src="[underbrace9x.png](view-source:file:///dati/daniele/progetti/md2xhtml/tests/underbrace/html/mathml/underbrace9x.png)" alt="/8  "  class="oalign"  /> <mo 
class="MathClass-bin">⋅</mo><img 
src="[underbrace13x.png](view-source:file:///dati/daniele/progetti/md2xhtml/tests/underbrace/html/mathml/underbrace13x.png)" alt="/8  "  class="oalign"  /> <mo 
class="MathClass-bin">⋅</mo><img 
src="[underbrace17x.png](view-source:file:///dati/daniele/progetti/md2xhtml/tests/underbrace/html/mathml/underbrace17x.png)" alt="/8  "  class="oalign"  /> <mo 
class="MathClass-bin">⋅</mo> <mn>8</mn></mrow> 
<mrow 
>
<img 
src="[underbrace21x.png](view-source:file:///dati/daniele/progetti/md2xhtml/tests/underbrace/html/mathml/underbrace21x.png)" alt="/8  "  class="oalign"  /> 
<mo 
class="MathClass-bin">⋅</mo><img 
src="[underbrace25x.png](view-source:file:///dati/daniele/progetti/md2xhtml/tests/underbrace/html/mathml/underbrace25x.png)" alt="/8  "  class="oalign"  /> <mo 
class="MathClass-bin">⋅</mo><img 
src="[underbrace29x.png](view-source:file:///dati/daniele/progetti/md2xhtml/tests/underbrace/html/mathml/underbrace29x.png)" alt="/8  "  class="oalign"  /></mrow></mfrac>   <mo 
class="MathClass-rel">=</mo> <mn>8</mn>
</math></td></tr></table>

</body> 
</html>
michal-h21 commented 2 years ago

I cannot reproduce that. How does your configuration file looks now? Note that the fixes that I provided in this thread previously (including cancel.4ht) are now included in TeX Live, so hopefully, if you update it, everything should work without need to use config files.

danielezambelli commented 2 years ago

I copied what was posted in the message 3 days ago into a file called cancel.4ht that I put in the dir:

/usr/share/texlive/texmf-dist/tex/generic/tex4ht/

I did not write it into the configuration file which remained the one sent 14 days ago.

Should I change the configuration file?

Thanks.

michal-h21 commented 2 years ago

No, you don't need to update the configuration file, but maybe try to update your distribution. You may need to remove your version of cancel.4ht from /usr/share/texlive/texmf-dist/tex/generic/tex4ht/, as I've changed few things in the distributed version.