WeBWorK Problems

cmp_class must be in all lowercase?

cmp_class must be in all lowercase?

by Alex Jordan -
Number of replies: 1
In writing a library of basic algebra problems, we are randomly generating the variable that's used, to reduce the dominance of x and y. We maintain a list of acceptable variables of various types (variable, integer, constant, function) and a macro file has a subroutine to pull one of these.

Sometimes I need to alter various strings related to math objects for feedback messages. My current example is that I'm using parserAssignment, and for this seed the answer is "B=0". Since "B" is the variable and since the default cmp_class is a little intimidating to intro algebra students, I use

cmp_class=>"an equation of the form B = ___"

or actually,

cmp_class=>"an equation of the form $var = ___"

This should show up in feedback messages like
"Your answer isn't an equation of the form B = ___"

However it shows up as
"Your answer isn't an equation of the form b = ___"

Which makes me think that strings for these math object keys are automatically made lowercase. Testing with other uppercase letters confirms this. Is there a way to prevent this?
In reply to Alex Jordan

Re: cmp_class must be in all lowercase?

by Davide Cervone -
You are right, the value of cmp_class does get set to lower case. There is no easy way to override this at the moment, as it is hard coded into several routines that would require editing the MathObject code to fix. I will look into doing that.

In the meantime, the only thing I can suggest is to use an HTML entity to represent the capital letter (so that it is not affected by the lower-case transformation). So something like

    $VAR = "".ord($var).";";
    ...
    cmp_class => "an equation of the form $VAR = ___"
should work. This makes $VAR be a numeric entity for the letter stored in $var. For example, if $var = "B", then $VAR will be B, which will not be changed when it is turned to lower case, and then when displayed in the browser, you will see a B.

It's a hack, but the easiest solution I can think of.

Davide