Difference between revisions of "ErrorMessageCustomization"
m |
(added historical tag and gave updated problem link) |
||
(9 intermediate revisions by 4 users not shown) | |||
Line 1: | Line 1: | ||
− | <h2>Error Message Customization: PG Code Snippet</h2> |
||
+ | {{historical}} |
||
+ | |||
+ | <p style="font-size: 120%;font-weight:bold">This problem has been replaced with [https://openwebwork.github.io/pg-docs/sample-problems/problem-techniques/ErrorMessageCustomization.html a newer version of this problem]</p> |
||
+ | <h2>Error Message Customization</h2> |
||
<!-- Header for these sections -- no modification needed --> |
<!-- Header for these sections -- no modification needed --> |
||
<p style="background-color:#eeeeee;border:black solid 1px;padding:3px;"> |
<p style="background-color:#eeeeee;border:black solid 1px;padding:3px;"> |
||
− | <em>This PG code shows how to customize (remap) the error messages students receive after submitting an incorrect response or making a syntax error when entering their answer. This requires using MathObjects or a macro file that loads MathObjects, so that a Context is defined. |
+ | <em>This PG code shows how to customize (remap) the error messages students receive after submitting an incorrect response or making a syntax error when entering their answer. This requires using MathObjects or a macro file that loads MathObjects, so that a Context is defined. |
+ | <br /> |
||
+ | <br /> |
||
+ | You may also be interested in [http://webwork.maa.org/wiki/AnswerHints AnswerHints] |
||
+ | </em> |
||
</p> |
</p> |
||
Line 25: | Line 28: | ||
DOCUMENT(); |
DOCUMENT(); |
||
loadMacros( |
loadMacros( |
||
− | "PGstandard.pl", |
+ | "PGstandard.pl", |
− | "MathObjects.pl", |
+ | "MathObjects.pl", |
); |
); |
||
TEXT(beginproblem()); |
TEXT(beginproblem()); |
||
Line 46: | Line 49: | ||
Context("Numeric"); |
Context("Numeric"); |
||
Context()->{error}{msg}{"Missing operand after '-'"} |
Context()->{error}{msg}{"Missing operand after '-'"} |
||
− | = "Enter '-1' instead of '-'"; |
+ | = "Enter '-1' instead of '-'"; |
− | $ans1 = Real( |
+ | $ans1 = Real(-1); |
$ans2 = Formula("x-2"); |
$ans2 = Formula("x-2"); |
||
</pre> |
</pre> |
||
Line 117: | Line 120: | ||
my $ans = shift; |
my $ans = shift; |
||
$ans->{ans_message} = "Enter '-1' instead of '-'" |
$ans->{ans_message} = "Enter '-1' instead of '-'" |
||
− | if $ans->{ans_message} eq |
+ | if $ans->{ans_message} eq "Missing operand after '-'"; |
− | + | return $ans; |
|
})); |
})); |
||
</pre> |
</pre> |
||
Line 136: | Line 139: | ||
<ul> |
<ul> |
||
− | <li>POD documentation: [http://webwork.maa.org/ |
+ | <li>POD documentation: [http://webwork.maa.org/pod/pg/macros/answerHints.html answerHints.pl]</li> |
− | <li>PG macro: [http:// |
+ | <li>PG macro: [http://webwork.maa.org/viewvc/system/trunk/pg/macros/answerHints.pl answerHints.pl]</li> |
</ul> |
</ul> |
Latest revision as of 08:18, 28 June 2023
This problem has been replaced with a newer version of this problem
Error Message Customization
This PG code shows how to customize (remap) the error messages students receive after submitting an incorrect response or making a syntax error when entering their answer. This requires using MathObjects or a macro file that loads MathObjects, so that a Context is defined.
You may also be interested in AnswerHints
PG problem file | Explanation |
---|---|
DOCUMENT(); loadMacros( "PGstandard.pl", "MathObjects.pl", ); TEXT(beginproblem()); |
Initialization: To be able to customize the error messages students receive, we must be using MathObjects or a macro that loads MathObjects and has a Context. |
Context("Numeric"); Context()->{error}{msg}{"Missing operand after '-'"} = "Enter '-1' instead of '-'"; $ans1 = Real(-1); $ans2 = Formula("x-2"); |
Setup:
First, specify a Context. One way to remap the error message
is through the context. In factoring For another way to customize the error message, see the Answer Evaluation section below. |
Context()->texStrings; BEGIN_TEXT Factor \( -1 \) from \( -x+2 \). $BR \( -x + 2 = \) \{ ans_rule(5) \} \( \cdot \big( \) \{ ans_rule(10) \} \( \big) \) END_TEXT Context()->normalStrings; |
Main Text: The problem text section of the file is as we'd expect. |
ANS( $ans1->cmp() ); ANS( $ans2->cmp() ); ENDDOCUMENT(); |
Answer Evaluation:
Another way to customize the error message ANS($ans1->cmp->withPostFilter(sub { my $ans = shift; $ans->{ans_message} = "Enter '-1' instead of '-'" if $ans->{ans_message} eq "Missing operand after '-'"; return $ans; })); |
- POD documentation: answerHints.pl
- PG macro: answerHints.pl