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 29: Line 29:
 
These <code>BEGIN</code> and <code>END</code> commands must be on a line by themselves, though they can be indented.
 
These <code>BEGIN</code> and <code>END</code> commands must be on a line by themselves, though they can be indented.
   
The formatting for the text that goes between them is described in more detail below, but PGML tries to make the formatting reflect the layout you have used within the <code>BEGIN/END</code>, and it uses the kinds of things you might type in an email message to indicate more advanced formatting. For example, a blank line indicates a paragraph break, indenting by 4 spaces indicates an indentation, asterisks and underlines indicate bold and italics, numbers at the beginning of a line indicates a numbered list, and so on.
+
The formatting for the text that goes between them is described in more detail below, but PGML tries to make the formatting reflect the layout you have used within the <code>BEGIN/END</code>, and it uses the kinds of things you might type in an email message that doesn't use advanced formatting. For example, a blank line indicates a paragraph break, indenting by 4 spaces indicated an indentation, asterisks and underlines indicate bold and italics, numbers at the beginning of a line indicates numbered lists, and so on.
   
 
== Basic Formatting ==
 
== Basic Formatting ==
   
One of the underlying motivations of PGML is to try to make how you format the text within your problem file be reflected in the formatting when the problem is displayed on screen. So if you want to have some text be indented on screen, you simply indent it in when you are typing the problem. PGML formats your output based on standard conventions used in email or other text-based documents. Some of the more important of these conventions are described below. Full details can be found in the [[#Further Reading|Further Reading]] below.
 
  +
== Further Reading ==
   
=== Paragraph and Line breaks ===
 
 
Paragraphs are separated by a blank line (just as you would in an email message, for example).
 
 
Paragraph one has a few lines
 
of text, but ends here.
 
 
This is paragraph two.
 
 
Line breaks normally are ignored, so several lines of text will become one paragraph, and that will reflow to fill the horizontal space allocated to the problem. In the example above, the line break between "few lines" and "of text" may not be where the line breaks on screen. To force a line break within a paragraph, end the line with two consecutive spaces. So using <code style="white-space:nowrap">"a few lines "</code> in the example above would guarantee that the line break on screen comes after "lines".
 
 
=== Indenting, Centering, and Justifying ===
 
 
To indent a paragraph, insert 4 spaces before the first word of the paragraph.
 
 
This paragraph is flush left.
 
 
But this one is indented.
 
 
Back to flush left.
 
 
You only need to indent the first line of the paragraph, but is is OK to indent them all if that is easier to read.
 
 
This is indented, but only the first line
 
needs to have the four spaces. The others
 
can be flush left.
 
 
But you can indent all the lines of
 
a paragraph if you want. That might
 
be easier to read.
 
 
You can have multiple indent levels:
 
 
This is flush left.
 
This is indented.
 
 
This is also indented.
 
And this is indented further.
 
 
To center text, put <code>&gt;&gt;</code> and <code>&lt;&lt;</code> around it.
 
 
>> Centered text <<
 
 
>> Centered paragraph
 
spanning more than one line. <<
 
 
>> You can mark each <<
 
>> line separately if you want <<
 
>> and all lines will be combined <<
 
>> into one centered paragraph. <<
 
 
Put two spaces after the <code>&lt;&lt;</code> to force a line break within the centered paragraph.
 
 
To right-justify some text, use just <code>&gt;&gt;</code> at the left
 
 
>> Right-justified text
 
 
>> Right-jutified paragraph
 
spanning multiple lines.
 
 
>> Right-justified paragraphs
 
>> can have markers on
 
>> each line.
 
 
=== Lists ===
 
 
You can create numbered, alphabetic, or bullet lists in PGML. Items in a numbered lists begin with a number followed by a period and at least one space.
 
 
1. This is the first item
 
2. This is the second item
 
which spans several lines.
 
 
A blank line ends the list, unless it is indented with four spaces, in which case it becomes a new paragraph in the previous numbered item.
 
 
Here is a list:
 
1. This is the first list item
 
continued on the next line.
 
2. Additional items are easy to add.
 
3. Continuation need not be indented,
 
such as this line.
 
 
A paragraph break ends the list...
 
1. Unless you indent the paragraph...
 
 
...in which case it is part of the list item.
 
2. See?
 
 
Note that the actual numbers used don't matter. PGML will always number from 1 and increment by one each time. So
 
 
1. Item A
 
2. Item B
 
3. Item C
 
 
and
 
 
8. Item A
 
1. Item B
 
3. Item C
 
 
both produce the same numbered list in the output (numbered as in the first example).
 
 
Alphabetic lists start with a letter followed by a period or a close parenthesis:
 
 
A list with alphabetic markers:
 
a) You can use dots
 
b) or parens to indicate the items
 
 
Roman numerals can be obtained using lists starting with roman numbers an a period:
 
 
A list with roman numeral markers:
 
i. Item 1
 
ii. Item 2
 
 
Uppercase letters or roman numerals produce lists with upper-case markers.
 
 
Bullet lists begin with an asterisk or a dash. Plus signs produce square bullets, and <code>o</code> produces open circles.
 
 
Bullets:
 
* Item A
 
* item B
 
 
Squares:
 
+ Item A'
 
+ Item B'
 
 
=== Emphasis ===
 
 
Asterisks are used to indicate '''bold'', and underscores produce ''italics''. (Note: some Markdown processors use <code>*</code> for italics and <code>**</code> for bold; we may adopt that convention in the future.)
 
 
This is *bold text*, and _italic text_.
 
They can be combined as *_bold italic text_*.
 
 
=== 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.
 
 
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 calculator notation, enclose it in <code>[: ... :]</code> for inline math, <code>[:: ... ::]</code> for display-style inline math, and <code>[::: ... :::]</code> for display style math.
 
 
For example,
 
 
What [`x`] makes [`\frac{x+2}{3} = 1`]?
 
 
What [:x:] makes [:(x+2)/3 = 1:]?
 
 
Both produce the same results with inline math.
 
 
And for example,
 
 
What [`x`] makes [``\frac{x+2}{3} = 1``]?
 
 
What [:x:] makes [::(x+2)/3 = 1::]?
 
 
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:::]
 
 
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 ==
 
 
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.
 
 
=== Variable Substitution ===
 
 
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
 
 
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)