WeBWorK Problems

GeoGebra in PDF

GeoGebra in PDF

by Alex Jordan -
Number of replies: 1
If you embed a GeoGebra into a problem, what do you do about the TeX version of the problem?

One solution is to just have it print "A GeoGebra applet is here. Go online to see it." Or print some generic GeoGebra image to convey the same message.

Another solution is to take a screen shot of the GGB in its initial state and print that in the PDF. If there is randomization in the problem, I've seen examples that take several screenshots, cleverly name the screenshot files, and rely on the randomization to use the right image file name. This seems tedious, even without randomization with only one image, taking screen shots manually. Also I'm not a fan of having to manage the separate image files.

First, is there any other known approach to this issue?

Second, I have an outline of an idea. I am posting about it here to see if someone can shoot it down immediately for some reason, specifically a security reason.

With the GGB API, you can get a base64 encoding of a PNG image of the GGB applet in its current state. So I'm thinking to run the GGB, get that base64 encoding, and print that in the .tex. There would be two steps. My question is really about the first step.

1. Since we are in TeX mode, how to run the javascript to run the GGB API to get the base64 string? I'd go out looking for a perl module that can function like a headless browser. Is it going to be a security concern to enable WW problems to activate a headless browser?

2. Once I have the base64, how to bring it to life as an image in the tex? I'd go looking for perl modules that could decode the base64 and write it as a temporary file, and include the image in the tex in the usual way.

In reply to Alex Jordan

Re: GeoGebra in PDF

by Davide Cervone -
Since we are in TeX mode, how to run the javascript to run the GGB API to get the base64 string? I'd go out looking for a perl module that can function like a headless browser.

You can use Chrome (version 59 and above) in a headless mode to do this type of thing. See Google's getting started page for that.

It looks like you can use the WWW:Mechanize::Cheom to drive headless chrome from perl. But if that doesn't work well, there is a Node.js module called Puppeteer bug Google (described in the link above) that you could use (by running a node.js program as an external command from perl). That is less efficient, and would require yet another dependency for WeBWorK (node), but it might work.

Or you might just be able to get away with running headless chrome directly (examples for creating screen snapshots are in the link above).

Is it going to be a security concern to enable WW problems to activate a headless browser?

Probably, but I can't think of an exploit off the top of my head.

Once I have the base64, how to bring it to life as an image in the tex? I'd go looking for perl modules that could decode the base64 and write it as a temporary file, and include the image in the tex in the usual way.

If you use headless Chrome with screen snapshots, you should get a png file directly. If you use javascript in the page to get a base64 encoding sent back to you, then you would have to do as you suggest. The MMIME::Base64 module should do that for you.