-
-
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
Implement TikZ images for problems. #432
Conversation
This builds on the work of Michael Gage and Peter Peluso (and others?) in PG openwebwork#292. Care is taken to ensure that the command line is not exposed. I have updated the examples in pg/t/tikz_test for its usage as I have implemented it.
pdflatex command.
@drgrice1 are there any sample problems that use this code? I've moved an old WeBWorK server onto Slightly off-topic, but related: if this works out, how unrealistic is Asymptote as a next step? I'm not sure you'd want to be compiling |
@sean-fitzpatrick for elementary tikz unit tests look at https://github.com/openwebwork/pg/tree/develop/t/tikz_test notice this is in the develop version of pg. existing 3d plots from Mathematica are at I notice that the labeling in Asymptote looks much nicer. Both use WebGL. |
Thanks. Mathematica is nice but we don't have a license. I think I'd have to save every penny of my professional expense account for three years to get a copy. I'm still trying to learn Asymptote but it's free and open. Plus it's Canadian ;-) I even know the two lead developers. John Bowman has been very helpful in working with us to optimize Asymptote for PreTeXt HTML. |
Did you make the changes to /etc/ImageMagick-6/policy.xml that are described on line 115 of /opt/webwork/webwork2/conf/site.conf.dist. |
The double slash doesn't matter. Linux ignores an extra slash in a path name. |
That did it, thanks. Forgot to update the conf files after moving to It's interesting that reloading the problem didn't get the image to load -- those image strings stay put. But if I delete the question from the set and then add it back in as a new problem, it loads fine. @mgage for those Mathematica plots, do you just ship the html with the pg file? (I assume WeBWorK is not generating them on the fly.) I wonder if those demos could be adapted for asymptote-generated versions. |
The images might have been cached by the browser? Did you do shift-reload? I'm sure that Goeff's implementation of LiveJar can be improved to use other inputs: |
Thanks. Maybe someone will have time to look at the 3D code. (Not me, at least any time soon.) How hard is it to set things up to load various TikZ libraries -- In particular, what if one wants to use |
If you can point us to several "real" TikZ problems that use libraries and preambles we can figure out how to add them to the current implementation. The 'examples' available at the moment were kludged together to test the proof-of-concept implementation that we've started with. What we need now is exactly what you are providing -- people who want to use TikZ for educational problems -- so that we can see what else needs to be done to make those problems run. |
I suspected that this question would come up. It wouldn't be hard to add options to the TikZImage.pm file for adding additional latex packages like pgfplots (pgfplots is not a tikz library, it is a latex package). Note that additional tikz libraries can already be added. Add them as in the following example: $image = createTikzImage();
$image->tikzLibraries("calc,arrows.meta"); |
So, here is the use case for us: we have a work in progress conversion of APEX Calculus from LaTeX into PreTeXt. Greg has a lot of exercises that have TikZ images (including pgfplots). @Alex-Jordan has done a lot of work to get all the exercises coded as PreTeXt WeBWorK in the earlier chapters. Frequency of TikZ images increases in later chapters (esp. applications of integration). So we have problems in the book that are currently in some intermediate state, like this one:
The webwork parts of the exercise are commented out so we can keep the TikZ image. (In this case we probably could replace it by a WeBWorK graph, but keeping TikZ would be nicer.) What you can't see in the above is the So if TikZ support goes live in 2.16, we'd need to figure out how PreTeXt should communicate the different pieces to the WeBWorK server to build the Here's the image preamble that gets loaded at the top of every
|
Does the current implementation of this allow for dynamic images? For example, can I set If not, then I think we (PreTeXt) do not need this right now. The right approach would just be for PTX to build image files from tikz in the PTX source, and those image files should be automatically packaged alongside the .pg files that PTX makes. We are interested in being able to make randomized versions of images too, so that we can code the PG problems to be randomizable. If that is part of this project, I'll think harder. |
Yes, this does allow for dynamic images. You can make a plot involving random parameters. |
I am submitting this now so that others can take a look and at Michael Gage's request in issue #418. There is a matching pull request to the webwork2 code (openwebwork/webwork2#1030) that loads the module and sets the external convert program.
The general implementation is that a uniquely named working directory is created in the general webwork tmp location. Then a tex file is written and pdflatex run. Then convert is called to convert the pdf to a png, gif, or svg image. The image data is read, and then written to disk by the insertGraph method.
I also added a simple macro that basically does the same thing the PGgraphmacros.pl macro does for images generated with GD in terms of setting up the file name.
I changed the output directory of that method from the gif directory to the images directory (inside the course temporary html location). That part can be reverted if needed, but it seems silly to write what are almost always png images to a gif directory, and have a separate general image directory.