Question Writing Oddities

Purpose of this document

This document describes some of the common pitfalls and oddities of the IMathAS question language. For detailed question language reference, please refer to the help file.

IMathAS Question Writing Oddities

Fractional Exponent Display

Fractional exponents do not seem to display well with MathML. For example, x^(2/3) will display as `x^(2/3)`. If you want to raise up the exponent higher, a silly trick to try is x^({::}^(2/3)). The {::} creates an invisible item. This renders as `x^({::}^(2/3))`. Another approach is to try x^(2//3), which renders as `x^(2//3)`.

Curly Braces

Beware of using curly braces {}. While curly braces can be used for display or for grouping, like in the TeX-style \frac{3}{5}, strange things can happen if you place variables inside the curly braces. This is because PHP, the back-end interpreter, uses curly braces to isolate variables from surrounding text.

For example, if you wanted to display `3x` rather than `3*x`, then you need to enter 3x rather than 3*x. With a variable coefficient, writing $ax doesn't work, since the interpreter thinks that "$ax" is the variable. Curly braces can avoid this, allowing you to write {$a}x to achieve the desired result. Alternatively, writing $a x works as well. In rendered math (inside backticks), extra spaces are removed.

As a side effect, writing \frac{$a}{$b} causes problems, since the interpreter essentially removes the curly braces during variable interpolation, leaving \frac34 (if $a=3,$b=4). A simple way to avoid this is to add spaces: enter \frac{ $a }{ $b } instead, and the interpreter will leave the curly braces alone, leaving \frac{ 3 }{ 4 }, which will correctly display as the desired `3/4`.

Dollar sign

Because dollar signs are used for variables, entering a dollar sign in question text requires caution. If $a=5, entering $$a will display correctly as $5, but entering ${$a} will not (it's something called a "variable variable" in PHP). To be extra safe, entering $ $a is recommended, or \$$a (the backslash says "don't try to interpret the next symbol").

Array Variables

You can define array variables, like $a = rands(1,5,3). $a is now an array of three numbers; the elements can be accessed as $a[0], $a[1], and $a[2] (note that arrays are zero-indexed). If you use this approach, enclose the variable reference in parenthesis in calculations, like $new = ($a[0])^2, and in curly brackets inside strings, like $string = "there were {$a[0]} people".

Variables with numbers in the name

Variables like $a1 are fine to use, but like array variables, should be enclosed in parentheses to prevent misinterpretation. For example, use ($a1)^($a2) instead of $a1^$a2

Function type $variables that share letters with functions

When defining variables for Function type answer, beware that if the variable shares a letter with a function being used, you have to be a bit careful. For example, if $variables="r", and you typed $answer = "rsqrt(2)", the system will get confused. This can be solved by putting an explicit multiplication between the r and the square root: $answer = "r*sqrt(2)". Students in their entry will also need to either put an explicit multiplication sign, or at least leave a space between the variable and the function name


If you define:

$a,$b,$c = rand(-5,5,3)
$eqn = "$a x^2 + $b x + $c"

then there is potential your $eqn would display as `4x^2+-3x+2` (that's 4x^2+-3x+2). To clean up the double sign issue, use the makepretty function:

$eqn = makepretty("$a x^2 + $b x + $c")

Makepretty is automatically run on $answer for Function type problems

Less than and Greater than signs

Because HTML uses angle brackets to denote HTML tags, and since IMathAS allows HTML tags for formatting purposes, the use of < and > in problem text can sometimes be problematic. The system attempts to differential between HTML tags and inequalities, but does not always do so successfully.

Generally, same direction inequalities are handled okay, such as 3 < x < 5. But mixed inequalities, such as "x < 3 and x > 1" are sometimes mishandled. To avoid this, it is recommended that you use the HTML &lt; and &gt; in place of < and >. Inside backticks (rendered as math), lt and gt are sufficient to denote < and >. You can also use le and ge or leq and geq inside backticks for `le` and `ge`.

© 2006 David Lippman
This guide was written with development grant support from the WA State Distance Learning Council