Copy MathML from Word 2007 and Paste into HTML? Do I have to remove the namespace for MathJax to recognize the MathML?

843 views
Skip to first unread message

Amanda Grover

unread,
Oct 11, 2011, 12:04:15 PM10/11/11
to MathJax Users
Is there a way I can configure MathJax to recognize the MathML that
comes directly from word, (i.e., <mml:math>)? Or do I have to remove
the "mml:" namespaces for MathJax to recognize the MathML in my HTML
page?

leathrum

unread,
Oct 12, 2011, 11:43:18 AM10/12/11
to MathJax Users
Where is the mml namespace set in the original document? Somewhere
(probably in the header stuff) there should be something that says
xmlns:mml="...". If you can't find it, that's OK -- try adding it
directly to the <mml:math> tag as an attribute:

xmlns:mml="http://www.w3.org/1998/Math/MathML"

So the tag should now read:

<mml:math xmlns:mml="http://www.w3.org/1998/Math/MathML">
...
</mml:math>

That should set the mml namespace for the entire context of the math
environment. If you don't want to add this to every math environment,
then add the xmlns:mml attribute to the <html> tag instead -- that
will set the namespace for the entire document. The browser should
handle the namespaces prior to anything MathJax does. If this doesn't
work, then your HTML may be using a doctype that doesn't recognize
namespaces. The HTML5 doctype should work fine.

Robert Miner

unread,
Oct 12, 2011, 12:29:58 PM10/12/11
to mathja...@googlegroups.com
The mml prefix is hardcoded into an XSL stylesheet that is part of Word, so it is a little problematic to change that.

So I think Tom is right, and it is a matter of getting the namespace into the MathML for MJ to pick it up. Casey Stark's screencast at http://www.mathjax.org/demos/copy-and-paste/ illustrates this with the 1.0? version of MJ.

I see that the docs don't have a very comprehensive or clear statement of just exactly how namespaces are handled by the MathML preprocessor. We should try to investigate/improve that. I think part of the problem is there are lots of idiosyncrasies to how browsers handle namespace prefixes in HTML, and lot of them are kind of broken. It would be really nice if there were an option to get un-namespaced MathML out of Word.

--Robert

Davide P. Cervone

unread,
Oct 14, 2011, 10:13:12 AM10/14/11
to mathja...@googlegroups.com
As long as the namespace is properly declared (as described in earlier
messages), MathJax should pick up the math elements even with the
namespace. Of course, with HTML5, there ARE no namespaces, so the
browser will remove the namespaces automatically.

Davide

Mandy Grover

unread,
Oct 19, 2011, 10:33:11 PM10/19/11
to MathJax Users
Since I'm taking the MathML directly from word (via Word 2007 equation
editor and then copy/paste in my HTML), my namespaces should be good
to go. However, unless I actually remove the namespaces (by find/
replace), MathJax won't recognize the MathML in my HTML.
Thanks for your help.

Mandy Grover

unread,
Oct 19, 2011, 10:34:26 PM10/19/11
to MathJax Users
I agree. Getting the MathML sans namespaces from Word would be great
for what I'm doing now.
Thanks.

On Oct 12, 11:29 am, "Robert Miner" <robe...@dessci.com> wrote:
> The mml prefix is hardcoded into an XSL stylesheet that is part of Word, so it is a little problematic to change that.
>
> So I think Tom is right, and it is a matter of getting the namespace into the MathML for MJ to pick it up. Casey Stark's screencast athttp://www.mathjax.org/demos/copy-and-paste/illustrates this with the 1.0? version of MJ.

Mandy Grover

unread,
Oct 19, 2011, 10:35:35 PM10/19/11
to MathJax Users
Thanks for the suggestions. I'm going to look into your idea that my
HTML may be using a doctype that doesn't recognize namespaces.

Davide P. Cervone

unread,
Oct 20, 2011, 6:18:03 AM10/20/11
to mathja...@googlegroups.com
If you declare the namespace on the <html> element, then MathJax will
be able to handle it. For example:

<!DOCTYPE html>
<html xmlns:mml="http://www.w3.org/1998/Math/MathML">
<head>
<title>MathJax MathML with namespace</title>
<script src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=MML_HTMLorMML
"></script>
</head>
<body>

Here is some math:
<mml:math>
<mml:mi>x</mml:mi>
<mml:mo>+</mml:mo>
<mml:mn>2</mml:mn>
</mml:math>

</body>
</html>

works for me. I don't think it will work if you declare the mml
namespace only on the <mml:math> tag itself. This works if you don't
include this DOCTYPE, and also if you have an xmlns="..." on the math
element itself. So

<html xmlns:mml="http://www.w3.org/1998/Math/MathML">
<head>
<title>MathJax MathML with namespace</title>
<script src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=MML_HTMLorMML
"></script>
</head>
<body>

Here is some math:
<mml:math xmlns="http://www.w3.org/1998/Math/MathML">
<mml:mi>x</mml:mi>
<mml:mo>+</mml:mo>
<mml:mn>2</mml:mn>
</mml:math>

</body>
</html>

also works for me. The key is having the xmlns:mml="..." on the
<html> tag. This is what I meant by declaring the namespace; it is
not something that gets copied with the MathML itself.

Davide

Mandy Grover

unread,
Oct 20, 2011, 11:37:12 AM10/20/11
to MathJax Users
Great! This is definitely the solution I've been looking for. Thank
you very much for your help. The only issue I'm dealing with now is
that when I move directly from Word to my HTML using the solution
you've given me, my summation symbol has turned into a question mark.
I'm wondering if this is an issue with the MathML that Word 2007 is
generating. Previously, I would take the Word MathML and copy/paste
into a text file and then do a find/replace to get rid of the mml
namespaces, and then I would copy/paste that into my html. With that
method, my summation symbol rendered fine. Thanks!
> >>> page?- Hide quoted text -
>
> - Show quoted text -

Davide P. Cervone

unread,
Oct 24, 2011, 11:42:04 AM10/24/11
to mathja...@googlegroups.com
I suspect there is a character encoding issue involved. There are several ways to represent Unicode characters, and I bet that the copy and paste isn't preserving it correctly.

Personally, I'd recommend using numeric character entities like &#x2211; for these rather than the unicode character itself, since that would avoid the encoding problems. Can you get word to generate those rather than direct unicode characters?

Davide

j.h.van.r...@gmail.com

unread,
Jul 4, 2012, 4:58:33 PM7/4/12
to mathja...@googlegroups.com
Maybe MathType can help you to convert.
 
Regards, Johan

Harsh Chhabra

unread,
Jul 5, 2012, 10:27:00 AM7/5/12
to mathja...@googlegroups.com
you dont need to use mml inside any tag.... As i myself use like as <mrow><mfrac>4 etc..and simply put this inside html body.
And you can convert any document file in to mathml using mathtype tool.

And one question i want to use if anybody knows that if i use mathtype it is converting all most equation in to mathml but except those which are written by subscript and superscript menu provided in microsoft word which causing problem in web display so Is there any tool as mathtype to convert such expressions in to mathml or in xhtml(to get fine display) ??? please help me, its urgent..

i am attaching a screenshot to describe problem,have a look.
and will be very thankful to you .
pic1.png

Davide P. Cervone

unread,
Jul 5, 2012, 12:10:47 PM7/5/12
to mathja...@googlegroups.com
> you dont need to use mml inside any tag.... As i myself use like as
> <mrow><mfrac>4 etc..and simply put this inside html body.
> And you can convert any document file in to mathml using mathtype
> tool.

I think the original questioner knew that he didn't have to use the
mml namespace, but was asking whether it HAD to be removed (as he
didn't want to have to edit the MathML that he already had).

> And one question i want to use if anybody knows that if i use
> mathtype it is converting all most equation in to mathml but except
> those which are written by subscript and superscript menu provided
> in microsoft word which causing problem in web display so Is there
> any tool as mathtype to convert such expressions in to mathml or in
> xhtml(to get fine display) ??? please help me, its urgent..

As we have mentioned in the topic that you started about this
question, since you have used text-based superscripts and formatted
the equations by hand as part of the text rather than as equations
that have been identified to Word as mathematics (as would have been
the case if you had used the equation editor), these equations are not
marked within the document as being mathematics, and so Word will not
export them as MathML (it thinks they are just part of the text). It
might be possible to write a program that tries to identify the styled
text with superscripts as mathematics, but I suspect that it will not
be very successful. Because the equations are not marked as
mathematics within the document, you are going to have trouble
identifying these equations programmatically.

In any case, these forums are for MathJax-specific problems, and this
is a Microsoft Word problem. You might have better luck asking your
question in a forum that is about using Microsoft Word, as someone
there might know a tool that would help.

Davide

Harsh Chhabra

unread,
Jul 5, 2012, 9:49:26 PM7/5/12
to mathja...@googlegroups.com
okay thank you david.
Reply all
Reply to author
Forward
0 new messages