BEGIN_TEXT/END_TEXT
works. In particular, it has to do with the fact that BEGIN_TEXT/END_TEXT
works by doing several passes over the text, one for each type of substitution that it makes. That means the order in which those are done is crucial. For BEGIN_TEXT/END_TEXT
, all the commands (\{...\}
) are substituted first, then variable substitutions ($...
) are made, and finally LaTeX expressions (\(...\)
and \[...\]
) are processed.
Because the substitutions are performed serially, the results of earlier substitutions can be affected by the following substitutions. So if a command substitution, for example, produces output that includes dollar signs, those dollar signs will cause variable substitutions later. Similar, if the command output includes LaTeX math delimiters, they will be processed in the later phases.
In your case, the text of your table is given within single quotations marks ('...'
). In perl, there is a difference between strings quoted with single quotes and ones that use double quotes: those with double quotes have variable substitution performed on them, while single-quoted strings don't. That means that when you use
'$BBOLD 1.5e) $EBOLD...'The values of
$BBOLD
and $EBOLD
are not substituted into the string at this point. These are included verbatim in the body of the table.
Because you are inserting the table into BEGIN_TEXT/END_TEXT
via \{...\}
, however, once that output is inserted into the text on the first pass, the second pass performs variable substitution, and the bold variables are inserted at that point. Similarly, the raw LaTeX becomes part of the table output and is inserted into the text output during the \{...\}
phase, but the later LaTeX phase causes it to be interpreted as math.
So your table works as expected in the BEGIN_TEXT/END_TEXT
setting because of the way that BEGIN_TEXT/END_TEXT
processes the output in several phases.
On the other hand, PGML
does not do multiple passes (it does not use regular expression substitutions, as BEGIN_TEXT/END_TEXT
does). So the output from the DataTable()
would be inserted into the PGML output with no further processing (that is, the dollar signs and the LaTeX source code would not be interpreted and would be included in the output literally). It turns out, however, that the empty cell is causing a problem, and the output is not being produced. If you remove the ''
entry, or change it to ' '
with a space, then you will see the output of the table, but with dollar signs in tact.
In order to get the output you want, you need to change the single quotes to double quotes so that the variable substitution is done when the strings are formed (i.e., before the DataTable()
macro is called) so that they will already be substituted by the time the output is created.
To handle the mathematics, you need to do two things: double the backslashes (since in double-quoted strings, the backslash is an escape character), and use three stars after the [@ ... @]
command. The three stars cause PGML to perform the standard PG LaTeX processing. Because many PG macros (like DataTable()
expect LaTeX to be processed in their output (as it would be in BEGIN_TEXT/END_TEXT
), PGML has the triple-star option in order to do that processing.
So the modified code that works for your table is the following:
BEGIN_PGML [@ DataTable( [ [ "$BBOLD 1.5e) $EBOLD Complete the table below for a correct sign analysis. Use the key at the right to enter the correct values for the function. Determine the signs of the function, and its first and second derivative before and after the vertical asymptote.", "inc = \\(f(x)\\) is increasing. $BR dec = \\(f(x)\\) is decreasing. $BR + = \\(f(x)\\) is positive. $BR - = \\(f(x)\\) is negative. $BR CU = \\(f''(x) > 0\\) and \\(f(x)\\) is concave up. $BR CD = \\(f''(x) < 0\\) and \\(f(x)\\) is concave down." ], ], caption => ' ', midrules=>1, align => '|p{3in}|p{3in}|' ) @]*** END_PGML
[____]{7}
into a table as an answer blank?
Is it also possible to use PGML style answer blanks inside the table?
Yes, that is easily done. If you are using the WeBWorK 2.13 or later, you can use the PGML()
command to process the contents of the entries in the data table, as in the example below:
loadMacros( "PGstandard.pl", "PGML.pl", "niceTables.pl" ); TEXT( DataTable([ [PGML('[____]{1}'), PGML('[____]{2}')], [PGML('[____]{3}'), PGML('[____]{4}')] ]) );If you are using an earlier version of WeBWorK, than you can use
sub PGML {PGML::Format2(@_)}to define the
PGML()
macro before you use it.
PGML()
macro in PGML.pl in 2.13 should make it easier to use. That's easier than PGML::Format2()
.
WEIGHTED_ANS()
(or whatever the command is) to give them their answer checkers. But I'm not sure that helps all that much.