ShowMath Applet
A Java Applet for Displaying Mathematical Equation on HTML Pages
October, 1996.
ShowMath is a Java applet developed by
Ariel Shamir for displaying mathematical formulas and equations on HTML pages. The
applete receives as input a string in (a subset of) LaTeX style syntax, and converts
it to displayed mathematical formula inside the HTML page.
The applet is based on a java lexical analayzer: JavaLex
Written by Elliot Berk
[edited by A. Appel]:
And on a java based LR-parser: java_cup
(Author: Scott Hudson
[home page] )
Fonts
This applet relays heavily on one particular symbol font, which I assumed is common and
available on all platforms and operating systems. However, it turns out that Netscape on
any platform, and appletviewer on unix, cannot find this font or can find only certain
sizes, and not a continous range as required by this applet. This of course, damages the
performance of the applet and only simple equations such as shown here are viewable.
To appreciate the possibilities of this applet you can use appletviewer (for example
on Windows platforms) and try the many exampels included in "examples.html" file in the
current directory. I hope to try and overcome this problem sometime later.
Some Examples:
Specifications
The two parameters for the applet are:
-
<mathtext> this is the Latex-Style math text to be parsed. The text
should begin with a $ sign and end with a $ sign. The text can include common LaTeX
style directions such as "$a_{i}$" "$\frac{1}{2}$" or "\sqrt{100}". A more elaborate
description will (hopefully) be added soon. For now, most of the common directions are
supported and in any doubt you can look at the examples or just check your equation
on the applet.
-
<maxfontsize> for the maximum (initial) font size. This can be used to scale
the equation up/down.
WishList/Problems/Discussion
I will describe some of the major problems/drawbacks in this applet, with the hope that
some day I will find time to fix them and/or enhance the applet to include more features.
-
The parser is Very sensitive to syntax errors (especialy since I send "space"
as a tokens, i.e. spaces count!, and multiple spaces are sent as one space).
-
To make things worse, there is no error recovery in the parser so any error just stops
the parsing.
-
The subset of LaTeX was chosen mainly according to what characters the common TrueType
Symbol font includes, and hopefully your browser can find this type of symbol font and
use it, or else... well, there is no point in math equations without any math symbols is there?
-
Due to some bug (feature?) a small change in font size (39 instead of 40 etc.) might
sometimes improve the overall look, so try playing with that until you get a better
result (or until I find out what causes this).
-
Some more features can be added (which means they are not supported in this version):
-
Overcome symbol font problems in netscape and support different type of fonts (italic etc.)
WebEQ: a similar applet
Someone has drawn my intension to a similar Java applet for showing math on a HTML page
(If only I had known previously...). It is called
WebEQ. Some notes
regarding this are:
-
Their syntax is based on an HTML3.0 proposal for math, My syntax is taken from LaTeX.
-
They build a symbol font by using gif files instead of a real font,
this means I am not alone in my difficulty of using symbol fonts.
-
They use only three predefined sizes of fonts in order to display equations, and I
use a whole range and calculate the proportional sizes. Therefore they can not display
very nicely a long line of symbol-recursion in equations such as:
\sqrt{\sqrt{sqrt{3}}} a^{b^{c^{d^{f}}}}
and, they cannot scale the equation continuously!
NEW! NEW! Another web site for LaTeX math inside HTML is:
HotEqn
The Source Files
-
ShowMath.java: The main program.
-
LaTeX.lex: The lexical analayzer definition file.
-
LaTeX.cup: The parser definition file.