Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change mathQuillOpts a bit and disable MathQuill for parserWordCompletion.pl #555

Merged
merged 2 commits into from
Apr 13, 2021

Conversation

drgrice1
Copy link
Member

@drgrice1 drgrice1 commented Mar 25, 2021

The stringify_answers method of Translator.pm now JSON encodes the mathQuillOpts key of the answer hash if defined and a hash reference. This allows the value of that key to be a hash. This is easier to work with than manually creating JSON strings. Furthermore, it can be directly passed to the mqedit.js javascript as a data attribute with an object value.

So this changes the way the mathQuillOpts answer hash key works.

Previously to disable the spaceBehavesLikeTabs option (i.e. to enable typing of spaces) and the disable rootsAreExponents you would need to do
$ans->cmp(mathQuillOpts => "spaceBehavesLikeTab: false, rootsAreExponents: false")
Now you will do
$ans->cmp(mathQuillOpts => { spaceBehavesLikeTab => 0, rootsAreExponents => 0 })

This changes the usage from before, but I doubt many were using these options yet.

Note that you can also use $ans->cmp(mathQuillOpts => "disabled") to disable MathQuill answers for an answer blank. (This is done in the webwork2 code).

This also automatically disables MathQuill answer boxes when the answer is a parserWordCompletion.pl answer.

This is paired with the webwork2 pull request openwebwork/webwork2#1288.

Copy link
Contributor

@Alex-Jordan Alex-Jordan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Except for my small comment about disabled in openwebwork/webwork2#1288, this works as described.

You got it to automatically disable for parserWordCompletion,pl answers. Do you have any thoughts on doing the same for parserNumberWithUnits.pl answers? That is the main reason local faculty are not using MathQuill. It turns answers like 2 m^2 into 2m^(2) and 2 m/s into (2 m)/s which are not understood by the parser. I tell faculty they could use text mode, but it's too much effort to train students about this issue.

@drgrice1
Copy link
Member Author

Sorry about the mistakes on the option names in the comments. I fixed that above. I don't care if the option is disabled or disable. That is in the webwork code, and not in the PG code, but that matters little.

Disabling this for the parserWordCompletion.pl macro is easy. Doing so for the parserNumberWithUnits.pl is not. Furthermore, in my opinion disabling this for that macro is not the correct thing to do. We discussed this (either last week or the week before) in our weekly meeting, and agree that there needs to be a better way of dealing with that. It is more likely that the parser or the macro need to be modified to make answers with units work better. So the correct thing to do for now is to use this disabled option for these problems until the better solution is figured out.

mathQuillOpts key of the answer hash if defined and a hash reference.
This allows the value of that key to be a hash.  This is easier to
work with than manually creating JSON strings.  Furthermore, it can be
directly passed to the mqedit.js javascript as a data attribute with an
object value.

So this changes the way the mathQuillOpts answer hash key works.
Previously to disable the spaceBehavesLikeTabs option (i.e. to enable
typing of spaces) and the disable rootsAreExponents you would need to do
  `$ans->cmp(mathQuillOpts => "spaceBehavesLikeTab: false, rootsAreExponents: false")`
Now you will do
  `$ans->cmp(mathQuillOpts => { spaceBehavesLikeTab => 0, rootsAreExponents => 0 })`

Note that you can also use `$ans->cmp(mathQuillOpts => "disables")` to
disable MathQuill answers for an answer blank.  (This is done in the
webwork2 code).

This also automatically disables MathQuill answer boxes when the answer
is a parserWordCompletion.pl answer.
stringify_hash is called, instead of just the mathQuillOpts key.

I enabled allow_unknown and allow_blessed just in case an array or hash
contains anything that would otherwise make JSON->encode barf (barf is
the wording in the JSON documentation, not mine).

I stopped short of JSON encoding blessed objects as we had discussed
because PG does a better stringification of many of those when in string
context than JSON->encode does (it just returns null).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants