WeBWorK Main Forum

nominator and denominator answer boxes

Re: nominator and denominator answer boxes

by Davide Cervone -
Number of replies: 0
No, there is no pretty way to do this in PGML (or in PG in general for that matter). The main reason is that one of the main output formats is images, meaning the TeX code is displayed as an image, and an image can't contain answer blanks, so you can't put answer blanks into your TeX code.

That being said, you can approximate this with some effort (though it is not pretty). Here is one approach:

    loadMacros(
      "PGstandard.pl",
      "PGML.pl",
      "unionTables.pl",
    );

    $a = 1; $b = 2;
    
    $FRAC = PGML::Format2("[``\frac{1}{2}``]");
    
    $F_ANS = PGML::Format2(<<END_PGML);
    >> [__________]{$a} <<
    >> ------------{6em}{1px} <<
    >> [__________]{$b} <<
    END_PGML;
    
    TEXT(
      BeginTable(),
      Row([$FRAC," = ",$F_ANS],separation=>10),
      EndTable()
    );
This uses two answer blanks with a horizontal rule between them to form the fraction. These are created using the PGML formatter, so that you can use PGML to specifiy that (it handles the centering and the creation of the answer rules and blanks).

But you need to use a table to lay out the expression containing the original fraction and the equal sign along with the anwer-blank fraction in order to get everything to align properly. PGML doesn't currently have any syntax for creating a table, so we use plain or TEXT() to do that. So that is not as pretty as you would like.

Tabling should be added to PGML, but I never worked that all out.

Note that with this approach the student will have to enter the fraction using the exact same numerator and denominator that you did. So they could not enter 3/6 and be marked correct for an answer of 1/2. (Unless you used a MultiAnswer object.)

It would be nice if the MathObject's Fraction class would have its ans_array method produce this type of layout so that you could get it easily, and the answers from the two blanks would be properly treated as a fraction.

Davide