The BEGIN_TEXT ... END_TEXT construction
BEGIN_TEXT and END_TEXT
must each appear on a line by themselves, with no additional white
space. (This last requirement can sometimes cause problems -- make sure
there is no white space on these lines.) The text between these two
tokens is evaluated as described below, and then released as the
"printed" output of the problem. Order of evaulation
- First everything inside the
\{ .... \}
braces is evaluated as a perl statement (or statements). The output of
the statement is expected to be a scalar (not a list or an array) and
this string is inserted at the point where the braces occured. If there
is more than one perl statement only the output of the last statement
is printed, so for example \{ $a=5; ""; \} sets the variable $a to 5, but does not produce any output. \{ (4,5,6 ) \}
will print "3" because it is evaluated in scalar context, and lists, in
scalar context, output their length. In order to output the list itself
use \{ join( " ", (4,5,6) ) \} which joins the elements of the list together into a string, separating them by a single space.
- Next all of the variables are interpolated -- that is
$a is replaced by its value, @list is replaced by its list of elements separated by a single space.
- The math and math display mode text ( found within \( ... \) or \[ ... \] ) is passed through the FEQ
subroutine. This fixes doubled signs, so that - $a which would become -
-4 if $a was negative, would be replaced by +4 by the FEQ subroutine.
- The same FEQ
subroutine also allows for limited formatting of number within the math
and math display modes. For example \( {$pi:%0.2f} \) becomes
3.14 while, \( {$pi:%0.4f} \) is replaced by 3.1415. The construction,
after interpolations have taken place, is {number:format}, where format
is the the formatting specification used by perl (and similar to C).
Simple examples are %0.5f which gives 5 decimal of fixed placed
notation. %0.5e which gives 5 significant figures of exponential
notation. (5.2345 E5 ) and %0.3g which uses fixed point notations for
small numbers, and exponential notation for large ones.
- Finally, in
tth
mode or formatted text mode, the math and math display modes are fed
through tth to produce HTML output which approximates the typeset
output of the formulas. - Final processing. The output from all of the
BEGIN_TEXT ... END_TEXT blocks, as well as the TEXT()
output (see below) is joined together to produce the complete problem.
When printing the output for hard copy, or when in typeset (Latex2HTML)
mode this final result is essentially a TeX document which is then
processed by TeX and dvi2ps or by Latex2HTML to produce the final copy
in either HTML or postscript (or PDF) format. In the other modes, no
final processing is done, since the output is already in HTML format.
Additional details
The PG macro TEXT($in1, $in2, $in3);
concatenates its inputs and produces the output of the problem. It is
the "print" command of the PG language. It is sometimes convenient to
use TEXT when it is known that no further processing of the input string is necessary. Example: TEXT(beginproblem());
The PG macro EV3($in1, $in2,...)
(EValuation3) contatenates its input, processes the string as described
above in the order of evaluation section, and outputs a string. The BEGIN_TEXT ... END_TEXT construction is literally replaced by
TEXT(EV3(<<'END_TEXT')); problem text goes here ... END_TEXT
It is possible to write evaluators to replace EV3 which evaluate the text differently. EV3 is defined in PGbasicmacros.pl
<| Post or View Comments |> |