column spanning

220 views
Skip to first unread message

David Carlisle

unread,
May 21, 2012, 5:03:27 AM5/21/12
to mathja...@googlegroups.com
It appears that column spanning isn't supported currently in the mathml parsing?

I ask as the MathJax enabled version of the spec runs some xslt to
rewrite mathml3 and content mathml features to presentation mathml2.
For mstack/msline and it uses columnspan and this currently fails.

Actually it uses a column span and then a style attribute to put a css
border for the rule as in (3) in the test file below.
That works in firefox native mathml, but isn't ideal actually as there
is no _requirement_ for a mathml processor to support style. I would
switch to a horizontal stretched line operator or anything else if it
worked.

It seems the content of the style doesn't survive mathjax processing.
A class attribute does survive so I could (in most cases) use a class
instead but currently it fails anyway due to the lack of an element
representing the span.

http://monet.nag.co.uk/~dpc/mjtest.html

shows (1) a simple mtable with a spanning column. (2) a mathml3 mstack
(example from the spec) and (3) the mtable currently produced by the
rewrite rules from (2).

Especially in the case of msline (ie an inter-row rule spanning some
but not usually all of the columns) I'd be interested to know if
there is _any_ javascript/css I could inject after mathjax has
finished to make a reasonable rendering. This case may? be easier than
a general column spanning code.

The test file above has the basic example, or look at

http://www.w3.org/Math/draft-spec/mathml.html#chapter3_presm.elemmath.examples

after selecting the render with MathJax option at the top of the file.

David

Davide P. Cervone

unread,
May 23, 2012, 12:40:20 PM5/23/12
to mathja...@googlegroups.com
It appears that column spanning isn't supported currently in the mathml parsing?

Sadly, yes, MathJax doesn't yet do column or row spanning.  It is one of the important features that is missing from mtable in MathJax at the moment (there are a few other as well).

I ask as the MathJax enabled version of the spec runs some xslt to
rewrite mathml3 and content mathml features to presentation mathml2.
For mstack/msline and it uses columnspan and this currently fails.

Yes, I noticed that, and thought it was pretty clever, though I did note that MathJax wouldn't be able to handle it.

Actually it uses a column span and then a style attribute to put a css
border for the rule as in  (3) in the test file below.
That works in firefox native mathml, but isn't ideal actually as there
is no _requirement_ for a mathml processor to support style. I would
switch to a horizontal stretched line operator or anything else if it
worked.

It is not easy to get what you ask, but I present you with two possibilities.  The first doesn't use a table at all, which will get the baseline correct for in-line math:

  <mn>0.142857</mn>
  <mpadded width="0" height=".925em" voffset=".85em" lspace="-1width">
    <mpadded background="black" height=".075em">
      <mphantom><mn>142857</mn></mphantom>
    </mpadded>
  </mpadded>
</math>

This presents the number as is, and then "backspaces" the horizontal bar over top.  The phantom gets an element with the proper width, then the inner mpadded make a black line of that width and height .075em.  The outer mpadded moves that line over top of the preceding decimals, while taking up no horizontal space itself, but extending the vertical space to include the overbar.  A terrible hack, but workable.  If you don't want to use the mphantom for getting the width, you could use a width of .5em per digit and multiply by the number of digits.

If you want to keep the mtable, you can do something similar by "faking" the column span:

<mtable xmlns:m="http://www.w3.org/1998/Math/MathML" columnspacing="0em">
<mtr>
  <mtd/><mtd/>
  <mtd>
    <mpadded width=".5em" voffset="-.3em">
      <mpadded background="black" height=".075em">
        <mphantom><mn>142857</mn></mphantom>
      </mpadded>
    </mpadded>
  </mtd>
</mtr>
<mtr>
<mtd><mn>0</mn></mtd><mtd><mn>.</mn></mtd><mtd><mn>1</mn></mtd><mtd><mn>4</mn></mtd><mtd><mn>2</mn></mtd><mtd><mn>8</mn></mtd><mtd><mn>5</mn></mtd><mtd><mn>7</mn></mtd>
</mtr>
</mtable>
</math>

This uses the same trick for getting a black line of the proper width, and uses an mpadded to allow it to extend over the right-hand side of the (one) column that it occupies.  It also positions it vertically, since there is some space between the rows, so that the line is closer to the numbers.  This will be visually OK, but takes up a lot more vertical space than needed, since the upper row still has the height of a row.

It seems the content of the style doesn't survive mathjax processing.

Actually it does, but the problem is that the cell is zero width since it has no content, and so the border doesn't show up.  MathJax doesn't really have an element that correctly corresponds to the full-size mtd that you have in mind.  This is another deficiency in the MathJax table model that needs work.  (It was a real bear to implement the MathML mtable layout in HTML with its various column width options and still be able to allow percentage widths to work dynamically as the page size changes.  I'm afraid there is still some work to be done.)

Especially in the case of msline (ie an inter-row rule spanning some
but not usually all of the columns)  I'd be interested to know if
there is _any_ javascript/css I could inject after mathjax has
finished to make a reasonable rendering. This case may? be easier than
a general column spanning code.

See if the examples I gave you above will work for you.  If not I may be able to come up with something else.

Davide

David Carlisle

unread,
May 23, 2012, 3:17:31 PM5/23/12
to mathja...@googlegroups.com
Davide ,

Thanks for your replies. I'll experiment and report back later. (I've
also been experimenting with using mfrac (as that allows a line
thickness directly in mathml, using mpadded/mphantom you can put one
in each of the "spanned" columns such that they overhang and touch
each other, but again the vertical spacing is rather large.

I have a more immediate problem that my mstack processing is wrong. It
gets confused with the nested position & shift possibilities (as can
be seen in the longdiv example in the spec, which shifts some rows by
an extra slot when they should be under the row above) I think I know
how to fix that then I'll come back to mathjax. I'm sure one of the
methods here will make something legible, which would be good. As that
would mean I think that all content and presentation examples in the
spec would have an acceptable rendering except for the malign example.
malignmark is just hard to "fake" so as is traditional that is being
left till last:-)


>

>
> It is not easy to get what you ask, but I present you with two
> possibilities.  The first doesn't use a table at all, which will get the
> baseline correct for in-line math:
>
> <math xmlns="http://www.w3.org/1998/Math/MathML">
>   <mn>0.142857</mn>
>   <mpadded width="0" height=".925em" voffset=".85em" lspace="-1width">
>     <mpadded background="black" height=".075em">
>       <mphantom><mn>142857</mn></mphantom>
>     </mpadded>
>   </mpadded>
> </math>
>
> This presents the number as is, and then "backspaces" the horizontal bar
> over top.  The phantom gets an element with the proper width, then the inner
> mpadded make a black line of that width and height .075em.

ooooh that looks fun. As I mentioned above, the only thing I could
think of in pure mathml to get a specified thickness was the fraction
bar, but this looks interesting:-)

> The outer
> mpadded moves that line over top of the preceding decimals, while taking up
> no horizontal space itself, but extending the vertical space to include the
> overbar.

> A terrible hack,


You're speaking to someone with a lifetime of writing TeX macros
behind him, "hack" is a term of endearment:-)

>ntom>
>       </mpadded>
>     </mpadded>
>   </mtd>
> </mtr>
> <mtr>
> <mtd><mn>0</mn></mtd><mtd><mn>.</mn></mtd><mtd><mn>1</mn></mtd><mtd><mn>4</mn></mtd><mtd><mn>2</mn></mtd><mtd><mn>8</mn></mtd><mtd><mn>5</mn></mtd><mtd><mn>7</mn></mtd>
> </mtr>
> </mtable>
> </math>
>

>  This will be visually OK, but takes up a lot more vertical space than
> needed, since the upper row still has the height of a row.

Yes that was the problem I had using mfrac as well.

>
> It seems the content of the style doesn't survive mathjax processing.
>
>
> Actually it does, but the problem is that the cell is zero width since it
> has no content, and so the border doesn't show up.

Oh maybe I just missed it, I was looking around the tree in firebug
and/or chrome's inspector and thought it wasn't there, although I
found an element with the original class.
As you say that isn't the width of the column, just the natural width
of the entry. I thought at one point I'd been clever and discovered
that the grandparent of that element was a positioned element
containing the column-so-far and had the right width so I gave that a
bottom border. It worked in one browser but you generated a different
element structure in a different browser, and anyway I don't really
want to be poking that far into mathjax internals, not in the spec,
anyway:-) Then I got sidetracked into generating (or not) the right
code from msgroup shifts before worrying whether mathjax can render
it....

>  MathJax doesn't really
> have an element that correctly corresponds to the full-size mtd that you
> have in mind.  This is another deficiency in the MathJax table model that
> needs work.  (It was a real bear to implement the MathML mtable layout in
> HTML with its various column width options and still be able to allow
> percentage widths to work dynamically as the page size changes.  I'm afraid
> there is still some work to be done.)

Not complaining, and yes I can guess:-)

>
> See if the examples I gave you above will work for you.  If not I may be
> able to come up with something else.
>
> Davide
>
Thanks for the thoughts,

David

David Carlisle

unread,
May 24, 2012, 11:56:34 AM5/24/12
to mathja...@googlegroups.com
Some progress:

the long division example here:

http://www.w3.org/Math/draft-spec/mathml.html#chapter3_presm.elemmath.examples

renders in a slightly odd but legible way in at least firefox and
chrome (in firefox case both with native rendering and using mathjax).

I kept with my mfrac line to get the msline rules for now as I had
that almost working and wanted to limit the changes in a single
checkin. I'll probably experiment with the background color version
later once things are all working.

The code to work out the position/shift offsets is overhauled
completely (and is better on the long division although I'm still out
in some of the examples, so if the rules look shifted don't blame
mathjax:-) Should be easy enough to fix but I wanted to check in the
code.

The crossout and other attributes on mscarry/mscarries are mostly not
supported. (should be possible to wrap the crossed out entries in a
suitable menclose, but not today)

David

Davide P. Cervone

unread,
May 24, 2012, 3:19:28 PM5/24/12
to mathja...@googlegroups.com
These look good. Remember, however, that by default the columns are
centered, so if you use the zero-width mpadded element to get your
rule into the right place, it may start at the middle of the column
rather than its left-hand side. You can either use width=".5em" so it
is as wide as a digit, or use left alignment on the table to resolve
this.

When you use fractions to generate the line, there is an additional
issue, which is that MathJax adds a thinspace on either side of the
fraction. Technically not what it should do, but to get the spacing
to work like TeX's this turned out to be an expedient way of doing so,
even though it is not always the right thing to do. I will probably
change that in a future release, but that's how it works for now. If
you change to the black background mpadded approach instead, then this
will not be an issue. BTW, my example should have used
mathbackground="black" rather than just background="black", but I do
the shorter one when I am experimenting (easier to type) and forgot to
fix it for the final version.

Davide

David Carlisle

unread,
May 24, 2012, 4:44:19 PM5/24/12
to mathja...@googlegroups.com
On 24 May 2012 20:19, Davide P. Cervone <dp...@union.edu> wrote:
> These look good.  Remember, however, that by default the columns are
> centered, so if you use the zero-width mpadded element to get your rule into
> the right place, it may start at the middle of the column rather than its
> left-hand side.

Oh I meant to have lspace="-0.5em" so it was zero width and sticking
out both sides.
but I missed one of the cases. (the width is a bit arbitrary, mathjax
pads the fractions and firefox appears to ignore the columnspacing so
pads all the columns (unless you remove the padding from mtd with css)
so I made the line rather wide. There are a few issues still with
the conversion, then hopefully I'll switch out the fraction anyway,
for your background colour version, we'll see. But thanks for the
warning;-)

>  You can either use width=".5em" so it is as wide as a
> digit, or use left alignment on the table to resolve this.
>
> When you use fractions to generate the line, there is an additional issue,
> which is that MathJax adds a thinspace on either side of the fraction.
>  Technically not what it should do, but to get the spacing to work like
> TeX's this turned out to be an expedient way of doing so, even though it is
> not always the right thing to do.  I will probably change that in a future
> release, but that's how it works for now.  If you change to the black
> background mpadded approach instead, then this will not be an issue.  BTW,
> my example should have used mathbackground="black" rather than just
> background="black", but I do the shorter one when I am experimenting (easier
> to type) and forgot to fix it for the final version.

Yes I plan to switch to this, thanks.
>
> Davide

David
Reply all
Reply to author
Forward
0 new messages