473,403 Members | 2,270 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

Outputting MathML via Javascript

Hi,

This is probably really simple, but I've only just been asked to look
at this and I've spent a full day trying to get it to work, so any help
will be very gratefully received!

At present I have an HTML page which calls a series of javascript
functions which output text into a browser. A client then asked if it
was possible to output mathematical equations instead of just plain
text! The solution I originally came up with was the MathML was set in
a javascript variable, displayed via the HTML page and the user needed
to download MathPlayer to be able to see the equation correctly.
However, because the clients users may access the pages from computers
where they can't install plug ins, if possible I need a solution that
won't require a plug in to work!!!!

That's when I came across the suggestions on the W3C site and created
the following simple example following the instructions on the site:

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="pmathml.xsl"?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
</head>

<body>
<h1>Example</h1>
....
<math xmlns="http://www.w3.org/1998/Math/MathML">
<mi>x</mi><mo>+</mo><mn>3</mn>
</math>
<br/><br/>

<math xmlns='http://www.w3.org/1998/Math/MathML'>
<mrow>
<mn>5</mn>
<msqrt><mrow><mo>-</mo><mn>1</mn></mrow></msqrt>
</mrow>
</math>

<script type="text/javascript" language="javascript">
document.write("<br/><br/>simple text<br/><br/>");
document.write("<math
xmlns='http://www.w3.org/1998/Math/MathML'><mrow><mn>5</mn><msqrt><mrow><mo>-</mo><mn>1</mn></mrow></msqrt></mrow></math>");
</script>
</body>
</html>

as an XHTML page. In the above example the first 2 bits of MathML are
displayed correctly, but the MathML displayed using the document.write
is not! Therefore, have I missed something? Is this possible? Does it
need to be an XHTML page or can I 'embed' this into my existing HTML
page?

Cheers

Matt

Dec 14 '05 #1
3 1638


BakedBean wrote:

<script type="text/javascript" language="javascript">
document.write("<br/><br/>simple text<br/><br/>");
document.write("<math
xmlns='http://www.w3.org/1998/Math/MathML'><mrow><mn>5</mn><msqrt><mrow><mo>-</mo><mn>1</mn></mrow></msqrt></mrow></math>");
</script>
as an XHTML page. In the above example the first 2 bits of MathML are
displayed correctly, but the MathML displayed using the document.write
is not!


Which browser is that? Mozilla does support mixed namespace XML document
with XHTML and MathML but it does not support document.write in such
documents. Check the JavaScript console, I think it shows a script error
for document.write calls in XHTML documents.

What should be possible in Mozilla is using the W3C Core DOM to create
elements in the MathML namespace e.g.
var mnElement = document.createElementNS(mathMLNamespace, 'mn');
mnElement.appendChild(document.createTextNode('5') );
mrowElement.appendChild(mnElement);
var msqrtElement = document.createElementNS(mathMLNamespace, 'msqrt');
var mrowElement2 = document.createElementNS(mathMLNamespace, 'mrow');
var moElement = document.createElementNS(mathMLNamespace, 'mo');
moElement.appendChild(document.createTextNode('-'));
mrowElement2.appendChild(moElement);
var mnElement2 = document.createElementNS(mathMLNamespace, 'mn');
mnElement2.appendChild(document.createTextNode('1' ));
mrowElement2.appendChild(mnElement2);
msqrtElement.appendChild(mrowElement2);
mrowElement.appendChild(msqrtElement);
mathElement.appendChild(mrowElement);

document.body.appendChild(mathElement);

Or you could use DOMParser to parse a string with MathML markup and then
use importNode.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Dec 14 '05 #2
Martin,

Thanks for the reply. Would this work in IE? I hear IE 7 is on it's
way, does anyone know if MathML is better supported?

I think I need to have a look at the W3C Core DOM and try to understand
that now!!! Are there any other reference sites/books you could
suggest?

Cheers

Matt

Dec 14 '05 #3


BakedBean wrote:

Would this work in IE? I hear IE 7 is on it's
way, does anyone know if MathML is better supported?
As far as I understand IE does not support MathML natively (like Mozilla
does) but rather with the help of a plugin. I don't know whether that
plugin allows scripting the MathML content, I doubt that.
The script I wrote is meant for W3C DOM Level 2 compatible
implementations which support document.createElementNS. IE 6 does not do
that, nor will IE 7 I think as "real XHTML" (meaning XHTML served as
application/xhtml+xml or at least application/xml) is not an aim for IE 7.
I think I need to have a look at the W3C Core DOM and try to understand
that now!!! Are there any other reference sites/books you could
suggest?


Reference site is certainly <http://www.w3.org/TR/DOM-Level-2-Core/>.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Dec 14 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Joachim Spoerhase | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hello, does anybody know a good WYSIWYG MathML Equation Editor for Linux? Many thanks in advance Joachim Spoerhase -----BEGIN PGP...
2
by: Florian Huber | last post by:
Hello! i've got a Problem: I'd like to build a website, which contains HTML and MathML, but it should be readable for most of the site visitors. I know about the ways mentioned at the...
2
by: Jon Thackray | last post by:
I'm trying to use the MathML DTD and stylesheets, but get some problems with xmlns attributes. If I do something like <math xmlns="http://..."> .... </math> then xmllint and xalan in...
4
by: Jon Thackray | last post by:
I'm trying to build some mathml for a paper. I've got the mathml2 dtd, and the style sheets also from the canonical website http://www.w3.org/Math/. But I'm having some trouble. I've input the...
7
by: DKM | last post by:
I need an equivalent for the following: document.getElementById('equation').update(); from Mathplayer to use it in Mozilla based browser. When I change any text node, the page updates just...
1
by: Stefan Behnel | last post by:
Hi! I was looking for an implementation of a parser/model/serializer for Content MathML in Python. Does anyone know about something useful? I need to work with math expressions...
3
by: Michel de Becdelièvre | last post by:
I have some *performance* trouble reading MathML files in my application (in ASP.Net). - I have small MathML files (2-3k) as input - as (almost) all MathML files these use entities. I have no...
3
by: dan_andrews | last post by:
<?xml version="1.0"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0//EN" "http://www.w3.org/TR/MathML2/dtd/xhtml-math11-f.dtd" > <html xmlns="http://www.w3.org/1999/xhtml">...
3
by: Fred | last post by:
I'm experimenting with MathML, and have run into difficulty. Given the simple XML: <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE component SYSTEM "mathml2.dtd"> <mathDisplay> <math> <msub>...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.