WeBWorK Main Forum

ans_rule in mathematical displays?

Re: ans_rule in mathematical displays?

by Davide Cervone -
Number of replies: 0
Because mathematics is usually displayed as an image, it is not possible to put answer rules within the mathematics in a way that would work in all viewing modes. (If you wanted to force your students to use jsMath mode it could be done, but there is no current mechanism for it.)

To do this sort of thing properly you need to use a table. I have attached a problem file that does this. The key section is the following:

    if ($displayMode eq 'TeX') {
      $integral =
        '\[\int_{'.ans_rule(4).'}^{'.ans_rule(4).'}'.
             ans_rule(35).'\,dx\]';
    } else {
      $integral =
       $PAR.
       $BCENTER.
       BeginTable().
         Row(['\(\displaystyle \int\)',
           ans_rule(4).$BR.$BR.ans_rule(4),
           ans_rule(35),
           '\(dx\).'],separation=>2).
       EndTable().
       $ECENTER;
    }
which uses the Union library's table macros to set up an integral with answer rules like you suggest. When hardcopy is requested ('TeX' mode), the layout is done without the table so that it formats a bit better.

Later, when you do the output of the problem, you simply use the variable $integral where you want this integral to appear.

Hope that helps.

Davide