WeBWorK Main Forum

Multiple Choice questions and PGML

Multiple Choice questions and PGML

by Yoav Freund -
Number of replies: 20
Is there a way to create multiple choice questions in PGML ?

Yoav

In reply to Yoav Freund

Re: Multiple Choice questions and PGML

by Andrew Dabrowski -
Wow, 3 years without a reply...I take it the answer is no?

I want to write some mulitple choice problems, and I was hoping that PGML would make everything simple, but apparently not. In particular it seems that PGML can't do latex on multiple choice answers. That's discouraging.

Should I just stick with plain vanilla PG?
In reply to Andrew Dabrowski

Re: Multiple Choice questions and PGML

by Gavin LaRose -

I'm not the best person to answer this, but I'll make a stab at it. Because one can frame multiple choice questions in several different ways in WeBWorK, I think this is possible in a couple of different ways. Here's one:

  loadMacros( "parserPopUp.pl", "PGML.pl" );
  ...
  @options = ( '\(\sin(x)\)', '\(\cos(x)\)', '\(\tan(x)\)' );
  $i = random(0,2,1);
  $pop = PopUp( [ @options ], $options[$i] );
  BEGIN_PGML
  The [$i] entry in the array
  ([@ join(", ", @options) @]*) is
  [__]{$pop}
  END_PGML
  ...

There a number of samples that do similar things in the Subject Area Templates page of the wiki: most of those have both standard PG and updated PGML example templates.

The second question is whether it is possible to embed LaTeX in multiple choice problems. I believe the above example does this. The checkbox_multiple_choice and similar macros from the old PGchoicemacros.pl file also support LaTeX. For example, the following will work in PGML, though it doesn't take advantage of PGML's careful linking of questions and answers:

  loadMacros( "PGchoicemacros.pl", "PGML.pl" );
  ...
  $mc->qa( 'Enter one of \(\sin(x)\), \(cos(x)\)', '\(\sin(x)\)','\(\cos(x)\)' );
  $mc->extra( '\(\tan(x)\)' );
  BEGIN_PGML
  [@ $mc->print_q() @]*
  [@ $mc->print_a() @]*
  END_PGML
  ANS( checkbox_cmp( $mc->correct_ans() ) );
  ...

This is also shown in the subject area templates.

Gavin

In reply to Gavin LaRose

Re: Multiple Choice questions and PGML

by Gavin LaRose -
Quick follow-up: in the PopUp example, I think the answer preview doesn't deal cleanly with the LaTeX delimiters, though it marks the problem correctly. This isn't an issue with the checkbox_multiple_choice construction, however.

Gavin
In reply to Gavin LaRose

Re: Multiple Choice questions and PGML

by Davide Cervone -
PopUp menus use the brewer's native menu facilities, and they only allow menu items to contain text, not more complicated markup (like images or mathematics). So PopUp's are limited to just textual answers -- not by WeBWorK, but by the browsers.

Checkboxes and other items don't have that limitation.
In reply to Davide Cervone

Re: Multiple Choice questions and PGML

by Andrew Dabrowski -
TeX formatting doesn't seem to be working with checkbox_multiple_choice either. Here's a minimal example.


DOCUMENT();

loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"PGML.pl",
"PGchoicemacros.pl"
);

TEXT(beginproblem);

@rowForms = ( '\(B_R(N) = N\)',
'\(B_R(N) = D\)',
'\(B_R(D) = N\)',
'\(B_R(D) = D\)' );
$mcRow = new_checkbox_multiple_choice();
$mcRow -> qa( "What is the best response function for the row player?",
$rowForms[0], $rowForms[2] );
$mcRow -> extra( $rowForms[1], $rowForms[3] );

BEGIN_PGML

[@ $mcRow -> print_q() @]*
[@ $mcRow -> print_a() @]*

END_PGML

##############################

$showPartialCorrectAnswers = 0;

ANS( checkbox_cmp( $mcRow->correct_ans() ) );


##############################

ENDDOCUMENT();


This produces no errors, but the question is displayed like this (attached).


Attachment ww_mc_latex.png
In reply to Andrew Dabrowski

Re: Multiple Choice questions and PGML

by Andrew Dabrowski -
I just noticed that although my example is displayed incorrectly when I view it on its own page, it displays correctly when I view it on the Library browser. Whqat could explain that?
In reply to Andrew Dabrowski

Re: Multiple Choice questions and PGML

by Davide Cervone -
Many of the instructor pages (like the library browser) load MathJax automatically, and since MathJax processes \(...\) when it is in the page, MathJax processes the math when the page is loaded, even though PGML didn't process it.
In reply to Andrew Dabrowski

Re: Multiple Choice questions and PGML

by Paul Pearson -
Hi Andrew,

The short answer is that you need the most up to date copy of PGML.pl (which you can put in your course/templates/macros directory or in a globally defined macros directory for site-wide use) and also to use [@ @]*** for substitutions instead of [@ @]*.  I have pasted your source code below with the appropriate *** notation and also attached the most up to date version of PGML.pl.

Everything between BEGIN_PGML and END_PGML is interpreted and processed by making substitutions that will make things work in the current mode (html or pdf hardcopy).  MathJax is smart and will post-process the html on the page and make math substitutions if given the right opportunity, which explains the discrepancy in typesetting between the Library Browser and outside the Library Browser (were you using images outside of the Library Browser?).

Best regards,

Paul Pearson




##############################################

DOCUMENT(); 

loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"PGML.pl",
"PGchoicemacros.pl"
);

TEXT(beginproblem);

@rowForms = ( '\(B_R(N) = N\)',
'\(B_R(N) = D\)',
'\(B_R(D) = N\)',
'\(B_R(D) = D\)' );
$mcRow = new_checkbox_multiple_choice();
$mcRow -> qa( "What is the best response function for the row player?",
$rowForms[0], $rowForms[2] );
$mcRow -> extra( $rowForms[1], $rowForms[3] ); 

BEGIN_PGML

[@ $mcRow -> print_q() @]***
[@ $mcRow -> print_a() @]***

END_PGML

##############################

$showPartialCorrectAnswers = 0;

ANS( checkbox_cmp( $mcRow->correct_ans() ) );


##############################

ENDDOCUMENT(); 

In reply to Paul Pearson

Re: Multiple Choice questions and PGML

by Andrew Dabrowski -
OK, next stupid question: where do I get the most up to date version of PGML.pl? I checked the git repository for Webwork2, couldn't find my way around. Was I in the wrong place?

OK, found it, I think. Is this the one?

PGML.pl Reverting additional changes. 9 months ago

from

https://github.com/openwebwork/pg/tree/master/macros?
In reply to Andrew Dabrowski

Re: Multiple Choice questions and PGML

by Davide Cervone -
It's the file linked at the upper right of Paul's answer (or mine).

@Paul, sorry, I didn't see you had already answered it.
In reply to Andrew Dabrowski

Re: Multiple Choice questions and PGML

by Davide Cervone -
If you want LaTeX to be processed, you need to use [@...@]*** with three stars. See Workshop2-PM-PGML problem 19 for details.
In reply to Davide Cervone

Re: Multiple Choice questions and PGML

by Andrew Dabrowski -
My version of webwork doesn't seem to recognize the three stars. This is what it gives me.

What is the best response function for the row player?*** <BR><INPUT TYPE=CHECKBOX NAME="AnSwEr0001" id="AnSwEr0001" VALUE="A" ><B> A. </B> \(B_R(N) = D\) <BR><INPUT TYPE=CHECKBOX NAME="AnSwEr0001" id="AnSwEr0001" VALUE="B" ><B> B. </B> \(B_R(N) = N\) <BR><INPUT TYPE=CHECKBOX NAME="AnSwEr0001" id="AnSwEr0001" VALUE="C" ><B> C. </B> \(B_R(D) = D\) <BR><INPUT TYPE=CHECKBOX NAME="AnSwEr0001" id="AnSwEr0001" VALUE="D" ><B> D. </B> \(B_R(D) = N\)<BR> ***

What version of webwork do I need?

A google search on "webwork Workshop2-PM-PGML" returns nothing. Do you have the link?

Or did you mean "Workshop-2PM-PGML"?
In reply to Andrew Dabrowski

Re: Multiple Choice questions and PGML

by Davide Cervone -
Sorry, we're running a problem authoring course at the moment, and they've been producing a lot of questions, and I thought yours was one of theirs. My fault for not looking closely enough.

You need an updated copy of PGML.pl (not yet even in the develop branch). I've attached it here. Put it in your course's templates/macros folder.
In reply to Davide Cervone

Re: Multiple Choice questions and PGML

by Andrew Dabrowski -
It worked! Thank you!

For future reference:

How am I supposed to find out things like the *** syntax? I don't see it anywhere at http://webwork.maa.org/wiki/Category:PGML

What repository do you use? I just tried github's Webwork2, but that version of PGML.pl apparently wasn't new enough. Is the version you attached from a dev branch?
In reply to Andrew Dabrowski

Re: Multiple Choice questions and PGML

by Davide Cervone -
I do have a github fork, but this hasn't been pushed to it yet. The *** was added just a few weeks ago, so hasn't been included in an official WeBWorK branch yet, and will not be added into the documentation until that occurs. I am still adding tweaks as we progress through this authoring course (which is the first one to use PGML extensively, so we're finding issues as we go), and wille be making a pull request next month after the course is over.
In reply to Davide Cervone

Re: Multiple Choice questions and PGML

by Andrew Dabrowski -
My timing was excellent then. A few weeks earlier and I'd have left frustrated.

I'm surprised to hear that now is the first time PGML has been used extensively in a workshop; I thought PGML had been the standard for the last several years.
In reply to Andrew Dabrowski

Re: Multiple Choice questions and PGML

by Davide Cervone -
PGML has existed for 7 years or so, but has not had a lot of traction getting into general use. We started pushing it more a few years ago, and there are now several contributed libraries that use it, but the vast majority of the OPL is still in the traditional format. We have included it in the PREP courses for several years, but only as an alternative to BEGIN_TEXT/END_TEXT. This time we used PGML as the primary method of writing the problems, and I think it has worked much better, but we did find some problems that needed to be addressed. I'm sure others who have been using PGML have run into them in the past, but few people report the problems. Having the class working with it and having immediate feedback about what doesn't work, as well as trying to convert all our course materials to use PGML, has meant that we have made some important improvements to PGML over the past few weeks.
In reply to Yoav Freund

Re: Multiple Choice questions and PGML

by Ryan Maccombs -
DOCUMENT();

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

TEXT(beginproblem());

$radio = RadioButtons(
["Red","Blue","Green","None of these"],
"Blue", # correct answer
last => ["None of these"], # can be a list
);

BEGIN_PGML
My favorite color is

[_]{$radio}

END_PGML

ENDDOCUMENT();
In reply to Ryan Maccombs

Re: Multiple Choice questions and PGML

by Alex Jordan -
I believe there was an evolution in the syntax for Radio Buttons. Formerly:

$radio = RadioButtons(
["Red","Blue","Green","None of these"],
"Blue", # correct answer
last => ["None of these"], # can be a list
);

would randomize the order of "Red","Blue","Green" and put "None of these" at the end. I think that now, this would make them all be printed in the given order, not randomized. But now there is syntax like:

[["Red","Blue","Green"],"None of these"],

will randomize the order of the first three. You can even do things like:

["Red",["Blue","Green"],"None of these"],

forcing "Red" to be first, and other such complications.

I find it nicer to specify the correct answer by its index, which I did not know was possible for a long time. So you can do:

$radio = RadioButtons([["Red","Blue","Green"],"None of these"], 1);

where the "1" is the index (sort of) of "Blue".