1

I am compiling the following latex file:

\documentclass{article}
\usepackage[british]{babel}

\begin{document}
\begin{equation}
  \begin{array}{|r|rrrr|}
    \hline
    & x_1 & x_2 & x_3 & x_4 \\
    \hline
    4 & 0 & -3 & 2 & 0 \\
    \hline
    x_1 = 2 & 1 & -1 & 1 & 0 \\
    \hline
    x_4 = 4 & 0 & 2^{*} & -1 & 1\\
    \hline
  \end{array}
\end{equation}
\end{document}

which, via pdflatex, results in:

enter image description here

Compiling the above via TeXlive 2022's

make4ht markup.tex 'mathml,mathjax'

results in a rather strange-looking table:

enter image description here

(rendered via CHTML, rendering via SVG produces a different but also wrong output)

Is there a particular reason why the output looks like this?

P.S. The problem does not occur when using 'mathjax' option as MathJax processes the array correctly. Unfortunately, I cannot switch to mathjax-only due to technical reasons.

1 Answer 1

1

\hline produces a table row that contains _ characters, which causes this issue. Try the following configuration file, which removes these spurious characters and vertical space. It is based on the code from TeX4ht sources:

\Preamble{xhtml}
\Css{.array .hline{height:0px;border-top:1px solid black;}}
\Css{.array .hline .hline-mtd{display:none;}}
\Css{.array .cline .cline-mtd{display:none;}}
\Css{.array .hline + .array-row:last-child{height:0px;}}
\Css{.array .hline + .array-row:last-child .array-td{display:none;}}
\catcode`\:=11
\Configure{array}
   {\halignTB{array}}
   {\ifvmode \IgnorePar\fi \expandafter\tmp:toks\expandafter{\Clr}%
\HCode{<!--\the\tmp:toks-->}%
\Tg</\a:mathml mtable>}
   {\Tg<\a:mathml mtr \mml:class="array-row">}{\Tg</\a:mathml mtr>}
   {\HCode{<\a:mathml mtd\Hnewline \mml:class="array-td"
   \ifnum 1<\HMultispan columnspan="\HMultispan"\fi}%
   \halignTD    \HCode{>}%
}
   {\Tg</\a:mathml mtd>}

\def\mathml:hborder{%
\Configure{HBorder}
   {<\a:mathml mtr\Hnewline \mml:class="hline">}
   {<\a:mathml mtd \mml:class="hline-mtd"></\a:mathml mtd>}
   {</\a:mathml mtr>}
   {<\a:mathml mtr\Hnewline \mml:class="cline">}
   {<\a:mathml mtd \mml:class="cline-mtd"></\a:mathml mtd>}
   {<\a:mathml mtd \mml:class="nocline-mtd"></\a:mathml mtd>}
   {</\a:mathml mtr>}
   {<\a:mathml mtr\Hnewline
         \mml:class="vspace" style="font-size:\HBorderspace">}
   {<\a:mathml mtd\Hnewline></\a:mathml mtd>}
   {</\a:mathml mtr>}
  }
\catcode`\:=12
\begin{document}
\EndPreamble

It uses CSS to draw the rules and to hide the hline rows. The downside is that CSS doesn't work in every MathML application, but it should work in web browsers. There are some special HTML attributes that should work universally, but they need to be used at the beginning of the table, before we know where the rules are used. I can try to post-process tables in make4ht DOM filters if you want.

Anyway, with the config file, this should be the result:

enter image description here

3
  • Thanks a lot Michal! make4ht works very smoothly which is why I was surprised that such a basic thing as \hline does not work as desired and requires extra configuration.
    – qarabala
    Commented Oct 24, 2022 at 17:41
  • 1
    @CebişMellim I've never changed this configuration, so it was there at least for 15 years. Nobody complained in that time, so I never knew about this. \hline in tabular works correctly, but maybe it is not used that much in array by TeX4ht users?
    – michal.h21
    Commented Oct 24, 2022 at 18:09
  • Yes, \hline is a tabular command rather than an array, you're right. Maybe I should just switch to tabular whenever I need such a structure. Anyway, thanks for a prompt reply (as always).
    – qarabala
    Commented Oct 24, 2022 at 20:31

You must log in to answer this question.

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