# Mathematical notation - PGML

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

## Mathematical Notation

Mathematical notation in PGML can be entered in two different formats: TeX and algebra notation. TeX (or LaTeX) is the format used by most mathematicians to write papers involving mathematics. You can recognize it from its use of backslashes to indicate "commands" and curly braces for grouping. An expression like \sum_{n=1}^\infty a_n is a TeX expression. Algebra notation is the notation used by students to enter their answers, and professors to create MathObjects in the PG problems that they write. You can use whichever form is most convenient for you, and you can even mix the two in the same PGML text block.

In addition to two types of math input, there are also two forms of math output: in-line and display math. In-line math tries to use as little vertical space as possible so as to not disrupt the line spacing within a paragraph. So things like summation signs will have their limits presented to the right of the sign rather than over top and underneath it, and fractions will use smaller fonts in the numerator and denominator to make the fraction smaller. Display mode, on the other hand, normally is presented on a line by itself, and so more vertical space can be used, so summation limits are shown above and below the summation sign.

Both input forms give you a way to indication whether you want in-line or displayed math. Note, however, that both forms can be used in-line. If you want your math to be displayed centered on a separate line (as it would be in TeX), you need to use the PGML centering and paragraph formatting to do that. This allows you to format the math the way you want it (flush left, centered, indented, or inline) to suit the problem you are writing.

### TeX Notation

To enter math in TeX notation, surround it by [...] for in-line math, and [...] for display-style math. For example

 This is in-line math: [\sqrt{b^2-4ac}], and this math is indented
in display-style, followed by centered math in display-style.

[\frac{x+1}{x-1}]

>> [\sum_{n=1}^\infty a_n] <<


### Algebra Notation

To enter math in algebra notation, surround it by [: ... :] for in-line math, and [:: ... ::] for display-style math. For example

 This is in-line math: [: sqrt(b^2-4ac) :], and this math is indented
in display-style, followed by centered math in display-style.

[:: (x+1)/(x-1) ::]

>> [:: Sum(n:1,infty; a_n) ::] <<


## Math and Variable Sibstitution

MathObjects can produce either a TeX version of themselves, or an algebra string version. In the traditional BEGIN_TEXT/END_TEXT block, you must be careful about how you insert a MathObject so as to produce the proper format. This involves either calling the TeX() method of the MathObject, or setting the Context to produce TeX strings automatically. This is awkward and easy to get wrong.

PGML, on the other hand, knows how you are using your MathObjects, and produces the proper format automatically. If a MathObject is inserted inside TeX delimiters, its TeX form is used, and if inside algebra delimiters (or not in math mode at all), its algebra form is used. So you should not have to worry about inserting MathObjects into PGML -- it should just work.

 $f = Formula("(x+1)/(x-1)"); BEGIN_PGML This is TeX: [ \int [$f]\,dx ]

This is algebra: [:: Int(x,[$f]) ::] This is text: [$f]
END_PGML


Here, the fist two should produce properly formatted integrals (one used TeX notation and the other algebra notation). The third one will include (x+1)/(x-1) as a literal algebra string.