Latex multicolumn is not recognized

HI

R0 = GF(3)
print R0.multiplication_table()

edit retag close merge delete

( 2019-11-05 19:07:35 +0200 )edit

Sorry John Palmieri, Yes, I forgot to precise :OS Ubuntu 18.04, notebook with SageMath 8.9

( 2019-11-06 07:22:14 +0200 )edit

Sort by » oldest newest most voted

Well...

sage: latex(GF(3).multiplication_table())
{\setlength{\arraycolsep}{2ex}
\begin{array}{r|*{3}{r}}
\multicolumn{1}{c|}{\ast}&a&b&c\\\hline
{}a&a&a&a\\
{}b&a&b&c\\
{}c&a&c&b\\
\end{array}}


In a console (or in emacs's sage-shell-view), view(GF(3).addition_table()) gets me this:

Sage's view uses Mathjax by default, but reverts to $\LaTeX$ when the latex string contains some "trigger" commands (this can be customized via latex.add_to_mathjax_avoid_list).

But, indeed, in a Jupyter notebook, this fails (not only on \multicolumn but also on {\setlength{\arraycolsep}{2ex}), probably because the notebook can't use $\LaTeX$\, and mathjax isn't a complete implementation if it).

By the way, the mathjax implementation of the present server has the same problem: A cut'n'paste of the $\LaTeX$ string generating the (correct) representation of the multiplication table gives this:

$${\setlength{\arraycolsep}{2ex} \begin{array}{r|*{3}{r}} \multicolumn{1}{c|}{\ast}&a&b&c\\hline {}a&a&a&a\ {}b&a&b&c\ {}c&a&c&b\ \end{array}}$$

This can probably worked around by saving the latex text, compiling it with an external LaTeX installation, converting the output to, say, .png and displaying it in the notebook. An utility function might be written for that.

One more reason to use $\LaTeX$ an Sagetex (or pythontex (or org-mode))...

HTH,

more

What is the point of \multicolumn{1}{...}, or at least what is its point here? Can we change this to make it compatible with MathJax?

( 2019-11-05 22:34:34 +0200 )edit

It affects alignment for that one cell, but I think we can have slight misalignments (which may only be relevant if the terms in the table have names with more than one character) to gain better functionality in the Jupyter notebook.

( 2019-11-05 22:44:47 +0200 )edit

LaTeX rendering in the Jupyter notebook is performed by MathJax. Unfortunately, MathJax does not support multicolumn, see https://docs.mathjax.org/en/v2.7-late... , in particular the sentence MathJax only implements a limited subset of the array environment’s preamble, i.e., only the l, r, c, and | characters alongside : for dashed lines; everything else is ignored.

more

(please ignore or delete this comment)

( 2019-11-06 03:34:37 +0200 )edit

Nils, your answer is perfectly valid and correct. Just less verbose than mine...

( 2019-11-06 11:48:27 +0200 )edit