[HOME] jsMath (Authors) [Prev][Up][Skip][Next]

Loading Extensions in jsMath

Since version 3.1, jsMath has the ability to automatically load extensions when they are used by the mathematics on a particular page. Certain lesser-used functions (like the double-clicking of mathematics to view the TeX source code, and the \mathchoice macro) have been removed from the base jsMath.js file and moved to extensions in order to speed up the initial download of jsMath. You don't need to do anything special to use these extensions, since they will be loaded automatically when needed; you should not even be aware that they are extensions.

The ability to load extensions at run time should make it easier to add features to jsMath. For these (non-standard) extensions, you may need to load a small definition file to declare the macros for the extension so that they will load the full package when they are used. You can load such a definition file in several ways.

If you are using the easy/load.js file, you can load extensions by placing their names in the loadFiles list. For example

    loadFiles: ["extensions/moreArrows.js"],
will load the jsMath/extensions/moreArrows.js file, which defines new macros for handling arrows that provide for labels above and below them.

Similarly, if you are using the autoload plugin, you can add the extension file to the jsMath.Autoload.loadFiles array.

If you are loading jsMath.js by hand rather than using easy/load.js or then autoload plugin, then you must use the jsMath.Extension.Require() command; for example

    <SCRIPT>
      jsMath.Extension.Require("moreArrows");
    </SCRIPT>

Alternatively, you can use the \require{} macro within a mathematical formula to load an extension:

    <SPAN CLASS="math">
      \require{moreArrows}
      \xrightarrow{f}
    </SPAN>
This loads the jsMath/extensions/moreArrows.js file and then uses one of the macros it defines. This makes it possible to load extensions into jsMath even when you can't enter SCRIPT tags into the web page (e.g., when you are using a content-management system).

One important type of extension to load is the definition file for a font that is not one of the six built-in fonts. If you use the \char macro to access a font that has not been loaded, jsMath will load its definition file automatically. (See the page on adding fonts to jsMath.)


Defining Your Own Extensions

Three things can trigger jsMath to load an extension: a macro, a LaTeX environment, or a font reference. If you want \xrightarrow to autoload the moreArrows.js extension, include

    <SCRIPT>
      jsMath.Extension.Macro('xrightarrow','moreArrows');
    </SCRIPT>
in your web page. Note that the moreArrows.js file should redefine \xrightarrow to do whatever it is really supposed to do (otherwise you will receive an error message after the extension is loaded).

Similarly, to have a macro load a font, use

    <SCRIPT>
      jsMath.Extension.Font('bbold');
    </SCRIPT>
so that \bbold will automatically load the bbold font definition file (see the page on creating your own fonts for information about the font definition files). If you include definitions like
    <SCRIPT>
      jsMath.Macro('boxplus','\\mathbin{\\char{msam10}{1}}');
    </SCRIPT>
in your page, this will cause \boxplus to autoload the msam10 file and then make a binary operator out of the character at position 1 in that font.

JsMath also has the ability to load a font based on a mathchardef definition. This is convenient if you are going to define control sequences to access many characters in a font (as is done, for example, in the AMSsymbols extension). In this case, you issue a command like the following:

    <SCRIPT>
      jsMath.Extension.MathChar('msam10',{
        boxminus:  [2,0x0C],
        boxtimes:  [2,0x02],
        boxdot:    [2,0x00],
        boxplus:   [2,0x01]
    </SCRIPT>
which defines four control sequences referring to characters in the msam10 font; the font will be loaded automatically whenever one of these four control sequences is used. The two values assigned to each represent the TeX math class (see the TeXbook p.154), and a character position within the font. In this example, all four are binary operators (class 2) and the character positions are given as hexadecimal constants.

Finally, a LaTeX environment can be tied to a file to be autoloaded using the command:

    <SCRIPT>
      jsMath.Extension.LaTeX('picture','picture-environment');
    </SCRIPT>
This would cause \begin{picture} to load jsMath/extensions/picture-environment.js (this is just an example; that extension doesn't exist yet). As with macros, the extension file should define what the given environment should actually do.


Get jsMath at SourceForge.net. Fast, secure and Free Open Source software downloads [HOME] jsMath web pages
Created: 17 Sep 2005
Last modified: 13 Sep 2008 10:07:37
Comments to: dpvc@union.edu
[Next] Processing only Part of a Web Page
[Skip] Browser Support for jsMath
[Up] Information for jsMath Authors
[Prev] Defining Macros for jsMath