Features & Development

Decoupling pg from webwork2

Decoupling pg from webwork2

by Nicholas Puterbaugh -
Number of replies: 5
When I first saw that pg was a separate project, I was interested in using it to simply feed it a pg file, possibly some options, and have a MathJax or LaTeX formatted question.

However it seems that pg is very tightly coupled with webwork. Such that it references many things defined within the project. Such as for example the course environment being passed into the Translator.

So here are my two questions:

1. In your opinion, how difficult would it be for me to decouple pg?
2. Link given below, the PG Problem Rendering Execution Path page on github is the best reference I can find for understand the ins and outs of generating a problem. Are there any other resources that you could direct me to?
In reply to Nicholas Puterbaugh

Re: Decoupling pg from webwork2

by Alex Jordan -
Hi Nicholas,

This is side-stepping your question, but I think it may be worth looking at for your underlying need. Over the past year or so I have added the "PTX" output mode (stands for PreTeXt). To the best degree I can make it happen, this processes the problem to output XML that works with PreTeXt (https://pretextbook.org/). From such XML, there would be ways to get simple static HTML or .tex versions of a question, including just using PreTeXt itself.

It's best to use a 2.14 server for this (or later) since I enhanced things recently.

Set the display mode to be "PTX" (instead of say "MathJax" or "images"). Maybe you need to do this directly in a course config file since I doubt "PTX" shows up in the Course Config GUI as an option. When you view the problem, your web browser will try to interpret the XML as HTML, so you can access the source to really see it.

Here is an example of what you can get. This is an OPL problem, rendered in the way you might embed a problem in some web page. Maybe you need to copy paste the whole link to get the "view source" part.

view-source:https://webwork.pcc.edu/webwork2/html2xml?&problemSeed=1&answersSubmitted=0&sourceFilePath=Library/PCC/BasicAlgebra/OrderOfOperations/orderOfOperations10.pg&displayMode=PTX&courseID=anonymous&userID=anonymous&course_password=open&outputformat=ptx

Note the URL has displaymode set to "PTX" and outputformat as "ptx".

There will be many problems in the OPL, particularly older ones, where PTX output will be malformed. Some coding techniques don't lend themselves to making PTX. Or at least I haven't figured out how to work them out yet.

Periodically I change the "password" details for having my server process files this way, so the link above may not work at some point.

Getting back to your question, you could scan through pg and webwork2 looking for instances of "PTX" and try making your own version of something like this, to output in a way that works for you. But maybe PTX output will be enough.
In reply to Alex Jordan

Re: Decoupling pg from webwork2

by Michael Gage -
Hi Nicholas,

There are some other options available as well that might be of interest. First there is the "embed webwork in a webpage" option which alex mentions such as the one here: https://demo.webwork.rochester.edu/gage/2017BMCC/mth162_overview.html.

Second there is "sendXMLRPC.pl" which is located in webwork2/clients:
which reads a pg file

sendXMLRPC -b t/input.pg

sends it to a webwork server for rendering and returns the result to your browser. (using -h returns all of the information available and prints it to the command line). Read about all of the other options in the POD documentation in the file.
You can also create a pdf or a tex file in this way. There is not yet a flag
for ptx output, but I think Alex has done all the hard work needed to make that possible.

It is still not completely separate from webwork2 because it uses the configuration files in webwork2/conf and a couple of webwork2 modules. The plan is to make it sendXMLRPC completely independent, but you may need to include copies of part of the current config files and of WebworkClient in the package.

There is another similar project which is on hold at the moment until sendxXMLRPC.pl is completely polished. That's :

which will connect directly to the PG collection of modules (via PG.pm and Translator) without the need of any internet connection. You just need to get the PG git repos (actually I would try to learn how to make it into a CPAN module). It will have the same collection of options as sendXMLRPC.pl -- at least as much as possible. It mostly works but it's not ready for primetime yet.

Hope this helps.

-- Mike


In reply to Michael Gage

Re: Decoupling pg from webwork2

by Nicholas Puterbaugh -
Thanks for both of your replies!

I will get an implementation of a webwork server running to see if the embedded option works for me.

However the standaloneProblemRenderer seems to just what I was looking for.

I apologize as I'm new to Perl, but if you could answer a question for me that would be greatly appreciated.

So I've been trying to run the project above.

I've fixed all of the lib references to the GitHub WeBWorK files for this such that it can find every file.

However any attempt to run the standalonePGproblemRenderer.pl script will return the following:

Use of uninitialized value $globalEnvironmentFile in concatenation (.) or string at WeBWorK/CourseEnvironment.pm line 158.


line 158 is a usage in which it's croaking on a failure to read the global environment file.

If you could offer any insight as to why this may have occurred I would love to know. Thanks!

In reply to Nicholas Puterbaugh

Re: Decoupling pg from webwork2

by Michael Gage -
Hi

I can’t help right at the moment but I can look at it this weekend. The standalonegenerator is not quite ready for primetime yet.
If you can get by with using the sendXMLRPC.pl version for a while that might be best.

One of the things missing from standalone and from sendXMLRPC is independent configuration files.
(some subset of the files webwork2/conf/default.config, webwork2/conf/localOverrides and myCourse/templates.course.conf )

I’d also like to get the cross dependence on webwork/ .pm files as small as possible.

Take care,

Mike
In reply to Michael Gage

Re: Decoupling pg from webwork2

by Michael Gage -
It seems most likely that the file /webwork2/conf/default.config is not being found. While I intend to decouple this version of the editor from most of webwork2 it still requires a number of files that are contained in the webwork2 directory.

I have webwork2 downloaded from github and pg downloaded from github and standalone.... downloaded, all in separate directories. I have the webwork root directory used by standalone set to the webwork2 directory and I have local
.conf files made from conf/site.conf.dist and conf/localOverrides.conf.dist.
The .conf files are set up as if I was going to run a webwork site but I don't know if that is completely necessary.

The error message you are getting seems to indicate that the file
webwork2/conf/defaults.config can't be found. (the error message is misleading -- there used to be a global configuration file but it was split up into site.conf,
defaults.config and localOverrides.conf) .

I'd still suggest that you try sendXMLRPC.pl code for now -- you can send the files to be rendered to the site demo.webwork.rochester.edu so you don't have to set up your own site. (see the credentials file for sendXMLRPC.pl -- by default it goes to a local site but there is a commented out configuration for the demo site)

I'll get back to isolating the dependencies in the standalonePGproblemeditor eventually but it won't be that soon. In any case the sendXMLPC.pl is faster at the moment because it is bouncing its requests off a running server while standalone has to get the entire code for PG read before it can respond.

Let us know your progress.

-- Mike