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

The eqn-number Extension

This extension allows you to have numbered displayed equations and references to those equations within your HTML pages. It uses \label and \ref macros similar to those in LaTeX. References work both forward and backward, but only to equations within the same file; you would need to hand code the references to equations in other HTML files.

Equations can be set to be numbered automatically, or numbers can be requested for specific equations individually. You can set the styles used for the numbering (for example, to make them be on the left rather than the right) and can specify the formats for how the labels and references should appear within the text of your page.

If you want to refer to the number elsewhere in your page, include \label{ID} in the TeX code for the displayed equation, where ID is an identifier that will be used to refer to the equation later on. For example:

    <DIV CLASS="math">
      \sqrt{x+1\over x-1}
would create a numbered equation with an ID of eqn1.

To refer to an equation with a particular ID, use \ref{id} in your web page at the point you want the reference. Note, however, that unlike real TeX or LaTeX, the \ref command must be within math mode (as jsMath does not process anything outside of math mode), and it must be the only thing in that particular math element. So you could use

   as seen in equation <SPAN CLASS="math">\ref{eqn1}</SPAN>
to refer to the formula labeled eqn1. If you are using the tex2math plugin, then you could use
   as seen in equation \(\ref{eqn1}\)
to do the same thing, or possibly
   as seen in equation $\ref{eqn1}$
if you have enabled the single-dollar math delimiters.

If you have configured eqn-number to perform automatic numbering, then every display-math formula will get an equation number automatically, whether it is labeled or not; otherwise, only those with an explicit \label command will be numbered. If automatic numbering is in effect, you can prevent specific equations from being numbered by using the \nolabel command somewhere within the TeX code for the equation.

Configuring the eqn-number plugin

You control the settings for the eqn-number plugin by setting values in the jsMath.EqnNumber object before loading the plugin.

If you want automatic equation numbers, use

    <SCRIPT> jsMath.EqnNumber = {autonumber: 1} </SCRIPT>

You can control the placement and style of the numbers by setting

      jsMath.EqnNumber = {styles: {
        '.jsMath_number': {style-settings},
        '.jsMath_ref':    {style-settings},
where style-settings are lists of name-value pairs that indicate the style settings you want to override. The defaults are equivalent to
      jsMath.EqnNumber = {styles: {
        '.jsMath_number': {
          position: 'absolute',
          right: '2em', top: '50%', 'margin-top': '-.5em',
          height: 'auto', width: 'auto'
        '.jsMath_ref': {'text-decoration': 'none'}

For example,

      jsMath.EqnNumber = {styles: {
        '.jsMath_number': {right: null, left: '1em'}
would put the numbers on the left at 1em in from the margin.

You can control the way the numbers are formatted by supplying a function for jsMath.EqnNumber.format. The default is to just return the number, but you could alter this, for example to include a dot:

      jsMath.EqnNumber = {format: function (n) {return n+"."}}};

You can also specify how the numbers are used within the labels and references through the formatLabel and formatRef values. The defaults are:

      jsMath.EqnNumber = {
        formatLabel: function (n) {
          return '<A NAME="eqn-'+n+'">('+n+')</A>'
        formatRef: function (n) {
          return '(<A CLASS="jsMath_ref" HREF="#eqn-'+n+'">'+n+'</A>)'
Note that these include the HTML code to make a named anchor for the label and a link from the reference. You can override these behaviors by supplying your own functions. For example, you could include the parenthses within the link in a reference if you wish.

Loading the eqn-number plugin

To activate the eqn-number extension, add "extensions/eqn-number.js" to the loadFiles array in your jsMath/easy/load.js file:
    loadFiles:  ["extensions/eqn-number.js"],

If you are using the autoload plugin instead of easy/load.js, you can set the jsMath.Autoload.loadFiles array to include "extensions/eqn-number.js" in order to have the extension loaded automatically when jsMath is needed.

If you are loading jsMath.js by hand rather than using easy/load.js or the autoload plugin, then include the command

in your HTML file after loading jsMath. Alternatively, you can use
    <SPAN CLASS="math">
to activate the extension from within the typeset mathematics itself.

Get jsMath at SourceForge.net. Fast, secure and Free Open Source software downloads [HOME] jsMath web pages
Created: 20 Mar 2006
Last modified: May 4, 2009 9:55:37 PM
Comments to: dpvc@union.edu
[Next] The autobold Extension
[Skip] Browser Support for jsMath
[Up] Information for jsMath Authors
[Prev] The AMSsymbols Extension