multicolumn, cline in mathjax array?

1,422 views
Skip to first unread message

Alasdair McAndrew

unread,
Oct 29, 2018, 11:46:53 PM10/29/18
to MathJax Users
Hello,

I'm trying to typeset a simple array which includes clines and multicolumns.  In ordinary LaTeX, I would use something like:

\[
\begin{array}{rr|rrrrr}
&\multicolumn{1}{c}{}&\multicolumn{5}{c}{\mbox{Demands}}\\
&\multicolumn{1}{c}{}&100&100&100&100&100\\
\cline{3-7}
&100&100&100&100&100&100\\
\mbox{Supplies}&100&100&100&100&100&100\\
&100&100&100&100&100&100
\end{array}
\]

However, Mathjax doesn't seem to support either multicolumn or cline - how can such an array be typeset in Mathjax?

cheers,
Alasdair

Davide Cervone

unread,
Oct 30, 2018, 10:42:45 AM10/30/18
to mathja...@googlegroups.com
You are right that MathJax doesn't currently support \multicolumn or \cline.  Because MathJax converts your TeX to MathML internally, support for \multicolumn would require the implementation of MathML's columnspan and rowspan attributes for the <mtd> element; these are not yet implemented (they complicate the layout algorithm considerably).  The \cline macro is also a bit tricky, since MathML only has support for lines that go across the complete table.  

It would be possible to use style attributes on the <mtd> elements to add borders to create shorter lines (at least in the CommonHTML output), but you don't have direct access to the underlying MathML from within TeX, so it would have to be done indirectly, and it would rely on knowing the internal workings of how the CommonHTML output is laid out.  For example, setting the style

.mjx-mtable.titled > .mjx-table > .mjx-mtr:first-child > .mjx-mtd:first-child {
    border-color: transparent ! important;
}

and then use

\class{titled}{
\begin{array}{r|cc}
& 1 & 2\\
\hline
10 & 50 & 60\\
1 & 100 & 300
\end{array}}

to get the lines like you asked for.  

To get the full table takes a bit more work:

.mjx-mtable.titled-labeled > .mjx-table > .mjx-mtr:first-child > .mjx-mtd:nth-child(2),
.mjx-mtable.titled-labeled > .mjx-table > .mjx-mtr:nth-child(2) > .mjx-mtd:nth-child(2),
.mjx-mtable.titled-labeled > .mjx-table > .mjx-mtr:nth-child(2) > .mjx-mtd:first-child {
    border-color: transparent ! important;
}

with

\class{titled-labeled}{\begin{array}{rr|rrrrr}
&&&&\hspace{-1.5em}\text{Demands}\hpace{-1.25em}\\
&&100&100&100&100&100\\
\hline
&100&100&100&100&100&100\\
\text{Supplies}&100&100&100&100&100&100\\
&100&100&100&100&100&100
\end{array}}

Here we use \hspace commands to hide the width of the top label, and the CSS removes the borders from the needed cells to get the lines you are looking for.  Remember, this requires the CommonHTML output, because it is the one that uses CSS borders to produce the lines in the array.  If the user switches to one of the other formats, the full lines will show.

Of course, this is a terrible hack.  The real problem, here, is that table really isn't mathematics at all, and so you are using math to do something that should really be part of the page layout in HTML, not math.  You have to do this sort of thing in LaTeX, because everything is done through TeX commands, but in web pages, you have HTML to do the page layout, and MathJax should only be used for the mathematics itself.  So the way MathJax expects you to do this sort of thing is to use HTML tables with individual MathJax expressions inside the table cells (if needed).

Davide


--
You received this message because you are subscribed to the Google Groups "MathJax Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mathjax-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Alasdair McAndrew

unread,
Oct 31, 2018, 6:39:47 PM10/31/18
to MathJax Users
Dear Davide,

Thank you very much.  I did in fact realize after I'd posted that tables should be better handled by HTML (with a side order of CSS).  But the trouble is that I'm so used to the LaTeX way of doing things, having used it for over 25 years, that I tend to think of all layout issues as having a LaTeX solution.   I guess I have now to carefully distinguish between LaTeX and non-LaTeX.  Anyway - thank you for MathJax! - it's a superb tool.

kind regards,
Alasdair
Reply all
Reply to author
Forward
0 new messages