Custom Error Message

This 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.

Complete Code

Download file: ErrorMessageCustomization.pg

PG problem file

Explanation

DOCUMENT();
loadMacros('PGstandard.pl', 'PGML.pl', 'PGcourse.pl');

Context()->{error}{msg}{"Missing operand after '-'"} =
    "Enter '-1' instead of '-'";

$ans1 = Real(-1);
$ans2 = Formula("x-2");

Preamble

These standard macros need to be loaded.
BEGIN_PGML
Factor [`-1`] from [`-x+2`]

[`-x+2 =`] [__]{$ans1} [`\cdot \big(`] [__]{$ans2} [`\big)`]
END_PGML

ENDDOCUMENT();

Statement

This is the problem statement in PGML.