# Formulae

### Brief Description

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.

### Overview

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:
[JAVA STUFF]
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.

### Syntax and Technical Overview

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>.

#### Size

The text displayed by Formulae can be a number of sizes, numbered sequentially from 0 (the largest) to 4 (the smallest):
"<SIZE>0FOX123abg</SIZE> <SIZE>1FOX123abg</SIZE> <SIZE>2FOX123abg</SIZE> <SIZE>3FOX123abg</SIZE> <SIZE>4FOX123abg</SIZE>"
[JAVA STUFF]

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.

#### & ; Pairs

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
The first three follow the HTML rules, so those of you in Web development should recognize these. (The &amp; before gt; and lt; are a kludge because browsers have a very hard time with just &lt; and &gt; It was a last minute bug I had no time to fix) I did not think anyone would be using up-carrots or underscores - ^ or _ - so I did not make the effort to add codes for them. The graphics for the applet are looked for in the directory "EDU/IMO/Formulae" off of the CODEBASE variable in the applet tag. The following are the standard graphics files - feel free to add any graphics you want. Just put them in the "EDU/IMO/Formulae" directory.

Geek Symbols
&alpha;
&beta;
&gamma;
&sum; (actually Sigma)
&pi;
&theta;
&isin; (element of/is in)
&inf; or &infinity;
&int; or &integral;
&rtarrow;
&ap; (approximately equal to)
&le; (less than or equal to)
&ge; (greater than or equal to)
&ne; (not equal to)
&ident; (identically equal to/defined as)
&plusmin; (plus or minus)

#### Boxes

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 AttachmentCodes
Subscripts _../_ or <SUB>..</SUB>
Superscripts/Exponents ^../^ or <SUP>..</SUP>
Things above <ABOVE>..</ABOVE>
Things below <BELOW>..</BELOW>
Usually, you can put subscripts and superscripts most places, but to be more precise, or if you're going to put something below or above something else, you'll want to tell the program what you want to attach the exponent/subscript/etc. to. Some Examples:

 x^2/^ [JAVA STUFF] {lim}x &rtarrow; 3x^2/^=9 [JAVA STUFF] 2H_2/_O_2/_ &rtarrow; 2H_2/_O+O_2/_ [JAVA STUFF]

#### Roots and Fractions

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 tag generates a root of magnitude n, where n is the first character after the <ROOT> tag. Fractions are described by the sequence {..<OVER>..} where the stuff between { and <OVER> is the numerator, and the stuff between <OVER> and } is the denominator.

 x={-b &plusmin; {b}^2/^-4ac2a} [JAVA STUFF] 38={8}^{13}/^=2 [JAVA STUFF]

#### Parentheses and Square Brackets

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.

#### Explanation of bugs / Future Enhancements

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.
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:
{&int;}<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:

• ExpContainer.java

• ExpFrac.java

• ExpParentheses.java

• ExpressionBox.java

• ExpRoot.java

• ExpSize.java

• ExpSymbol.java

• ExpText.java

• SymbolImage.java

• MalformedExpressionException.java

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.
• ExpressionTester.java

• DummyTesterWindow.java

• EqnEditor.java

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