## WeBWorK Main Forum

### Whitespace sensitivity in WeBWorK2?

by Bob Palais -
Number of replies: 2
Hi I'm new here, but have been using WW with great results in our online Calculus courses for the past few years.

We've switched to the new version and students have been running into trouble with some problems under the new system.

In particular, if they leave a space after a comma, it calls an answer incorrect, but not if there is no space.

(The problem in question is for where the slope of f(x)=x^2-2x+3
is positive, negative, zero, and the answers are asked for in interval notation, with INF to be used for infinity. The answers (1,INF), (-INF,1), 1 are accepted, but (1, INF), (-INF, 1). Either one was accepted under the old version, and when I checked the coding, it is written as follows:

ANS(str_cmp("(1,INF)", remove_whitespace ));
ANS(str_cmp("(-INF,1)", remove_whitespace ));

Does anyone have any idea why this does not render the answer whitespace insensitive, as it seems to in the previous incarnation,
and what I should do to prevent it in the future? I think it could be especially discouraging for the students who are having their first experience with the system.

Thanks!!

Bob

### Re: Whitespace sensitivity in WeBWorK2?

by Davide Cervone -
Well, it's hard to decide where to start with this, as there are a number of issues with your code.

My initial concern is that remove_whitespace needs to be quoted, so you should have

    ANS(str_cmp("(1,INF)", 'remove_whitespace' ));

Without this, remove_whitespace acts as a function call, not a string, and the remove_whitespace call should return an error since it is supposed to be passed an answer hash. The str_cmp() filters were overhauled several years ago, and it may have worked without the quotes before, but certainly doesn't now. When I include the quotes, the whitespace is correctly ignored.

On the other hand, while this may have been an acceptable approach in the early days of WeBWorK, a string comparison certainly is the wrong approach given the current set of tools. This answer checker would fail to match (1.0,INF), for example, or (3-2,INF), or (2sin(pi/6),INF), or any other equivalent correct answer. With the remove_whitespace filter, you would also find that (1, I N F) would be accepted. Also, you will not get any useful error messages for incorrect answers, like if the student didn't add a close parenthesis, or had the wrong type of interval endpoints, or whatever.

The MathObjects library includes an Interval object, and that is a better choice for this problem. Use something like

    loadMacros("MathObjects.pl");
Context("Interval");

ANS(Interval("(1,INF)")->cmp);

instead. You can also do unions
    ANS(Union("(-inf,0) U (0,inf)")->cmp);

or lists of intervals
    ANS(List("(1,3],[10,inf)")->cmp);

and you will also get reasonable error messages when the student makes syntactical errors. You can even use formulas in the endpoints, like (x,2x].

Hope that helps.

Davide