From WeBWorK

Jump to: navigation


Context("AlternateIntervals") - Provides a context that allows the entry of intervals using reversed bracket notation for open endpoints (e.g., ]a,b[ rather than (a,b) for an open interval).


This macro file defines contexts in which open intervals can be specified using reversed brackets rather than parentheses. Both forms are always recognized, but you can determine whether one or the other form produces an error message when used. You can also force the display of intervals to use one or the other form.


To use this file, first load it into your problem, then select the context that you wish to use. There are three pre-defined contexts, AlternateIntervals, AlternateIntervals-Only, and AlternateIntervals-Warning. The first allows both the standard and alternate forms to be used, the second allows only the alternate form, and the third allows only the standard form, but recognizes the alternate form and gives an error message when it is used.

        $I1 = Compute("]2,5[");
        $I2 = Compute("(2,5)");    # equivalent to $I1;
        $I1 = Compute("]2,5[");
        $I2 = Compute("(2,5)");    # causes an error message
        $I1 = Compute("]2,5[");    # causes an error message
        $I2 = Compute("(2,5)");

There are two context flags that control the input and output of intervals.

enterIntervals => "either" (or "alternate" or "stanard")

This specifies what formats the student is allowed to use to enter an interval. A value of "either" allows either of the formats to be accepted, while the other two options produce error messages if the wrong form is used.

displayIntervals => "either" (or "alternate" or "standard")

This controls how intervals are displayed. When set to "either", the interval is displayed in whatever format was used to create it. When set to "standard" or "alternate", the display is forced to be in the given format regardless of how it was entered.

The AlternateIntervals context has both flags set to "either", so the intervals remain in the format the student entered them, and either form can be used. The AlternateIntervals-Only context has both set to "alternate", so only the alternate format can be used, and any Interval will be displayed in alternate format. The AlternateIntervals-Warning context has both set to "standard", so only standard format can be used, and all intervals will be displayed in standard format.

It is possible to set enterIntervals and displayIntervals to different values. For example.

          enterIntervals => "either",
          displayIntervals => "standard",

would allow students to enter intervals in either format, but all intervals would be displayed in standard form.


If you want to force existing problems that use the Interval context to use one of the alternate contexts instead, then create a file named in your course's templates/macros directory, and enter the following in it:


This will alter the Interval context so that students can enter intervals in either format (and they will be shown in whatever format that was used to enter them).

You could also do


to cause a warning message to appear when students enter the alternate format.

If you want to force students to enter the alternate format, use


This will force the display of all intervals into the alternate form (so even the ones created in the problem using standard form will show using the alternate format), and will force students to enter their results using the alternate format, though professor's answers will still be allowed to be entered in either format (the Default() function converts the first "alternate" to "either", but arranges that the default flags for the answer checker are set to only allow students to enter the alternative format). This allows you to force alternate notation in problems without having to rewrite them.