## WeBWorK Problems

### Essay questions in PGML

by Joy Morris -
Number of replies: 15

I found on this wiki some code that allows me to use an essay box in PGML. However, when I use this and preview the answer I've entered, the preview makes it look as if my entire answer was a MathObject. (So "Let x be 5" looks like Letxbe5. How do I fix this? I tried removing the square brackets around the essay box, but then it didn't render the essay box at all. Here's the relevant code:

BEGIN_PGML

Text of problem.
[@ ANS(essay_cmp); essay_box(5,50) @]*

END_PGML

ENDDOCUMENT();

### Re: Essay questions in PGML

by Glenn Rice -

I am unable to reproduce this.  On the essay problems that I have, if I enter "Let x be 5" into the essay box and hit preview I get "Let x be 5" in the "Answer Preview".

Perhaps post the entire code of your problem so we can see if there is something else going on.

Also provide the versions of WeBWorK and PG that you are using.

### Re: Essay questions in PGML

by Sean Fitzpatrick -
We are running 2.15 for both WeBWorK and PG. Last git pull was about a month ago.
I snuck into Joy's course as admin and found the question.
Code is below. There are several variables that contain strings, and those strings contain some LaTeX. These render fine if you view the problem, but not in the homework sets editor. So that is probably what's causing the trouble.

I think there's probably a context setting that's missing?

## DBsubject(Abstract algebra)
## DBchapter(Groups)
## DBsection(Subgroups)
## Institution(University of Lethbridge)
## Author(Joy Morris)
## Level(4)
## MO(1)
## KEYWORDS('subgroup proof')

DOCUMENT();

TEXT(beginproblem());
$showPartialCorrectAnswers = 0;$choiceArray = ( 0,0,0,0,0);

$rand = random (0,4,1);$choiceArray[$rand] = 1;$step1[0] = String("Define the set. H = \{ a^i | 1 \le i \le 5\}.");

$step1[1] = "Define the set. H = \{ a^i | 0 \le i \le 5\}.";$step2[0] = "Show e \in H. Notice that since |a|=5 we have a^5=e. Therefore e=a^5 and since 1 \le 5 \le 5 we see that e \in H by our definition of H.";

$step2[1] = "Show e \in H. We see that e=a \in H so e \in H by our definition of H.";$step3[0] = "Let x,y be arbitrary elements of H. By definition of H, this means that there exist i,j with 1 \le i,j \le 5 such that x=a^i and y=a^j.";

$step3[1] = "Let x,y be arbitrary elements of H. By definition of H, this means that there exist i,j with 1 \le i,j \le 5 and i \neq j such that x=a^i and y=a^j.";$step4[0] = "Deduce that x^{-1} \in H. If i=5 so that x=a^5=e then x^{-1}=e=a^5 \in H by definition of identity and inverses, since e \cdot e = e. Otherwise, 1 \le i \le 4 and we have x^{-1}=(a^i)^{-1}=a^{-i}, and since 1 \le i \le 4 we have -4 \le -i\le -1. Since a^5=e, we have x^{-1}=a^{-i}=e\cdot a^{-i}=a^{5-i}, and 1 \le 5-i \le 4, so again x^{-1} \in H.";

$step4[1] = "Deduce that x^{-1} \in H. If i=5 so that x=a^5=e then x^{-1}=e=a^5 \in H by definition of identity and inverses, since e \cdot e = e. Otherwise, 1 \le i \le 4 and we have x^{-1}=(a^{-i})^{-1}=a^{i}, and since 1 \le i \le 4 we see that x^{-1} \in H.";$step5[0] = "Deduce that xy \in H. We have xy=a^ia^j=a^{i+j}. If 1 \le i+j \le 5 then it is immediately clear that xy \in H. If i +j \ge 6 then since 1 \le i,j \le 5 we have 6 \le i+j \le 10. So a^{i+j}=a^{5+k}=a^5a^k=a^k for some 1 \le k \le 5. Therefore, again we see that x=a^k \in H.";

$step5[1] = "Deduce that xy \in H. We have xy=a^ia^j=a^{i+j}. If 1 \le i+j \le 4 then it is immediately clear that xy \in H. If i +j \ge 5 then since 1 \le i,j \le 4 we have 5 \le i+j \le 8. So a^{i+j}=a^{4+k}=a^4a^k=a^k for some 1 \le k \le 5. Therefore, again we see that x=a^k \in H."; BEGIN_PGML Consider the following subgroup proof. Read it carefully. In the box below, write about any errors you find in this proof and explain how to fix them. If you need to use mathematical notation, just do your best to type in what you mean. Let [ G ] be a group, and let [ a\in G ] with [|a|=5]. We will prove that [H=\{ a,a^2,a^3,a^4,a^5=e\}] is a subgroup of [G]. [$step1[$choiceArray[0]]] [$step2[$choiceArray[1]]] [$step3[$choiceArray[2]]] [$step4[$choiceArray[3]]] [$step5[$choiceArray[4]]] By the five-step subgroup test, we have proven that [H \le G]. [@ essay_box(5,50) @]* END_PGML ANS(essay_cmp()); ENDDOCUMENT(); In reply to Sean Fitzpatrick ### Re: Essay questions in PGML by Davide Cervone - I believe that your issue is that the math within the $step arrays is not encoded properly. The math in PGML should be enclosed in [...], not just .... So the math is not processed by PG and is sent to the page as is. The reason this "works" is that backtics are the delimiters for AsciiMath, and since AsciiMath handles some simple LaTeX symbols as well as standard AsciiMath notation, MathJax will still process the math in the browser, even though PG didn't mark it as math. So it appears to work even though it is not properly encoded.

To handle the math correctly, you should use things like

$step2[0] = "Show [e \in H]. Notice that since [|a|=5] we have [a^5=e]. Therefore [e=a^5] and since [1 \le 5 \le 5] we see that [e \in H] by our definition of [H].";  and then use [$step1[$choiceArray[0]]]**  (with two stars) to have PGML process the inserted string as additional PGML. In reply to Sean Fitzpatrick ### Re: Essay questions in PGML by Glenn Rice - I tested the code as posted, and I get an error from$step1[0] = String("Define the set. H = \{ a^i | 1 \le i \le 5\}.");

complaining about the string constant not being defined in this context.

If I remove the "String(" ... ")" call then the problem works.  I thought the brackets would be needed as Davide pointed out, but MathJax is rendering the math in backticks correctly without the brackets.

However, I still see "Let x be 5" with spaces.  So I am still not seeing the issue that was originally posted.

### Re: Essay questions in PGML

by Joy Morris -

Thanks, Sean. Sorry I set this aside for a few days and have just now come back to look at it.

Davide, I initially tried using the [...] syntax but didn't know about the ** at the end of the line in which it was printed. Without the ** the code would not process with the [...] but processed just fine with the ... syntax. I appreciate that, I'd rather do things properly! However, I've now tried fixing the problem this way and it did not resolve the issue.

Glenn, the String(..) syntax I think was probably something Sean added as an idea of his own to test out, and neglected to remove in that one line. It wasn't in my problem code. But I have no idea why you can't replicate my error. I'm attaching a screen shot of the problem I'm seeing. Note the "Answer Preview" at the bottom.

### Re: Essay questions in PGML

by Glenn Rice -

Okay, now I see the missing piece of information that you aren't telling us.  You are doing this in a gateway quiz, correct?  Otherwise the results table would be above.  It would also have the results table format for homework problems.

Note that as of WeBWorK 2.16 the results table for homework will also be used for gateway quizzes, and that fixes the problem that you are seeing.

If I put this problem into a gateway quiz with WeBWorK 2.15 I see the issue that you see.  I will try take a look at this and see what is going on, and what can be done about it.

### Re: Essay questions in PGML

by Glenn Rice -
The problem is that the results table that is created in AttemptsTable.pm for homework problems (and for gateway quiz problems starting with WeBWorK 2.16) has a special case for essay problems to prevent the answer from being displayed via MathJax. That special case is not handled in the results table in GatewayQuiz.pm in WeBWorK 2.15.

if ($displayMode eq "plainText") { to if ($displayMode eq "plainText" || (\$answerResult->{type}//'') eq 'essay') {

There is no way to fix this if you do not have system administrative access.

Perhaps we will hot patch this into WeBWorK 2.15 if there is enough pressure to do so.

I also don't think there is a way to grade essay problems in gateway quizzes like there is for homework problems (other than setting the status in the homework sets editor set detail for that student). Gateway quizzes are just not set up to handle essay problems.

### Re: Essay questions in PGML

by Sean Fitzpatrick -
I'm the admin on that server, so I can make that change. Actually, I could move the server all the way to 2.16, since it sounds like I'm going to want it there soon for some PreTeXt stuff Alex is working on. I haven't been following on GitHub: how risky is it to move a production server to 2.16 at this point? We won't be seeing many students in the until September.

### Re: Essay questions in PGML

by Alex Jordan -
2.16 is not really a thing yet. It's still the develop branch. And the PreTeXt features haven't been submitted yet as a PR. Probably later this week, and then it will take time to be reviewed.

### Re: Essay questions in PGML

by Glenn Rice -

Alex is correct. 2.16 is not a release. That release, when it comes, will have the mentioned changes. Those changes have been accepted into the development branch.

I wouldn't recommend using the development branch on a production server.  There may be bugs that need to be worked out, and support for issues that arise will not be as good.

### Re: Essay questions in PGML

by Alex Jordan -
I'll stress something that Glenn says: it will be tedious to grade essay questions in a Gateway Quiz. The only way that I know of to do this involves opening a student's set details page and viewing the particular quiz version while acting as them. With two tabs open at the same time, you can read their response in one, and set a score for them in the other. And that's one student at a time. And this is not accounting for possible multiple versions taken. And on top of all that, I've seen it happen where near the end of taking a quiz version, all student answer inputs are cleared so that their most recent submission is empty. (This is only relevant if you allow multiple graded submissions.) So to be thorough, you'd want to see past submissions as well for each student.

### Re: Essay questions in PGML

by Joy Morris -

Ouch. Thanks for this. Yes, I have set this up as a gateway/quiz. In light of COVID, I am trying to find good ways to move some parts of what I would normally ask on exams to an "online" format, and it seemed to me that the best ways to do this include some randomisation, and some open-format answer options like this one. In order to limit cheating, I also wanted to limit the time they had, without limiting the window during which the set is open too much for those whose schedules may not be very flexible. I'm very new to WebWork, but I think that requires the gateway/quiz environment. I'd just been trying to test how to grade this question, and also struggling to figure that out, so I very much appreciate the pointers here even though they're pretty discouraging!

Oddly, harking back to my original question, I discovered today that when I have two of these questions in a quiz, the second one seems to format the answer correctly.

### Re: Essay questions in PGML

by Alex Jordan -

For some encouragement, I think one of two things will happen this summer (but maybe not in time for version 2.16).

1. An alternative quiz mechanism to Gateway. Fewer configuration options, but closer in look/feel to regular homework.
2. A tool to make it easy to review Gateway answers manually. That would help with the essay answers. But there is a need for this with regular answers too. I always manually review "incorrect" answers from a GW quiz because of things like "(1.2)" when they meant "(1,2)" and made a typo. Or things like "1/(x+1" (a different kind of typo). Or even "1/x+1" when they meant "1/(x+1)". In a quiz setting, I'm less concerned about how they have internalized keyboard order of operations. If the quiz does not allow multiple graded submissions, or it does but it does not show the student their scores, then being marked wrong for answers like these is not what I want. So I go through that tedious process I outlined. It's doable, but not fun, and takes more time than it should.
So I am motivated to work on either 1 or 2. I was going to ask the community for input about which direction is more desirable right now. I think even option 1 would need a tool similar to option 2, so I suspect option 2 is less work. The only thing I like about option 1 is the idea that the quiz environment could become more familiar to students who have only previously experienced regular homework assignments.

### Re: Essay questions in PGML

by Sean Fitzpatrick -

I think you'd find a customer base for something like a "timed homework", with a sliding completion window. (E.g. you have 30 minutes, but those 30 minutes could happen anywhere in the next 24 hours.)

We use Moodle for our LMS, and I've been trying (unsuccessfully) to work with IT and our Teaching Centre on getting the Opaque question type working. That would let Joy and others set up a Moodle quiz, and use a standard Moodle question type for essay answers (randomization can still be enabled by having multiple versions of a question), and Opaque when we need the extra power of WeBWorK.

I suspect that Opaque is sort of dead in the water though. I'll nudge Mike again because I think he's the only one who really knows it. (I posted some questions on this forum last month but that thread didn't go anywhere.)