[HOME] jsMath (Authors/2.x) [Prev][Top][Up][Next]

Loading jsMath in the Document HEAD

The usual way to load jsMath is with a SCRIPT command within the BODY of the document. This is because jsMath need to be able to write content to the body of the document (like the HTML needed to produce the jsMath button at the lower right of the page). There are also other, subtler items that must be written to document body as it is being created that can not be included during the BODY's onLoad handler, for example.

It may be better for some authors to be able to load jsMath.js in the document HEAD rather then the BODY (for example, if you are trying to add jsMath to a content-management system that doesn't have a convenient means of adding fixed content to the document body). For this reason, the portion of jsMath that must run in the document body has been isolated into a single routine, so you can load jsMath.js in the document HEAD (where it will know not to run the BODY routine), but then you have to run jsMath.Setup.Body() yourself somewhere in the body of the document. The jsMath.Process() or jsMath.ProcessBeforeShowing() commands can run in the BODY's onLoad hander, so the only thing (other than the SPAN and DIV tags that mark the mathematics itself) that must be in the body of the document is the jsMath.Setup.Body() call itself.

Note that jsMath.Setup.Body() really must be within the BODY of the document, not the onLoad handler, or it may not operate properly in some browsers. It is OK to run jsMath.Setup.Body() more than once (for example, before every SPAN or DIV used to mark mathematics), because it checks to see if it has already been run before it does anything. So if you are adding jsMath to a bulletin-board or blog system where you can insert text into the page based on tags entered by the user, it is OK to insert

    <SCRIPT>jsMath.Setup>Body()</SCRIPT><SPAN CLASS="math">
at the beginning of the math and
    </SPAN>
at the end.

It is possible to leave jsMath.Setup.Body() to the very bottom of the page, just before the jsMath.Process() or jsMath.ProcessBeforeShowing() call, but this is not recommended. One action that jsMath.Setup.Body takes is to set up the styles used by jsMath, and if portions of the page have already been displayed before jsMath.Setup.Body runs, the rendering of the page might change drastically, causing visual confusion for your reader.



Get jsMath at SourceForge.net. Fast, secure and Free Open Source software downloads [HOME] jsMath web pages
Created: 10 Jul 2005
Last modified: 02 Dec 2005 13:00:06
Comments to: dpvc@union.edu
[Next] Adding jsMath to a BLOG or Bulletin-Board System
[Up] Information for jsMath v2.x Authors
[Prev] Dynamic mathematics using jsMath