WeBWorK Problems

Vertical space between radio buttons

Re: Vertical space between radio buttons

by Davide Cervone -
Number of replies: 0
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:

    #  Set up context to have mi and ft, and make them print properly
    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(
      separator => "$BR$BR",
    $radioQ_a $BR$BR

Hope that helps.