Formulae - David's Equation formatter for the web - written, of course, in Java! Formulae really was only a five day project (ending about 1400 August 2 1996) to get some sort of decent Math-text formatter up and running so it could be incorporated into GeoAnimatorStudio (next year's ThinkQuest project). In the process, I came up with a darn good (in my opinion) program.
The editor above (EqnEditorApplet.class) is very simple. You type text in for the interpreter to display and hit the "Update" button. If your text complies with the specifications, you get nice looking text on the right side. Otherwise you get an error message and can usually see what the interpreter is yakking about by pressing the "Errors" button. When you get text the way you want it to look in a web page, you copy your work and paste it into your HTML editor as the "text" parameter to the FormulaeApplet.class and pop it into your web page. e.g.:
<applet code=EDU.IMO.Formulae.FormulaeApplet.class CODEBASE="../media" width=20 height=30>
<PARAM NAME="text" VALUE="<SIZE>2{a}^2/^</SIZE>">
</applet>
Which would produce:
The applet may come out a bit large, though, so you have to be careful about the dimensions (width and height) in the parameters to your applet. To help you out, if you view your web page in a Java-enabled browser, and look at your Java-console, you will see Formulae tell you the ideal dimensions for your Math text and you can adjust your <APPLET> code accordingly.
The specifications for this are based largely on the HTML spec. for math, though there are a number of notable deviations. Formulae will automatically strip any carriage returns from what you type, but any spaces you type will be accounted for in the output. Also, codes always (except for the fractions) occur in pairs - differentiable by the slash "/" in the ending half. For example: <SQRT>..</SQRT>.
You can set the font to one size larger or smaller (up or down) by by using the sequences "<SIZE>u..</SIZE>" and "<SIZE>d..</SIZE>", respectively.
These pairs usually serve to signify external graphics for symbols. Whatever is between the & and the ; is interpreted as the name of the image file minus the ".gif". There are five notable exceptions to this rule -
| & | ampersand |
| &gt; | greater than sign |
| &lt; | less than sign |
| &lcb; | left curly brace |
| &rcb; | right curly brace |
| Geek Symbols | |
|---|---|
| α |
|
| β |
|
| γ |
|
| ∑ (actually Sigma) |
|
| π |
|
| θ |
|
| ∈ (element of/is in) |
|
| &inf; or &infinity; |
|
| ∫ or &integral; |
|
| &rtarrow; |
|
| ≈ (approximately equal to) |
|
| ≤ (less than or equal to) |
|
| ≥ (greater than or equal to) |
|
| ≠ (not equal to) |
|
| &ident; (identically equal to/defined as) |
|
| &plusmin; (plus or minus) |
|
Boxes are the basic units that you can put things on and are denoted by {..} or <BOX>..</BOX>. Boxes are intrinsic in default text, parentheses (), and square brackets [].
| Box Attachment | Codes |
|---|---|
| Subscripts | _../_ or <SUB>..</SUB> |
| Superscripts/Exponents | ^../^ or <SUP>..</SUP> |
| Things above | <ABOVE>..</ABOVE> |
| Things below | <BELOW>..</BELOW> |
| x^2/^ | |
| {lim}<below>x &rtarrow; 3</below>x^2/^=9 | |
| 2H_2/_O_2/_ &rtarrow; 2H_2/_O+O_2/_ |
Expressing roots and fractions is also pretty simple. A Root can be described by either <SQRT>..</SQRT> or <ROOT>n..</ROOT>. The <SQRT> tag generates a square root, and the
Parentheses and Square brackets act as "stretchy delimiters," stretching vertically to fit what they are around. Hence,
'[' &
']' and
'(' &
')' must occur in pairs. You can attach anything to either of these pair sets that you can to a box.
The EDU.IMO.* packages are licensed to all under the GNU General Public License. Just include that note saying that David is the author of the original stuff and can be contacted at eger@home.dmv.com when you distribute the software to your friends. Also, if you make any changes, include a list of them and who you are and how you can be reached. All of the source code is included.
x={-b &plusmin; <SQRT>{b}^2/^-4ac</SQRT><OVER>2a}
<ROOT>38</ROOT>={8}^{1<OVER>3}/^=2
Parentheses and Square Brackets
Explanation of bugs / Future Enhancements
A decision was made near the end of the making of Formulae as to whether to center all of the items in a row vertically or not. As a comparison of the problem I will show you two examples.
An integral described by:
{∫}<ABOVE>b</ABOVE><BELOW>a</BELOW> {x}^3/^=<FRAC>{x}^4/^<OVER>4</FRAC>
And a short expression described by:
x+{x}^2/^
Old, vertically centered Formulae New, baseline-based Formulae 



I just couldn't stand that off-center x2. It really was a trade off, but in the future, I can make special codes for things like integrals so they will come out right. For now, I'll have to do without integrals. I'll put some special codes in later to take care of it - something like:
<INTEGRAL><ABOVE>. .</ABOVE><BELOW>. .</BELOW>. . .</INTEGRAL>
Also, I'll put in some handling for matrices. But now I have to move on to the larger project.
If you explore the package, you will find that there are a core set of classes:
The file EqnDisp.java is a container for an entire expression that can be used as an element in a Layout and is used by the three main programs.
The only Application is ExpressionTester.java, a program I used to check to see how the development of the Exp*.java classes was coming. It is basically a dumb window that, when you click on it, brings up an Equation Editor window, much like the EqnEditor Applet. To run ExpressionTester and have it work, you will needto run it from the directory that contains all of the images for the program. ExpressionTester consists of the following files.
The Equation Editor Applet is in EqnEditorApplet.java and the Formulae displaying applet is in FormulaeApplet.java.
If you're wondering what all of those fonts[] parameters are to all of the ExpressionBox derived constructors are, I was planning to implement features to let the writer specify Bold and Italic print, but never got around to it.
-David
![]()