How make Webwork display *MULTILINE* string answers properly when student wants Webwork to "Show correct answers" ?
by Christian Seberino - Number of replies: 15HOWEVER, when I try to set the correct answer to a multi-line string, that multi-line string doesn't get displayed correctly by Webwork when students select the box to "Show correct answers".
Is there a simple tweak I can do that will make Webwork display mult-line string answers WITHOUT any formatting like centering, special treatment of newlines, etc?
Thanks,
Chris
Re: How make Webwork display *MULTILINE* string answers properly when student wants Webwork to "Show correct answers" ?
by Davide Cervone -First, MathObjects are targeted around single-line answers, so there isn't much support for multi-line answers, as you have found. The ArbitraryString context that you have been using wasn't intended for multi-line input, and so it fails in severals ways when these are used.
Second, the correct answer used to be displayed as a string, but now it is the result of a TeX expression. That is a fairly recent change, and it was added on top of the MathObjects library in what was perhaps not he bet possible way (I am going to need to look into straightening that out).
In any case, the contextArbitraryString.pl
file can be modified to do what you are looking for. I have made the modifications, and attach the changed file. Put it in your course's templates/macros
file (or in the system pg/macros
directory), and then you can use something like:
DOCUMENT(); loadMacros( "PGstandard.pl", "contextArbitraryString.pl", "problemPreserveAnswers.pl", ); TEXT(beginproblem()); Context("ArbitraryString"); $a = Compute("Line 1~~nLine 2"); BEGIN_TEXT Enter your code:$BR \{ANS_BOX(0,5,20)\} END_TEXT ANS($a->cmp); ENDDOCUMENT();should do what you want.
The ArbitraryString context will now properly handle multi-line input and correct answers. It renders the answers via an array (so that it can be rendered by TeX). The problemPreserveAnswers.pl
file is loaded above in order to allow student answers to include characters like $ and @ that would not be properly saved by WeBWorK otherwise.
Note that the linebreaks that are returned as part of the answer can vary from platform to platform, so Mac browsers may give you carriage returns, and Windows may give you carriage return-linefeed pairs. This is taken care of in the ArbitraryString comparison routine, but if you do your one custom answer checker, you may need to normalize the line breaks yourself.
Davide
Re: How make Webwork display *MULTILINE* string answers properly when student wants Webwork to "Show correct answers" ?
by Christian Seberino -Thanks so much! It worked... even with PGML!
Webwork can handle more than just math!.....science and now programming classes.
cs
Re: How make Webwork display *MULTILINE* string answers properly when student wants Webwork to "Show correct answers" ?
by Christian Seberino -I noticed if I tried to indent a line in my answer, that it didn't display correctly.
The closest I got to adding spaces was with backslashes....
e.g.
print "hello";
\ \ \ \ # This is an indented comment.
print "there";
When the answer is displayed the backslashes appear.
I also tried double backslashes and "~~ ".
Sincerely,
Chris
Re: How make Webwork display *MULTILINE* string answers properly when student wants Webwork to "Show correct answers" ?
by Davide Cervone -
Instead, I have modified the contextArbitraryString.pl
file again so that it will (optionally) display student and correct answers using HTML rather than TeX. To do this, add
Context()->flags->set(noLaTeXresults => 1);right after setting the Context to
ArbitraryString
.
This version also fixes a couple of other issues, so see if that works better for you. In particular, it now handles the line-terminator conversion (from Mac and Windows linebreaks to unix line breaks) automatically.
Davide
Re: How make Webwork display *MULTILINE* string answers properly when student wants Webwork to "Show correct answers" ?
by Christian Seberino -Thanks!
This version converts multiple spaces into a single space and
multiple indented lines seem to have different amounts of spaces each.
For example...
aaaaaa
XXXXXXXXbbbbb
XXXXXXXXccccc
XXXXXXXXddddd
becomes
aaaaaa
Xbbbbb
XXccccc
XXXddddd
for some reason where X represents a blank space.
chris
Re: How make Webwork display *MULTILINE* string answers properly when student wants Webwork to "Show correct answers" ?
by Davide Cervone -Re: How make Webwork display *MULTILINE* string answers properly when student wants Webwork to "Show correct answers" ?
by Davide Cervone -Can you provide a complete problem where you see this behavior?
Have you used the
noLaTeXresults
setting that I suggested in my earlier message?Davide
Re: How make Webwork display *MULTILINE* string answers properly when student wants Webwork to "Show correct answers" ?
by Christian Seberino -I forgot to add the
noLaTeXresults
setting. Now that I did that allis working perfectly.
Re: How make Webwork display *MULTILINE* string answers properly when student wants Webwork to "Show correct answers" ?
by Davide Cervone -Davide
Re: How make Webwork display *MULTILINE* string answers properly when student wants Webwork to "Show correct answers" ?
by Christian Seberino -I found a subtle bug that isn't a show stopper but I wanted to mention it.
The current system with your changes above displays multiline answers
correctly IF STUDENTS ENTER AN ANSWER.
If the answer field is left blank by a student and they check
the "Show correct answers", the correct answer is NOT shown correctly.
Subsequent lines have the indentation messed up as shown in the
example problem I've attached FYI.
(To recreate the problem, don't type an answer. Just leave the field blank.
If you type anything as an answer, the correct answer will suddenly
be formatted correctly!)
Sincerely,
Chris
Re: How make Webwork display *MULTILINE* string answers properly when student wants Webwork to "Show correct answers" ?
by Davide Cervone -\verb
which is used in contextArbitraryString.pl
. If you used image mode, it would display correctly.Because of the way that the LaTeXed correct answer was added to the MathObjects answer checker, it is difficult to get all these situations to work properly in a reasonable way. I will be correcting that, but haven't had the opportunity yet.
In the meantime, here is a new version that should work better for you. The original works as though
noLaTeXresults
is false in the case where the answer is blank. This one works as through it is true in that case (which is the value you are using).Hope that does what you need.
Davide
Re: How make Webwork display *MULTILINE* string answers properly when student wants Webwork to "Show correct answers" ?
by Christian Seberino -cs
Re: How make Webwork display *MULTILINE* string answers properly when student wants Webwork to "Show correct answers" ?
by Davide Cervone -PS, there are a couple of issues with the code that you attached to your previous message.
You don't need to include the pattern for strings any longer as it is now part of the
contextArbitraryStrings.pl
file.Your
@answers[0]
should be$answers[0]
, since you want the scalar value that is the 0-th entry of the array, not the array consisting of just the first entry of the@answers
array.
Davide
Re: How make Webwork display *MULTILINE* string answers properly when student wants Webwork to "Show correct answers" ?
by Christian Seberino -@answers[0]
seems to work even though it should be $answers[0]
as you said.
I don't know why as I'm a Python guy myself. Maybe it was just dumb luck on my part?! :)
Re: How make Webwork display *MULTILINE* string answers properly when student wants Webwork to "Show correct answers" ?
by Davide Cervone -f((1,2),(3,4))
is the same as f(1,2,3,4)
, so your array of one value is the same as passing one value directly, but the semantics are wrong, and it is a bad habit to make arrays when you mean scalars.