Features & Development

Render PG problems to LaTeX?

Render PG problems to LaTeX?

by Danny Glin -
Number of replies: 4
I believe I read somewhere in the past that there was a way to get a WeBWorK server to return the LaTeX output of a problem. Can anyone point me to something like this?

We are looking to use PG to generate problems that will be used on written exams, so I'm looking for something that allows me to call a PG problem and obtain the LaTeX version of how the problem would be displayed.
In reply to Danny Glin

Re: Render PG problems to LaTeX?

by Alex Jordan -
If you are on 2.13+, one way is to put this in a browser, or otherwise request this:

https://webwork.yourschool.edu/webwork2/html2xml?&answersSubmitted=0&sourceFilePath=...&problemSeed=1&displayMode=tex&courseID=mycourse&userID=myuserID&course_password=mypassword&outputformat=simple

where you replace
webwork.yourschool.edu
with your server's domain

replace ... with a problem file path that is valid from the course's templates folder, like "Library/foo/bar.pg".

replace mycourse with a course's name

replace myuserID with a user ID in that course

replace mypassword with that user's password (not the password hash). For doing this you may want to create a new user with proctor level permissions and a throw-away password.

You could change the seed in that url too if you like.

You'll need to take the HTML source that comes out and throw away everything but the tex in the middle.




In reply to Alex Jordan

Re: Render PG problems to LaTeX?

by Danny Glin -
Thanks Alex!

Is there documentation for this somewhere?

A couple of initial questions: I notice it's called HTML2XML. Does that mean that it's possible to get XML output? What would be ideal for my purposes is if there were an easy way to obtain just the question text, and obtain the correct answer TeX string separately.
In reply to Danny Glin

Re: Render PG problems to LaTeX?

by Alex Jordan -
I'm not sure what can be done right now in 2.13, but I don't think any flavor of XML (except HTML) is an output option with WW in 2.13.

In develop (and 2.14 when it is out) you will be able to get PreTeXt source for a problem, which is XML. (See http://mathbook.pugetsound.edu/ for what PreTeXt is.) You'd change the selectors to make:
&displayMode=PTX
and:
&outputformat=ptx

None of the PreTeXt stuff is documented, but probably I'll do that for the 2.14 release. Mike has the basic XMLRPC mechanism described in his blog:
http://michaelgage.blogspot.com/2015/06/whether-writing-full-text-book-or-just.html. The example there uses &displayMode=MathJax to get the HTML version of the problem.
In reply to Danny Glin

Re: Render PG problems to LaTeX?

by Michael Gage -
Hi Danny,

Look at the pull request: https://github.com/openwebwork/webwork2/pull/844

(I thought I had made this pull request earlier.) The script

webwork2/clients/sendXMLRPC.pl

allows for rendering of problems with many different kinds of outputs. Look at the POD documentation included in the file for instructions on how to use it.

I haven't tested this pull request recently -- I'll look at it again this weekend -- but I think it will still merge cleanly with your installation.

Another version of this renderer is at
https://github.com/mgage/standaloneProblemRenderer

but it's probably not ready for primetime yet. The eventual idea is to have it's user interface nearly identical to send XMLRPC.pl but to only require that the
pg/ directory be available on your desktop/laptop in order to use it.

Take care,

Mike