jsMath Sample Page
This is a sample file showing you how to use jsMath to display mathematics in your web pages. Be sure you have followed the installation instructions before loading this file. Also, you may need to edit thejsMath/easy/load.js
file to set the root URL for where jsMath can be found on your web site. The rest of this document gives examples of how to enter mathematics in your pages. Depending on the settings injsMath/easy/load.js
, not all of the mathematics below will be processed by jsMath. Experiment with the settings in that file to see how they work.
Some mathematics using
The easiest way to enter mathematics is to use jsMath's tex2math plugin to identify the mathematics in your document by looking for \rm\TeX-like math delimiters. Here are some math equations using those markers. Some inline math: $\sqrt{1-x^2}$ or \(ax^2+bx+c\), and some displayed math: $$\int {1\over x}\,dx = \ln(x)+C$$ and \[\sum_{i=1}^n i = {n(n+1)\over 2}.\] Note that the first of these will not be processed unless you have enabledtex2math
processSingleDollars
injsMath/easy/load.js
, which is disabled by default. That is because a single dollar sign can appear in normal text (as in "That will cost from $3.50 to $5.00 to repair"), and you don't want jsMath to try to typeset the "3.50 to " as mathematics.If you enable
processSingleDollars
, you might also want to enablefixEscapedDollars
, so that it is possible to enter dollar signs by preceding them with a backslash. Here's one that you can use to see the results of these settings: \$ (an escaped dollar) and $x+1$ (not escaped).It is also possible to use your own custom delimiters for marking the mathematics within your pages. If you uncomment the
customDelimiters
array injsMath/easy/load.js
, then the following math will be typeset by jsMath: some inline math [math]\sin(2\pi x)[/math] and some display math [display]x={-b\pm \sqrt{b^2-4ac}\over 2a}.[/display] You may change the delimiters to nearly anything you want, but they can not look like HTML tags, since some browsers will eliminate unknown tags, and jsMath doesn't get to look for the custom delimiters until after the browser has interpreted the page.
You can prevent thetex2math
plugin from processing a portion of a page by enclosing it in a tag that is ofCLASS="tex2math_ignore"
. Often, that tag will be aDIV
orSPAN
, but it can be anything. This paragraph is wrapped in a DIV tag withCLASS="tex2math_ignore"
, and so no math delimiters will be processed: $f\colon X\to Y$, \(x^2 \gt 5\), $$1\over 1+x^2$$ and \[\matrix{a& b\cr c& d}.\] Note that this includes the processing of escaped dollars (\$) and custom delimiters ([math]a \mapsto a^2[/math]) as well. This makes it possible to produce examples of how to enter mathematics on your site, for instance.JsMath will automatically ignore the text within
PRE
tags, so you can easily enter examples that way as well:$f\colon X\to Y$, \(x^2 \gt 5\), $$1\over 1+x^2$$ and \[\matrix{a& b\cr c& d}.\]Note that since the < and > symbols are used to denote HTML tags, these can be hard to incorporate into your \rm\TeX code. Often, putting spaces around the < or > will make it work, but it is probably better to use
\lt
and\gt
instead. Also note that thetex2math
plugin does not allow any HTML tags to be within the math delimiters, with the exception of<BR>
, which is ignored.See the tex2math documentation for more information.
Mathematics without
tex2math
If you are not using
tex2math
, then you will need to enclose your mathematics withinSPAN
orDIV
tags that are ofCLASS="math"
. Use aSPAN
for in-line math and aDIV
for displayed math. For instance, P = (x_1,\ldots,x_n) andA = \left\lgroup\matrix{a_{11}& \cdots& a_{1m}\cr \vdots& \ddots& \vdots\cr a_{n1}& \cdots& a_{nm}\cr}\right\rgroup.
More information
See the jsMath example files for more examples of using jsMath. There are several extensions to \rm\TeX that allow jsMath to interact better with HTML. These provide features such as colored text, tagging mathematics with CSS styles, and so on.
More information is available from the jsMath author's documentation site. JsMath also has a home page at SourceForge, and that includes public forums for jsMath where you can ask the jsMath user community for help.