(X)HTML embedded in MathML

261 views
Skip to first unread message

Tilman Rassy

unread,
Jun 5, 2011, 11:50:24 AM6/5/11
to MathJax Users
Hi,

in Firefox, you can embed XHTML in MathML. The embedded XHTML can even
contain further MathML elements. This is extremely useful with
formulas containing logical quantors like "for each x > 0". In LaTeX,
you would use the \mbox or \text command for this.

When I try to render such an MathML formula with MathJax, it says
"Unknown node type: span".

I already looked at the code and discovered that the error is thrown
by the MakeMML function, which converts the MathML to the internal jax
structure. Would it be possible to include (X)HTML nodes in this
structure and later render them, instead of throwing an error?

Thanks in advance and best regards,
Tilman Rassy

Frédéric WANG

unread,
Jun 5, 2011, 12:02:32 PM6/5/11
to mathja...@googlegroups.com
Hi,

I don't think you need to use such a syntax to write things like "for each x > 0". In MathML, text fragments are written within the <mtext> element and that's what MathJax's LateX parser generates when \mbox or \text are used. You can use MathJax's math menu to read the MathML source and hence get an idea of the appropriate code.

In general, there is no provisions in MathML to include foreign languages (that would be similar to SVG's foreignObject). There are some possibilities with the <semantics>, but this one is not really designed for that purpose.

Frédéric
--
Frédéric Wang.
Website - Weblog

Davide P. Cervone

unread,
Jun 5, 2011, 12:05:51 PM6/5/11
to mathja...@googlegroups.com
The <annotation-xml> code in v1.1 is broken, but it is being corrected
in v1.1a (currently in final testing).

You should note that the MathML specification does not provide for the
usage you are suggesting (though I know how useful it would be).
Firefox's behavior is when <semantics> contains an <annotation-xml>
node as its first (only?) node, it will display that, but this
structure is not allowed by the MathML specification, which implies
that a standard (i.e., non-annotation) MathML node should be the
first child of a <semantics> element (see http://www.w3.org/TR/MathML3/chapter5.html#mixing.semantic.annotations
, particularly the first paragraph of 5.2.1.1).

Even with the improved annotation-xml support in the coming v1.1a,
however, MathJax will not handle the recursive processing of the
embedded MathML inside an XHTML annotation within a MathML element.
The contents of the annotation element are not further processed by
MathJax once they are identified.

Davide

David Carlisle

unread,
Jun 5, 2011, 12:15:49 PM6/5/11
to mathja...@googlegroups.com


On 5 June 2011 17:05, Davide P. Cervone <dp...@union.edu> wrote:
The <annotation-xml> code in v1.1 is broken, but it is being corrected in v1.1a (currently in final testing).

You should note that the MathML specification does not provide for the usage you are suggesting


well... yes and no:-)

core mathml only allows character data in mathml token elements, but it does explicitly suggest that someone designing a compound document format may extend the content model of token elements (or just mtext) to allow elements from the host language. that's what the designers of html5 chose to do.


see

http://www.w3.org/TR/MathML3/chapter6.html#interf.xhtml

David

Tilman Rassy

unread,
Jun 5, 2011, 8:05:53 PM6/5/11
to MathJax Users
Thank you all for your quick replies!

Perhaps it's helpful to explain my problem in more detail. We have
legacy MathML+XHTML code of the following form:

<math xmlns:mathml="http://www.w3.org/1998/Math/MathML"
display="block">
<mi>f</mi>
<mo>(</mo>
<mi>x</mi>
<mo>)</mo>
<mo>&gt;</mo>
<mn>0</mn>
<mspace width="1em" />
<mrow>
<span xmlns="http://www.w3.org/1999/xhtml" class="embedded-
html">
for each
<math display="inline">
<mi>x</mi>
<mo>&gt;</mo>
<mn>2</mn>
</math>
</span>
</mrow>
</math>

Thus, presentation MathML with embedded XHTML "span" elements. It
works perfectly in Firefox. Currently, we try to get it running with
MathJax to support other browsers, too. Since we have so much legacy
code (hundreds of documents), changing the code is not really an
option. At least, we would be happy if we can avoid that. However,
automatic changes would be possible, of course.

I know what the MathML specification says about mixing MathML and
XHTML. It's forbidden in pure MathML, but, as David pointed out above,
it may be allowed in compound documents. I think that would be quite
useful, because it reflects the real world of mathematical writing.
The mtext element is not enough, because it can only contain text.
It's very common among LaTeX authors to write something like \mbox{for
each $x>2}. In a XHTML+MathML document, that would result in something
like the above code. And it would be great if MathJax would support
that :-)

Best regards
Tilman

Davide P. Cervone

unread,
Jun 5, 2011, 8:51:57 PM6/5/11
to mathja...@googlegroups.com
I wasn't aware the Firefox would process this. It is not valid
MathML, and it would certainly confuse MathPlayer if native MathML
output were used. Not sure what Opera's limited MathML support would
make of it.

Anyway, I have a couple of questions:

1. Is it always a <span> element that is used, or are there other
elements that are the direct children of a MathML element like <mrow>?

2. It is always just plain text intermixed with <math> elements, or
are there other HTML elements used (like <b> or <input>, etc.)?

3. How much is it worth to you to get this working in MathJax (i.e.,
would you be willing to pay for me to produce some custom extensions
for MathJax that handle this for you)? We can have this discussion
privately, if you prefer.


Davide

Davide P. Cervone

unread,
Jun 5, 2011, 8:58:23 PM6/5/11
to mathja...@googlegroups.com
It's very common among LaTeX authors to write something like \mbox{for
each $x>2}. In a XHTML+MathML document, that would result in something
like the above code. 

That is not the only possible approach.  For example, MathJax converts

\f(x)>0 \quad \mbox{for each $x>2$}

to

<math xmlns="http://www.w3.org/1998/Math/MathML"> <mi>f</mi> <mo stretchy="false">(</mo> <mi>x</mi> <mo stretchy="false">)</mo> <mo>&gt;</mo> <mn>0</mn> <mspace width="1em" /> <mtext>for each&#xA0;</mtext> <mrow> <mi>x</mi> <mo>&gt;</mo> <mn>2</mn> </mrow> </math>

which doesn't require the nested languages.

Davide

Tilman Rassy

unread,
Jun 6, 2011, 5:02:16 AM6/6/11
to MathJax Users
Hi Davide,
Yes, that may be a solution. I already thought about a workaround
where an XSL stylesheet converts

<span>Some text <math>Some math<math> Some other text ...</span>

to

<mtext>Some text </mtext><math>Some math<math><mtext> Some other
text ... </mtext>

Concerning your questions:

1. Yes, it's always a <span> element

2. Other markup is allowed, but our authors don't use it. Thus, we can
abandon that.

3. I'll discuss that in our group and come back to you afterwards. In
any case, thanks for your willingness to do that!

Best regards
Tilman

David Carlisle

unread,
Jun 6, 2011, 5:08:38 AM6/6/11
to mathja...@googlegroups.com

   <mn>0</mn>
   <mspace width="1em" />
   <mrow>
     <span xmlns="http://www.w3.org/1999/xhtml" class="embedded-
html">

Note that form (although firefox (and mozilla before that) have always supported it) isn't allowed by the extended xhtml+mathml schema suggested by mathml3 and specified by html5. There, as in latex, you need an wrapper element to force the context swich back to text/html mode, so would need an <mtext> around that xhtml section.

<mrow>
    <mtext>
     <span xmlns="http:

...


David



Davide P. Cervone

unread,
Jun 6, 2011, 9:00:45 AM6/6/11
to mathja...@googlegroups.com
> Yes, that may be a solution. I already thought about a workaround
> where an XSL stylesheet converts
>
> <span>Some text <math>Some math<math> Some other text ...</span>
>
> to
>
> <mtext>Some text </mtext><math>Some math<math><mtext> Some other
> text ... </mtext>


I had a similar thought in mind (which your answers to the questions
suggest would work). My first thought was to write a MathJax
preprocessor that would make the translation that you suggest, but
without the <math> tags, since they are not needed, and in fact
invalid (I think). XSL would be another way to handle that.

The alternative would be to implement a span node type in MathJax.

The former has the advantage that the MathML is then valid MathML, so
if you use the Show Source menu option, it will be something you can
copy and paste into other applications. The disadvantage is that it
requires an additional preprocessing step, but that should be
relatively fast.

The latter has the advantage that it would take the MathML you have
directly, and could be made to include other HTML tags inside the
<span>. The disadvantage is that it is more complicated to write, and
in particular, the nested MathML inside the span would take some care.

Either is possible. The first would be quicker to write, but a little
less flexible; the second takes more time, but allows for more complex
content.

Let me know if you want to work on either of these.

Davide

Tilman Rassy

unread,
Jun 7, 2011, 7:06:43 PM6/7/11
to MathJax Users
Hi Davide,

meanwhile, I wrote the XSL that converts the spans as described above,
but without the math tags (you were complete right in this point).
Thus,

<span>Some text <math>Some math<math> Some other text ...</span>

becomes

<mtext>Some text </mtext>Some math<mtext> Some other text ...</
mtext>

It works fine :-)

This solves our problem.

So far, the results of testing MathJax are very positive, so we'll
probably use it in our e-learning platform.

Thank you very much for you effort and help!

Best regards
Tilman

Davide P. Cervone

unread,
Jun 8, 2011, 9:57:52 AM6/8/11
to mathja...@googlegroups.com
>
> meanwhile, I wrote the XSL that converts the spans as described above,
> but without the math tags (you were complete right in this point).
> Thus,
>
> <span>Some text <math>Some math<math> Some other text ...</span>
>
> becomes
>
> <mtext>Some text </mtext>Some math<mtext> Some other text ...</
> mtext>
>
> It works fine :-)

One thing that you might need to do is make the final space in the
first <mtext> into &#xA0; (the entity reference for a non-breaking
space), and the same for the initial space in the second <mtext>. The
MathML specification states that leading and trailing spaces are
removed from token elements, so if you want to have spaces, you need
to make sure they are non-breaking spaces.

> This solves our problem.

Glad to hear you got it to work out!

> So far, the results of testing MathJax are very positive, so we'll
> probably use it in our e-learning platform.

Excellent. Let us know how it goes (and what your site is).

Best of luck with it.

Davide

Reply all
Reply to author
Forward
Message has been deleted
0 new messages