Skip to content
Classroom

Math Entry Settings

Math entry settings control how a student's typed or palette-entered math expression is evaluated against the correct answer. These settings are configured per answer part.

Answer Comparison Methods

There is no separate comparison-method setting. The answer type you choose in the editor decides how an entry is compared:

Answer type How the student's entry is compared
Number Read as a plain number (expressions such as 1/2 are not evaluated) and compared with $answer within a tolerance
Calculated Evaluated to a number and compared with $answer within a tolerance
Function (numfunc) Both expressions are evaluated at sample points and the values compared. The check is numeric, not symbolic, so (x+1)^2 and x^2+2x+1 both match. Add $answerformat = "sameform" to accept only rearrangements of the same form
String Compared as text. By default case is ignored and runs of whitespace are compressed; $strflags changes this

Tolerance

For numerical comparison, set a tolerance to allow small rounding differences:

  • Absolute tolerance — e.g., ±0.001 means the student's answer must be within 0.001 of the correct value
  • Relative tolerance — e.g., ±0.1% means within 0.1% of the correct value

Set them as variables in Common Control. Use one or the other:

$abstolerance = 0.001    // absolute: within ±0.001 of the answer
$reltolerance = 0.001    // relative: within 0.1%, written as a fraction, not a "%" string

If both are set, $abstolerance is used. If neither is set, a relative tolerance of 0.0015 applies. There is no $tolerance variable, and $reltolerance = "0.1%" is read as 0.1, which is a 10% tolerance.

Choose relative tolerance for large numbers (where absolute differences are meaninglessly small) and absolute tolerance for answers near zero.

Allowed Answer Forms

Accepted forms are controlled by $answerformat, a comma-separated list of flags set in Common Control. With no $answerformat, a Calculated answer accepts any entry that evaluates to the right value, so 0.5, 1/2 and 2/4 all pass. It rejects a mixed number such as 1 1/2. A Number answer does not evaluate fractions at all; use Calculated when students may type 1/2.

$answerformat flag Effect
"decimal" only a decimal is accepted: 0.5 passes, 1/2 is rejected
"fraction" only a fraction or integer is accepted: 1/2 and 2/4 pass, 0.5 is rejected
"reducedfraction" as "fraction", but 2/4 is rejected; only 1/2 passes
"mixednumber" a mixed number such as 1 1/2 is accepted; an improper fraction such as 3/2 is rejected
"allowmixed" a mixed number is accepted in addition to the other forms

Units (Physics/Chemistry Questions)

For questions that require units, you can:

  • Accept the numeric value and check units separately (two answer parts)
  • Set $answerformat = "units" on a Number question, so the student types the value with its unit and both are graded
  • In a Conditional question, compare with comparenumberswithunits()

For targeted feedback on a part where the student types a bare number, list the value they get in the wrong unit as a $partial entry of getfeedbacktxtnumber (see Feedback Macros). That macro strips the unit before comparing, so it cannot give this feedback where the student types the unit.

Implicit Multiplication

2x is always interpreted as 2*x, and implicit multiplication cannot be switched off. To insist that students write the *, set $requiretimes to a symbol-count rule, given as a string of symbol, comparison pairs. For example, $requiretimes = "*,>=1" rejects 2x but accepts 2*x. It counts symbols, so an answer with two products needs "*,>=2".

Answer Previews

Students see a preview of their answer. It is controlled by two of the student's own preferences, Live preview and Math Display, not by question settings:

  • whether the preview updates as they type or only when they click Preview
  • how the math is rendered (MathJax, KaTeX, image-based, or calculator-style linear text such as x^2/3)

The per-question controls are $hidepreview, which hides the preview, and $previewloc, which you place in the question text to move the preview and its Preview button away from their default spot after the answer box.

Common Configuration Examples

Rounding to 2 decimal places:

$a = rand(10, 99)
$b = rand(3, 9)
$answer = round($a / $b, 2)
$abstolerance = 0.005    // half a unit in the last place

Accepting equivalent fractions:

$num = 3
$den = 4
$answer = "$num/$den"
// Calculated type, no $answerformat: 3/4, 6/8 and 0.75 are all accepted.
// $answerformat = "fraction" would reject 0.75; "reducedfraction" would also reject 6/8.

Exact integer:

$a = rand(2, 12)
$b = rand(2, 12)
$answer = $a * $b
$abstolerance = 0    // exact: no rounding allowed

Algebraic expression:

$a = nonzerorand(-5, 5)
$b = nonzerorand(-9, 9)
$c = nonzerorand(-9, 9)
$answer = "$a*x^2 + $b*x + $c"
$variables = "x"
// Function (numfunc) type: compared by evaluating at sample points, so for
// 2x^2+3x+1 both x^2*2+x*3+1 and (2x+1)(x+1) are accepted.
// Add $answerformat = "sameform" to accept only rearrangements such as x^2*2+x*3+1.