Mathematical notation - PGML

From WeBWorK_wiki
Jump to navigation Jump to search

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 three forms of math output: inline, display-style inline, and display. Inline 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-style inline math uses more vertical space, so summation limits are shown above and below the summation sign. This often means that more space is used between adjacent lines. Display math places the math on its own line, centered, with some buffering space above and below. And things like the summation limits are handled just like display-style inline.

Both input forms give you a way to indicate whether you want inline, display-style inline, or display math.

TeX Notation

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

 This is in-line math: [`\frac{x+1}{x-1}`], and this math is inline display-style: [``\frac{x+1}{x-1}``], and this math is display: [```\frac{x+1}{x-1}```]

Algebra Notation

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

 This is in-line math: [:(x+1)/(x-1):], and this math is inline display-style: [::(x+1)/(x-1)::], and this math is display: [:::(x+1)/(x-1):::]

The algebra notation uses MathObjects to parse the mathematics for display. By default, it uses a special context called the Typeset Context that includes many more functions and operators than most other contexts. It is designed to allow you to produce sophisticated mathematical output without the need for TeX, if you prefer a simpler notation.

If you want to use a different context, however, you can select one by putting its name in braces after the closing bracket for the math delimiters.

 This is in the Vector context: [: <1,2,3> :]{"Vector"}

You can also provide a Context object instead.

 $context = Context("Vector");
 BEGIN_PGML
 This is also in Vector context: [: <1,2,3> :]{$context}
 END_PGML

Finally, if you want to use the current context rather than the Typeset context, place an asterisk after the delimiter.

 Context("Vector");
 BEGIN_PGML
 This is also in Vector context: [: <1,2,3> :]*
 END_PGML

Math and Variable Substitution

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