Difference between revisions of "Mathematical notation - PGML"

From WeBWorK_wiki
Jump to navigation Jump to search
m (fix spelling typo)
(→‎Mathematical Notation: document display-style inline versus display math)
Line 4: Line 4:
 
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 <code>\sum_{n=1}^\infty a_n</code> 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.
 
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 <code>\sum_{n=1}^\infty a_n</code> 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.
+
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 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.
 
  +
Both input forms give you a way to indicate whether you want inline, display-style inline, or display math.
   
 
=== TeX Notation ===
 
=== TeX Notation ===
   
To enter math in TeX notation, surround it by <code>[`...`]</code> for in-line math, and <code>[``...``]</code> for display-style math. For example
+
To enter math in TeX notation, surround it by <code>[`...`]</code> for inline math, <code>[``...``]</code> for display-style inline math, and <code>[```...```]</code> for display math. For example
   
This is in-line math: [`\sqrt{b^2-4ac}`], and this math is indented
+
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}```]
in display-style, followed by centered math in display-style.
 
 
[``\frac{x+1}{x-1}``]
 
 
>> [``\sum_{n=1}^\infty a_n``] <<
 
   
 
=== Algebra Notation ===
 
=== Algebra Notation ===
   
To enter math in algebra notation, surround it by <code>[: ... :]</code> for in-line math, and <code>[:: ... ::]</code> for display-style math. For example
+
To enter math in algebra notation, surround it by <code>[: ... :]</code> for inline math, <code>[:: ... ::]</code> for display-style inline math, and <code>[::: ... :::]</code> for display math. For example
   
This is in-line math: [: sqrt(b^2-4ac) :], and this math is indented
+
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):::]
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.
+
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.
 
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.
Line 33: Line 33:
 
END_PGML
 
END_PGML
   
Finally, if you want to use the current context rather than the Typeset context, place an asterisk after the delimiter
+
Finally, if you want to use the current context rather than the Typeset context, place an asterisk after the delimiter.
   
 
Context("Vector");
 
Context("Vector");

Revision as of 23:57, 5 January 2019

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