Difference between revisions of "Mathematical notation - PGML"
(Initial version) |
(Add information about context selection.) |
||
Line 29: | Line 29: | ||
>> [:: Sum(n:1,infty; a_n) ::] << |
>> [:: Sum(n:1,infty; a_n) ::] << |
||
+ | |||
+ | 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 Sibstitution == |
== Math and Variable Sibstitution == |
Revision as of 15:09, 10 May 2015
Contents
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) ::] <<
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 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.