HomeCurrent UR
|
NAME
PGbasicmacros.pl --- located in the courseScripts directory
SYNPOSIS
DESCRIPTION
Answer blank macros:These produce answer blanks of various sizes or pop up lists or radio answer buttons. The names for the answer blanks are generated implicitly.
ans_rule( width )
tex_ans_rule( width )
ans_radio_buttons(value1=>label1, value2,label2 => value3,label3=>...)
pop_up_list(@list) # list consists of (value => label, PR => "Product rule",...)
pop_up_list([@list]) # list consists of values
In the last case, one can use To indicate the checked position of radio buttons put a '%' in front of the value:
The following method is defined in PG.pl for entering the answer evaluators corresponding to answer rules with automatically generated names. The answer evaluators are matched with the answer rules in the order in which they appear on the page.
ANS(ans_evaluator1, ans_evaluator2,...);
These are more primitive macros which produce answer blanks for specialized cases when complete control over the matching of answers blanks and answer evaluators is desired. The names of the answer blanks must be generated manually, and it is best if they do NOT begin with the default answer prefix (currently AnSwEr).
labeled_ans_rule(name, width) # an alias for NAMED_ANS_RULE where width defaults
to 20 if omitted.
NAMED_ANS_RULE(name, width)
NAMED_ANS_BOX(name, rows, cols)
NAMED_ANS_RADIO(name, value,label,)
NAMED_ANS_RADIO_EXTENSION(name, value,label)
NAMED_ANS_RADIO_BUTTONS(name,value1,label1,value2,label2,...)
check_box('-name' =>answer5,'-value' =>'statement3','-label' =>'I loved this
course!' )
NAMED_POP_UP_LIST($name, @list) # list consists of (value => tag, PR => "Product
rule",...)
NAMED_POP_UP_LIST($name, [@list]) # list consists of a list of values (and each
tag will be set to the corresponding value)
(Name is the name of the variable, value is the value given to the variable when this option is selected, and label is the text printed next to the button or check box. Check box variables can have multiple values.) NAMED_ANS_RADIO_BUTTONS creates a sequence of NAMED_ANS_RADIO and NAMED_ANS_RADIO_EXTENSION items which are output either as an array or, in scalar context, as the array glued together with spaces. It is usually easier to use this than to manually construct the radio buttons by hand. However, sometimes extra flexibility is desiredin which case: When entering radio buttons using the "NAMED" format, you should use NAMED_ANS_RADIO button for the first button and then use NAMED_ANS_RADIO_EXTENSION for the remaining buttons. NAMED_ANS_RADIO requires a matching answer evalutor, while NAMED_ANS_RADIO_EXTENSION does not. The name used for NAMED_ANS_RADIO_EXTENSION should match the name used for NAMED_ANS_RADIO (and the associated answer evaluator). The following method is defined in PG.pl for entering the answer evaluators corresponding to answer rules with automatically generated names. The answer evaluators are matched with the answer rules in the order in which they appear on the page.
NAMED_ANS(name1 => ans_evaluator1, name2 => ans_evaluator2,...);
These auxiliary macros are defined in PG.pl
NEW_ANS_NAME( number ); # produces a new answer blank name from a number by adding
a prefix (AnSwEr)
# and registers this name as an implicitly labeled answer
# Its use is paired with each answer evaluator being entered
using ANS()
ANS_NUM_TO_NAME(number); # adds the prefix (AnSwEr) to the number, but does
nothing else.
RECORD_ANS_NAME( name ); # records the order in which the answer blank is
rendered
# This is called by all of the constructs above, but must
# be called explicitly if an input blank is constructed explictly
# using HTML code.
These are legacy macros:
ANS_RULE( number, width ); # equivalent to NAMED_ANS_RULE(
NEW_ANS_NAME(number), width)
ANS_BOX( question_number,height, width ); # equivalent to NAMED_ANS_BOX(
NEW_ANS_NAME(number), height,
width)
ANS_RADIO( question_number, value,tag ); # equivalent to NAMED_ANS_RADIO(
NEW_ANS_NAME(number), value,tag)
ANS_RADIO_OPTION( question_number, value,tag ); # equivalent to NAMED_ANS_RADIO_EXTENSION(
ANS_NUM_TO_NAME(number),
value,tag)
answer_matrix
Usage \[ \{ answer_matrix(rows,columns,width_of_ans_rule, @options) \}
\]
Creates an array of answer blanks and passes it to display_matrix which returns
text which represents the matrix in TeX format used in math display mode.
Answers
are then passed back to whatever answer evaluators you write at the end of
the problem.
(note, if you have an m x n matrix, you will need mn answer evaluators, and
they will be
returned to the evaluaters starting in the top left hand corner and proceed
to the left
and then at the end moving down one row, just as you would read them.)
The options are passed on to display_matrix.
Hints and solutions macros
solution('text','text2',...);
SOLUTION('text','text2',...); # equivalent to TEXT(solution(...));
hint('text', 'text2', ...);
HINT('text', 'text2',...); # equivalent to TEXT("$BR$HINT" . hint(@_) . "$BR")
if hint(@_);
Solution prints its concatenated input when the check box named 'ShowSol' is set and the time is after the answer date. The check box 'ShowSol' is visible only after the answer date or when the problem is viewed by a professor. $main::envir{'displaySolutionsQ'} is set to 1 when a solution is to be displayed. Hints are shown only after the number of attempts is greater than $:showHint ($main::showHint defaults to 1) and the check box named 'ShowHint' is set. The check box 'ShowHint' is visible only after the number of attempts is greater than $main::showHint. $main::envir{'displayHintsQ'} is set to 1 when a hint is to be displayed.
Comments to instructors
COMMENT('text','text2',...);
Takes the text to be lines of a comment to be shown only in the Library Browser below the rendered problem. The function COMMENT stores the needed html in the variable pgComment, which gets transfered to the flag 'comment' in PG_FLAGS.
Pseudo-random number generator
Usage:
random(0,5,.1) # produces a random number between 0 and 5 in increments
of .1
non_zero_random(0,5,.1) # gives a non-zero random number
list_random(2,3,5,6,7,8,10) # produces random value from the list
list_random(2,3, (5..8),10) # does the same thing
SRAND(seed) # resets the main random generator -- use very cautiously
SRAND($envir->{'inputs_ref'}->{'key'} ) will create a different problem for each login session. This is probably what is desired.
Display MacrosThese macros produce different output depending on the display mode being used to show the problem on the screen, or whether the problem is being converted to TeX to produce a hard copy output.
MODES ( TeX => "Output this in TeX mode",
HTML => "output this in HTML mode",
HTML_tth => "output this in HTML_tth mode",
HTML_dpng => "output this in HTML_dpng mode",
Latex2HTML => "output this in Latex2HTML mode",
)
TEX (tex_version, html_version) #obsolete
M3 (tex_version, latex2html_version, html_version) #obsolete
Display constants
@ALPHABET ALPHABET() capital letter alphabet -- ALPHABET[0] =
'A'
$PAR PAR() paragraph character (\par or <p>)
$BR BR() line break character
$LQ LQ() left double quote
$RQ RQ() right double quote
$BM BM() begin math
$EM EM() end math
$BDM BDM() begin display math
$EDM EDM() end display math
$LTS LTS() strictly less than
$GTS GTS() strictly greater than
$LTE LTE() less than or equal
$GTE GTE() greater than or equal
$BEGIN_ONE_COLUMN BEGIN_ONE_COLUMN() begin one-column mode
$END_ONE_COLUMN END_ONE_COLUMN() end one-column mode
$SOL SOLUTION_HEADING() solution headline
$SOLUTION SOLUTION_HEADING() solution headline
$HINT HINT_HEADING() hint headline
$US US() underscore character
$SPACE SPACE() space character (tex and latex only)
$BBOLD BBOLD() begin bold typeface
$EBOLD EBOLD() end bold typeface
$BITALIC BITALIC() begin italic typeface
$EITALIC EITALIC() end italic typeface
$BCENTER BCENTER() begin centered environment
$ECENTER ECENTER() end centered environment
$HR HR() horizontal rule
$LBRACE LBRACE() left brace
$LB LB () left brace
$RBRACE RBRACE() right brace
$RB RB () right brace
$DOLLAR DOLLAR() a dollar sign
$PERCENT PERCENT() a percent sign
$CARET CARET() a caret sign
$PI PI() the number pi
$E E() the number e
TEXT macros
Usage:
TEXT(@text);
This is the simplest way to print text from a problem. The strings in the array
Usage:
BEGIN_TEXT
text.....
END_TEXT
This is the most common way to enter text into the problem. All of the text between
BEGIN_TEXT and END_TEXT
is processed by the
Evaluation macros
EV3
TEXT(EV3("This is a formulat \( \int_0^5 x^2 \, dx \) ");
TEXT(EV3(@text));
TEXT(EV3(<<'END_TEXT'));
text stuff...
END_TEXT
The BEGIN_TEXT/END_TEXT construction is translated into the construction above by PGtranslator.pm. END_TEXT must appear on a line by itself and be left justified. (The << construction is known as a "here document" in UNIX and in PERL.) The single quotes around END_TEXT mean that no automatic interpolation of variables takes place in the text. Using EV3 with strings which have been evaluated by double quotes may lead to unexpected results. The evaluation macro E3 first evaluates perl code inside the braces: Next interpolation of all variables (e.g. Then mathematical formulas in TeX are evaluated within the
FEQ
FEQ($string); # processes and outputs the string
The mathematical formulas are run through the macro The resulting string is output (and usually fed into TEXT to be printed in the problem).
Usage:
$string2 = FEQ($string1);
This is a filter which is used to format equations by
$string1 = "${a}x^2 + ${b}x + {$c:%.1f}"; $a = 3;, $b = -2; $c = -7.345;
when interpolated becomes:
$string1 = '3x^2 + -2x + {-7.345:%0.1f}
FEQ first changes the number of decimal places displayed, so that the last term becomes -7.3 Then it removes the extraneous plus and minus signs, so that the final result is what you want:
$string2 = '3x^2 - 2x -7.3';
(The %0.1f construction is the same formatting convention used by Perl and nearly identical to the one used by the C printf statement. Some common usage: %0.3f 3 decimal places, fixed notation; %0.3e 3 significant figures exponential notation; %0.3g uses either fixed or exponential notation depending on the size of the number.) Two additional legacy formatting constructions are also supported:
EV2
TEXT(EV2(@text));
TEXT(EV2(<<END_OF_TEXT));
text stuff...
END_OF_TEXT
This is a precursor to EV3. In this case the constants are interpolated first, before
the evaluation of the \{ ...code...\}
construct. This can lead to unexpected results. For example The unexpected results have to do with the number of times backslashed constructions have to be escaped. It is quite messy. For more details get a good Perl book and then read the code. :-)
Formatting macros
beginproblem() # generates text listing number and the point value of
# the problem. It will also print the file name containing
# the problem for users listed in the PRINT_FILE_NAMES_FOR PG_environment
# variable.
OL(@array) # formats the array as an Ordered List ( <OL> </OL> ) enumerated
by letters.
htmlLink($url, $text)
# Places a reference to the URL with the specified text in the problem.
# A common usage is \{ htmlLink(alias('prob1_help.html') \}, 'for help')
# where alias finds the full address of the prob1_help.html file in the
same directory
# as the problem file
appletLink($url, $parameters)
# For example
# appletLink(q! archive="http: //webwork.math.rochester.edu/gage/xFunctions/xFunctions.zip"
code="xFunctionsLauncher.class" width=100 height=14!,
" parameter text goes here")
# will link to xFunctions.
low level:
spf($number, $format) # prints the number with the given format
sspf($number, $format) # prints the number with the given format, always including
a sign.
nicestring($coefficients, $terms) # print a linear combinations of terms using
coefficients
nicestring($coefficients) # uses the coefficients to make a polynomial
# For example
# nicestring([1,-2, 0]) produces 'x^2-2x'
# nicestring([2,0,-1],[", 't', 't^2']) produces '2-t^2'
protect_underbar($string) # protects the underbar (class_name) in strings which
may have to pass through TeX.
Sorting and other list macros
Usage:
lex_sort(@list); # outputs list in lexigraphic (alphabetical) order
num_sort(@list); # outputs list in numerical order
uniq( @list); # outputs a list with no duplicates. Order is unspecified.
PGsort( \&sort_subroutine, @list);
# &sort_subroutine defines order. It's output must be 1 or 0 (true or false)
Macros for handling tables
Usage:
begintable( number_of_columns_in_table)
row(@dataelements)
endtable()
Example of useage:
BEGIN_TEXT
This problem tests calculating new functions from old ones:$BR
From the table below calculate the quantities asked for:$BR
\{begintable(scalar(@firstrow)+1)\}
\{row(" \(x\) ",@firstrow)\}
\{row(" \(f(x)\) ", @secondrow)\}
\{row(" \(g(x)\) ", @thirdrow)\}
\{row(" \(f'(x)\) ", @fourthrow)\}
\{row(" \(g'(x)\) ", @fifthrow)\}
\{endtable()\}
(The arrays contain numbers which are placed in the table.)
END_TEXT
Macros for displaying static images
Usage:
$string = image($image, width => 100, height => 100, tex_size => 800)
$string = image($image, width => 100, height => 100, extra_html_tags => 'align="middle"',
tex_size => 800)
$string = image([$image1, $image2], width => 100, height => 100, tex_size =>
800)
$string = caption($string);
$string = imageRow([$image1, $image2 ], [$caption1, $caption2]);
# produces a complete table with rows of pictures.
File path = /ww/webwork/pg/macros/PGbasicmacros.pl
|
||
Last update: Wednesday, January 10, 2007 at 9:57:30 PM.
This site maintained using Manila and Frontier software. |
|||