Editing Introduction to PGML

Jump to navigation Jump to search

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.

Latest revision Your text
Line 5: Line 5:
 
PGML provides easy means of creating paragraphs, lists, headers, indentation, centering, and other formatting features. It also allows you to link the answer directly to its answer blank for easy problem maintenance. The underlying idea behind PGML is to make what you type as the text of the problem look as close to the result on screen as possible.
 
PGML provides easy means of creating paragraphs, lists, headers, indentation, centering, and other formatting features. It also allows you to link the answer directly to its answer blank for easy problem maintenance. The underlying idea behind PGML is to make what you type as the text of the problem look as close to the result on screen as possible.
   
PGML is for creating the ''text'' of the problem and for associating answers to their answer blanks. The setup and computational portion of the problem is still done in the traditional way. PGML integrates with [[:Category:MathObjects|MathObjects]] to make it easy to work with answers and answer checkers, and to present mathematics within the text of your problem.
+
PGML is for creating the ''text'' of the problem and for associating answers to their answer blanks. The setup and computational portion of the problem is still done in the traditional way. PGML integrates with MathObjects to make it easy to work with answers and answer checkers, and to present mathematics within the text of your problem.
   
 
PGML can also be used to create the solutions to your problem, with many of the same advantages that you have for the text of the problem itself.
 
PGML can also be used to create the solutions to your problem, with many of the same advantages that you have for the text of the problem itself.
Line 90: Line 90:
 
To right-justify some text, use just <code>&gt;&gt;</code> at the left
 
To right-justify some text, use just <code>&gt;&gt;</code> at the left
   
>> Right-justified text
+
>> Right-justified text
 
 
 
>> Right-jutified paragraph
 
>> Right-jutified paragraph
Line 169: Line 169:
 
=== Mathematical Notation ===
 
=== Mathematical Notation ===
   
PGML allows you to specify mathematics in two different formats: TeX and calculator notation. The TeX notation allows you to use the standard TeX and LaTeX commands to format your mathematics. The calculator notation uses MathObjects to parse and format the mathematics (so this is the notation that you use to create formulas in your PG problems, and that students use to enter their answers). Both formats come in three forms: inline, display-style inline, and display style. The inline form uses spacing rules that try to minimize the impact on line spacing, while display-style inline allows for easier readability at the cost of using more vertical space. Full display style places the math on its own line with buffering space above and below.
+
PGML allows you to specify mathematics in two different formats: TeX and calculator notation. The TeX notation allows you to use the standard TeX and LaTeX commands to format your mathematics. The calculator notation uses MathObjects to parse and format the mathematics (so this is the notation that you use to create formulas in your PG problems, and that students use to enter their answers). Both formats come in two forms: in-line and display style. The in-line form uses spacing rules that try to minimize the impact on line spacing, while display style allows for easier readability at the cost of using more vertical space.
   
To use TeX-formatted mathematics, enclose it in <code>[`...`]</code> for inline math, <code>[``...``]</code> for display-style inline math, and <code>[```...```]</code> for display style math.
+
To use TeX-formatted mathematics, enclose it in <code>[`...`]</code> for in-line math and <code>[``...``]</code> for display-style math.
   
To use calculator notation, enclose it in <code>[: ... :]</code> for inline math, <code>[:: ... ::]</code> for display-style inline math, and <code>[::: ... :::]</code> for display style math.
+
To use calculator notation, enclose it in <code>[: ... :]</code> for in-line math and <code>[:: ... ::]</code> for display-style math.
   
 
For example,
 
For example,
Line 181: Line 181:
 
What [:x:] makes [:(x+2)/3 = 1:]?
 
What [:x:] makes [:(x+2)/3 = 1:]?
   
Both produce the same results with inline math.
+
both produce the same results (with in-line math).
   
And for example,
 
  +
Note that, unlike with TeX, display-mode math is not automatically centered on a separate line. If you want that, you must provide the formatting for that yourself:
   
What [`x`] makes [``\frac{x+2}{3} = 1``]?
 
  +
[``\sum_{n=0}^{10} 2^n``] is flush left
 
 
What [:x:] makes [::(x+2)/3 = 1::]?
 
  +
[``\sum_{n=0}^{10} 2^n``] is indented
 
Both produce the same results with inline math, but the second math is display-style inline, so the fraction numerator and denominator typically will appear larger. This can comes at the cost of awkward spacing between consecutive lines of text.
 
 
And for example,
 
 
Find [`x`] that solves the equation: [```\frac{x+2}{3} = 1```]
 
 
 
Find [:x:] that solves the equation: [:::(x+2)/3 = 1:::]
 
  +
>> [``\sum_{n=0}^{10} 2^n ``] is centered <<
 
Both produce the same results with inline math for the "x", and then displayed math on its own line for the equation.
 
   
 
== Interaction with PG ==
 
== Interaction with PG ==
   
There are two important ways that PGML must interact with the rest of the PG problem: inserting the values of perl variables into the problem (e.g., the randomized parameters for the problem), and making the answer blanks where students will enter their answers and tying those blanks to the correct answers. Both of these are easy to do, and are described below.
 
  +
answer checkers
  +
variable substitution
   
=== Variable Substitution ===
 
  +
== Further Reading ==
   
To insert the value of a variable into your PGML text, enclose the variable name with <code>[...]</code>. For example, if you have a variable <code>$a</code> in your problem, then you can use
 
  +
links to other pages
 
BEGIN_PGML
 
Suppose that a train leaves Chicago traveling [$a] miles per hour due south.
 
END_PGML
 
 
You can access array or hash entries similarly, e.g., <code>[$b[0]]</code> or <code>[$c{neg}]</code> or <code>[$d->{period}]</code>.
 
 
Note that a variable that holds a [[:Category:MathObjects|MathObject]] can produce either a TeX string or a calculator-notation string; which one it produces depends on the context in which it is used. If it is inserted inside of TeX math delimiters (e.g., inside <code>[`...`]</code>), it will produce its TeX form, while if it is inserted inside calculator delimiters (e.g., <code>[: ... :]</code>), or not inside any delimiters, then it produces calculator-style notation. So if <code>$f = Formula("(x+1)/(x-1)")</code>, then
 
 
Suppose [`f(x) = [$f]`].
 
 
and
 
 
Suppose [:f(x) = [$f]:].
 
 
will both produce properly formatted mathematical output with no special handling needed on your part. (Note that this is in sharp contrast to the traditional <code>BEGIN_TEXT/END_TEXT</code> approach, which requires you to handle the TeX versions specially.)
 
 
=== Answer Blanks ===
 
 
One of the key ingredients in any WeBWorK problem is answer blanks where students can enter their answers. In PGML, these are created using <code>[_____]</code>, where the number of underscores indicates how wide the answer blank should be. For example
 
 
If [: x = [$a] :], then the value of [: x^2 :] is [___________]
 
 
sets up an answer blank for the student to enter his or her value for <math>x^2</math>. The answer checker for this blank can be provided via <code>ANS()</code> in the traditional way. PGML provides an easier way to tie answers to answer blanks, however. Simply insert the answer inside braces following the answer blank:
 
 
If [: x = [$a] :], then the value of [: x^2 :] is [___________]{$a**2}
 
 
Note that, as in this example, you can use a mathematical expression, or you could use a constant, or a variable. Here, you don't need to enclose the variable in brackets, as this is a perl expression, not PGML text.
 
 
If your answer is a formula, enclose it in quotation marks
 
 
The parabola that opens upward and passes through [`x = 1`] and [`x = -1`]
 
is [` y = `] [_______________________]{"x^2-1"}
 
 
or use a Formula MathObject:
 
 
$f = Compute("x^2-1");
 
 
BEGIN_PGML
 
The parabola that opens upward and passes through [`x = 1`] and [`x = -1`]
 
is [` y = `] [_______________________]{$f}
 
END_PGML
 
 
If your expression has random parameter, you insert them as you would in a call to the MathObject <code>Compute()</code> command:
 
 
$a = random(2,5,1);
 
 
BEGIN_PGML
 
The parabola that opens upward and passes through [`x = [$a]`] and [`x = 0`]
 
is [` y = `] [_______________________]{"x(x-$a)"}
 
END_PGML
 
 
(Again, no brackets are needed in the answer string).
 
 
If you want to pass parameters to a MathObject answer checker, you can:
 
 
$f = Compute("sqrt(x^2-10)");
 
 
BEGIN_PGML
 
The answer is [_________________]{$f->cmp(limits=>[4,6])}
 
END_PGML
 
 
This is just an overview of working with answer blanks. There are other possibilities for what you can pass as the answer, and how you can control the format of the answer blanks. See the documents linked below for more details.
 
 
== Further Reading ==
 
* '''[[:Category:PGML Syntax|PGML Syntax]]''' -- reference documentation for the various formatting commands
 
* '''[[:Category:PGML Answers|Answer Checking]]''' -- reference documentation for answer checking in PGML
 
   
 
[[Category:PGML]]
 
[[Category:PGML]]

Please note that all contributions to WeBWorK_wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see The WeBWorK Project wiki:Copyrights for details). Do not submit copyrighted work without permission!

Cancel Editing help (opens in new window)