-
-
Notifications
You must be signed in to change notification settings - Fork 76
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
Radio buttons #227
Radio buttons #227
Conversation
…rs in string values (needed in order to make RadioButtons and other subclasses of String work better).
…ontext to take advantage of the new Value::String definitions.
…bels better. The order, first, and last options are no longer needed, as these functions can now be handled directly in the choice array. Use new string routines to make answers safe to include mathematics and long string values.
… for attribute values)
…pecial characters. Also avoid a warning message when labels are not defined.
…o include things like bold. Add some more comments to clarify the use of math in button choices and the need for labels in that case.
Does it matter that this splits off of a branch called |
It actually is the other way, popup-menus was branched from this (but the network diagram may not make that clear). I will make a pull request for popup-menus after this one is merged. Both branches needed the changes to the String object. |
I've been testing this out and have run across some problems. The minor ones are:
The big issue is that something is broken with string that is breaking some normal functionality. If I try to generate a graph, or a number of other things I end up with errors that look like.
Some code that fails is
|
Excellent.
This is a flaw in handling of student and correct answers the hardcopy module of WeBWorK itself. The answers are put into verbatim mode, so even if they include TeX code, that code is displayed verbatim. I don't know if the hardcopy module actually calls the problem to get an AnswerHash (I think it must to get the correct answers) or simply uses the student answers from the database, but if it gets an AnswerHash, it should use the The reason the HTML is showing up in the correct answers is again because of the flaw in the hardcopy generator. The string that is being used is the The real source of the problem is that AnswerHash really should have Because the correct answers needed to show up correctly in the results table, I was forced to HTML escape the plain text strings that are used in the table. That has the adverse affect of having the HTML show up in hardcopy (which uses the supposed plain text answers even when LaTeX versions are available). There is no way around that in the current hardcopy generator. As far as the radio buttons go, you will find a similar problem when you view the student answers if there is math in the radio button choice. This is because the "Entered" column is supposed to be text, not formatted math, and the formatted math one is being handled as a String, and strings don't contain formatted math. While it would be potentially possible to breaking out of the verbatim mode if math is present in the button choice, it was not clear what should be done with the "entered" column, so I didn't do that. Note that the documentation suggests that you use |
So it seems like the correct answers thing should be fixed by using labels. This is appropriate since if you have mathobjects as the display strings then the correct answers end up as stuff like What about the actual radio button rendering, though? Why is the text to the left of the radio buttons in verbatim? |
I tried switching over to labels and displayLabels and those aren't printing well either. (They also have verbatim strings in hardcopy). Maybe the solution isn't to put html in the correct answer string. The issue is that the results table tries to render almost everything in math mode. However, it does pay some attention to the type of answer. For example, it doesn't put essay question answers in math mode. How about adding code to the results table which outputs some problem types (e.g. string, radio buttons, etc...) without trying to have them rendered? (I.E. add additional answer types here: https://github.com/openwebwork/webwork2/blob/master/lib/WeBWorK/ContentGenerator/Problem.pm#L426 and again in previewCorrectAnswer) |
…ecked option, better documentation of forceLabels, fixing problem with maxLabelSize, problem with contextString being selected accidentally, and issues with hardcopy output.
This turns out to be due to Once that context is set, the only valid MathObjects in that context are the strings (and there are none initially), so the first attempt to create a MathObject in that context will fail. I didn't notice this during my testing because I didn't create any other MathObjects, so never got the message. I have removed the use of
The I've also changed the default for The change in
The
That depends on how you set up your initial choices. I'm assuming you did something like
This works because the first choice is the literal string On the other hand, you could do several other things. One would be
where the Or you could do
to get the same result (but again labels would be useful). Finally, you could do something like
to get a label that formats better in the results table but a choice text that formats nicely within the problem. I suppose that another solution to the problem of how to handle math would be to have the "Entered" column of the results table show something like "Button 1" while the "Preview" column shows the actual choice text (with math displayed as typeset math). That would avoid having the
I'm not sure I understand the text you are referring to. Can you give a specific example?
I changed the escaping code to be more dependent on the
For screen output, you have to if you want to allow the output to include things like
That's not a problem, because there is
I think that is a bad idea, in general. You don't want the webwork2 code (like the code that creates the results table) having to know any specifics about the PG code (like MathObjects). This also means you have lots of special cases to worry about that have to be handled in all the places that rendering might be done. It also makes is harder to make new classes that behave like these ones, as that requires system-level changes in webwork2 rather than just additional macro files in PG. If you wanted to add an AnswerHash property that controlled how the results table handles the student and correct answers, that might be useful. In any case, its' not really there results table that is the problem, it is the hardcopy handling of student and correct answers that is the real problem. There is no reasonable way to avoid its use of verbatim, when it would be perfectly possible for it to use the latex strings that are available in the AnswerHash instead. |
Well, it turns out that this is (once again) the difficulty of not knowing what has been escaped and what hasn't. When you use things like I had intended to make it possible to use the choice text as verbatim text (so that you didn't have to worry about things like That has at least one adverse consequence (in addition to the positive ones of allowing math mode and variable substitution). The choice text gets used in the radio buttons in three distinct ways: as text within the page listing the button choices, as the string answers entered by students in the "Entered" column of the results table (and the correct answer popover), and as LaTeX versions of the student and correct answers in the entered table. Unfortunately, math and things like images can't be used in the results table very easily, and macros for handling the special characters like The In any case, I'll have to remove the protection of the choice text and leave that in the hands of the problem author. Sigh. I'll think about the label situation and make another commit when I figure out the course to take. |
If the choices are going to support complicated text then I think you are right, the labels should be shown and used by default unless choices is explicitly set. Even if you could get the choices working in the student answer and correct answer it would look bad. I think this is the same issue I was having with the math I put in the image above. The math is coming from a MathObject which was a variable substitution. (Perhaps if I had explicitly gotten the TeX from the object it would have worked?) So fixing images will fix my other issue. If this all seems like too much, the correct answer may be that variable substitution isn't supported in radio buttons. That's not a completely unreasonable approach. I could probably have figured out ways to code both of my problems to avoid it. However, if this is the solution then it would probably be best to have RadioButtons keep the variables from being substituted at all (i.e. not within the main problem text). Then it will be more clear to problem authors that they will need to get their values into the RadioButton object another way. |
…bels if the text includes anything that could be problematic. This should allow the use of math, images, and special characters in the choice text, and still make the student and correct answers show up OK.
OK, I think I have it worked out now. You can use math, images, etc. in the choice text, and if you do, then the RadioButtons will use "Choice 1", "Choice 2", etc., as the labels unless you override that with your own labels. If the choice text can be used safely for the answers, they will be used (this is for backward compatibility mainly). You can force the choice text to be used by using I have updated the documentation it reflect the new situation. @goehle, thanks for all your work in testing this. As always, the thoroughness of your testing has been a big help. |
Sorry I didn't get to this earlier. I've been juggling lots of stuff. One very last thing, and feel free to say its not going to come up. When I test the example you posted above,
I get |
The original example no longer applies, because we are no longer protecting special characters in the menu choices. So if you want the menu choice to include literal I should remove (or modify) the original example. |
I figured it was something like this. I think the extra utility of having math and images in the radio buttons is worth the cost, and as you said, there are macros for including those special characters. |
I agree. The end result is better than the original pull request. Thanks for the help. |
This pull request enhances the MathObject
RadioButtons()
macro in several ways.HTML and TeX special characters are handled properly.HTML and TeX special characters must be properly escaped by the problem author.The ability to handle any text is implemented by updating the underlying bring MathObject class to handle arbitrary text properly (it was originally designed only to handle a single word, so didn't handle spaces or special characters properly).
See the updated documentation at the top of the file for how to handle randomization and labels. The changes should be backward compatible (all the original options are still processed, though some are no longer needed in light of the new randomization options).
Some PG code that can be used to test some of the new features include:
for testing that the String object can handle the HTML and TeX special characters, in both screen and hardcopy.
to test mathematics in button text (in both screen and hardcopy),
and
to test randomization,
to test automatic labels, and
to test explicit labels (in this case, to make math format more reasonably in the results table).