WeBWorK Main Forum

display of a two value function

Re: display of a two value function

by Davide Cervone -
Number of replies: 0
There are a number of problems with your example array. The main problem with this in WeBWorK is that \{ is used by WeBWork to delimit commands to be performed whose output is to be included in the output text. These commands are performed before mathematics is processed, so WeBWorK tries to use part of your mathematics as a command to execute. To prevent that, you need to use $LBRACE in place of \{.

On the other hand, you should really be using \begin{cases}...\end{cases} rather than an array environment. That will obviate the need for the left brace in the first place, and also the \quad will no longer bee needed either.

Also, the \mbox{...} is not needed (and is in fact an error, though WeBWorK's math processor will ignore it). An \mbox will put TeX into text mode rather than math mode, so -B \leq x \eq B would not be processed properly.

So the final version should be more like

    \[f(x) = \begin{cases}
         A & -B \leq x \leq B\\
         0 & |x| > B\\
       \end{cases}\]

This should produce [dmath] f(x) = \begin{cases} A & -B \leq x \leq B\\ 0 & |x| > B\\ \end{cases} [/dmath]

It is also possible to use the piecewiseFunctions.pl macro file from the Union macro library. (Read the documentation at the top of the file). This is a non-TeX specific way of creating the piecewise function, and it will work correctly in more display modes than the raw TeX code above. This is older code, but still works.

Finally, the MathObjects contextPiecewiseFunction.pl context can be used to create multi-branched functions that display properly, but also can be entered by students, evaluated, differentiated, and so. But it is restricted to using actual constants as the limits of the branches, not symbolic constants, so it won't be able to do the [math]-B \le x \le B[/math] that you have above. I've looked into changing this, but it is not as easy to modify as I had hoped.

Davide