## PREP 2014 Question Authoring - Archived

### How are mathematical expressions displayed with radio button options?

by Mary Cameron -
Number of replies: 4

When following the documentation for radio buttons from http://webwork.maa.org/wiki/MultipleChoiceRadio1if I replace “Green” with "$$\displaystyle \frac {a x} {b y}$$   " what gets displayed after that radio button is:  [math] ax/by “>ax/by.   How do you get simply the fraction     ax/by?

Below is the code.  Thanks, Mary

DOCUMENT();

"PGstandard.pl",
"MathObjects.pl",
);

TEXT(beginproblem());

############################ Setup
Context("Numeric");
Context() -> variables -> add( y => "Real");
$ar = 1; while ($ar == 1) {
$a = random(2,10,1);$b = random(11,20, 1);
($ar,$br) = reduce($a,$b);
}

$radio = RadioButtons( ["Red","Blue","$$\displaystyle \frac {ar x} {br y}$$","None of these"], "Blue", # correct answer last => ["None of these"], # can be a list ); ############################ Text Context()->texStrings; BEGIN_TEXT My favorite color is $$\displaystyle \frac {ar x} {br y}$$$BR  $BR \{$radio->buttons() \}
END_TEXT
Context()->normalStrings;
$showPartialCorrectAnswers = 0; ANS($radio->cmp() );

ENDDOCUMENT();

### Re: How are mathematical expressions displayed with radio button options?

by Paul Pearson -
Hi Mary,

The parserRadioButtons.pl macro is a MathObjects macro for making multiple choice questions.  There are macros that predate this one and can also generate multiple choice radio buttons questions.  For instance, see the first example at:

http://webwork.maa.org/wiki/MultipleChoiceProblems

I have included a pre-MathObjects example below my signature.

Best regards,

Paul Pearson

########### begin PG code

DOCUMENT();

"PGstandard.pl",
"PGchoicemacros.pl",
);

$ar = 1; while ($ar == 1) {
$a = random(2,10,1);$b = random(11,20, 1);
($ar,$br) = reduce($a,$b);
}

$mc = new_multiple_choice();$mc->qa(
"Select $$\displaystyle \frac {ar x} {br y}$$",
"$$\displaystyle \frac{ar x}{br y}$$"
);
$mc->extra( "red", "green", );$mc->makeLast("none of the above");

BEGIN_TEXT
\{ $mc->print_q() \}$BR
\{ $mc->print_a() \} END_TEXT$showPartialCorrectAnswers = 0;

ENDDOCUMENT();

### Re: How are mathematical expressions displayed with radio button options?

by Paul Pearson -
Hi Mary,

Thanks for pointing this out.  After some careful inspection, I could not see anything wrong with the PG code that you wrote.  (You could have avoided adding the variable y to the context since you only used variable names inside of strings.)

To this post, I have attached a png picture of what I see when I run your code using "images" display mode.

Best regards,

Paul Pearson

### Re: How are mathematical expressions displayed with radio button options?

by Paul Pearson -
Hi Mary,

I had to make a second Moodle post to attach a picture of the question in "MathJax" display mode.  Why has the randomization changed just by changing the display mode from "images" to "MathJax" (nothing else changed)?  Something is fishy...

Best regards,

Paul Pearson
  <input type="radio button" value="$$\frac{2x}{3x}$$"> \(\frac{2x}{3x}

both copies of the math are processed, and that inserted HTML into the value attribute, which is illegal, and it turns out that it ends the <input> element early, leaving part of the rest of the HTML as plain text rather than tags. This is why you see things like "> or [math] with a second copy of the math.