WeBWorK Main Forum

Showing correct answer to a GraphTool question

Showing correct answer to a GraphTool question

by Alex Jordan -
Number of replies: 2

I have found that when $gt is a GraphTool, I can use the following in PGML:

    The answer is: [@ MODES( TeX => $gt, HTML => $gt->cmp()->{rh_ans}{correct_ans_latex_string}) @]*

and in HTML it shows the correct answer graph (although with a CSS width applications that makes it seem compressed). As probably comes as no surprise, it does not work to do this and also display the correct answer graph in the results table at the same time.

I'm only doing this in certain SOLUTION blocks when it's nice to show the correct solution graph following some sort of explanation of how you would construct it. I could build the correct answer graph manually using PGlateximage.pl, but it feels like that shouldn't be necessary.

Is there a method that is less hackish for accomplishing the same thing? Would it make sense for the TeX method of a GraphTool object to produce the correct answer graph? (Right now it makes things like `\left\{\text{interval}, \left[-2,\infty \right)\right\}` which is a LaTeX-y version of what the string method makes.


In reply to Alex Jordan

Re: Showing correct answer to a GraphTool question

by Glenn Rice -

For me adding

    The answer is: [@ MODES( TeX => $gt, HTML => $gt->cmp()->{rh_ans}{correct_ans_latex_string}) @]*

to a BEGIN_PGML_SOLUTION/END_PGML_SOLUTION block did not work.  The issue is the the knowl javascript is loaded before the graphtool javascript, and so the knowl javascript runs first (but after the DOMContentLoaded event has already fired).  So what happens is that the script inside the solution knowl is executed before the global graphTool method is defined.  Adding a timeout to delay execution works though.

Of course with that, the correct answer in the results table won't work because there is an html id clash.  The div for the jsx graph of the correct answer in the results table has the same id of the div for the jsx graph in the solution.  You could reimplement the graph construction from the parserGraphTool.pl cmp method.  Although there are some limitations to that approach because the parser::GraphTool package doesn't make everything public that is needed (that is the customTools string).

A method could be added to parserGraphTool.pl that would allow you to inject additional graphs with unique ids.

Unfortunately it would not work to make the TeX method output the correct answer graph.  That would cause problems with the way the results table works.  So you would also have to make modifications to how that is implemented to allow for that to work.

In reply to Glenn Rice

Re: Showing correct answer to a GraphTool question

by Glenn Rice -
I said that making the TeX method output the correct answer graph would cause problems with the way the results table works, but I meant that would cause problems with the way that hardcopy generation works. That is what would need modification to make it work.