axiom-developer
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Axiom-developer] the XHTML-ization of jsMath


From: Bob McElrath
Subject: [Axiom-developer] the XHTML-ization of jsMath
Date: Mon, 31 Oct 2005 09:06:58 -0800
User-agent: Mutt/1.5.11

I decided to try my hand again at xhtml-izing jsMath.

Important developments in this space are:
1) firefox (1.5 betas) fixed innerHTML with XHTML documents.  (It is
still depricated, but works anyway)
2) I figured out how to do document.write in XHTML using the DOMParser
class:
    jsMath.domparser = new DOMParser();
    jsMath.write = function(s) {
        var newelement = jsMath.domparser.parseFromString(
            '<html xmlns="http://www.w3.org/1999/xhtml"; xml:lang="en"><body>'
            +s+'</body></html>','application/xhtml+xml');
        var appendme = newelement.firstChild.firstChild.firstChild;  // node is
            // Document, child is html, child of child is body, child of child 
of
            // child is the requested text.
        document.getElementsByTagName('body')[0].appendChild(appendme);
    }
using this functions rather than document.write basically fixes jsMath
for XHTML mode.  Using these methods, styles written to the head with
jsMath.writehead get applied and scripts written with jsMath.write get
loaded and evaluated.  (So no need for AJAX/XMLHTTPRequest as we
previously discussed)

Attached are several patches.
    1) jsMath-xhtml-lowercase.patch
        lower-cases all HTML and adds closing / to tags like <br />,
        <img ... /> etc.  This is required by XHTML and doesn't affect
        HTML.  (no functionality change)  This patch is huge, but
        trivial.  (Note that due to some strange line formatting in your
        distributed mimeTeX.js, this patch replaces that file, but the
        only changes are as described)
    2) jsMath-xhtml-mozfix.patch
        Fixes several warnings and errors generated by Firefox 1.5 beta:
            1. If a function ever returns a value, it must always return
                a value.  e.g. 
                    function() { if(a) { return 1 } return; }
                generates this warning.
            2. "variable hides argument" when a variable is declared
                with the same name as a function argument.
            3. various missing variable declarations, missing
                semicolons, etc.
            4. use cloneNode rather than setting innerHTML in
                jsMath-controls.html. (the old method fails in XHTML
                mode, the new way works for HTML and XHTML)
    3) jsMath-xhtml.patch 
        1. document.write replacement: adds the functions jsMath.write and
        jsMath.writehead.  (document.writeln is redundant so I replaced
        it with jsMath.write)  This may require some more tooling to be
        more cross-browser.  By isolating the document.write business we
        can be both cross browser and cross HTML/XHTML.

        2. Rewrote jsMath.Setup.Script to use DOM to add scripts, since
        document.write and innerHTML are depricated, and my jsMath.write
        doesn't actually load scripts (I think this is a mozilla bug:
            https://bugzilla.mozilla.org/show_bug.cgi?id=314435 )

(the patches should be applied in this order)

With all that, XHTML works, but it seems that the offsetWidth and
offsetHeight functions you use in BBoxFor do not work (they are always
zero), which results in a couple of NaN's in the generated code, and
obviously, things being measured improperly.  I'm trying to track down
whether this is a mozilla bug, and report it if so...

I would appreciate any comments on this, and if you could add these to
jsMath.  Obviously XHTML support will require further testing
(especially on other browsers).  However the first two patches above
involve no functionality change, and are the bulk of what is required
for XHTML, so I'd appreciate if you could incorporate those two into
jsMath.

--
Cheers,
Bob McElrath [Univ. of California at Davis, Department of Physics]

    "In science, 'fact' can only mean 'confirmed to such a degree that it would
    be perverse to withhold provisional assent.' I suppose that apples might
    start to rise tomorrow, but the possibility does not merit equal time in
    physics classrooms." -- Stephen Jay Gould (1941 - 2002)

Attachment: jsMath-xhtml-lowercase.patch
Description: Text document

Attachment: jsMath-xhtml-mozfix.patch
Description: Text document

Attachment: jsMath-xhtml.patch
Description: Text document

Attachment: signature.asc
Description: Digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]