WeBWorK Problems

Vertical space between radio buttons

Vertical space between radio buttons

by Louis Zulli -
Number of replies: 3
How can additional vertical space be created between successive radio buttoned answers to a multiple choice problem? I've tried including various commands and special characters in the individual answer strings, but clearly that's not the solution.

Thanks.
In reply to Louis Zulli

Re: Vertical space between radio buttons

by Davide Cervone -
Well, if you used my new parserRadioButtons.pl macros, you could use the separator=>"..." option to change what is between the radio buttons. For example, you could use separator=>$PAR to make paragraph breaks between the choices. Or perhaps separator=>"$BR$BR".

Otherwise, since you are using new_multiple_choice, you would have to replace the print_q method to one that formats the choices in the way you want to. It's more complicated than you might want.

Davide
In reply to Davide Cervone

Re: Vertical space between radio buttons

by Robin Cruz -

I wanted to add vertical space between radio buttons and found these notes. parserRadioButtons added the space I wanted but it does not seem to be playing nicely with MathJax. Here's the code I tried. A picture of what it produced is attached. By the way, the math typesetting works fine using the old method for making radio buttons, but then I can't (easily) adjust the vertical space between the buttons.

Thanks -- rac

---------------------------------------------------------------------

TEXT(beginproblem());

DOCUMENT();

loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"parserRadioButtons.pl"
);

$radioQ_a = "Which of these is a flavor of 1 to change ft to miles?";
$radio_a = RadioButtons(["\(\mathsf{ \frac{5280\ ft}{1\ mi} }\)",
"\(\mathsf{ \frac{5280\ mi}{1\ ft} }\)",
"\(\mathsf{ \frac{1\ ft}{5280\ mi} }\)",
"\(\mathsf{ \frac{1\ mi}{5280\ ft} }\)"],
"\(\mathsf{ \frac{1\ mi}{5280\ ft} }\)",
separator => "$BR $BR");

BEGIN_TEXT

$radioQ_a $BR
\{$radio_a->buttons\}

END_TEXT

ANS($radio_a->cmp);

ENDDOCUMENT();

Attachment RadioButtonForum_Note_2013_01_29_rac.png
In reply to Robin Cruz

Re: Vertical space between radio buttons

by Davide Cervone -
It also doesn't play nicely with image mode. The problem is that the radio buttons need a value to use as the student's answer, and by default that is the text of the button's choice. In your case, that "text" is math, and so you get either an image tag for that or some HTML tags that MathJax uses to identify the math. That doesn't make a good value for the button, and it messes up the HTML that handles the button.

But parserRadioButtons.pl has the ability to assign alternative labels to the buttons. These are what are used for the student answer and preview, so in your case, you should use that mechanism to make something more meaningful for the labels. One choice would be to add

	labels => "ABC"
to the RadioButtons() call, which would make the answers be labeled A, B, C, etc. These are what would show up for the student answers in the results table when they check their answers. It also prevents the math tags from being used as the values of the buttons, so you won't get the extra stuff on screen.

But you could be fancier and have them labeled by the actual expressions. Since these labels are actually used as the student answers, they have to be valid expressions that MathObjects would need to parse. One way would be to add things like "1 mi/5280 ft" as strings, and then use these as the labels.

Alternatively, you can add mi and ft to the context and set things up so that the quotients stringify nicely. Here's an example of that:

    DOCUMENT();
    
    loadMacros(
      "PGstandard.pl",
      "MathObjects.pl",
      "parserRadioButtons.pl",
    );
    
    #
    #  Set up context to have mi and ft, and make them print properly
    #
    Context("Numeric");
    Context()->constants->add(mi => 1, ft => 1000);
    Context()->constants->set(mi => {TeX => "\ \mathsf{mi}"}, ft => {TeX => "\ \mathsf{ft}"});
    Context()->operators->set("*" => {string => " "}, "/" => {rightparens=>""});
    
    #
    #  The MathObjects for the answer choices
    #
    @answers = (
      Formula("(5280 ft)/(1 mi)"),
      Formula("(5280 mi)/(1 ft)"),
      Formula("(1 mi)/(5280 ft)"),
      Formula("(1 ft)/(5280 mi)"),
    );
    
    #
    #  The radio button choices (the text next to the button) 
    #  and labels (what is used for the student answers)
    #
    @choices = map {" \(".$_->TeX."\)"} @answers;
    @labels   = map {$_->string} @answers;
    
    $radioQ_a = "Which of these is a flavor of 1 to change ft to miles?";
    $radio_a = RadioButtons(
      [@choices],
      $choices[2],
      separator => "$BR$BR",
      labels=>[@labels],
    );
    
    BEGIN_TEXT
    $radioQ_a $BR$BR
    \{$radio_a->buttons\}
    END_TEXT
    
    ANS($radio_a->cmp);

Hope that helps.

Davide