Difference between revisions of "Special Characters - PGML"

From WeBWorK_wiki
Jump to navigation Jump to search
(Initial version)
 
(Add more escaping details)
 
Line 45: Line 45:
   
 
would form a numbered list with one item ("But 2 is OK") following a paragraph ("No one can eat just").
 
would form a numbered list with one item ("But 2 is OK") following a paragraph ("No one can eat just").
  +
  +
Because <code>\</code> is an escape character in PGML, in order to get a litter backslash, you need to escape it, so use ''two'' backslashes.
  +
  +
This is a literal backslash: \\
  +
  +
Finally, in the case where an asterisk or brace would be interpreted following a close bracket (e.g., to provide an answer after an answer blank), you can quite the star or brace in order to prevent its usual interpretation and produce a literal asterisk or brace.
  +
  +
This blank [_____]\{\} is followed by braces that will
  +
appear in the output, and this variable's value [$a]\* will
  +
have a star after it.
   
 
[[Category:PGML]]
 
[[Category:PGML]]

Latest revision as of 07:52, 10 May 2015

TeX and HTML Special Characters

In a traditional BEGIN_TEXT/END_TEXT, you have to be careful about using characters that have special meaning in HTML or LaTeX, as using them could cause unwanted results on screen or in hardcopy (and testing in one form didn't mean it would work in the other). These characters are the following:

 <, >, &, %, $, ^, _, #, &, ~, {, }

With PGML, these characters are handled appropriately regardless of which output method you are using, so there is no need for special treatment. So you can use these characters without fear of adverse repercussions. For example, you can include

 The company "Johnson & Sons" sells a product for $125 a unit.
 If their profit is 60% per unit, how many units must they sell
 in order to make $1,000 in profits?

in your problem, and not worry about the special characters that are used. PGML will handle them properly for you.

Smart Quotes

PGML will convert the standard single- and double-quote characters to their "smart-quote" versions (ones that differ for opening and closing quotes). You do not need to do anything special to get these smart quotes. So

 Quotes are "smart" ("even here"), and don't forget about 'other' quotes.

Will produce

 Quotes are “smart” (“even here”), and don’t forget about ‘other’ quotes.

If you really want the traditional version of the quotes, you can escape the quotes:

 You can escape a quote: \"dumb quotes\".

Escaping PGML Special Characters

You can use a backslash to prevent PGML from having their normal effect. So if you want a literal asterisk (rather than bold), you can escape the asterisks.

 This is \*not\* bold.

Any of the PGML special characters can be treated this way. For example, if a line starts with a 1 and it is also the end of a sentence, that would normally start a numbered list, but you can escape the 1 (to the period after it) to prevent a list for being formed. Here,

 No one can eat just
 \1.  But 2 is OK.

the two lines will be joined into one paragraph, whereas

 No one can eat just
 1.  But 2 is OK

would form a numbered list with one item ("But 2 is OK") following a paragraph ("No one can eat just").

Because \ is an escape character in PGML, in order to get a litter backslash, you need to escape it, so use two backslashes.

 This is a literal backslash: \\

Finally, in the case where an asterisk or brace would be interpreted following a close bracket (e.g., to provide an answer after an answer blank), you can quite the star or brace in order to prevent its usual interpretation and produce a literal asterisk or brace.

 This blank [_____]\{\} is followed by braces that will
 appear in the output, and this variable's value [$a]\* will
 have a star after it.